The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2010-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This is the implementation of the API for GATT module of BTA. |
| 22 | * |
| 23 | ******************************************************************************/ |
| 24 | |
| 25 | #include "bt_target.h" |
| 26 | |
| 27 | #if defined(BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE) |
| 28 | |
| 29 | #include <string.h> |
Pavlin Radoslavov | 258c253 | 2015-09-27 20:59:05 -0700 | [diff] [blame] | 30 | #include "bt_common.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 31 | #include "bta_sys.h" |
| 32 | #include "bta_gatt_api.h" |
| 33 | #include "bta_gattc_int.h" |
| 34 | |
| 35 | /***************************************************************************** |
| 36 | ** Constants |
| 37 | *****************************************************************************/ |
| 38 | |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 39 | static const tBTA_SYS_REG bta_gattc_reg = |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 40 | { |
| 41 | bta_gattc_hdl_event, |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 42 | BTA_GATTC_Disable |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 45 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 46 | /******************************************************************************* |
| 47 | ** |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 48 | ** Function BTA_GATTC_Disable |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 49 | ** |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 50 | ** Description This function is called to disable GATTC module |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 51 | ** |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 52 | ** Parameters None. |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 53 | ** |
| 54 | ** Returns None |
| 55 | ** |
| 56 | *******************************************************************************/ |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 57 | void BTA_GATTC_Disable(void) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 58 | { |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 59 | if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) |
| 60 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 61 | APPL_TRACE_WARNING("GATTC Module not enabled/already disabled"); |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 62 | return; |
| 63 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 64 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 65 | BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR)); |
| 66 | p_buf->event = BTA_GATTC_API_DISABLE_EVT; |
| 67 | |
| 68 | bta_sys_sendmsg(p_buf); |
| 69 | bta_sys_deregister(BTA_ID_GATTC); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /******************************************************************************* |
| 73 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 74 | ** Function BTA_GATTC_AppRegister |
| 75 | ** |
| 76 | ** Description This function is called to register application callbacks |
| 77 | ** with BTA GATTC module. |
| 78 | ** |
| 79 | ** Parameters p_app_uuid - applicaiton UUID |
| 80 | ** p_client_cb - pointer to the application callback function. |
| 81 | ** |
| 82 | ** Returns None |
| 83 | ** |
| 84 | *******************************************************************************/ |
| 85 | void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) |
| 86 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 87 | tBTA_GATTC_API_REG *p_buf = |
| 88 | (tBTA_GATTC_API_REG *)osi_malloc(sizeof(tBTA_GATTC_API_REG)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 89 | |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 90 | if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 91 | bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 92 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 93 | p_buf->hdr.event = BTA_GATTC_API_REG_EVT; |
| 94 | if (p_app_uuid != NULL) |
| 95 | memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID)); |
| 96 | p_buf->p_cback = p_client_cb; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 97 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 98 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /******************************************************************************* |
| 102 | ** |
| 103 | ** Function BTA_GATTC_AppDeregister |
| 104 | ** |
| 105 | ** Description This function is called to deregister an application |
| 106 | ** from BTA GATTC module. |
| 107 | ** |
| 108 | ** Parameters client_if - client interface identifier. |
| 109 | ** |
| 110 | ** Returns None |
| 111 | ** |
| 112 | *******************************************************************************/ |
| 113 | void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if) |
| 114 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 115 | tBTA_GATTC_API_DEREG *p_buf = |
| 116 | (tBTA_GATTC_API_DEREG *)osi_malloc(sizeof(tBTA_GATTC_API_DEREG)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 117 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 118 | p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT; |
| 119 | p_buf->client_if = client_if; |
| 120 | |
| 121 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /******************************************************************************* |
| 125 | ** |
| 126 | ** Function BTA_GATTC_Open |
| 127 | ** |
| 128 | ** Description Open a direct connection or add a background auto connection |
| 129 | ** bd address |
| 130 | ** |
| 131 | ** Parameters client_if: server interface. |
| 132 | ** remote_bda: remote device BD address. |
| 133 | ** is_direct: direct connection or background auto connection |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 134 | ** transport: Transport to be used for GATT connection (BREDR/LE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 135 | ** |
| 136 | ** Returns void |
| 137 | ** |
| 138 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 139 | void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, |
| 140 | BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 141 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 142 | tBTA_GATTC_API_OPEN *p_buf = |
| 143 | (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 144 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 145 | p_buf->hdr.event = BTA_GATTC_API_OPEN_EVT; |
| 146 | p_buf->client_if = client_if; |
| 147 | p_buf->is_direct = is_direct; |
| 148 | p_buf->transport = transport; |
| 149 | memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 150 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 151 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /******************************************************************************* |
| 155 | ** |
| 156 | ** Function BTA_GATTC_CancelOpen |
| 157 | ** |
| 158 | ** Description Cancel a direct open connection or remove a background auto connection |
| 159 | ** bd address |
| 160 | ** |
| 161 | ** Parameters client_if: server interface. |
| 162 | ** remote_bda: remote device BD address. |
| 163 | ** is_direct: direct connection or background auto connection |
| 164 | ** |
| 165 | ** Returns void |
| 166 | ** |
| 167 | *******************************************************************************/ |
| 168 | void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct) |
| 169 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 170 | tBTA_GATTC_API_CANCEL_OPEN *p_buf = |
| 171 | (tBTA_GATTC_API_CANCEL_OPEN *)osi_malloc(sizeof(tBTA_GATTC_API_CANCEL_OPEN)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 172 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 173 | p_buf->hdr.event = BTA_GATTC_API_CANCEL_OPEN_EVT; |
| 174 | p_buf->client_if = client_if; |
| 175 | p_buf->is_direct = is_direct; |
| 176 | memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 177 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 178 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /******************************************************************************* |
| 182 | ** |
| 183 | ** Function BTA_GATTC_Close |
| 184 | ** |
| 185 | ** Description Close a connection to a GATT server. |
| 186 | ** |
| 187 | ** Parameters conn_id: connectino ID to be closed. |
| 188 | ** |
| 189 | ** Returns void |
| 190 | ** |
| 191 | *******************************************************************************/ |
| 192 | void BTA_GATTC_Close(UINT16 conn_id) |
| 193 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 194 | BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 195 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 196 | p_buf->event = BTA_GATTC_API_CLOSE_EVT; |
| 197 | p_buf->layer_specific = conn_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 198 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 199 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 200 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 201 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 202 | /******************************************************************************* |
| 203 | ** |
Andre Eisenbach | 9426d53 | 2014-03-25 06:31:17 -0700 | [diff] [blame] | 204 | ** Function BTA_GATTC_ConfigureMTU |
| 205 | ** |
| 206 | ** Description Configure the MTU size in the GATT channel. This can be done |
| 207 | ** only once per connection. |
| 208 | ** |
| 209 | ** Parameters conn_id: connection ID. |
| 210 | ** mtu: desired MTU size to use. |
| 211 | ** |
| 212 | ** Returns void |
| 213 | ** |
| 214 | *******************************************************************************/ |
| 215 | void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu) |
| 216 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 217 | tBTA_GATTC_API_CFG_MTU *p_buf = |
| 218 | (tBTA_GATTC_API_CFG_MTU *)osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU)); |
Andre Eisenbach | 9426d53 | 2014-03-25 06:31:17 -0700 | [diff] [blame] | 219 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 220 | p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT; |
| 221 | p_buf->hdr.layer_specific = conn_id; |
| 222 | p_buf->mtu = mtu; |
Andre Eisenbach | 9426d53 | 2014-03-25 06:31:17 -0700 | [diff] [blame] | 223 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 224 | bta_sys_sendmsg(p_buf); |
Andre Eisenbach | 9426d53 | 2014-03-25 06:31:17 -0700 | [diff] [blame] | 225 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 226 | |
Andre Eisenbach | 9426d53 | 2014-03-25 06:31:17 -0700 | [diff] [blame] | 227 | /******************************************************************************* |
| 228 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 229 | ** Function BTA_GATTC_ServiceSearchRequest |
| 230 | ** |
| 231 | ** Description This function is called to request a GATT service discovery |
| 232 | ** on a GATT server. This function report service search result |
| 233 | ** by a callback event, and followed by a service search complete |
| 234 | ** event. |
| 235 | ** |
| 236 | ** Parameters conn_id: connection ID. |
| 237 | ** p_srvc_uuid: a UUID of the service application is interested in. |
| 238 | ** If Null, discover for all services. |
| 239 | ** |
| 240 | ** Returns None |
| 241 | ** |
| 242 | *******************************************************************************/ |
| 243 | void BTA_GATTC_ServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid) |
| 244 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 245 | const size_t len = sizeof(tBTA_GATTC_API_SEARCH) + sizeof(tBT_UUID); |
| 246 | tBTA_GATTC_API_SEARCH *p_buf = (tBTA_GATTC_API_SEARCH *)osi_calloc(len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 247 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 248 | p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT; |
| 249 | p_buf->hdr.layer_specific = conn_id; |
| 250 | if (p_srvc_uuid) { |
| 251 | p_buf->p_srvc_uuid = (tBT_UUID *)(p_buf + 1); |
| 252 | memcpy(p_buf->p_srvc_uuid, p_srvc_uuid, sizeof(tBT_UUID)); |
| 253 | } else { |
| 254 | p_buf->p_srvc_uuid = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 255 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 256 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 257 | bta_sys_sendmsg(p_buf); |
| 258 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 259 | |
| 260 | /******************************************************************************* |
| 261 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 262 | ** Function BTA_GATTC_GetServices |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 263 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 264 | ** Description This function is called to find the services on the given server. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 265 | ** |
| 266 | ** Parameters conn_id: connection ID which identify the server. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 267 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 268 | ** Returns returns list_t of tBTA_GATTC_SERVICE or NULL. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 269 | ** |
| 270 | *******************************************************************************/ |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 271 | const list_t* BTA_GATTC_GetServices(UINT16 conn_id) { |
| 272 | return bta_gattc_get_services(conn_id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /******************************************************************************* |
| 276 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 277 | ** Function BTA_GATTC_GetCharacteristic |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 278 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 279 | ** Description This function is called to find the characteristic on the given server. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 280 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 281 | ** Parameters conn_id - connection ID which identify the server. |
| 282 | ** handle - characteristic handle |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 283 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 284 | ** Returns returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 285 | ** |
| 286 | *******************************************************************************/ |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 287 | const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle) { |
| 288 | return bta_gattc_get_characteristic(conn_id, handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 289 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 290 | |
| 291 | /******************************************************************************* |
| 292 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 293 | ** Function BTA_GATTC_GetDescriptor |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 294 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 295 | ** Description This function is called to find the characteristic on the given server. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 296 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 297 | ** Parameters conn_id - connection ID which identify the server. |
| 298 | ** handle - descriptor handle |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 299 | ** |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 300 | ** Returns returns pointer to tBTA_GATTC_DESCRIPTOR or NULL. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 301 | ** |
| 302 | *******************************************************************************/ |
Jakub Pawlowski | 5204fd7 | 2016-03-15 15:35:00 -0700 | [diff] [blame] | 303 | const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle) { |
| 304 | return bta_gattc_get_descriptor(conn_id, handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 305 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 306 | |
| 307 | /******************************************************************************* |
| 308 | ** |
Jakub Pawlowski | 533fdbf | 2016-01-21 23:26:11 -0800 | [diff] [blame] | 309 | ** Function BTA_GATTC_GetGattDb |
| 310 | ** |
| 311 | ** Description This function is called to get the GATT database. |
| 312 | ** |
| 313 | ** Parameters conn_id: connection ID which identify the server. |
| 314 | ** db: output parameter which will contain the GATT database copy. |
| 315 | ** Caller is responsible for freeing it. |
| 316 | ** count: number of elements in database. |
| 317 | ** |
| 318 | *******************************************************************************/ |
Jakub Pawlowski | 9fd552b | 2016-02-10 15:26:14 -0800 | [diff] [blame] | 319 | void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, |
| 320 | btgatt_db_element_t **db, int *count) |
Jakub Pawlowski | 533fdbf | 2016-01-21 23:26:11 -0800 | [diff] [blame] | 321 | { |
Jakub Pawlowski | 9fd552b | 2016-02-10 15:26:14 -0800 | [diff] [blame] | 322 | bta_gattc_get_gatt_db(conn_id, start_handle, end_handle, db, count); |
Jakub Pawlowski | 533fdbf | 2016-01-21 23:26:11 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /******************************************************************************* |
| 326 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 327 | ** Function BTA_GATTC_ReadCharacteristic |
| 328 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 329 | ** Description This function is called to read a characteristics value |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 330 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 331 | ** Parameters conn_id - connection ID. |
| 332 | ** handle - characteritic handle to read. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 333 | ** |
| 334 | ** Returns None |
| 335 | ** |
| 336 | *******************************************************************************/ |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 337 | void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 338 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 339 | tBTA_GATTC_API_READ *p_buf = |
| 340 | (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 341 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 342 | p_buf->hdr.event = BTA_GATTC_API_READ_EVT; |
| 343 | p_buf->hdr.layer_specific = conn_id; |
| 344 | p_buf->auth_req = auth_req; |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 345 | p_buf->handle = handle; |
| 346 | p_buf->cmpl_evt = BTA_GATTC_READ_CHAR_EVT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 347 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 348 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /******************************************************************************* |
| 352 | ** |
| 353 | ** Function BTA_GATTC_ReadCharDescr |
| 354 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 355 | ** Description This function is called to read a descriptor value. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 356 | ** |
| 357 | ** Parameters conn_id - connection ID. |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 358 | ** handle - descriptor handle to read. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 359 | ** |
| 360 | ** Returns None |
| 361 | ** |
| 362 | *******************************************************************************/ |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 363 | void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 364 | { |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 365 | tBTA_GATTC_API_READ *p_buf = |
| 366 | (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 367 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 368 | p_buf->hdr.event = BTA_GATTC_API_READ_EVT; |
| 369 | p_buf->hdr.layer_specific = conn_id; |
| 370 | p_buf->auth_req = auth_req; |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 371 | p_buf->handle = handle; |
| 372 | p_buf->cmpl_evt = BTA_GATTC_READ_DESCR_EVT; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 373 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 374 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 375 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 376 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 377 | /******************************************************************************* |
| 378 | ** |
| 379 | ** Function BTA_GATTC_ReadMultiple |
| 380 | ** |
| 381 | ** Description This function is called to read multiple characteristic or |
| 382 | ** characteristic descriptors. |
| 383 | ** |
| 384 | ** Parameters conn_id - connectino ID. |
| 385 | ** p_read_multi - pointer to the read multiple parameter. |
| 386 | ** |
| 387 | ** Returns None |
| 388 | ** |
| 389 | *******************************************************************************/ |
| 390 | void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi, |
| 391 | tBTA_GATT_AUTH_REQ auth_req) |
| 392 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 393 | tBTA_GATTC_API_READ_MULTI *p_buf = |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 394 | (tBTA_GATTC_API_READ_MULTI *)osi_calloc(sizeof(tBTA_GATTC_API_READ_MULTI)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 395 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 396 | p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_EVT; |
| 397 | p_buf->hdr.layer_specific = conn_id; |
| 398 | p_buf->auth_req = auth_req; |
| 399 | p_buf->num_attr = p_read_multi->num_attr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 400 | |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 401 | if (p_buf->num_attr > 0) |
| 402 | memcpy(p_buf->handles, p_read_multi->handles, sizeof(UINT16) * p_read_multi->num_attr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 403 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 404 | bta_sys_sendmsg(p_buf); |
| 405 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 406 | |
| 407 | /******************************************************************************* |
| 408 | ** |
| 409 | ** Function BTA_GATTC_WriteCharValue |
| 410 | ** |
| 411 | ** Description This function is called to write characteristic value. |
| 412 | ** |
| 413 | ** Parameters conn_id - connection ID. |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 414 | ** handle - characteristic handle to write. |
| 415 | ** write_type - type of write. |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 416 | ** value - the value to be written. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 417 | ** |
| 418 | ** Returns None |
| 419 | ** |
| 420 | *******************************************************************************/ |
| 421 | void BTA_GATTC_WriteCharValue ( UINT16 conn_id, |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 422 | UINT16 handle, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 423 | tBTA_GATTC_WRITE_TYPE write_type, |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 424 | std::vector<uint8_t> value, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 425 | tBTA_GATT_AUTH_REQ auth_req) |
| 426 | { |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 427 | tBTA_GATTC_API_WRITE *p_buf = (tBTA_GATTC_API_WRITE *) |
| 428 | osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 429 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 430 | p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; |
| 431 | p_buf->hdr.layer_specific = conn_id; |
| 432 | p_buf->auth_req = auth_req; |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 433 | p_buf->handle = handle; |
| 434 | p_buf->cmpl_evt = BTA_GATTC_WRITE_CHAR_EVT; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 435 | p_buf->write_type = write_type; |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 436 | p_buf->len = value.size(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 437 | |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 438 | if (value.size() > 0) { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 439 | p_buf->p_value = (UINT8 *)(p_buf + 1); |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 440 | memcpy(p_buf->p_value, value.data(), value.size()); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 441 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 442 | |
| 443 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 444 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 445 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 446 | /******************************************************************************* |
| 447 | ** |
| 448 | ** Function BTA_GATTC_WriteCharDescr |
| 449 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 450 | ** Description This function is called to write descriptor value. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 451 | ** |
| 452 | ** Parameters conn_id - connection ID |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 453 | ** handle - descriptor hadle to write. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 454 | ** write_type - write type. |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 455 | ** value - the value to be written. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 456 | ** |
| 457 | ** Returns None |
| 458 | ** |
| 459 | *******************************************************************************/ |
| 460 | void BTA_GATTC_WriteCharDescr (UINT16 conn_id, |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 461 | UINT16 handle, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 462 | tBTA_GATTC_WRITE_TYPE write_type, |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 463 | std::vector<uint8_t> value, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 464 | tBTA_GATT_AUTH_REQ auth_req) |
| 465 | { |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 466 | tBTA_GATTC_API_WRITE *p_buf = (tBTA_GATTC_API_WRITE *) |
| 467 | osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 468 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 469 | p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; |
| 470 | p_buf->hdr.layer_specific = conn_id; |
| 471 | p_buf->auth_req = auth_req; |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 472 | p_buf->handle = handle; |
| 473 | p_buf->cmpl_evt = BTA_GATTC_WRITE_DESCR_EVT; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 474 | p_buf->write_type = write_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 475 | |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 476 | if (value.size() != 0) { |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 477 | p_buf->p_value = (UINT8 *)(p_buf + 1); |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 478 | p_buf->len = value.size(); |
| 479 | memcpy(p_buf->p_value, value.data(), value.size()); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 480 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 481 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 482 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 483 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 484 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 485 | /******************************************************************************* |
| 486 | ** |
| 487 | ** Function BTA_GATTC_PrepareWrite |
| 488 | ** |
| 489 | ** Description This function is called to prepare write a characteristic value. |
| 490 | ** |
| 491 | ** Parameters conn_id - connection ID. |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 492 | ** p_char_id - GATT characteritic ID of the service. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 493 | ** offset - offset of the write value. |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 494 | ** value - the value to be written. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 495 | ** |
| 496 | ** Returns None |
| 497 | ** |
| 498 | *******************************************************************************/ |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 499 | void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle, UINT16 offset, |
| 500 | std::vector<uint8_t> value, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 501 | tBTA_GATT_AUTH_REQ auth_req) |
| 502 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 503 | tBTA_GATTC_API_WRITE *p_buf = |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 504 | (tBTA_GATTC_API_WRITE *)osi_calloc(sizeof(tBTA_GATTC_API_WRITE) + value.size()); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 505 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 506 | p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT; |
| 507 | p_buf->hdr.layer_specific = conn_id; |
| 508 | p_buf->auth_req = auth_req; |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 509 | p_buf->handle = handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 510 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 511 | p_buf->write_type = BTA_GATTC_WRITE_PREPARE; |
| 512 | p_buf->offset = offset; |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 513 | p_buf->len = value.size(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 514 | |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 515 | if (value.size() > 0) { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 516 | p_buf->p_value = (UINT8 *)(p_buf + 1); |
Jakub Pawlowski | 26ecec0 | 2016-05-27 09:42:21 -0700 | [diff] [blame^] | 517 | memcpy(p_buf->p_value, value.data(), value.size()); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 518 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 519 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 520 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 521 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 522 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 523 | /******************************************************************************* |
| 524 | ** |
| 525 | ** Function BTA_GATTC_ExecuteWrite |
| 526 | ** |
| 527 | ** Description This function is called to execute write a prepare write sequence. |
| 528 | ** |
| 529 | ** Parameters conn_id - connection ID. |
| 530 | ** is_execute - execute or cancel. |
| 531 | ** |
| 532 | ** Returns None |
| 533 | ** |
| 534 | *******************************************************************************/ |
| 535 | void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute) |
| 536 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 537 | tBTA_GATTC_API_EXEC *p_buf = |
| 538 | (tBTA_GATTC_API_EXEC *)osi_calloc(sizeof(tBTA_GATTC_API_EXEC)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 539 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 540 | p_buf->hdr.event = BTA_GATTC_API_EXEC_EVT; |
| 541 | p_buf->hdr.layer_specific = conn_id; |
| 542 | p_buf->is_execute = is_execute; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 543 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 544 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 545 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 546 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 547 | /******************************************************************************* |
| 548 | ** |
| 549 | ** Function BTA_GATTC_SendIndConfirm |
| 550 | ** |
| 551 | ** Description This function is called to send handle value confirmation. |
| 552 | ** |
| 553 | ** Parameters conn_id - connection ID. |
| 554 | ** p_char_id - characteristic ID to confirm. |
| 555 | ** |
| 556 | ** Returns None |
| 557 | ** |
| 558 | *******************************************************************************/ |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 559 | void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 560 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 561 | tBTA_GATTC_API_CONFIRM *p_buf = |
| 562 | (tBTA_GATTC_API_CONFIRM *)osi_calloc(sizeof(tBTA_GATTC_API_CONFIRM)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 563 | |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 564 | APPL_TRACE_API("%s conn_id=%d handle=0x%04x", __func__, conn_id, handle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 565 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 566 | p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT; |
| 567 | p_buf->hdr.layer_specific = conn_id; |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 568 | p_buf->handle = handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 569 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 570 | bta_sys_sendmsg(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /******************************************************************************* |
| 574 | ** |
| 575 | ** Function BTA_GATTC_RegisterForNotifications |
| 576 | ** |
| 577 | ** Description This function is called to register for notification of a service. |
| 578 | ** |
| 579 | ** Parameters client_if - client interface. |
| 580 | ** bda - target GATT server. |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 581 | ** handle - GATT characteristic handle. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 582 | ** |
| 583 | ** Returns OK if registration succeed, otherwise failed. |
| 584 | ** |
| 585 | *******************************************************************************/ |
| 586 | tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if, |
Jakub Pawlowski | 063ca02 | 2016-04-25 10:43:02 -0700 | [diff] [blame] | 587 | const BD_ADDR bda, UINT16 handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 588 | { |
| 589 | tBTA_GATTC_RCB *p_clreg; |
| 590 | tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER; |
| 591 | UINT8 i; |
| 592 | |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 593 | if (!handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 594 | { |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 595 | APPL_TRACE_ERROR("deregistration failed, handle is 0"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 596 | return status; |
| 597 | } |
| 598 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 599 | if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL) |
| 600 | { |
| 601 | for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) |
| 602 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 603 | if ( p_clreg->notif_reg[i].in_use && |
| 604 | !memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) && |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 605 | p_clreg->notif_reg[i].handle == handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 606 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 607 | APPL_TRACE_WARNING("notification already registered"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 608 | status = BTA_GATT_OK; |
| 609 | break; |
| 610 | } |
| 611 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 612 | if (status != BTA_GATT_OK) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 613 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 614 | for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) |
| 615 | { |
| 616 | if (!p_clreg->notif_reg[i].in_use) |
| 617 | { |
| 618 | memset((void *)&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG)); |
| 619 | |
| 620 | p_clreg->notif_reg[i].in_use = TRUE; |
| 621 | memcpy(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN); |
| 622 | |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 623 | p_clreg->notif_reg[i].handle = handle; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 624 | status = BTA_GATT_OK; |
| 625 | break; |
| 626 | } |
| 627 | } |
| 628 | if (i == BTA_GATTC_NOTIF_REG_MAX) |
| 629 | { |
| 630 | status = BTA_GATT_NO_RESOURCES; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 631 | APPL_TRACE_ERROR("Max Notification Reached, registration failed."); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 632 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | else |
| 636 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 637 | APPL_TRACE_ERROR("Client_if: %d Not Registered", client_if); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 638 | } |
| 639 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 640 | return status; |
| 641 | } |
| 642 | |
| 643 | /******************************************************************************* |
| 644 | ** |
| 645 | ** Function BTA_GATTC_DeregisterForNotifications |
| 646 | ** |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 647 | ** Description This function is called to de-register for notification of a servbice. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 648 | ** |
| 649 | ** Parameters client_if - client interface. |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 650 | ** remote_bda - target GATT server. |
| 651 | ** handle - GATT characteristic handle. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 652 | ** |
| 653 | ** Returns OK if deregistration succeed, otherwise failed. |
| 654 | ** |
| 655 | *******************************************************************************/ |
| 656 | tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if, |
Jakub Pawlowski | 063ca02 | 2016-04-25 10:43:02 -0700 | [diff] [blame] | 657 | const BD_ADDR bda, UINT16 handle) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 658 | { |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 659 | if (!handle) { |
| 660 | APPL_TRACE_ERROR("%s: deregistration failed, handle is 0", __func__); |
| 661 | return BTA_GATT_ILLEGAL_PARAMETER; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 662 | } |
| 663 | |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 664 | tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(client_if); |
| 665 | if (p_clreg == NULL) { |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 666 | APPL_TRACE_ERROR("%s client_if: %d not registered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", |
| 667 | __func__, client_if, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 668 | return BTA_GATT_ILLEGAL_PARAMETER; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Jakub Pawlowski | 9dc9985 | 2016-03-17 12:05:54 -0700 | [diff] [blame] | 671 | for (int i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) { |
| 672 | if (p_clreg->notif_reg[i].in_use && |
| 673 | !memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) && |
| 674 | p_clreg->notif_reg[i].handle == handle) { |
| 675 | APPL_TRACE_DEBUG("%s deregistered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", |
| 676 | __func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
| 677 | memset(&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG)); |
| 678 | return BTA_GATT_OK; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | APPL_TRACE_ERROR("%s registration not found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x", |
| 683 | __func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]); |
| 684 | return BTA_GATT_ERROR; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 687 | /******************************************************************************* |
| 688 | ** |
| 689 | ** Function BTA_GATTC_Refresh |
| 690 | ** |
| 691 | ** Description Refresh the server cache of the remote device |
| 692 | ** |
| 693 | ** Parameters remote_bda: remote device BD address. |
| 694 | ** |
| 695 | ** Returns void |
| 696 | ** |
| 697 | *******************************************************************************/ |
Jakub Pawlowski | 063ca02 | 2016-04-25 10:43:02 -0700 | [diff] [blame] | 698 | void BTA_GATTC_Refresh(const BD_ADDR remote_bda) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 699 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 700 | tBTA_GATTC_API_OPEN *p_buf = |
| 701 | (tBTA_GATTC_API_OPEN *)osi_malloc(sizeof(tBTA_GATTC_API_OPEN)); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 702 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 703 | p_buf->hdr.event = BTA_GATTC_API_REFRESH_EVT; |
| 704 | memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 705 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 706 | bta_sys_sendmsg(p_buf); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 707 | } |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 708 | |
| 709 | /******************************************************************************* |
| 710 | ** |
| 711 | ** Function BTA_GATTC_Listen |
| 712 | ** |
| 713 | ** Description Start advertisement to listen for connection request for a GATT |
| 714 | ** client application. |
| 715 | ** |
| 716 | ** Parameters client_if: server interface. |
| 717 | ** start: to start or stop listening for connection |
| 718 | ** remote_bda: remote device BD address, if listen to all device |
| 719 | ** use NULL. |
| 720 | ** |
| 721 | ** Returns void |
| 722 | ** |
| 723 | *******************************************************************************/ |
| 724 | void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda) |
| 725 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 726 | tBTA_GATTC_API_LISTEN *p_buf = |
| 727 | (tBTA_GATTC_API_LISTEN *)osi_malloc(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN); |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 728 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 729 | p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT; |
| 730 | p_buf->client_if = client_if; |
| 731 | p_buf->start = start; |
| 732 | if (target_bda) { |
| 733 | p_buf->remote_bda = (UINT8*)(p_buf + 1); |
| 734 | memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN); |
| 735 | } else { |
| 736 | p_buf->remote_bda = NULL; |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 737 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 738 | |
| 739 | bta_sys_sendmsg(p_buf); |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Andre Eisenbach | a4611ac | 2014-03-05 15:41:53 -0800 | [diff] [blame] | 742 | /******************************************************************************* |
| 743 | ** |
| 744 | ** Function BTA_GATTC_Broadcast |
| 745 | ** |
| 746 | ** Description Start broadcasting (non-connectable advertisements) |
| 747 | ** |
| 748 | ** Parameters client_if: client interface. |
| 749 | ** start: to start or stop listening for connection |
| 750 | ** |
| 751 | ** Returns void |
| 752 | ** |
| 753 | *******************************************************************************/ |
| 754 | void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start) |
| 755 | { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 756 | tBTA_GATTC_API_LISTEN *p_buf = |
| 757 | (tBTA_GATTC_API_LISTEN *)osi_malloc(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN); |
Andre Eisenbach | a4611ac | 2014-03-05 15:41:53 -0800 | [diff] [blame] | 758 | |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 759 | p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT; |
| 760 | p_buf->client_if = client_if; |
| 761 | p_buf->start = start; |
| 762 | |
| 763 | bta_sys_sendmsg(p_buf); |
Andre Eisenbach | a4611ac | 2014-03-05 15:41:53 -0800 | [diff] [blame] | 764 | } |
| 765 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 766 | #endif /* BTA_GATT_INCLUDED */ |