btif_gatt_client.cc revision 96ac0a3c16a4a9f98169baf158bae16528cde79b
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 3895b74f252f534ec757aab1fc08e086e02b2cfe8dSharvil Nanavati#include "btcore/include/bdaddr.h" 39ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_common.h" 40ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_util.h" 41ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 426975b4d711142b885af479721cada448952c6b41Andre Eisenbach#include <hardware/bt_gatt.h> 43db554581079863974af8e1289646f5deea6fc044Marie Janssen 44ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_api.h" 45eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski#include "bta_closure_api.h" 46ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_gatt_api.h" 47ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_config.h" 48db554581079863974af8e1289646f5deea6fc044Marie Janssen#include "btif_dm.h" 49ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt.h" 50ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt_util.h" 51ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_storage.h" 5244802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati#include "osi/include/log.h" 53b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach#include "vendor_api.h" 54b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach 55140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskiusing base::Bind; 56140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskiusing base::Owned; 5726ecec06be48502eba1c24a6b1fdbb66eafa8032Jakub Pawlowskiusing std::vector; 58140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski 5996ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskiextern bt_status_t btif_gattc_test_command_impl( 6096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski int command, const btgatt_test_params_t* params); 616bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watsonextern const btgatt_callbacks_t* bt_gatt_callbacks; 62140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski 63ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/******************************************************************************* 646bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson * Constants & Macros 65ee96a3c60fca590d38025925c072d264e06493c4Myles Watson ******************************************************************************/ 66ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 6740cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson#define CLI_CBACK_IN_JNI(P_CBACK, ...) \ 6840cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson do { \ 6940cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) { \ 7040cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson BTIF_TRACE_API("HAL bt_gatt_callbacks->client->%s", #P_CBACK); \ 7140cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson do_in_jni_thread(Bind(bt_gatt_callbacks->client->P_CBACK, __VA_ARGS__)); \ 7240cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } else { \ 7340cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson ASSERTC(0, "Callback is NULL", 0); \ 7440cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } \ 7540cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } while (0) 76da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski 7740cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson#define CHECK_BTGATT_INIT() \ 7840cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson do { \ 7940cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson if (bt_gatt_callbacks == NULL) { \ 8040cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson LOG_WARN(LOG_TAG, "%s: BTGATT not initialized", __func__); \ 8140cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson return BT_STATUS_NOT_READY; \ 8240cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } else { \ 8340cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson LOG_VERBOSE(LOG_TAG, "%s", __func__); \ 8440cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } \ 8540cde56d28ab9751ba76bded0b7ac5974c750a97Myles Watson } while (0) 86ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 876bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson#define BLE_RESOLVE_ADDR_MSB \ 886bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson 0x40 /* bit7, bit6 is 01 to be resolvable random \ 8944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski */ 9044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski#define BLE_RESOLVE_ADDR_MASK 0xc0 /* bit 6, and bit7 */ 91c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowskiinline bool BTM_BLE_IS_RESOLVE_BDA(const bt_bdaddr_t& x) { 92c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski return ((x.address)[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB; 93c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski} 9444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskinamespace { 95ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 9644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskiuint8_t rssi_request_client_if; 97ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 986bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watsonvoid btif_gattc_upstreams_evt(uint16_t event, char* p_param) { 99b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen LOG_VERBOSE(LOG_TAG, "%s: Event %d", __func__, event); 100ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 1016bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson tBTA_GATTC* p_data = (tBTA_GATTC*)p_param; 10244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski switch (event) { 10344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_DEREG_EVT: 10444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 105ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 10644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_EXEC_EVT: { 10744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->execute_write_cb, 10844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->exec_cmpl.conn_id, p_data->exec_cmpl.status); 10944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 11044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 111ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 11244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_SEARCH_CMPL_EVT: { 11344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->search_complete_cb, 11444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->search_cmpl.conn_id, p_data->search_cmpl.status); 11544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 11644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 117ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 11844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_NOTIF_EVT: { 11944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski btgatt_notify_params_t data; 120ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 121c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski data.bda = p_data->notify.bda; 12244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski memcpy(data.value, p_data->notify.value, p_data->notify.len); 123ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 12444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski data.handle = p_data->notify.handle; 12544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski data.is_notify = p_data->notify.is_notify; 12644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski data.len = p_data->notify.len; 127ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 12844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->notify_cb, p_data->notify.conn_id, 12996ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski data); 130ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 131b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen if (p_data->notify.is_notify == false) 13244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski BTA_GATTC_SendIndConfirm(p_data->notify.conn_id, p_data->notify.handle); 1339dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski 13444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 13544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 136ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 13744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_OPEN_EVT: { 138c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski DVLOG(1) << "BTA_GATTC_OPEN_EVT " << p_data->open.remote_bda; 13944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->open_cb, p_data->open.conn_id, 140c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski p_data->open.status, p_data->open.client_if, 14196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski p_data->open.remote_bda); 1426975b4d711142b885af479721cada448952c6b41Andre Eisenbach 14344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski if (GATT_DEF_BLE_MTU_SIZE != p_data->open.mtu && p_data->open.mtu) { 14444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, 14544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->open.conn_id, p_data->open.status, p_data->open.mtu); 14644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 1479426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach 14844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski if (p_data->open.status == BTA_GATT_OK) 14944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski btif_gatt_check_encrypted_link(p_data->open.remote_bda, 15044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->open.transport); 15144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 15244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 153ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 15444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CLOSE_EVT: { 15544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->close_cb, p_data->close.conn_id, 156c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski p_data->status, p_data->close.client_if, 15796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski p_data->close.remote_bda); 15844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 15944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 160ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 16144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_ACL_EVT: 16244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski LOG_DEBUG(LOG_TAG, "BTA_GATTC_ACL_EVT: status = %d", p_data->status); 16344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski /* Ignore for now */ 16444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 1659426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach 16644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CANCEL_OPEN_EVT: 16744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 16817b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach 16944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CFG_MTU_EVT: { 17044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, 17144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->cfg_mtu.conn_id, p_data->cfg_mtu.status, 17244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->cfg_mtu.mtu); 17344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 174ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 1758444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach 17644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski case BTA_GATTC_CONGEST_EVT: 17744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->congestion_cb, 17844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski p_data->congest.conn_id, p_data->congest.congested); 17944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 18044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski 181eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski case BTA_GATTC_PHY_UPDATE_EVT: 182eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->phy_updated_cb, 183eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski p_data->phy_update.conn_id, p_data->phy_update.tx_phy, 184eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski p_data->phy_update.rx_phy, p_data->phy_update.status); 185eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski break; 186eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski 187b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski case BTA_GATTC_CONN_UPDATE_EVT: 188b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->conn_updated_cb, 189b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski p_data->conn_update.conn_id, p_data->conn_update.interval, 190b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski p_data->conn_update.latency, p_data->conn_update.timeout, 191b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski p_data->conn_update.status); 192b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski break; 193b5ba4fdbc433544de3806f8e82976898e444b491Jakub Pawlowski 19444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski default: 195b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen LOG_ERROR(LOG_TAG, "%s: Unhandled event (%d)!", __func__, event); 19644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski break; 19744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski } 198ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 199ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 2006bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watsonvoid bta_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) { 20124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski bt_status_t status = 20224ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski btif_transfer_context(btif_gattc_upstreams_evt, (uint16_t)event, 2036bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson (char*)p_data, sizeof(tBTA_GATTC), NULL); 20444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status); 205ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 206ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 2076bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watsonvoid btm_read_rssi_cb(tBTM_RSSI_RESULTS* p_result) { 2086bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson if (!p_result) return; 2097294d958dcb610d7828f06c3a1cde933127694d3Jakub Pawlowski 210c171ac407cfc6d30a11af6b12ead39688eb897f7Jakub Pawlowski CLI_CBACK_IN_JNI(read_remote_rssi_cb, rssi_request_client_if, 21196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski p_result->rem_bda, p_result->rssi, p_result->status); 212ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 213ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 214ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/******************************************************************************* 2156bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson * Client API Functions 216ee96a3c60fca590d38025925c072d264e06493c4Myles Watson ******************************************************************************/ 217ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 21896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_register_app(const bt_uuid_t& uuid) { 219c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski CHECK_BTGATT_INIT(); 220c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski 221c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski tBT_UUID bt_uuid; 22296ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btif_to_bta_uuid(&bt_uuid, &uuid); 223221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski 224221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski return do_in_jni_thread(Bind( 225221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski [](tBT_UUID bt_uuid) { 226221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski BTA_GATTC_AppRegister( 227221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bta_gattc_cback, 228221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski base::Bind( 229221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski [](tBT_UUID bt_uuid, uint8_t client_id, uint8_t status) { 230221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski do_in_jni_thread(Bind( 231221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski [](tBT_UUID bt_uuid, uint8_t client_id, uint8_t status) { 232221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid_t app_uuid; 233221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bta_to_btif_uuid(&app_uuid, &bt_uuid); 234221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->register_client_cb, 23596ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski status, client_id, app_uuid); 236221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski }, 237221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid, client_id, status)); 238221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski }, 239221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid)); 240221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski }, 241221e9bf6c9e9f974efd92ea4f054dbdba248d2dbJakub Pawlowski bt_uuid)); 242c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski} 243c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski 24444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskivoid btif_gattc_unregister_app_impl(int client_if) { 245c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski BTA_GATTC_AppDeregister(client_if); 246c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski} 247c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski 24844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_unregister_app(int client_if) { 249c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski CHECK_BTGATT_INIT(); 250c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski return do_in_jni_thread(Bind(&btif_gattc_unregister_app_impl, client_if)); 251ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 252ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 253c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowskivoid btif_gattc_open_impl(int client_if, bt_bdaddr_t address, bool is_direct, 25496fb273d92a31204edcf43ab2594a19876d14056Jakub Pawlowski int transport_p, 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); 30947474c3e584806e0b49b27e1e5330c1e6646cfb9Jakub Pawlowski BTA_GATTC_Open(client_if, address, is_direct, transport, false, 31047474c3e584806e0b49b27e1e5330c1e6646cfb9Jakub Pawlowski initiating_phys); 31126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski} 31226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski 31396ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_open(int client_if, const bt_bdaddr_t& bd_addr, 31496fb273d92a31204edcf43ab2594a19876d14056Jakub Pawlowski bool is_direct, int transport, 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, 319c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski is_direct, transport, initiating_phys)); 320ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 321ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 322c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowskivoid btif_gattc_close_impl(int client_if, bt_bdaddr_t address, int conn_id) { 323b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski // Disconnect established connections 324b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski if (conn_id != 0) 325b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski BTA_GATTC_Close(conn_id); 326b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski else 327b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen BTA_GATTC_CancelOpen(client_if, address, true); 328b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski 329b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski // Cancel pending background connections (remove from whitelist) 330b7f64bc45dec7f7fec74ceb04874f322b9434bbfMarie Janssen BTA_GATTC_CancelOpen(client_if, address, false); 331b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski} 332b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski 33396ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_close(int client_if, const bt_bdaddr_t& bd_addr, 33444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int conn_id) { 335b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski CHECK_BTGATT_INIT(); 336b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski return do_in_jni_thread( 33796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski Bind(&btif_gattc_close_impl, client_if, bd_addr, conn_id)); 338ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 339ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 34096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_refresh(int client_if, const bt_bdaddr_t& bd_addr) { 341140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski CHECK_BTGATT_INIT(); 34296ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_Refresh, bd_addr)); 343ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 344ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 34596ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_search_service(int conn_id, 34696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const bt_uuid_t* filter_uuid) { 347d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski CHECK_BTGATT_INIT(); 348d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski 349d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski if (filter_uuid) { 3506bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson tBT_UUID* uuid = new tBT_UUID; 351d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski btif_to_bta_uuid(uuid, filter_uuid); 352d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski return do_in_jni_thread( 353d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski Bind(&BTA_GATTC_ServiceSearchRequest, conn_id, base::Owned(uuid))); 354d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski } else { 355d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski return do_in_jni_thread( 356d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski Bind(&BTA_GATTC_ServiceSearchRequest, conn_id, nullptr)); 357d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski } 358ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 359ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 36096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskivoid btif_gattc_discover_service_by_uuid(int conn_id, const bt_uuid_t& p_uuid) { 36145aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski tBT_UUID* uuid = new tBT_UUID; 36296ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btif_to_bta_uuid(uuid, &p_uuid); 36345aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski do_in_jni_thread( 36445aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski Bind(&BTA_GATTC_DiscoverServiceByUuid, conn_id, base::Owned(uuid))); 36545aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski} 36645aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski 36761a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowskivoid btif_gattc_get_gatt_db_impl(int conn_id) { 3686bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson btgatt_db_element_t* db = NULL; 36961a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski int count = 0; 37061a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski BTA_GATTC_GetGattDb(conn_id, 0x0000, 0xFFFF, &db, &count); 371533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski 37261a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->get_gatt_db_cb, conn_id, db, count); 37361a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski osi_free(db); 37461a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski} 37561a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski 37644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_get_gatt_db(int conn_id) { 37761a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski CHECK_BTGATT_INIT(); 37861a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski return do_in_jni_thread(Bind(&btif_gattc_get_gatt_db_impl, conn_id)); 379533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski} 380533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski 38124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid read_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 3826bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson uint16_t len, uint8_t* value, void* data) { 3836bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson btgatt_read_params_t* params = new btgatt_read_params_t; 38424ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->value_type = 0x00 /* GATTC_READ_VALUE_TYPE_VALUE */; 38524ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->status = status; 38624ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->handle = handle; 38724ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski params->value.len = len; 388f2af1c42ccb2f642b241c2261b42d0be61d45438Jack He CHECK(len <= BTGATT_MAX_ATTR_LEN); 38924ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski if (len > 0) memcpy(params->value.value, value, len); 39024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 391f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // clang-tidy analyzer complains about |params| is leaked. It doesn't know 392f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // that |param| will be freed by the callback function. 393f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang CLI_CBACK_IN_JNI(read_characteristic_cb, conn_id, status, /* NOLINT */ 39424ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski base::Owned(params)); 39524ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 39624ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 39744be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_read_char(int conn_id, uint16_t handle, int auth_req) { 39861a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski CHECK_BTGATT_INIT(); 39924ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_ReadCharacteristic, conn_id, handle, 40024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski auth_req, read_char_cb, nullptr)); 40124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 40224ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 4037dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowskivoid read_using_char_uuid_cb(uint16_t conn_id, tGATT_STATUS status, 4047dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski uint16_t handle, uint16_t len, uint8_t* value, 4057dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski void* data) { 4067dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski btgatt_read_params_t* params = new btgatt_read_params_t; 4077dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->value_type = 0x00 /* GATTC_READ_VALUE_TYPE_VALUE */; 4087dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->status = status; 4097dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->handle = handle; 4107dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski params->value.len = len; 4117dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski CHECK(len <= BTGATT_MAX_ATTR_LEN); 4127dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski if (len > 0) memcpy(params->value.value, value, len); 4137dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski 414f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // clang-tidy analyzer complains about |params| is leaked. It doesn't know 415f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang // that |param| will be freed by the callback function. 416f69ddd4515ea69fdbd42825a0ee4ec80c8b8a718Ting-Yuan Huang CLI_CBACK_IN_JNI(read_characteristic_cb, conn_id, status, /* NOLINT */ 4177dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski base::Owned(params)); 4187dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski} 4197dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski 42096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_read_using_char_uuid(int conn_id, const bt_uuid_t& uuid, 4217dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski uint16_t s_handle, 4227dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski uint16_t e_handle, int auth_req) { 4237dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski CHECK_BTGATT_INIT(); 4247dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski tBT_UUID bt_uuid; 42596ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btif_to_bta_uuid(&bt_uuid, &uuid); 4267dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_ReadUsingCharUuid, conn_id, bt_uuid, 4277dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski s_handle, e_handle, auth_req, 4287dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski read_using_char_uuid_cb, nullptr)); 4297dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski} 4307dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski 43124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid read_desc_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 4326bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson uint16_t len, uint8_t* value, void* data) { 43396ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski btgatt_read_params_t params; 43496ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.value_type = 0x00 /* GATTC_READ_VALUE_TYPE_VALUE */; 43596ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.status = status; 43696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.handle = handle; 43796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski params.value.len = len; 438f2af1c42ccb2f642b241c2261b42d0be61d45438Jack He CHECK(len <= BTGATT_MAX_ATTR_LEN); 43996ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski if (len > 0) memcpy(params.value.value, value, len); 44024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 44196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski CLI_CBACK_IN_JNI(read_descriptor_cb, conn_id, status, params); 442ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 443ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 44444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_read_char_descr(int conn_id, uint16_t handle, 44544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int auth_req) { 44661a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski CHECK_BTGATT_INIT(); 44724ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_ReadCharDescr, conn_id, handle, 44824ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski auth_req, read_desc_cb, nullptr)); 44924ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 45024ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 45124ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid write_char_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 4526bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson void* data) { 45324ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski CLI_CBACK_IN_JNI(write_characteristic_cb, conn_id, status, handle); 454ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 455ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 45644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_write_char(int conn_id, uint16_t handle, int write_type, 457ec79baaaed83529dae14d492ea2f73aedee9e4d0Jakub Pawlowski int auth_req, vector<uint8_t> value) { 45839a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski CHECK_BTGATT_INIT(); 45939a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski 4606bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson if (value.size() > BTGATT_MAX_ATTR_LEN) value.resize(BTGATT_MAX_ATTR_LEN); 46139a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski 46239a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharValue, conn_id, handle, 46324ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski write_type, std::move(value), auth_req, 46424ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski write_char_cb, nullptr)); 46524ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski} 46624ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski 46724ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowskivoid write_descr_cb(uint16_t conn_id, tGATT_STATUS status, uint16_t handle, 4686bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson void* data) { 46924ea892320ca85c7f6cdd77343da50818fe29002Jakub Pawlowski CLI_CBACK_IN_JNI(write_descriptor_cb, conn_id, status, handle); 470ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 471ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 47244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle, 473bb920a65b959fbb593403587f89bc3fc7e831732Jakub Pawlowski int auth_req, vector<uint8_t> value) { 474ec79baaaed83529dae14d492ea2f73aedee9e4d0Jakub Pawlowski CHECK_BTGATT_INIT(); 475ec79baaaed83529dae14d492ea2f73aedee9e4d0Jakub Pawlowski 4766bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson if (value.size() > BTGATT_MAX_ATTR_LEN) value.resize(BTGATT_MAX_ATTR_LEN); 47739a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski 47839a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharDescr, conn_id, handle, 4796bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson std::move(value), auth_req, write_descr_cb, 4806bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson nullptr)); 481ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 482ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 48344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_execute_write(int conn_id, int execute) { 484a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski CHECK_BTGATT_INIT(); 485a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski return do_in_jni_thread( 486a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski Bind(&BTA_GATTC_ExecuteWrite, conn_id, (uint8_t)execute)); 487ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 488ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 48944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskivoid btif_gattc_reg_for_notification_impl(tBTA_GATTC_IF client_if, 49096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const bt_bdaddr_t& bda, 491c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski uint16_t handle) { 492c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski tBTA_GATT_STATUS status = 493c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_GATTC_RegisterForNotifications(client_if, bda, handle); 494ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 49544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski // TODO(jpawlowski): conn_id is currently unused 496ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb, 497ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski /* conn_id */ 0, 1, status, handle); 498ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 499ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 50044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_reg_for_notification(int client_if, 50196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const bt_bdaddr_t& bd_addr, 50244be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski uint16_t handle) { 503ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski CHECK_BTGATT_INIT(); 504ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 505ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski return do_in_jni_thread( 506ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski Bind(base::IgnoreResult(&btif_gattc_reg_for_notification_impl), client_if, 50796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski bd_addr, handle)); 508ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski} 509ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 51044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskivoid btif_gattc_dereg_for_notification_impl(tBTA_GATTC_IF client_if, 51196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const bt_bdaddr_t& bda, 5126bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson uint16_t handle) { 513c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski tBTA_GATT_STATUS status = 514c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_GATTC_DeregisterForNotifications(client_if, bda, handle); 515ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 51644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski // TODO(jpawlowski): conn_id is currently unused 517ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb, 518ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski /* conn_id */ 0, 0, status, handle); 519ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski} 520ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 52144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_dereg_for_notification(int client_if, 52296ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const bt_bdaddr_t& bd_addr, 52344be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski uint16_t handle) { 524ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski CHECK_BTGATT_INIT(); 525ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski 526ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski return do_in_jni_thread( 527ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski Bind(base::IgnoreResult(&btif_gattc_dereg_for_notification_impl), 52896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski client_if, bd_addr, handle)); 529ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 530ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 53144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_read_remote_rssi(int client_if, 53296ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const bt_bdaddr_t& bd_addr) { 533c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski CHECK_BTGATT_INIT(); 534c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski rssi_request_client_if = client_if; 535c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski 53696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski return do_in_jni_thread(Bind(base::IgnoreResult(&BTM_ReadRSSI), bd_addr, 5376bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson (tBTM_CMPL_CB*)btm_read_rssi_cb)); 538ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 539ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 54044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowskibt_status_t btif_gattc_configure_mtu(int conn_id, int mtu) { 541c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski CHECK_BTGATT_INIT(); 542c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski return do_in_jni_thread( 543c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski Bind(base::IgnoreResult(&BTA_GATTC_ConfigureMTU), conn_id, mtu)); 5449426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach} 5459426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach 5463021c5a5aac9760e8c4885cbf9c220d1b04dbdb3Jakub Pawlowskivoid btif_gattc_conn_parameter_update_impl(bt_bdaddr_t addr, int min_interval, 5477cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski int max_interval, int latency, 5487cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski int timeout) { 549c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski if (BTA_DmGetConnectionState(addr)) 550c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_DmBleUpdateConnectionParams(addr, min_interval, max_interval, latency, 551c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski timeout); 5527cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski else 553c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski BTA_DmSetBlePrefConnParams(addr, min_interval, max_interval, latency, 554c2276b06572ab6fc1f900fbb1f41087e77d47e2aJakub Pawlowski timeout); 5557cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski} 5567cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski 55796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_conn_parameter_update(const bt_bdaddr_t& bd_addr, 55844be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int min_interval, int max_interval, 55944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int latency, int timeout) { 5607cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski CHECK_BTGATT_INIT(); 5617cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski return do_in_jni_thread( 56296ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski Bind(base::IgnoreResult(&btif_gattc_conn_parameter_update_impl), bd_addr, 5636bd442f543972b072ef2cbbcf2f7c91202de1045Myles Watson min_interval, max_interval, latency, timeout)); 56452a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach} 56552a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach 5665a475e71a01322367a2ba591aecd62781902cfc2Avish Shahbt_status_t btif_gattc_set_preferred_phy(const bt_bdaddr_t& bd_addr, 5675a475e71a01322367a2ba591aecd62781902cfc2Avish Shah uint8_t tx_phy, uint8_t rx_phy, 5685a475e71a01322367a2ba591aecd62781902cfc2Avish Shah uint16_t phy_options) { 569eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski CHECK_BTGATT_INIT(); 5705a475e71a01322367a2ba591aecd62781902cfc2Avish Shah do_in_bta_thread(FROM_HERE, 5715a475e71a01322367a2ba591aecd62781902cfc2Avish Shah Bind(&BTM_BleSetPhy, bd_addr, tx_phy, rx_phy, phy_options)); 572eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski return BT_STATUS_SUCCESS; 573eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski} 574eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski 575eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowskibt_status_t btif_gattc_read_phy( 5765a475e71a01322367a2ba591aecd62781902cfc2Avish Shah const bt_bdaddr_t& bd_addr, 577eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb) { 578eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski CHECK_BTGATT_INIT(); 5795a475e71a01322367a2ba591aecd62781902cfc2Avish Shah do_in_bta_thread(FROM_HERE, Bind(&BTM_BleReadPhy, bd_addr, 580eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski jni_thread_wrapper(FROM_HERE, cb))); 581eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski return BT_STATUS_SUCCESS; 582eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski} 583eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski 58496ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskiint btif_gattc_get_device_type(const bt_bdaddr_t& bd_addr) { 58544be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski int device_type = 0; 58644be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski char bd_addr_str[18] = {0}; 587ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 58896ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski bdaddr_to_string(&bd_addr, bd_addr_str, sizeof(bd_addr_str)); 58944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski if (btif_config_get_int(bd_addr_str, "DevType", &device_type)) 59044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski return device_type; 59144be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski return 0; 592ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 593ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 59496ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t btif_gattc_test_command(int command, 59596ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const btgatt_test_params_t& params) { 59696ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski return btif_gattc_test_command_impl(command, ¶ms); 597ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 598ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 59944be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski} // namespace 60044be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski 601ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battaconst btgatt_client_interface_t btgattClientInterface = { 602ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_register_app, 603ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_unregister_app, 604ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_open, 605ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_close, 606ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_refresh, 607ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_search_service, 60845aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski btif_gattc_discover_service_by_uuid, 609ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_read_char, 6107dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski btif_gattc_read_using_char_uuid, 611ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_write_char, 612ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_read_char_descr, 613ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_write_char_descr, 614ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_execute_write, 615ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_reg_for_notification, 616ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_dereg_for_notification, 617ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_read_remote_rssi, 618ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btif_gattc_get_device_type, 6199426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach btif_gattc_configure_mtu, 62052a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach btif_gattc_conn_parameter_update, 621eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski btif_gattc_set_preferred_phy, 622eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski btif_gattc_read_phy, 623533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski btif_gattc_test_command, 62444be0690a1d15d1ffc97e4c7560d8aee5bb86062Jakub Pawlowski btif_gattc_get_gatt_db}; 625