1ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/****************************************************************************** 2ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 3c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji * Copyright (C) 2009-2014 Broadcom Corporation 4ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 5ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Licensed under the Apache License, Version 2.0 (the "License"); 6ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * you may not use this file except in compliance with the License. 7ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * You may obtain a copy of the License at: 8ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 9ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * http://www.apache.org/licenses/LICENSE-2.0 10ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 11ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Unless required by applicable law or agreed to in writing, software 12ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * distributed under the License is distributed on an "AS IS" BASIS, 13ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * See the License for the specific language governing permissions and 15ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * limitations under the License. 16ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 17ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta ******************************************************************************/ 18ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 19ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/******************************************************************************* 20ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 21ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Filename: btif_gatt_client.c 22ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 23ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * Description: GATT client implementation 24ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta * 25ee96a3c60fca590d38025925c072d264e06493c4Myles Watson ******************************************************************************/ 26ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 2749120dc867c7818511b5afec461dfc97d17eef58Marie Janssen#define LOG_TAG "bt_btif_gattc" 2849120dc867c7818511b5afec461dfc97d17eef58Marie Janssen 29140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski#include <base/at_exit.h> 30140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski#include <base/bind.h> 31140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski#include <base/threading/thread.h> 3249a86709488e5cfd5e23759da18bf9613e15b04dMarie Janssen#include <errno.h> 33ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <hardware/bluetooth.h> 34ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <stdlib.h> 35ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <string.h> 366ed1548be2295fc1bec14f10cd0fade4f63daa6aSatya Calloji#include "device/include/controller.h" 376ed1548be2295fc1bec14f10cd0fade4f63daa6aSatya Calloji 38ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_common.h" 39ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_util.h" 40ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 416975b4d711142b885af479721cada448952c6b41Andre Eisenbach#include <hardware/bt_gatt.h> 42db554581079863974af8e1289646f5deea6fc044Marie Janssen 43ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_api.h" 44eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski#include "bta_closure_api.h" 45ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_gatt_api.h" 46ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_config.h" 47db554581079863974af8e1289646f5deea6fc044Marie Janssen#include "btif_dm.h" 48ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt.h" 49ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt_util.h" 50ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_storage.h" 5144802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati#include "osi/include/log.h" 52b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach#include "vendor_api.h" 53b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach 54140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskiusing base::Bind; 55140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskiusing base::Owned; 5626ecec06be48502eba1c24a6b1fdbb66eafa8032Jakub Pawlowskiusing std::vector; 57140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski 5896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskiextern bt_status_t btif_gattc_test_command_impl( 5996ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski int command, const btgatt_test_params_t* params); 606bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watsonextern const btgatt_callbacks_t* bt_gatt_callbacks; 61140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski 62ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/******************************************************************************* 636bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson * Constants & Macros 64ee96a3c60fca590d38025925c072d264e06493c4Myles Watson ******************************************************************************/ 65ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 6640cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson#define CLI_CBACK_IN_JNI(P_CBACK, ...) \ 6740cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson do { \ 6840cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) { \ 6940cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson BTIF_TRACE_API("HAL bt_gatt_callbacks->client->%s", #P_CBACK); \ 7040cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson do_in_jni_thread(Bind(bt_gatt_callbacks->client->P_CBACK, __VA_ARGS__)); \ 7140cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } else { \ 7240cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson ASSERTC(0, "Callback is NULL", 0); \ 7340cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } \ 7440cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } while (0) 75da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski 7640cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson#define CHECK_BTGATT_INIT() \ 7740cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson do { \ 7840cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson if (bt_gatt_callbacks == NULL) { \ 7940cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson LOG_WARN(LOG_TAG, "%s: BTGATT not initialized", __func__); \ 8040cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson return BT_STATUS_NOT_READY; \ 8140cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } else { \ 8240cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson LOG_VERBOSE(LOG_TAG, "%s", __func__); \ 8340cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } \ 8440cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } while (0) 85ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 866bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson#define BLE_RESOLVE_ADDR_MSB \ 876bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson 0x40 /* bit7, bit6 is 01 to be resolvable random \ 8844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski */ 8944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski#define BLE_RESOLVE_ADDR_MASK 0xc0 /* bit 6, and bit7 */ 90a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskiinline bool BTM_BLE_IS_RESOLVE_BDA(const RawAddress& x) { 91c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski return ((x.address)[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB; 92c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski} 9344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskinamespace { 94ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 9544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskiuint8_t rssi_request_client_if; 96ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 976bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watsonvoid btif_gattc_upstreams_evt(uint16_t event, char* p_param) { 98b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen LOG_VERBOSE(LOG_TAG, "%s: Event %d", __func__, event); 99ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 1006bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson tBTA_GATTC* p_data = (tBTA_GATTC*)p_param; 10144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski switch (event) { 10244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_DEREG_EVT: 10344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 104ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 10544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_EXEC_EVT: { 10644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->execute_write_cb, 10744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->exec_cmpl.conn_id, p_data->exec_cmpl.status); 10844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 10944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 110ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 11144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_SEARCH_CMPL_EVT: { 11244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->search_complete_cb, 11344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->search_cmpl.conn_id, p_data->search_cmpl.status); 11444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 11544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 116ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 11744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_NOTIF_EVT: { 11844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski btgatt_notify_params_t data; 119ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 120c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski data.bda = p_data->notify.bda; 12144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski memcpy(data.value, p_data->notify.value, p_data->notify.len); 122ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 12344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski data.handle = p_data->notify.handle; 12444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski data.is_notify = p_data->notify.is_notify; 12544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski data.len = p_data->notify.len; 126ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 12744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->notify_cb, p_data->notify.conn_id, 12896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski data); 129ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 130b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen if (p_data->notify.is_notify == false) 13144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski BTA_GATTC_SendIndConfirm(p_data->notify.conn_id, p_data->notify.handle); 1329dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski 13344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 13444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 135ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 13644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_OPEN_EVT: { 137c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski DVLOG(1) << "BTA_GATTC_OPEN_EVT " << p_data->open.remote_bda; 13844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->open_cb, p_data->open.conn_id, 139c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski p_data->open.status, p_data->open.client_if, 14096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski p_data->open.remote_bda); 1416975b4d711142b885af479721cada448952c6b41Andre Eisenbach 14244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski if (GATT_DEF_BLE_MTU_SIZE != p_data->open.mtu && p_data->open.mtu) { 14344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, 14444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->open.conn_id, p_data->open.status, p_data->open.mtu); 14544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 1469426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach 14744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski if (p_data->open.status == BTA_GATT_OK) 14844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski btif_gatt_check_encrypted_link(p_data->open.remote_bda, 14944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->open.transport); 15044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 15144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 152ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 15344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CLOSE_EVT: { 15444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->close_cb, p_data->close.conn_id, 155c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski p_data->status, p_data->close.client_if, 15696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski p_data->close.remote_bda); 15744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 15844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 159ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 16044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_ACL_EVT: 16144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski LOG_DEBUG(LOG_TAG, "BTA_GATTC_ACL_EVT: status = %d", p_data->status); 16244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski /* Ignore for now */ 16344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 1649426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach 16544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CANCEL_OPEN_EVT: 16644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 16717b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 16844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CFG_MTU_EVT: { 16944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, 17044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->cfg_mtu.conn_id, p_data->cfg_mtu.status, 17144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->cfg_mtu.mtu); 17244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 173ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 1748444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach 17544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CONGEST_EVT: 17644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->congestion_cb, 17744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->congest.conn_id, p_data->congest.congested); 17844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 17944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski 180eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski case BTA_GATTC_PHY_UPDATE_EVT: 181eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->phy_updated_cb, 182eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski p_data->phy_update.conn_id, p_data->phy_update.tx_phy, 183eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski p_data->phy_update.rx_phy, p_data->phy_update.status); 184eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski break; 185eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski 186b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski case BTA_GATTC_CONN_UPDATE_EVT: 187b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->conn_updated_cb, 188b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski p_data->conn_update.conn_id, p_data->conn_update.interval, 189b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski p_data->conn_update.latency, p_data->conn_update.timeout, 190b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski p_data->conn_update.status); 191b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski break; 192b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski 19344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski default: 194b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen LOG_ERROR(LOG_TAG, "%s: Unhandled event (%d)!", __func__, event); 19544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 19644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 197ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 198ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 1996bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watsonvoid bta_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) { 20024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski bt_status_t status = 20124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski btif_transfer_context(btif_gattc_upstreams_evt, (uint16_t)event, 2026bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson (char*)p_data, sizeof(tBTA_GATTC), NULL); 20344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status); 204ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 205ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 206aa4322821bc8cca05e7810451971ccc6a17acbf3Pavlin Radoslavovvoid btm_read_rssi_cb(tBTM_RSSI_RESULT* p_result) { 2076bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson if (!p_result) return; 2087294d958dcb610d7828f06c3a1cde933127694d3Jakub Pawlowski 209c171ac407cfc6d30a11af6b12ead39688eb897f7Jakub Pawlowski CLI_CBACK_IN_JNI(read_remote_rssi_cb, rssi_request_client_if, 21096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski p_result->rem_bda, p_result->rssi, p_result->status); 211ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 212ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 213ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/******************************************************************************* 2146bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson * Client API Functions 215ee96a3c60fca590d38025925c072d264e06493c4Myles Watson ******************************************************************************/ 216ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 21796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_register_app(const bt_uuid_t& uuid) { 218c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski CHECK_BTGATT_INIT(); 219c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski 220c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski tBT_UUID bt_uuid; 22196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btif_to_bta_uuid(&bt_uuid, &uuid); 222221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski 223221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski return do_in_jni_thread(Bind( 224221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski [](tBT_UUID bt_uuid) { 225221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski BTA_GATTC_AppRegister( 226221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bta_gattc_cback, 227221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski base::Bind( 228221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski [](tBT_UUID bt_uuid, uint8_t client_id, uint8_t status) { 229221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski do_in_jni_thread(Bind( 230221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski [](tBT_UUID bt_uuid, uint8_t client_id, uint8_t status) { 231221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid_t app_uuid; 232221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bta_to_btif_uuid(&app_uuid, &bt_uuid); 233221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->register_client_cb, 23496ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski status, client_id, app_uuid); 235221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski }, 236221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid, client_id, status)); 237221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski }, 238221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid)); 239221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski }, 240221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid)); 241c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski} 242c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski 24344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskivoid btif_gattc_unregister_app_impl(int client_if) { 244c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski BTA_GATTC_AppDeregister(client_if); 245c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski} 246c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski 24744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_unregister_app(int client_if) { 248c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski CHECK_BTGATT_INIT(); 249c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski return do_in_jni_thread(Bind(&btif_gattc_unregister_app_impl, client_if)); 250ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 251ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 252a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskivoid btif_gattc_open_impl(int client_if, RawAddress address, bool is_direct, 2535120fedf20eb29fa65cef561c475d18d51197b25Jack He int transport_p, bool opportunistic, 2545120fedf20eb29fa65cef561c475d18d51197b25Jack He int initiating_phys) { 25526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // Ensure device is in inquiry database 25626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski int addr_type = 0; 25726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski int device_type = 0; 25826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski tBTA_GATT_TRANSPORT transport = (tBTA_GATT_TRANSPORT)BTA_GATT_TRANSPORT_LE; 25926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 26026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski if (btif_get_address_type(address, &addr_type) && 26126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski btif_get_device_type(address, &device_type) && 26226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski device_type != BT_DEVICE_TYPE_BREDR) { 26326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski BTA_DmAddBleDevice(address, addr_type, device_type); 26426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski } 26526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 26626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // Check for background connections 26726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski if (!is_direct) { 26826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // Check for privacy 1.0 and 1.1 controller and do not start background 26926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // connection if RPA offloading is not supported, since it will not 27026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // connect after change of random address 27126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski if (!controller_get_interface()->supports_ble_privacy() && 27244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski (addr_type == BLE_ADDR_RANDOM) && BTM_BLE_IS_RESOLVE_BDA(address)) { 27326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski tBTM_BLE_VSC_CB vnd_capabilities; 27426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski BTM_BleGetVendorCapabilities(&vnd_capabilities); 27526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski if (!vnd_capabilities.rpa_offloading) { 27626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->open_cb, 0, BT_STATUS_UNSUPPORTED, 27796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski client_if, address); 27826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski return; 27926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski } 28026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski } 28183211b0ccceb53586ac651a4d67ded7443b2f222Jakub Pawlowski BTA_DmBleStartAutoConn(); 28226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski } 28326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 28426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // Determine transport 28526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski if (transport_p != GATT_TRANSPORT_AUTO) { 28626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski transport = transport_p; 28726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski } else { 28826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski switch (device_type) { 28926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski case BT_DEVICE_TYPE_BREDR: 29026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski transport = BTA_GATT_TRANSPORT_BR_EDR; 29126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski break; 29226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 29326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski case BT_DEVICE_TYPE_BLE: 29426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski transport = BTA_GATT_TRANSPORT_LE; 29526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski break; 29626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 29726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski case BT_DEVICE_TYPE_DUMO: 2983bd07c3618c7dea6e8b63237898a0a9e903df482Jakub Pawlowski if (transport_p == GATT_TRANSPORT_LE) 29926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski transport = BTA_GATT_TRANSPORT_LE; 30026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski else 30126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski transport = BTA_GATT_TRANSPORT_BR_EDR; 30226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski break; 30326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski } 30426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski } 30526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 30626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // Connect! 30796fb273d92a31204edcf43ab2594a19876d14056Jakub Pawlowski BTIF_TRACE_DEBUG("%s Transport=%d, device type=%d, phy=%d", __func__, 30896fb273d92a31204edcf43ab2594a19876d14056Jakub Pawlowski transport, device_type, initiating_phys); 3095120fedf20eb29fa65cef561c475d18d51197b25Jack He BTA_GATTC_Open(client_if, address, is_direct, transport, opportunistic, 31047474c3e584806e0b49b27e1e5330c1e6646cfb9Jakub Pawlowski initiating_phys); 31126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski} 31226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 313a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskibt_status_t btif_gattc_open(int client_if, const RawAddress& bd_addr, 3145120fedf20eb29fa65cef561c475d18d51197b25Jack He bool is_direct, int transport, bool opportunistic, 31596fb273d92a31204edcf43ab2594a19876d14056Jakub Pawlowski int initiating_phys) { 31626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski CHECK_BTGATT_INIT(); 31726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski // Closure will own this value and free it. 31896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski return do_in_jni_thread(Bind(&btif_gattc_open_impl, client_if, bd_addr, 3195120fedf20eb29fa65cef561c475d18d51197b25Jack He is_direct, transport, opportunistic, 3205120fedf20eb29fa65cef561c475d18d51197b25Jack He initiating_phys)); 321ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 322ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 323a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskivoid btif_gattc_close_impl(int client_if, RawAddress address, int conn_id) { 324b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski // Disconnect established connections 325b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski if (conn_id != 0) 326b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski BTA_GATTC_Close(conn_id); 327b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski else 328b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen BTA_GATTC_CancelOpen(client_if, address, true); 329b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski 330b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski // Cancel pending background connections (remove from whitelist) 331b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen BTA_GATTC_CancelOpen(client_if, address, false); 332b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski} 333b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski 334a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskibt_status_t btif_gattc_close(int client_if, const RawAddress& bd_addr, 33544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int conn_id) { 336b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski CHECK_BTGATT_INIT(); 337b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski return do_in_jni_thread( 33896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski Bind(&btif_gattc_close_impl, client_if, bd_addr, conn_id)); 339ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 340ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 341a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskibt_status_t btif_gattc_refresh(int client_if, const RawAddress& bd_addr) { 342140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski CHECK_BTGATT_INIT(); 34396ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_Refresh, bd_addr)); 344ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 345ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 34696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_search_service(int conn_id, 34796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const bt_uuid_t* filter_uuid) { 348d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski CHECK_BTGATT_INIT(); 349d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski 350d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski if (filter_uuid) { 3516bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson tBT_UUID* uuid = new tBT_UUID; 352d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski btif_to_bta_uuid(uuid, filter_uuid); 353d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski return do_in_jni_thread( 354d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski Bind(&BTA_GATTC_ServiceSearchRequest, conn_id, base::Owned(uuid))); 355d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski } else { 356d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski return do_in_jni_thread( 357d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski Bind(&BTA_GATTC_ServiceSearchRequest, conn_id, nullptr)); 358d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski } 359ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 360ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 36196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskivoid btif_gattc_discover_service_by_uuid(int conn_id, const bt_uuid_t& p_uuid) { 36245aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski tBT_UUID* uuid = new tBT_UUID; 36396ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btif_to_bta_uuid(uuid, &p_uuid); 36445aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski do_in_jni_thread( 36545aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski Bind(&BTA_GATTC_DiscoverServiceByUuid, conn_id, base::Owned(uuid))); 36645aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski} 36745aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski 36861a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowskivoid btif_gattc_get_gatt_db_impl(int conn_id) { 3696bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson btgatt_db_element_t* db = NULL; 37061a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski int count = 0; 37161a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski BTA_GATTC_GetGattDb(conn_id, 0x0000, 0xFFFF, &db, &count); 372533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski 37361a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->get_gatt_db_cb, conn_id, db, count); 37461a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski osi_free(db); 37561a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski} 37661a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski 37744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_get_gatt_db(int conn_id) { 37861a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski CHECK_BTGATT_INIT(); 37961a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski return do_in_jni_thread(Bind(&btif_gattc_get_gatt_db_impl, conn_id)); 380533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski} 381533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski 38224ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid read_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 3836bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson uint16_t len, uint8_t* value, void* data) { 3846bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson btgatt_read_params_t* params = new btgatt_read_params_t; 38524ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->value_type = 0x00 /* GATTC_READ_VALUE_TYPE_VALUE */; 38624ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->status = status; 38724ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->handle = handle; 38824ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->value.len = len; 389f2af1c42ccb2f642b241c2261b42d0be61d45438Jack He CHECK(len <= BTGATT_MAX_ATTR_LEN); 39024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski if (len > 0) memcpy(params->value.value, value, len); 39124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 392f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // clang-tidy analyzer complains about |params| is leaked. It doesn't know 393f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // that |param| will be freed by the callback function. 394f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang CLI_CBACK_IN_JNI(read_characteristic_cb, conn_id, status, /* NOLINT */ 39524ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski base::Owned(params)); 39624ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 39724ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 39844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_read_char(int conn_id, uint16_t handle, int auth_req) { 39961a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski CHECK_BTGATT_INIT(); 40024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_ReadCharacteristic, conn_id, handle, 40124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski auth_req, read_char_cb, nullptr)); 40224ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 40324ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 4047dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowskivoid read_using_char_uuid_cb(uint16_t conn_id, tGATT_STATUS status, 4057dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski uint16_t handle, uint16_t len, uint8_t* value, 4067dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski void* data) { 4077dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski btgatt_read_params_t* params = new btgatt_read_params_t; 4087dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->value_type = 0x00 /* GATTC_READ_VALUE_TYPE_VALUE */; 4097dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->status = status; 4107dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->handle = handle; 4117dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->value.len = len; 4127dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski CHECK(len <= BTGATT_MAX_ATTR_LEN); 4137dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski if (len > 0) memcpy(params->value.value, value, len); 4147dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski 415f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // clang-tidy analyzer complains about |params| is leaked. It doesn't know 416f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // that |param| will be freed by the callback function. 417f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang CLI_CBACK_IN_JNI(read_characteristic_cb, conn_id, status, /* NOLINT */ 4187dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski base::Owned(params)); 4197dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski} 4207dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski 42196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_read_using_char_uuid(int conn_id, const bt_uuid_t& uuid, 4227dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski uint16_t s_handle, 4237dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski uint16_t e_handle, int auth_req) { 4247dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski CHECK_BTGATT_INIT(); 4257dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski tBT_UUID bt_uuid; 42696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btif_to_bta_uuid(&bt_uuid, &uuid); 4277dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_ReadUsingCharUuid, conn_id, bt_uuid, 4287dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski s_handle, e_handle, auth_req, 4297dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski read_using_char_uuid_cb, nullptr)); 4307dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski} 4317dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski 43224ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid read_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 4336bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson uint16_t len, uint8_t* value, void* data) { 43496ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btgatt_read_params_t params; 43596ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.value_type = 0x00 /* GATTC_READ_VALUE_TYPE_VALUE */; 43696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.status = status; 43796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.handle = handle; 43896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.value.len = len; 439f2af1c42ccb2f642b241c2261b42d0be61d45438Jack He CHECK(len <= BTGATT_MAX_ATTR_LEN); 44096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski if (len > 0) memcpy(params.value.value, value, len); 44124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 44296ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski CLI_CBACK_IN_JNI(read_descriptor_cb, conn_id, status, params); 443ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 444ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 44544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_read_char_descr(int conn_id, uint16_t handle, 44644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int auth_req) { 44761a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski CHECK_BTGATT_INIT(); 44824ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_ReadCharDescr, conn_id, handle, 44924ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski auth_req, read_desc_cb, nullptr)); 45024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 45124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 45224ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid write_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 4536bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson void* data) { 45424ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski CLI_CBACK_IN_JNI(write_characteristic_cb, conn_id, status, handle); 455ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 456ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 45744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_write_char(int conn_id, uint16_t handle, int write_type, 458ec79baaaed83529dae14d492ea2f73aedee9e4d0Jakub Pawlowski int auth_req, vector<uint8_t> value) { 45939a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski CHECK_BTGATT_INIT(); 46039a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski 4616bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson if (value.size() > BTGATT_MAX_ATTR_LEN) value.resize(BTGATT_MAX_ATTR_LEN); 46239a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski 46339a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharValue, conn_id, handle, 46424ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski write_type, std::move(value), auth_req, 46524ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski write_char_cb, nullptr)); 46624ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 46724ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 46824ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid write_descr_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 4696bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson void* data) { 47024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski CLI_CBACK_IN_JNI(write_descriptor_cb, conn_id, status, handle); 471ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 472ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 47344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle, 474bb920a65b959fbb593403587f89bc3fc7e831732Jakub Pawlowski int auth_req, vector<uint8_t> value) { 475ec79baaaed83529dae14d492ea2f73aedee9e4d0Jakub Pawlowski CHECK_BTGATT_INIT(); 476ec79baaaed83529dae14d492ea2f73aedee9e4d0Jakub Pawlowski 4776bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson if (value.size() > BTGATT_MAX_ATTR_LEN) value.resize(BTGATT_MAX_ATTR_LEN); 47839a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski 47939a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharDescr, conn_id, handle, 4806bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson std::move(value), auth_req, write_descr_cb, 4816bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson nullptr)); 482ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 483ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 48444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_execute_write(int conn_id, int execute) { 485a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski CHECK_BTGATT_INIT(); 486a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski return do_in_jni_thread( 487a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski Bind(&BTA_GATTC_ExecuteWrite, conn_id, (uint8_t)execute)); 488ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 489ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 49044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskivoid btif_gattc_reg_for_notification_impl(tBTA_GATTC_IF client_if, 491a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bda, 492c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski uint16_t handle) { 493c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski tBTA_GATT_STATUS status = 494c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_GATTC_RegisterForNotifications(client_if, bda, handle); 495ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 49644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski // TODO(jpawlowski): conn_id is currently unused 497ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb, 498ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski /* conn_id */ 0, 1, status, handle); 499ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 500ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 50144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_reg_for_notification(int client_if, 502a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bd_addr, 50344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski uint16_t handle) { 504ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski CHECK_BTGATT_INIT(); 505ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 506ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski return do_in_jni_thread( 507ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski Bind(base::IgnoreResult(&btif_gattc_reg_for_notification_impl), client_if, 50896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski bd_addr, handle)); 509ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski} 510ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 51144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskivoid btif_gattc_dereg_for_notification_impl(tBTA_GATTC_IF client_if, 512a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bda, 5136bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson uint16_t handle) { 514c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski tBTA_GATT_STATUS status = 515c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_GATTC_DeregisterForNotifications(client_if, bda, handle); 516ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 51744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski // TODO(jpawlowski): conn_id is currently unused 518ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb, 519ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski /* conn_id */ 0, 0, status, handle); 520ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski} 521ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 52244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_dereg_for_notification(int client_if, 523a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bd_addr, 52444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski uint16_t handle) { 525ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski CHECK_BTGATT_INIT(); 526ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 527ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski return do_in_jni_thread( 528ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski Bind(base::IgnoreResult(&btif_gattc_dereg_for_notification_impl), 52996ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski client_if, bd_addr, handle)); 530ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 531ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 53244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_read_remote_rssi(int client_if, 533a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bd_addr) { 534c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski CHECK_BTGATT_INIT(); 535c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski rssi_request_client_if = client_if; 536c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski 53796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski return do_in_jni_thread(Bind(base::IgnoreResult(&BTM_ReadRSSI), bd_addr, 5386bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson (tBTM_CMPL_CB*)btm_read_rssi_cb)); 539ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 540ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 54144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_configure_mtu(int conn_id, int mtu) { 542c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski CHECK_BTGATT_INIT(); 543c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski return do_in_jni_thread( 544c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski Bind(base::IgnoreResult(&BTA_GATTC_ConfigureMTU), conn_id, mtu)); 5459426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach} 5469426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach 547a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskivoid btif_gattc_conn_parameter_update_impl(RawAddress addr, int min_interval, 5487cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski int max_interval, int latency, 5497cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski int timeout) { 550c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski if (BTA_DmGetConnectionState(addr)) 551c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_DmBleUpdateConnectionParams(addr, min_interval, max_interval, latency, 552c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski timeout); 5537cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski else 554c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_DmSetBlePrefConnParams(addr, min_interval, max_interval, latency, 555c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski timeout); 5567cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski} 5577cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski 558a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskibt_status_t btif_gattc_conn_parameter_update(const RawAddress& bd_addr, 55944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int min_interval, int max_interval, 56044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int latency, int timeout) { 5617cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski CHECK_BTGATT_INIT(); 5627cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski return do_in_jni_thread( 56396ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski Bind(base::IgnoreResult(&btif_gattc_conn_parameter_update_impl), bd_addr, 5646bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson min_interval, max_interval, latency, timeout)); 56552a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach} 56652a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach 567a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskibt_status_t btif_gattc_set_preferred_phy(const RawAddress& bd_addr, 5685a475e71a01322367a2ba591aecd62781902cfc2Avish Shah uint8_t tx_phy, uint8_t rx_phy, 5695a475e71a01322367a2ba591aecd62781902cfc2Avish Shah uint16_t phy_options) { 570eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski CHECK_BTGATT_INIT(); 5715a475e71a01322367a2ba591aecd62781902cfc2Avish Shah do_in_bta_thread(FROM_HERE, 5725a475e71a01322367a2ba591aecd62781902cfc2Avish Shah Bind(&BTM_BleSetPhy, bd_addr, tx_phy, rx_phy, phy_options)); 573eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski return BT_STATUS_SUCCESS; 574eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski} 575eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski 576eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowskibt_status_t btif_gattc_read_phy( 577a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bd_addr, 578eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb) { 579eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski CHECK_BTGATT_INIT(); 5805a475e71a01322367a2ba591aecd62781902cfc2Avish Shah do_in_bta_thread(FROM_HERE, Bind(&BTM_BleReadPhy, bd_addr, 581eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski jni_thread_wrapper(FROM_HERE, cb))); 582eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski return BT_STATUS_SUCCESS; 583eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski} 584eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski 585a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskiint btif_gattc_get_device_type(const RawAddress& bd_addr) { 58644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int device_type = 0; 587ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 588b707f447cbb916de2e0dfd2b4e9bf15818376e64Jakub Pawlowski if (btif_config_get_int(bd_addr.ToString().c_str(), "DevType", &device_type)) 58944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski return device_type; 59044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski return 0; 591ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 592ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 59396ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_test_command(int command, 59496ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const btgatt_test_params_t& params) { 59596ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski return btif_gattc_test_command_impl(command, ¶ms); 596ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 597ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 59844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski} // namespace 59944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski 600ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battaconst btgatt_client_interface_t btgattClientInterface = { 601ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_register_app, 602ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_unregister_app, 603ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_open, 604ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_close, 605ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_refresh, 606ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_search_service, 60745aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski btif_gattc_discover_service_by_uuid, 608ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_read_char, 6097dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski btif_gattc_read_using_char_uuid, 610ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_write_char, 611ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_read_char_descr, 612ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_write_char_descr, 613ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_execute_write, 614ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_reg_for_notification, 615ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_dereg_for_notification, 616ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_read_remote_rssi, 617ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_get_device_type, 6189426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach btif_gattc_configure_mtu, 61952a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach btif_gattc_conn_parameter_update, 620eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski btif_gattc_set_preferred_phy, 621eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski btif_gattc_read_phy, 622533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski btif_gattc_test_command, 62344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski btif_gattc_get_gatt_db}; 624