Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2014 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 | * |
| 22 | * Filename: btif_gatt_multi_adv_util.c |
| 23 | * |
| 24 | * Description: Multi ADV helper implementation |
| 25 | * |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
Wei Wang | bf0e4b2 | 2014-05-19 23:23:35 -0700 | [diff] [blame] | 30 | #include "bt_target.h" |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 31 | |
| 32 | #define LOG_TAG "BtGatt.btif" |
| 33 | #if (BLE_INCLUDED == TRUE) |
| 34 | |
| 35 | #include "btif_gatt_multi_adv_util.h" |
| 36 | #include "btif_common.h" |
| 37 | #include <hardware/bt_gatt.h> |
| 38 | #include "bta_gatt_api.h" |
| 39 | #include "btif_gatt_util.h" |
| 40 | |
| 41 | /******************************************************************************* |
| 42 | ** Static variables |
| 43 | ********************************************************************************/ |
| 44 | static int multi_adv_enable_count = 0; |
| 45 | static btgatt_multi_adv_common_data *p_multi_adv_com_data_cb = NULL; |
| 46 | |
| 47 | btgatt_multi_adv_common_data *btif_obtain_multi_adv_data_cb() |
| 48 | { |
| 49 | if(p_multi_adv_com_data_cb == NULL) |
| 50 | p_multi_adv_com_data_cb = GKI_getbuf(sizeof(btgatt_multi_adv_common_data)); |
| 51 | return p_multi_adv_com_data_cb; |
| 52 | } |
| 53 | |
| 54 | void btif_gattc_init_multi_adv_cb(void) |
| 55 | { |
| 56 | int i; |
| 57 | btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb(); |
| 58 | |
| 59 | if(NULL == p_multi_adv_data_cb) |
| 60 | return; |
| 61 | |
| 62 | if(multi_adv_enable_count == 0) |
| 63 | { |
| 64 | memset(p_multi_adv_data_cb,0,sizeof(btgatt_multi_adv_common_data)); |
| 65 | |
| 66 | for (i=0; i < BTM_BLE_MULTI_ADV_MAX; i++) |
| 67 | { |
| 68 | p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX] = INVALID_ADV_INST; |
| 69 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX] = INVALID_ADV_INST; |
| 70 | } |
| 71 | } |
| 72 | multi_adv_enable_count++; |
| 73 | } |
| 74 | |
| 75 | void btif_gattc_destroy_multi_adv_cb() |
| 76 | { |
| 77 | if(multi_adv_enable_count > 0) |
| 78 | multi_adv_enable_count --; |
| 79 | if(multi_adv_enable_count == 0) |
| 80 | { |
| 81 | GKI_freebuf(p_multi_adv_com_data_cb); |
| 82 | p_multi_adv_com_data_cb = NULL; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | int btif_multi_adv_add_instid_map(int client_if, int inst_id, BOOLEAN gen_temp_instid) |
| 87 | { |
| 88 | int i=0; |
| 89 | |
| 90 | btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb(); |
| 91 | |
| 92 | if(NULL == p_multi_adv_data_cb) |
| 93 | return INVALID_ADV_INST; |
| 94 | |
| 95 | for(i=0; i < BTM_BLE_MULTI_ADV_MAX; i++) |
| 96 | { |
| 97 | if(client_if == p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX]) |
| 98 | { |
| 99 | if(!gen_temp_instid) |
| 100 | { |
| 101 | // Write the final inst_id value obtained from stack layer |
| 102 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX] = inst_id; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 103 | BTIF_TRACE_DEBUG("%s -Index: %d, Found client_if: %d", __FUNCTION__, |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 104 | i, p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX]); |
| 105 | break; |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | //Store the passed in inst_id value |
| 110 | if(inst_id != INVALID_ADV_INST) |
| 111 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX] = inst_id; |
| 112 | else |
| 113 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX] = (i + 1); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 114 | BTIF_TRACE_DEBUG("%s - Index:%d,Found client_if: %d", __FUNCTION__, |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 115 | i, p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX]); |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if(i < BTM_BLE_MULTI_ADV_MAX) |
| 122 | return i; |
| 123 | |
| 124 | // If client ID if is not found, then write both values |
| 125 | for(i=0; i < BTM_BLE_MULTI_ADV_MAX; i++) |
| 126 | { |
| 127 | if(INVALID_ADV_INST == p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX]) |
| 128 | { |
| 129 | p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX] = client_if; |
| 130 | if(inst_id != INVALID_ADV_INST) |
| 131 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX] = inst_id; |
| 132 | else |
| 133 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX] = (i + 1); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 134 | BTIF_TRACE_DEBUG("%s -Not found - Index:%d, client_if: %d, Inst ID: %d", |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 135 | __FUNCTION__,i, |
| 136 | p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX], |
| 137 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX]); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if(i < BTM_BLE_MULTI_ADV_MAX) |
| 143 | return i; |
| 144 | return INVALID_ADV_INST; |
| 145 | } |
| 146 | |
| 147 | int btif_multi_adv_instid_for_clientif(int client_if) |
| 148 | { |
| 149 | int i=0, ret = INVALID_ADV_INST; |
| 150 | |
| 151 | btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb(); |
| 152 | |
| 153 | if(NULL == p_multi_adv_data_cb) |
| 154 | return INVALID_ADV_INST; |
| 155 | |
| 156 | // Retrieve the existing inst_id for the client_if value |
| 157 | for(i=0; i < BTM_BLE_MULTI_ADV_MAX; i++) |
| 158 | { |
| 159 | if(client_if == p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX]) |
| 160 | ret = p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX]; |
| 161 | } |
| 162 | |
| 163 | if(ret != INVALID_ADV_INST) |
| 164 | return ret; |
| 165 | |
| 166 | return INVALID_ADV_INST; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | int btif_gattc_obtain_idx_for_datacb(int value, int arrindex) |
| 171 | { |
| 172 | int i=0; |
| 173 | |
| 174 | btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb(); |
| 175 | |
| 176 | if(NULL == p_multi_adv_data_cb) |
| 177 | return INVALID_ADV_INST; |
| 178 | |
| 179 | // Retrieve the array index for the inst_id value |
| 180 | for(i=0; i < BTM_BLE_MULTI_ADV_MAX; i++) |
| 181 | { |
| 182 | if(value == p_multi_adv_data_cb->clntif_map[i][arrindex]) |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | if(i < BTM_BLE_MULTI_ADV_MAX) |
| 187 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 188 | BTIF_TRACE_DEBUG("%s, %d",__FUNCTION__,i+1); |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 189 | return (i + 1); |
| 190 | } |
| 191 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 192 | BTIF_TRACE_DEBUG("%s Invalid instance",__FUNCTION__); |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 193 | return INVALID_ADV_INST; |
| 194 | } |
| 195 | |
| 196 | |
| 197 | void btif_gattc_adv_data_packager(int client_if, bool set_scan_rsp, |
| 198 | bool include_name, bool include_txpower, int min_interval, int max_interval, |
| 199 | int appearance, uint16_t manufacturer_len, char* manufacturer_data, |
| 200 | uint16_t service_data_len, char* service_data, uint16_t service_uuid_len, |
| 201 | char* service_uuid, btif_adv_data_t *p_multi_adv_inst) |
| 202 | { |
| 203 | memset(p_multi_adv_inst, 0 , sizeof(btif_adv_data_t)); |
| 204 | |
| 205 | p_multi_adv_inst->client_if = (uint8_t) client_if; |
| 206 | p_multi_adv_inst->set_scan_rsp = set_scan_rsp; |
| 207 | p_multi_adv_inst->include_name = include_name; |
| 208 | p_multi_adv_inst->include_txpower = include_txpower; |
| 209 | p_multi_adv_inst->min_interval = min_interval; |
| 210 | p_multi_adv_inst->max_interval = max_interval; |
| 211 | p_multi_adv_inst->appearance = appearance; |
| 212 | p_multi_adv_inst->manufacturer_len = manufacturer_len; |
| 213 | |
| 214 | if(manufacturer_len > 0) |
| 215 | { |
| 216 | p_multi_adv_inst->p_manufacturer_data = GKI_getbuf(manufacturer_len); |
| 217 | memcpy(p_multi_adv_inst->p_manufacturer_data, manufacturer_data, manufacturer_len); |
| 218 | } |
| 219 | |
| 220 | p_multi_adv_inst->service_data_len = service_data_len; |
| 221 | if(service_data_len > 0) |
| 222 | { |
| 223 | p_multi_adv_inst->p_service_data = GKI_getbuf(service_data_len); |
| 224 | memcpy(p_multi_adv_inst->p_service_data, service_data, service_data_len); |
| 225 | } |
| 226 | |
| 227 | p_multi_adv_inst->service_uuid_len = service_uuid_len; |
| 228 | if(service_uuid_len > 0) |
| 229 | { |
| 230 | p_multi_adv_inst->p_service_uuid = GKI_getbuf(service_uuid_len); |
| 231 | memcpy(p_multi_adv_inst->p_service_uuid, service_uuid, service_uuid_len); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | BOOLEAN btif_gattc_copy_datacb(int cbindex, btif_adv_data_t *p_adv_data, BOOLEAN bInstData) |
| 236 | { |
| 237 | int i=0; |
| 238 | btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb(); |
| 239 | if(NULL == p_multi_adv_data_cb || cbindex < 0) |
| 240 | return false; |
| 241 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 242 | BTIF_TRACE_DEBUG("%s", __FUNCTION__); |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 243 | memset(&p_multi_adv_data_cb->inst_cb[cbindex],0, sizeof(btgatt_multi_adv_inst_cb)); |
| 244 | memset(&p_multi_adv_data_cb->inst_cb[cbindex].data, 0, sizeof(tBTA_BLE_ADV_DATA)); |
| 245 | |
| 246 | if (!p_adv_data->set_scan_rsp) |
| 247 | { |
| 248 | p_multi_adv_data_cb->inst_cb[cbindex].is_scan_rsp = p_adv_data->set_scan_rsp ? 1 : 0; |
| 249 | p_multi_adv_data_cb->inst_cb[cbindex].mask = BTM_BLE_AD_BIT_FLAGS; |
| 250 | p_multi_adv_data_cb->inst_cb[cbindex].data.flag = ADV_FLAGS; |
| 251 | } |
| 252 | |
| 253 | if (p_adv_data->include_name) |
| 254 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_DEV_NAME; |
| 255 | |
| 256 | if (p_adv_data->include_txpower) |
| 257 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_TX_PWR; |
| 258 | |
| 259 | if (false == bInstData && p_adv_data->min_interval > 0 && p_adv_data->max_interval > 0 && |
| 260 | p_adv_data->max_interval > p_adv_data->min_interval) |
| 261 | { |
| 262 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_INT_RANGE; |
| 263 | p_multi_adv_data_cb->inst_cb[cbindex].data.int_range.low = |
| 264 | p_adv_data->min_interval; |
| 265 | p_multi_adv_data_cb->inst_cb[cbindex].data.int_range.hi = |
| 266 | p_adv_data->max_interval; |
| 267 | } |
| 268 | else |
| 269 | if(true == bInstData) |
| 270 | { |
| 271 | if (p_multi_adv_data_cb->inst_cb[cbindex].param.adv_int_min > 0 && |
| 272 | p_multi_adv_data_cb->inst_cb[cbindex].param.adv_int_max > 0 && |
| 273 | p_multi_adv_data_cb->inst_cb[cbindex].param.adv_int_max > |
| 274 | p_multi_adv_data_cb->inst_cb[cbindex].param.adv_int_min) |
| 275 | { |
| 276 | p_multi_adv_data_cb->inst_cb[cbindex].data.int_range.low = |
| 277 | p_multi_adv_data_cb->inst_cb[cbindex].param.adv_int_min; |
| 278 | p_multi_adv_data_cb->inst_cb[cbindex].data.int_range.hi = |
| 279 | p_multi_adv_data_cb->inst_cb[cbindex].param.adv_int_max; |
| 280 | } |
| 281 | |
| 282 | if (p_adv_data->include_txpower) |
| 283 | { |
| 284 | p_multi_adv_data_cb->inst_cb[cbindex].data.tx_power = |
| 285 | p_multi_adv_data_cb->inst_cb[cbindex].param.tx_power; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (p_adv_data->appearance != 0) |
| 290 | { |
| 291 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_APPEARANCE; |
| 292 | p_multi_adv_data_cb->inst_cb[cbindex].data.appearance = p_adv_data->appearance; |
| 293 | } |
| 294 | |
| 295 | if (p_adv_data->manufacturer_len > 0 && p_adv_data->p_manufacturer_data != NULL) |
| 296 | { |
| 297 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_manu = |
| 298 | GKI_getbuf(sizeof(tBTA_BLE_MANU)); |
| 299 | if(p_multi_adv_data_cb->inst_cb[cbindex].data.p_manu != NULL) |
| 300 | { |
| 301 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_manu->p_val = |
| 302 | GKI_getbuf(p_adv_data->manufacturer_len); |
| 303 | if (p_multi_adv_data_cb->inst_cb[cbindex].data.p_manu->p_val != NULL) |
| 304 | { |
| 305 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_MANU; |
| 306 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_manu->len = |
| 307 | p_adv_data->manufacturer_len; |
| 308 | memcpy(p_multi_adv_data_cb->inst_cb[cbindex].data.p_manu->p_val, |
| 309 | p_adv_data->p_manufacturer_data, p_adv_data->manufacturer_len); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | tBTA_BLE_PROP_ELEM *p_elem_service_data = NULL; |
| 315 | tBTA_BLE_PROP_ELEM *p_elem_service_128 = NULL; |
| 316 | |
| 317 | if (p_adv_data->service_data_len > 0 && p_adv_data->p_service_data != NULL) |
| 318 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 319 | BTIF_TRACE_DEBUG("%s - In service_data", __FUNCTION__); |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 320 | p_elem_service_data = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM)); |
| 321 | if (p_elem_service_data != NULL) |
| 322 | { |
| 323 | p_elem_service_data->p_val = GKI_getbuf(p_adv_data->service_data_len); |
| 324 | if (p_elem_service_data->p_val != NULL) |
| 325 | { |
| 326 | p_elem_service_data->adv_type = BTM_BLE_AD_TYPE_SERVICE_DATA; |
| 327 | p_elem_service_data->len = p_adv_data->service_data_len; |
| 328 | memcpy(p_elem_service_data->p_val, p_adv_data->p_service_data, |
| 329 | p_adv_data->service_data_len); |
| 330 | } else { |
| 331 | GKI_freebuf(p_elem_service_data); |
| 332 | p_elem_service_data = NULL; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if (p_adv_data->service_uuid_len > 0 && p_adv_data->p_service_uuid != NULL) |
| 338 | { |
| 339 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_services = |
| 340 | GKI_getbuf(sizeof(tBTA_BLE_SERVICE)); |
| 341 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_services->list_cmpl = FALSE; |
| 342 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_services->num_service = 0; |
| 343 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_services->p_uuid = |
| 344 | GKI_getbuf(p_adv_data->service_uuid_len / LEN_UUID_128 * LEN_UUID_16); |
| 345 | if (p_multi_adv_data_cb->inst_cb[cbindex].data.p_services->p_uuid != NULL) |
| 346 | { |
| 347 | UINT16 *p_uuid_out = p_multi_adv_data_cb->inst_cb[cbindex].data.p_services->p_uuid; |
| 348 | while (p_adv_data->service_uuid_len >= LEN_UUID_128) |
| 349 | { |
| 350 | bt_uuid_t uuid; |
| 351 | memset(&uuid, 0, sizeof(bt_uuid_t)); |
| 352 | memcpy(&uuid.uu, p_adv_data->p_service_uuid, LEN_UUID_128); |
| 353 | tBT_UUID bt_uuid; |
| 354 | memset(&bt_uuid, 0, sizeof(tBT_UUID)); |
| 355 | btif_to_bta_uuid(&bt_uuid, &uuid); |
| 356 | |
| 357 | if (bt_uuid.len == LEN_UUID_16) |
| 358 | { |
| 359 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_SERVICE; |
| 360 | ++p_multi_adv_data_cb->inst_cb[cbindex].data.p_services->num_service; |
| 361 | *p_uuid_out++ = bt_uuid.uu.uuid16; |
| 362 | } else if (bt_uuid.len == LEN_UUID_128 && p_elem_service_128 == NULL) { |
| 363 | /* Currently, only one 128-bit UUID is supported */ |
| 364 | p_elem_service_128 = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM)); |
| 365 | if (p_elem_service_128 != NULL) |
| 366 | { |
| 367 | p_elem_service_128->p_val = GKI_getbuf(LEN_UUID_128); |
| 368 | if (p_elem_service_128->p_val != NULL) |
| 369 | { |
| 370 | p_elem_service_128->adv_type = BTM_BLE_AD_TYPE_128SRV_PART; |
| 371 | p_elem_service_128->len = LEN_UUID_128; |
| 372 | memcpy(p_elem_service_128->p_val, bt_uuid.uu.uuid128, LEN_UUID_128); |
| 373 | } else { |
| 374 | GKI_freebuf(p_elem_service_128); |
| 375 | p_elem_service_128 = NULL; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | p_adv_data->p_service_uuid += LEN_UUID_128; |
| 380 | p_adv_data->service_uuid_len -= LEN_UUID_128; |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | if (p_elem_service_data != NULL || p_elem_service_128 != NULL) |
| 386 | { |
| 387 | p_multi_adv_data_cb->inst_cb[cbindex].data.p_proprietary = |
| 388 | GKI_getbuf(sizeof(tBTA_BLE_PROPRIETARY)); |
| 389 | if (p_multi_adv_data_cb->inst_cb[cbindex].data.p_proprietary != NULL) |
| 390 | { |
| 391 | tBTA_BLE_PROPRIETARY *p_prop = p_multi_adv_data_cb->inst_cb[cbindex]. |
| 392 | data.p_proprietary; |
| 393 | tBTA_BLE_PROP_ELEM *p_elem = NULL; |
| 394 | p_prop->num_elem = 0; |
| 395 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_PROPRIETARY; |
| 396 | if (p_elem_service_128 != NULL) |
| 397 | ++p_prop->num_elem; |
| 398 | if (p_elem_service_data != NULL) |
| 399 | ++p_prop->num_elem; |
| 400 | p_prop->p_elem = GKI_getbuf(sizeof(tBTA_BLE_PROP_ELEM) * p_prop->num_elem); |
| 401 | p_elem = p_prop->p_elem; |
| 402 | if (p_elem_service_128 != NULL) |
| 403 | { |
| 404 | memcpy(p_elem++, p_elem_service_128, sizeof(tBTA_BLE_PROP_ELEM)); |
| 405 | GKI_freebuf(p_elem_service_128); |
| 406 | } |
| 407 | if (p_elem_service_data != NULL) |
| 408 | { |
| 409 | memcpy(p_elem++, p_elem_service_data, sizeof(tBTA_BLE_PROP_ELEM)); |
| 410 | GKI_freebuf(p_elem_service_data); |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | #if (defined(BLE_PERIPHERAL_ADV_NAME) && (BLE_PERIPHERAL_ADV_NAME == TRUE)) |
| 416 | p_multi_adv_data_cb->inst_cb[cbindex].mask |= BTM_BLE_AD_BIT_DEV_NAME; |
| 417 | #endif |
| 418 | return true; |
| 419 | } |
| 420 | |
| 421 | void btif_gattc_clear_clientif(int client_if) |
| 422 | { |
| 423 | int i=0; |
| 424 | |
| 425 | btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb(); |
| 426 | |
| 427 | if(NULL == p_multi_adv_data_cb) |
| 428 | return; |
| 429 | |
| 430 | // Clear both the inst_id and client_if values |
| 431 | for(i=0; i < BTM_BLE_MULTI_ADV_MAX; i++) |
| 432 | { |
| 433 | if(client_if == p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX]) |
| 434 | { |
| 435 | p_multi_adv_data_cb->clntif_map[i][INST_ID_IDX] = INVALID_ADV_INST; |
| 436 | p_multi_adv_data_cb->clntif_map[i][CLNT_IF_IDX] = INVALID_ADV_INST; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 437 | BTIF_TRACE_DEBUG("Cleaning up index %d for clnt_if :%d,", i, client_if); |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 438 | break; |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | void btif_gattc_cleanup_inst_cb(int inst_id) |
| 444 | { |
| 445 | int cbindex = 0; |
| 446 | // Check for invalid instance id |
| 447 | if (inst_id < 0 || inst_id > BTM_BLE_MULTI_ADV_MAX) |
| 448 | return; |
| 449 | |
| 450 | btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb(); |
| 451 | |
| 452 | if(NULL == p_multi_adv_data_cb) |
| 453 | return; |
| 454 | |
| 455 | if(inst_id > 0) |
| 456 | { |
| 457 | cbindex = btif_gattc_obtain_idx_for_datacb(inst_id, INST_ID_IDX); |
| 458 | if (cbindex < 0) |
| 459 | return; |
| 460 | } |
| 461 | else |
| 462 | if(STD_ADV_INSTID == inst_id) |
| 463 | cbindex = STD_ADV_INSTID; |
| 464 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame^] | 465 | BTIF_TRACE_DEBUG("Cleaning up multi_inst_cb for inst_id %d, cbindex %d", inst_id, cbindex); |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 466 | btif_gattc_cleanup_multi_inst_cb(&p_multi_adv_data_cb->inst_cb[cbindex]); |
| 467 | } |
| 468 | |
| 469 | void btif_gattc_cleanup_multi_inst_cb(btgatt_multi_adv_inst_cb *p_multi_inst_cb) |
| 470 | { |
| 471 | // Manufacturer data cleanup |
| 472 | if (p_multi_inst_cb->data.p_manu != NULL) |
| 473 | { |
| 474 | if (p_multi_inst_cb->data.p_manu->p_val != NULL) |
| 475 | GKI_freebuf(p_multi_inst_cb->data.p_manu->p_val); |
| 476 | GKI_freebuf(p_multi_inst_cb->data.p_manu); |
| 477 | } |
| 478 | |
| 479 | // Proprietary data cleanup |
| 480 | if (p_multi_inst_cb->data.p_proprietary != NULL) |
| 481 | { |
| 482 | int i = 0; |
| 483 | tBTA_BLE_PROP_ELEM *p_elem = p_multi_inst_cb->data.p_proprietary->p_elem; |
| 484 | while (i++ != p_multi_inst_cb->data.p_proprietary->num_elem |
| 485 | && p_elem) |
| 486 | { |
| 487 | if (p_elem->p_val != NULL) |
| 488 | GKI_freebuf(p_elem->p_val); |
| 489 | ++p_elem; |
| 490 | } |
| 491 | |
| 492 | if (p_multi_inst_cb->data.p_proprietary->p_elem != NULL) |
| 493 | GKI_freebuf(p_multi_inst_cb->data.p_proprietary->p_elem); |
| 494 | GKI_freebuf(p_multi_inst_cb->data.p_proprietary); |
| 495 | } |
| 496 | |
| 497 | // Service list cleanup |
| 498 | if (p_multi_inst_cb->data.p_services != NULL) |
| 499 | { |
| 500 | if (p_multi_inst_cb->data.p_services->p_uuid != NULL) |
| 501 | GKI_freebuf(p_multi_inst_cb->data.p_services->p_uuid); |
| 502 | GKI_freebuf(p_multi_inst_cb->data.p_services); |
| 503 | } |
| 504 | |
| 505 | // Service data cleanup |
| 506 | if (p_multi_inst_cb->data.p_service_data != NULL) |
| 507 | { |
| 508 | if (p_multi_inst_cb->data.p_service_data->p_val != NULL) |
| 509 | GKI_freebuf(p_multi_inst_cb->data.p_service_data->p_val); |
| 510 | GKI_freebuf(p_multi_inst_cb->data.p_service_data); |
| 511 | } |
| 512 | |
| 513 | if (p_multi_inst_cb->data.p_services_128b != NULL) |
| 514 | GKI_freebuf(p_multi_inst_cb->data.p_services_128b); |
| 515 | |
| 516 | if (p_multi_inst_cb->data.p_service_32b != NULL) |
| 517 | { |
| 518 | if (p_multi_inst_cb->data.p_service_32b->p_uuid != NULL) |
| 519 | GKI_freebuf(p_multi_inst_cb->data.p_service_32b->p_uuid); |
| 520 | GKI_freebuf(p_multi_inst_cb->data.p_service_32b); |
| 521 | } |
| 522 | |
| 523 | if (p_multi_inst_cb->data.p_sol_services != NULL) |
| 524 | { |
| 525 | if (p_multi_inst_cb->data.p_sol_services->p_uuid != NULL) |
| 526 | GKI_freebuf(p_multi_inst_cb->data.p_sol_services->p_uuid); |
| 527 | GKI_freebuf(p_multi_inst_cb->data.p_sol_services); |
| 528 | } |
| 529 | |
| 530 | if (p_multi_inst_cb->data.p_sol_service_32b != NULL) |
| 531 | { |
| 532 | if (p_multi_inst_cb->data.p_sol_service_32b->p_uuid != NULL) |
| 533 | GKI_freebuf(p_multi_inst_cb->data.p_sol_service_32b->p_uuid); |
| 534 | GKI_freebuf(p_multi_inst_cb->data.p_sol_service_32b); |
| 535 | } |
| 536 | |
| 537 | if(p_multi_inst_cb->data.p_sol_service_128b != NULL) |
| 538 | GKI_freebuf(p_multi_inst_cb->data.p_sol_service_128b); |
| 539 | } |
| 540 | |
| 541 | #endif |