btif_gatt_client.cc revision da5b59b5bf9cb34574c16ba784c1484055fcb1e3
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 *
25ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta *******************************************************************************/
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 <stdio.h>
35ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <stdlib.h>
36ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include <string.h>
376ed1548be2295fc1bec14f10cd0fade4f63daa6aSatya Calloji#include "device/include/controller.h"
386ed1548be2295fc1bec14f10cd0fade4f63daa6aSatya Calloji
39ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
4095b74f252f534ec757aab1fc08e086e02b2cfe8dSharvil Nanavati#include "btcore/include/bdaddr.h"
41ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_common.h"
42ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_util.h"
43ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
44ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
45ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
466975b4d711142b885af479721cada448952c6b41Andre Eisenbach#include <hardware/bt_gatt.h>
47db554581079863974af8e1289646f5deea6fc044Marie Janssen
48ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_api.h"
49ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "bta_gatt_api.h"
50ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_config.h"
51db554581079863974af8e1289646f5deea6fc044Marie Janssen#include "btif_dm.h"
52ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt.h"
53db554581079863974af8e1289646f5deea6fc044Marie Janssen#include "btif_gatt_multi_adv_util.h"
54ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_gatt_util.h"
55ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#include "btif_storage.h"
56db554581079863974af8e1289646f5deea6fc044Marie Janssen#include "btif_storage.h"
5744802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati#include "osi/include/log.h"
58b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach#include "vendor_api.h"
59b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach
60140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskiusing base::Bind;
61140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskiusing base::Owned;
62140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski
63140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskiextern bt_status_t do_in_jni_thread(const base::Closure& task);
64140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski
65ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
66ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**  Constants & Macros
67ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta********************************************************************************/
68ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
69da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski#define CLI_CBACK_IN_JNI(P_CBACK, ...)                                       \
70da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski  if (bt_gatt_callbacks && bt_gatt_callbacks->client->P_CBACK) {             \
71da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski    BTIF_TRACE_API("HAL bt_gatt_callbacks->client->%s", #P_CBACK);           \
72da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski    do_in_jni_thread(Bind(bt_gatt_callbacks->client->P_CBACK, __VA_ARGS__)); \
73da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski  } else {                                                                   \
74da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski    ASSERTC(0, "Callback is NULL", 0);                                       \
75da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski  }
76da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski
77ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#define CHECK_BTGATT_INIT() if (bt_gatt_callbacks == NULL)\
78ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {\
79db554581079863974af8e1289646f5deea6fc044Marie Janssen        LOG_WARN(LOG_TAG, "%s: BTGATT not initialized", __FUNCTION__);\
80ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        return BT_STATUS_NOT_READY;\
81ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    } else {\
82db554581079863974af8e1289646f5deea6fc044Marie Janssen        LOG_VERBOSE(LOG_TAG, "%s", __FUNCTION__);\
83ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
84ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
85a1e649b2566040d1f9e620753f18ca1fc088c64fAndre Eisenbach#define BLE_RESOLVE_ADDR_MSB                 0x40   /* bit7, bit6 is 01 to be resolvable random */
86a1e649b2566040d1f9e620753f18ca1fc088c64fAndre Eisenbach#define BLE_RESOLVE_ADDR_MASK                0xc0   /* bit 6, and bit7 */
87a1e649b2566040d1f9e620753f18ca1fc088c64fAndre Eisenbach#define BTM_BLE_IS_RESOLVE_BDA(x)           ((x[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB)
88ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
89ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#define BTIF_GATT_MAX_OBSERVED_DEV 40
90ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
91ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#define BTIF_GATT_OBSERVE_EVT   0x1000
92ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#define BTIF_GATTC_RSSI_EVT     0x1001
93979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach#define BTIF_GATTC_SCAN_FILTER_EVT  0x1003
94ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
95c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji#define ENABLE_BATCH_SCAN 1
96c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji#define DISABLE_BATCH_SCAN 0
97c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
98ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
99ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**  Local type definitions
100ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta********************************************************************************/
101c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Callojitypedef struct
102c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji{
103c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t report_format;
104c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint16_t data_len;
105c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t num_records;
106c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t *p_rep_data;
107c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji} btgatt_batch_reports;
108c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
109c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Callojitypedef struct
110c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji{
111c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t  status;
112c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t  client_if;
1131acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji    uint8_t  action;
1141acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji    uint8_t  avbl_space;
1151acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji    uint8_t  lost_timeout;
116f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji    tBLE_ADDR_TYPE addr_type;
117c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t  batch_scan_full_max;
118c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t  batch_scan_trunc_max;
119c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint8_t  batch_scan_notify_threshold;
120979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach    tBTA_BLE_BATCH_SCAN_MODE scan_mode;
121c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint32_t scan_interval;
122c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    uint32_t scan_window;
123c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    tBTA_BLE_DISCARD_RULE discard_rule;
124f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji    btgatt_batch_reports  read_reports;
125c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji} btgatt_batch_track_cb_t;
126ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1271a9247a1229aa65b3d1dce16426177bc5828e54dSatya Callojitypedef tBTA_DM_BLE_PF_FILT_PARAMS btgatt_adv_filt_param_t;
1281a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji
1291a9247a1229aa65b3d1dce16426177bc5828e54dSatya Callojitypedef struct
1301a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji{
1311a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     client_if;
1321a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     action;
1331a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    tBTA_DM_BLE_PF_COND_TYPE filt_type;
1341a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    bt_bdaddr_t bd_addr;
1351a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     value[BTGATT_MAX_ATTR_LEN];
1361a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     value_len;
1371a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     filt_index;
1381a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint16_t    conn_id;
1391a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint16_t    company_id_mask;
1401a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    bt_uuid_t   uuid;
1411a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    bt_uuid_t   uuid_mask;
1421a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     value_mask[BTGATT_MAX_ATTR_LEN];
1431a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     value_mask_len;
1441a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     has_mask;
1451a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     addr_type;
1461a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    uint8_t     status;
1471a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    tBTA_DM_BLE_PF_AVBL_SPACE avbl_space;
1481a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    tBTA_DM_BLE_SCAN_COND_OP cond_op;
1491a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    btgatt_adv_filt_param_t adv_filt_param;
1501a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji} btgatt_adv_filter_cb_t;
1511a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji
152ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct
153ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
154ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     value[BTGATT_MAX_ATTR_LEN];
155a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    uint8_t     inst_id;
156ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bt_bdaddr_t bd_addr;
157ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btgatt_srvc_id_t srvc_id;
158ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btgatt_srvc_id_t incl_srvc_id;
1595f9c140d094ebf4a269cdc6ae083900bf25f7faeAndre Eisenbach    btgatt_gatt_id_t char_id;
1605f9c140d094ebf4a269cdc6ae083900bf25f7faeAndre Eisenbach    btgatt_gatt_id_t descr_id;
1619dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski    uint16_t    handle;
162ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bt_uuid_t   uuid;
163b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach    bt_uuid_t   uuid_mask;
164ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint16_t    conn_id;
165ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint16_t    len;
166b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach    uint16_t    mask;
167979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach    uint32_t    scan_interval;
168979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach    uint32_t    scan_window;
169ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     client_if;
170ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     action;
171ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     is_direct;
172ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     search_all;
173ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     auth_req;
174ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     write_type;
175ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     status;
176ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t     addr_type;
1775c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    uint8_t     start;
178b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach    uint8_t     has_mask;
179ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    int8_t      rssi;
1807fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    uint8_t     flag;
181ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    tBT_DEVICE_TYPE device_type;
1827fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    btgatt_transport_t transport;
183ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} __attribute__((packed)) btif_gattc_cb_t;
184ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
185ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct
186ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
187ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bt_bdaddr_t bd_addr;
18852a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    uint16_t    min_interval;
18952a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    uint16_t    max_interval;
19052a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    uint16_t    timeout;
19152a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    uint16_t    latency;
19252a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach} btif_conn_param_cb_t;
19352a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach
19452a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbachtypedef struct
19552a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach{
19652a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    bt_bdaddr_t bd_addr;
197ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    BOOLEAN     in_use;
198ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}__attribute__((packed)) btif_gattc_dev_t;
199ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
200ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battatypedef struct
201ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
202ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_dev_t remote_dev[BTIF_GATT_MAX_OBSERVED_DEV];
2037fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    uint8_t            addr_type;
2047fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta    uint8_t            next_storage_idx;
205ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}__attribute__((packed)) btif_gattc_dev_cb_t;
206ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
207ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
208ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**  Static variables
209ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta********************************************************************************/
210ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
211ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battaextern const btgatt_callbacks_t *bt_gatt_callbacks;
212ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic btif_gattc_dev_cb_t  btif_gattc_dev_cb;
213ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic btif_gattc_dev_cb_t  *p_dev_cb = &btif_gattc_dev_cb;
214ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic uint8_t rssi_request_client_if;
215ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
216ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
217ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**  Static functions
218ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta********************************************************************************/
219ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
2209dd5a9c11f2022fa9709f0c34f04560c21105152Andre Eisenbachstatic bt_status_t btif_gattc_multi_adv_disable(int client_if);
22178bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavovstatic void btif_multi_adv_stop_cb(void *data)
2229dd5a9c11f2022fa9709f0c34f04560c21105152Andre Eisenbach{
22378bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavov    int client_if = PTR_TO_INT(data);
2249dd5a9c11f2022fa9709f0c34f04560c21105152Andre Eisenbach    btif_gattc_multi_adv_disable(client_if); // Does context switch
2259dd5a9c11f2022fa9709f0c34f04560c21105152Andre Eisenbach}
2269dd5a9c11f2022fa9709f0c34f04560c21105152Andre Eisenbach
227979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbachstatic btgattc_error_t btif_gattc_translate_btm_status(tBTM_STATUS status)
228979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach{
229979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach    switch(status)
230979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach    {
231979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_SUCCESS:
232979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_SUCCESS_NO_SECURITY:
233979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_COMMAND_SUCCESS;
234979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
235979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_CMD_STARTED:
236979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_COMMAND_STARTED;
237979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
238979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_BUSY:
239979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_COMMAND_BUSY;
240979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
241979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_CMD_STORED:
242979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_COMMAND_STORED;
243979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
244979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_NO_RESOURCES:
245979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_NO_RESOURCES;
246979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
247979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_MODE_UNSUPPORTED:
248979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_WRONG_MODE:
249979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_MODE4_LEVEL4_NOT_SUPPORTED:
250979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_MODE_UNSUPPORTED;
251979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
252979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_ILLEGAL_VALUE:
253979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_SCO_BAD_LENGTH:
254979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_ILLEGAL_VALUE;
255979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
256979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_UNKNOWN_ADDR:
257979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_UNKNOWN_ADDR;
258979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
259979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_DEVICE_TIMEOUT:
260979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_DEVICE_TIMEOUT;
261979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
262979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_FAILED_ON_SECURITY:
263979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_REPEATED_ATTEMPTS:
264979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_NOT_AUTHORIZED:
265979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_SECURITY_ERROR;
266979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
267979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_DEV_RESET:
268979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_ILLEGAL_ACTION:
269979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_INCORRECT_STATE;
270979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
271979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_BAD_VALUE_RET:
272979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_INVALID_CONTROLLER_OUTPUT;
273979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
274979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_DELAY_CHECK:
275979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach            return BT_GATTC_DELAYED_ENCRYPTION_CHECK;
276979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
277979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       case BTM_ERR_PROCESSING:
278979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach       default:
279979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach          return BT_GATTC_ERR_PROCESSING;
280979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach    }
281979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach}
282979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
2838444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbachstatic void btapp_gattc_req_data(UINT16 event, char *p_dest, char *p_src)
2848444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach{
28552a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    tBTA_GATTC *p_dest_data = (tBTA_GATTC*) p_dest;
28652a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    tBTA_GATTC *p_src_data = (tBTA_GATTC*) p_src;
2878444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
2888444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    if (!p_src_data || !p_dest_data)
2898444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach       return;
2908444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
2918444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    // Copy basic structure first
2923f06e14fddc0e674347ae28ea4a25218d4ce1d2aPavlin Radoslavov    maybe_non_aligned_memcpy(p_dest_data, p_src_data, sizeof(*p_src_data));
2938444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
2948444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    // Allocate buffer for request data if necessary
2958444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    switch (event)
2968444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    {
2978444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach        case BTA_GATTC_READ_CHAR_EVT:
2988444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach        case BTA_GATTC_READ_DESCR_EVT:
2998444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
300e4020c28c8a9dc56f927b03a8ca3a17d9401bc1eAndre Eisenbach            if (p_src_data->read.p_value != NULL)
3018444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            {
302713993d1784ab7c23aee1fa3cf1ab8676cc0aa69Jakub Pawlowski                p_dest_data->read.p_value = (tBTA_GATT_UNFMT *)osi_malloc(sizeof(tBTA_GATT_UNFMT));
3038444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
304717a4a9f3a044f264ec2482c2d1806ec3093707aPavlin Radoslavov                memcpy(p_dest_data->read.p_value, p_src_data->read.p_value,
3059dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                       sizeof(tBTA_GATT_UNFMT));
306717a4a9f3a044f264ec2482c2d1806ec3093707aPavlin Radoslavov
307717a4a9f3a044f264ec2482c2d1806ec3093707aPavlin Radoslavov                // Allocate buffer for att value if necessary
3089dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                if (p_src_data->read.p_value->len > 0 &&
3099dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                    p_src_data->read.p_value->p_value != NULL) {
3109dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                    p_dest_data->read.p_value->p_value =
311713993d1784ab7c23aee1fa3cf1ab8676cc0aa69Jakub Pawlowski                        (UINT8 *)osi_malloc(p_src_data->read.p_value->len);
3129dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                    memcpy(p_dest_data->read.p_value->p_value,
3139dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                           p_src_data->read.p_value->p_value,
3149dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                           p_src_data->read.p_value->len);
3158444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach                }
316717a4a9f3a044f264ec2482c2d1806ec3093707aPavlin Radoslavov            } else {
317e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati                BTIF_TRACE_WARNING("%s :Src read.p_value ptr is NULL for event  0x%x",
318e4020c28c8a9dc56f927b03a8ca3a17d9401bc1eAndre Eisenbach                                    __FUNCTION__, event);
319e4020c28c8a9dc56f927b03a8ca3a17d9401bc1eAndre Eisenbach                p_dest_data->read.p_value = NULL;
320e4020c28c8a9dc56f927b03a8ca3a17d9401bc1eAndre Eisenbach
321e4020c28c8a9dc56f927b03a8ca3a17d9401bc1eAndre Eisenbach            }
3228444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            break;
3238444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
3248444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach        default:
3258444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            break;
3268444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    }
3278444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach}
3288444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
3298444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbachstatic void btapp_gattc_free_req_data(UINT16 event, tBTA_GATTC *p_data)
3308444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach{
3318444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    switch (event)
3328444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    {
3338444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach        case BTA_GATTC_READ_CHAR_EVT:
3348444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach        case BTA_GATTC_READ_DESCR_EVT:
3358444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            if (p_data != NULL && p_data->read.p_value != NULL)
3368444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            {
3379dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                if (p_data->read.p_value->len > 0)
3389dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                    osi_free_and_reset((void **)&p_data->read.p_value->p_value);
3399dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski
340cceb430489a70add1b996d54289867c17f4ac0fdPavlin Radoslavov                osi_free_and_reset((void **)&p_data->read.p_value);
3418444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            }
3428444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            break;
3438444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
3448444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach        default:
3458444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach            break;
3468444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    }
3478444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach}
3488444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
349ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btif_gattc_init_dev_cb(void)
350ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
351ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    memset(p_dev_cb, 0, sizeof(btif_gattc_dev_cb_t));
352ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
353c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
354ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btif_gattc_add_remote_bdaddr (BD_ADDR p_bda, uint8_t addr_type)
355ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
356ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t i;
357ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    for (i = 0; i < BTIF_GATT_MAX_OBSERVED_DEV; i++)
358ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
359ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if (!p_dev_cb->remote_dev[i].in_use )
360ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
361ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            memcpy(p_dev_cb->remote_dev[i].bd_addr.address, p_bda, BD_ADDR_LEN);
362ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_dev_cb->addr_type = addr_type;
363ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            p_dev_cb->remote_dev[i].in_use = TRUE;
364db554581079863974af8e1289646f5deea6fc044Marie Janssen            LOG_VERBOSE(LOG_TAG, "%s device added idx=%d", __FUNCTION__, i  );
365ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
366ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
367ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
368ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
369ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    if ( i == BTIF_GATT_MAX_OBSERVED_DEV)
370ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
371ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        i= p_dev_cb->next_storage_idx;
372ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        memcpy(p_dev_cb->remote_dev[i].bd_addr.address, p_bda, BD_ADDR_LEN);
373ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_dev_cb->addr_type = addr_type;
374ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_dev_cb->remote_dev[i].in_use = TRUE;
375db554581079863974af8e1289646f5deea6fc044Marie Janssen        LOG_VERBOSE(LOG_TAG, "%s device overwrite idx=%d", __FUNCTION__, i  );
376ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        p_dev_cb->next_storage_idx++;
37716fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham        if (p_dev_cb->next_storage_idx >= BTIF_GATT_MAX_OBSERVED_DEV)
378ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta               p_dev_cb->next_storage_idx = 0;
379ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
380ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
381ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
382ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic BOOLEAN btif_gattc_find_bdaddr (BD_ADDR p_bda)
383ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
384ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t i;
385ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    for (i = 0; i < BTIF_GATT_MAX_OBSERVED_DEV; i++)
386ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
387ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        if (p_dev_cb->remote_dev[i].in_use &&
388ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            !memcmp(p_dev_cb->remote_dev[i].bd_addr.address, p_bda, BD_ADDR_LEN))
389ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
390ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            return TRUE;
391ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
392ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
393ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    return FALSE;
394ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
395ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
396ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btif_gattc_update_properties ( btif_gattc_cb_t *p_btif_cb )
397ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
398ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t remote_name_len;
399ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t *p_eir_remote_name=NULL;
400ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bt_bdname_t bdname;
401ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
402a50fc88c9f784a2422ceac014fea47ac1717647bZach Johnson    p_eir_remote_name = BTM_CheckEirData(p_btif_cb->value,
403ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                                         BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
404ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
40516fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    if (p_eir_remote_name == NULL)
406ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
407a50fc88c9f784a2422ceac014fea47ac1717647bZach Johnson        p_eir_remote_name = BTM_CheckEirData(p_btif_cb->value,
408ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                                BT_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
409ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
410ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
41116fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    if (p_eir_remote_name)
412ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
413bcbf9cd0727f6903f9cf6c165453539fc55b6072Mike J. Chen        memcpy(bdname.name, p_eir_remote_name, remote_name_len);
414bcbf9cd0727f6903f9cf6c165453539fc55b6072Mike J. Chen        bdname.name[remote_name_len]='\0';
415ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
416db554581079863974af8e1289646f5deea6fc044Marie Janssen        LOG_DEBUG(LOG_TAG, "%s BLE device name=%s len=%d dev_type=%d", __FUNCTION__, bdname.name,
417ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta              remote_name_len, p_btif_cb->device_type  );
418ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        btif_dm_update_ble_remote_properties( p_btif_cb->bd_addr.address,   bdname.name,
419ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                                               p_btif_cb->device_type);
420ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
421ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
422ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
423ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btif_gattc_upstreams_evt(uint16_t event, char* p_param)
424ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
425db554581079863974af8e1289646f5deea6fc044Marie Janssen    LOG_VERBOSE(LOG_TAG, "%s: Event %d", __FUNCTION__, event);
426ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
42752a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    tBTA_GATTC *p_data = (tBTA_GATTC*) p_param;
428ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    switch (event)
429ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
430ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_REG_EVT:
431ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
432ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bt_uuid_t app_uuid;
433ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bta_to_btif_uuid(&app_uuid, &p_data->reg_oper.app_uuid);
434ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->register_client_cb
435ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->reg_oper.status
436ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->reg_oper.client_if
437ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , &app_uuid
438ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            );
439ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
440ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
441ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
442ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_DEREG_EVT:
443ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
444ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
445ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_READ_CHAR_EVT:
446ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
447ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            btgatt_read_params_t data;
448ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            set_read_value(&data, &p_data->read);
449ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
450ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->read_characteristic_cb
451ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->read.conn_id, p_data->read.status, &data);
452ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
453ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
454ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
455ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_WRITE_CHAR_EVT:
456ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_PREP_WRITE_EVT:
457ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
4589dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski            HAL_CBACK(bt_gatt_callbacks, client->write_characteristic_cb,
4599dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                p_data->write.conn_id, p_data->write.status, p_data->write.handle);
460ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
461ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
462ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
463ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_EXEC_EVT:
464ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
465ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->execute_write_cb
466ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->exec_cmpl.conn_id, p_data->exec_cmpl.status
467ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            );
468ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
469ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
470ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
471ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_SEARCH_CMPL_EVT:
472ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
473ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->search_complete_cb
474ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->search_cmpl.conn_id, p_data->search_cmpl.status);
475ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
476ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
477ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
478ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_READ_DESCR_EVT:
479ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
480ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            btgatt_read_params_t data;
481ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            set_read_value(&data, &p_data->read);
482ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
483ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->read_descriptor_cb
484ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->read.conn_id, p_data->read.status, &data);
485ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
486ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
487ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
488ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_WRITE_DESCR_EVT:
489ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
4909dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski            HAL_CBACK(bt_gatt_callbacks, client->write_descriptor_cb,
4919dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                p_data->write.conn_id, p_data->write.status, p_data->write.handle);
492ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
493ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
494ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
495ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_NOTIF_EVT:
496ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
497ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            btgatt_notify_params_t data;
498ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
499ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bdcpy(data.bda.address, p_data->notify.bda);
500ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            memcpy(data.value, p_data->notify.value, p_data->notify.len);
501ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
5029dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski            data.handle = p_data->notify.handle;
503ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            data.is_notify = p_data->notify.is_notify;
504ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            data.len = p_data->notify.len;
505ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
5069dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski            HAL_CBACK(bt_gatt_callbacks, client->notify_cb, p_data->notify.conn_id, &data);
507ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
508ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (p_data->notify.is_notify == FALSE)
5099dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski                BTA_GATTC_SendIndConfirm(p_data->notify.conn_id, p_data->notify.handle);
5109dc998503590163068845827d951fc2f05a17bdaJakub Pawlowski
511ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
512ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
513ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
514ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_OPEN_EVT:
515ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
516ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bt_bdaddr_t bda;
517ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bdcpy(bda.address, p_data->open.remote_bda);
518ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
519ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->open_cb, p_data->open.conn_id
520ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->open.status, p_data->open.client_if, &bda);
5216975b4d711142b885af479721cada448952c6b41Andre Eisenbach
5229426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach            if (GATT_DEF_BLE_MTU_SIZE != p_data->open.mtu && p_data->open.mtu)
5239426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach            {
5249426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach                HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, p_data->open.conn_id
5259426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach                    , p_data->open.status , p_data->open.mtu);
5269426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach            }
5279426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach
5286975b4d711142b885af479721cada448952c6b41Andre Eisenbach            if (p_data->open.status == BTA_GATT_OK)
5294f6c9b4f68d152baf7aa029cbe9b570994584101Nitin Arora                btif_gatt_check_encrypted_link(p_data->open.remote_bda, p_data->open.transport);
530ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
531ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
532ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
533ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_CLOSE_EVT:
534ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
535ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bt_bdaddr_t bda;
536ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bdcpy(bda.address, p_data->close.remote_bda);
537ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->close_cb, p_data->close.conn_id
538ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                , p_data->status, p_data->close.client_if, &bda);
539ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
540ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
541ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
542ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_ACL_EVT:
543db554581079863974af8e1289646f5deea6fc044Marie Janssen            LOG_DEBUG(LOG_TAG, "BTA_GATTC_ACL_EVT: status = %d", p_data->status);
544ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            /* Ignore for now */
545ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
546ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
547ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_GATTC_CANCEL_OPEN_EVT:
548ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
549ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
550ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTIF_GATT_OBSERVE_EVT:
551ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
55252a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*) p_param;
553aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi            uint8_t remote_name_len;
554aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi            uint8_t *p_eir_remote_name=NULL;
5557fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            bt_device_type_t dev_type;
5567fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            bt_property_t properties;
557aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi
558a50fc88c9f784a2422ceac014fea47ac1717647bZach Johnson            p_eir_remote_name = BTM_CheckEirData(p_btif_cb->value,
559aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi                                         BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
560aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi
56116fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham            if (p_eir_remote_name == NULL)
562ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
563a50fc88c9f784a2422ceac014fea47ac1717647bZach Johnson                p_eir_remote_name = BTM_CheckEirData(p_btif_cb->value,
564aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi                                BT_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
565aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi            }
566aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi
567aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi            if ((p_btif_cb->addr_type != BLE_ADDR_RANDOM) || (p_eir_remote_name))
568aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi            {
569aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi               if (!btif_gattc_find_bdaddr(p_btif_cb->bd_addr.address))
570aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi               {
571aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi                  btif_gattc_add_remote_bdaddr(p_btif_cb->bd_addr.address, p_btif_cb->addr_type);
572aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi                  btif_gattc_update_properties(p_btif_cb);
573aefcb184639ff24bf294dfa4f91bd22202d1f93eSunny Kapdi               }
574ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
5757fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta
576713993d1784ab7c23aee1fa3cf1ab8676cc0aa69Jakub Pawlowski             dev_type = (bt_device_type_t) p_btif_cb->device_type;
5777fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta             BTIF_STORAGE_FILL_PROPERTY(&properties,
5787fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta                        BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
5797fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta             btif_storage_set_remote_device_property(&(p_btif_cb->bd_addr), &properties);
5807fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta
5817b9fe757f5df8c529c506b1c41403f2f3f204f9eAndre Eisenbach            btif_storage_set_remote_addr_type( &p_btif_cb->bd_addr, p_btif_cb->addr_type);
5827b9fe757f5df8c529c506b1c41403f2f3f204f9eAndre Eisenbach
583ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->scan_result_cb,
584ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                      &p_btif_cb->bd_addr, p_btif_cb->rssi, p_btif_cb->value);
585ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
586ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
587ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
588ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTIF_GATTC_RSSI_EVT:
589ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
59052a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*) p_param;
591ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            HAL_CBACK(bt_gatt_callbacks, client->read_remote_rssi_cb, p_btif_cb->client_if,
592ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                      &p_btif_cb->bd_addr, p_btif_cb->rssi, p_btif_cb->status);
593ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
594ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
595ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
5965c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        case BTA_GATTC_LISTEN_EVT:
5975c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        {
5985c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            HAL_CBACK(bt_gatt_callbacks, client->listen_cb
5995c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                , p_data->reg_oper.status
6005c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach                , p_data->reg_oper.client_if
6015c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            );
6025c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach            break;
6035c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach        }
6049426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach
6059426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach        case BTA_GATTC_CFG_MTU_EVT:
6069426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach        {
6079426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach            HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, p_data->cfg_mtu.conn_id
6089426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach                , p_data->cfg_mtu.status , p_data->cfg_mtu.mtu);
6099426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach            break;
6109426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach        }
61117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach
612a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_GATTC_MULT_ADV_ENB_EVT:
613a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        {
61452a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*) p_param;
61516fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham            if (0xFF != p_btif_cb->inst_id)
61616fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham                btif_multi_adv_add_instid_map(p_btif_cb->client_if, p_btif_cb->inst_id, false);
617a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            HAL_CBACK(bt_gatt_callbacks, client->multi_adv_enable_cb
618a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                    , p_btif_cb->client_if
619a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                    , p_btif_cb->status
620a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                );
6219dd5a9c11f2022fa9709f0c34f04560c21105152Andre Eisenbach            btif_multi_adv_timer_ctrl(p_btif_cb->client_if,
62278bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavov                                      (p_btif_cb->status == BTA_GATT_OK) ?
62378bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavov                                      btif_multi_adv_stop_cb : NULL);
624a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
625a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        }
626a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
627a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_GATTC_MULT_ADV_UPD_EVT:
628a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        {
62952a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*) p_param;
630a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            HAL_CBACK(bt_gatt_callbacks, client->multi_adv_update_cb
631a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                , p_btif_cb->client_if
632a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                , p_btif_cb->status
633a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            );
6349dd5a9c11f2022fa9709f0c34f04560c21105152Andre Eisenbach            btif_multi_adv_timer_ctrl(p_btif_cb->client_if,
63578bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavov                                      (p_btif_cb->status == BTA_GATT_OK) ?
63678bcff79e1b1f0efce436b33bdd6da88745bfc8aPavlin Radoslavov                                      btif_multi_adv_stop_cb : NULL);
637a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
638a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        }
639a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
640a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_GATTC_MULT_ADV_DATA_EVT:
641a6ce7751d84218c193eb90d390aef23217b1737eWei Wang         {
64252a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*) p_param;
6433770c47387d3dfc6d2e2d32f4409a82119e726e3Satya Calloji            btif_gattc_clear_clientif(p_btif_cb->client_if, FALSE);
644a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            HAL_CBACK(bt_gatt_callbacks, client->multi_adv_data_cb
645a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                , p_btif_cb->client_if
646a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                , p_btif_cb->status
647a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            );
648a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
649a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        }
650a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
651a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_GATTC_MULT_ADV_DIS_EVT:
652a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        {
65352a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t*) p_param;
6543770c47387d3dfc6d2e2d32f4409a82119e726e3Satya Calloji            btif_gattc_clear_clientif(p_btif_cb->client_if, TRUE);
655a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            HAL_CBACK(bt_gatt_callbacks, client->multi_adv_disable_cb
656a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                , p_btif_cb->client_if
657a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                , p_btif_cb->status
658a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            );
659a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
660a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        }
661a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
662a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_GATTC_ADV_DATA_EVT:
663a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        {
6643770c47387d3dfc6d2e2d32f4409a82119e726e3Satya Calloji            btif_gattc_cleanup_inst_cb(STD_ADV_INSTID, FALSE);
665a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            /* No HAL callback available */
666a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
667a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        }
668a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
66917b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach        case BTA_GATTC_CONGEST_EVT:
67017b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach            HAL_CBACK(bt_gatt_callbacks, client->congestion_cb
67117b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach                , p_data->congest.conn_id
67217b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach                , p_data->congest.congested
67317b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach            );
67417b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach            break;
67517b04bd498405f2bb109a85562ebbdcb6bb06e95Andre Eisenbach
676c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_GATTC_BTH_SCAN_CFG_EVT:
677c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
67852a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btgatt_batch_track_cb_t *p_data = (btgatt_batch_track_cb_t*) p_param;
679c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            HAL_CBACK(bt_gatt_callbacks, client->batchscan_cfg_storage_cb
680c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                , p_data->client_if
681c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                , p_data->status
682c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            );
683c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            break;
684c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
685c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
686c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_GATTC_BTH_SCAN_ENB_EVT:
687c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
68852a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btgatt_batch_track_cb_t *p_data = (btgatt_batch_track_cb_t*) p_param;
689c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            HAL_CBACK(bt_gatt_callbacks, client->batchscan_enb_disable_cb
690c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , ENABLE_BATCH_SCAN
691c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , p_data->client_if
692c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , p_data->status);
693c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            break;
694c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
695c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
696c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_GATTC_BTH_SCAN_DIS_EVT:
697c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
69852a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btgatt_batch_track_cb_t *p_data = (btgatt_batch_track_cb_t*) p_param;
699c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            HAL_CBACK(bt_gatt_callbacks, client->batchscan_enb_disable_cb
700c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , DISABLE_BATCH_SCAN
701c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , p_data->client_if
702c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , p_data->status);
703c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            break;
704c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
705c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
706c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_GATTC_BTH_SCAN_THR_EVT:
707c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
70852a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btgatt_batch_track_cb_t *p_data = (btgatt_batch_track_cb_t*) p_param;
709c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            HAL_CBACK(bt_gatt_callbacks, client->batchscan_threshold_cb
710c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , p_data->client_if);
711c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            break;
712c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
713c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
714c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_GATTC_BTH_SCAN_RD_EVT:
715c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
71652a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach            btgatt_batch_track_cb_t *p_data = (btgatt_batch_track_cb_t*) p_param;
717c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            uint8_t *p_rep_data = NULL;
718c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
719adb7bb50469db992969295792a7ba3b73f9e24b3Satya Calloji            if (p_data->read_reports.data_len > 0 && NULL != p_data->read_reports.p_rep_data)
720c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            {
721713993d1784ab7c23aee1fa3cf1ab8676cc0aa69Jakub Pawlowski                p_rep_data = (uint8_t *)osi_malloc(p_data->read_reports.data_len);
722c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                memcpy(p_rep_data, p_data->read_reports.p_rep_data, p_data->read_reports.data_len);
723c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            }
724c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
725c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            HAL_CBACK(bt_gatt_callbacks, client->batchscan_reports_cb
726c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , p_data->client_if, p_data->status, p_data->read_reports.report_format
727c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                    , p_data->read_reports.num_records, p_data->read_reports.data_len, p_rep_data);
728cceb430489a70add1b996d54289867c17f4ac0fdPavlin Radoslavov            osi_free(p_rep_data);
729c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            break;
730c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
731c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
7321acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji        case BTA_GATTC_ADV_VSC_EVT:
7331acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji        {
734f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji            btgatt_track_adv_info_t *p_data = (btgatt_track_adv_info_t*)p_param;
735f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji            btgatt_track_adv_info_t adv_info_data;
736f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji
737f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji            memset(&adv_info_data, 0, sizeof(btgatt_track_adv_info_t));
738f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji
739f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji            btif_gatt_move_track_adv_data(&adv_info_data, p_data);
740f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji            HAL_CBACK(bt_gatt_callbacks, client->track_adv_event_cb, &adv_info_data);
7411acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji            break;
7421acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji        }
7431acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji
744ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        default:
745db554581079863974af8e1289646f5deea6fc044Marie Janssen            LOG_ERROR(LOG_TAG, "%s: Unhandled event (%d)!", __FUNCTION__, event);
746ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            break;
747ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
7488444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach
7498444d1e649864c28b0c124bc2d16f7c153f01f14Andre Eisenbach    btapp_gattc_free_req_data(event, p_data);
750ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
751ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
7526975b4d711142b885af479721cada448952c6b41Andre Eisenbachstatic void bta_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
753ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
754ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bt_status_t status = btif_transfer_context(btif_gattc_upstreams_evt,
755713993d1784ab7c23aee1fa3cf1ab8676cc0aa69Jakub Pawlowski                    (uint16_t) event, (char*) p_data, sizeof(tBTA_GATTC), btapp_gattc_req_data);
756ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status);
757ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
758ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
759a6ce7751d84218c193eb90d390aef23217b1737eWei Wangstatic void bta_gattc_multi_adv_cback(tBTA_BLE_MULTI_ADV_EVT event, UINT8 inst_id,
760a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                                    void *p_ref, tBTA_STATUS call_status)
761a6ce7751d84218c193eb90d390aef23217b1737eWei Wang{
762a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_gattc_cb_t btif_cb;
763a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    tBTA_GATTC_EVT upevt;
764a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    uint8_t client_if = 0;
765a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
76616fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    if (NULL == p_ref)
767a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    {
76816fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham        BTIF_TRACE_WARNING("%s Invalid p_ref received",__FUNCTION__);
76916fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    }
77016fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    else
77116fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    {
77216fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham        client_if = *(UINT8 *) p_ref;
773a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    }
774a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
775e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati    BTIF_TRACE_DEBUG("%s -Inst ID %d, Status:%x, client_if:%d",__FUNCTION__,inst_id, call_status,
776a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                       client_if);
777a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_cb.status = call_status;
778a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_cb.client_if = client_if;
779a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_cb.inst_id = inst_id;
780a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
781a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    switch(event)
782a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    {
783a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_BLE_MULTI_ADV_ENB_EVT:
784a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            upevt = BTA_GATTC_MULT_ADV_ENB_EVT;
785a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
786a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
787a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_BLE_MULTI_ADV_DISABLE_EVT:
788a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            upevt = BTA_GATTC_MULT_ADV_DIS_EVT;
789a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
790a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
791a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_BLE_MULTI_ADV_PARAM_EVT:
792a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            upevt = BTA_GATTC_MULT_ADV_UPD_EVT;
793a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
794a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
795a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        case BTA_BLE_MULTI_ADV_DATA_EVT:
796a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            upevt = BTA_GATTC_MULT_ADV_DATA_EVT;
797a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            break;
798a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
799a6ce7751d84218c193eb90d390aef23217b1737eWei Wang        default:
800a6ce7751d84218c193eb90d390aef23217b1737eWei Wang            return;
801a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    }
802a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
803a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    bt_status_t status = btif_transfer_context(btif_gattc_upstreams_evt, (uint16_t) upevt,
804a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                        (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
805a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status);
806a6ce7751d84218c193eb90d390aef23217b1737eWei Wang}
807a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
808a6ce7751d84218c193eb90d390aef23217b1737eWei Wangstatic void bta_gattc_set_adv_data_cback(tBTA_STATUS call_status)
809a6ce7751d84218c193eb90d390aef23217b1737eWei Wang{
810a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    UNUSED(call_status);
811a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_gattc_cb_t btif_cb;
812a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_cb.status = call_status;
813a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_cb.action = 0;
814a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_transfer_context(btif_gattc_upstreams_evt, BTA_GATTC_ADV_DATA_EVT,
815a6ce7751d84218c193eb90d390aef23217b1737eWei Wang                          (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
816a6ce7751d84218c193eb90d390aef23217b1737eWei Wang}
817a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
818c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Callojistatic void bta_batch_scan_setup_cb (tBTA_BLE_BATCH_SCAN_EVT evt,
819c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                                            tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status)
820c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji{
821c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    UINT8 upevt = 0;
822c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btgatt_batch_track_cb_t btif_scan_track_cb;
823c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
824c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.status = status;
825c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.client_if = ref_value;
8261a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    BTIF_TRACE_DEBUG("bta_batch_scan_setup_cb-Status:%x, client_if:%d, evt=%d",
827c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            status, ref_value, evt);
828c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
829c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    switch(evt)
830c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    {
831c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_BLE_BATCH_SCAN_ENB_EVT:
832c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
833c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           upevt = BTA_GATTC_BTH_SCAN_ENB_EVT;
834c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           break;
835c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
836c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
837c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_BLE_BATCH_SCAN_DIS_EVT:
838c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
839c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           upevt = BTA_GATTC_BTH_SCAN_DIS_EVT;
840c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           break;
841c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
842c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
843c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_BLE_BATCH_SCAN_CFG_STRG_EVT:
844c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
845c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           upevt = BTA_GATTC_BTH_SCAN_CFG_EVT;
846c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           break;
847c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
848c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
849c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_BLE_BATCH_SCAN_DATA_EVT:
850c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
851c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           upevt = BTA_GATTC_BTH_SCAN_RD_EVT;
852c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           break;
853c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
854c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
855c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        case BTA_BLE_BATCH_SCAN_THRES_EVT:
856c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        {
857c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           upevt = BTA_GATTC_BTH_SCAN_THR_EVT;
858c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji           break;
859c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        }
860c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
861c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        default:
862c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji            return;
863c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    }
864c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
865c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_transfer_context(btif_gattc_upstreams_evt, upevt,(char*) &btif_scan_track_cb,
866c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                          sizeof(btgatt_batch_track_cb_t), NULL);
867c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
868c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji}
869c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
870c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Callojistatic void bta_batch_scan_threshold_cb(tBTA_DM_BLE_REF_VALUE ref_value)
871c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji{
872c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btgatt_batch_track_cb_t btif_scan_track_cb;
873c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.status = 0;
874c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.client_if = ref_value;
875c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
8761a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    BTIF_TRACE_DEBUG("%s - client_if:%d",__FUNCTION__, ref_value);
877c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
878c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_transfer_context(btif_gattc_upstreams_evt, BTA_GATTC_BTH_SCAN_THR_EVT,
879c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                          (char*) &btif_scan_track_cb, sizeof(btif_gattc_cb_t), NULL);
880c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji}
881c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
882c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Callojistatic void bta_batch_scan_reports_cb(tBTA_DM_BLE_REF_VALUE ref_value, UINT8 report_format,
883c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                                            UINT8 num_records, UINT16 data_len,
884c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                                            UINT8* p_rep_data, tBTA_STATUS status)
885c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji{
886c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btgatt_batch_track_cb_t btif_scan_track_cb;
887adb7bb50469db992969295792a7ba3b73f9e24b3Satya Calloji    memset(&btif_scan_track_cb, 0, sizeof(btgatt_batch_track_cb_t));
8881a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    BTIF_TRACE_DEBUG("%s - client_if:%d, %d, %d, %d",__FUNCTION__, ref_value, status, num_records,
889c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji                                    data_len);
890c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
891c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.status = status;
892c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
893c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.client_if = ref_value;
894c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.read_reports.report_format = report_format;
895c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.read_reports.data_len = data_len;
896c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_scan_track_cb.read_reports.num_records = num_records;
897c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
89816fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    if (data_len > 0)
899c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    {
900713993d1784ab7c23aee1fa3cf1ab8676cc0aa69Jakub Pawlowski        btif_scan_track_cb.read_reports.p_rep_data = (UINT8 *)osi_malloc(data_len);
901c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        memcpy(btif_scan_track_cb.read_reports.p_rep_data, p_rep_data, data_len);
902cceb430489a70add1b996d54289867c17f4ac0fdPavlin Radoslavov        osi_free(p_rep_data);
903c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    }
904c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
905c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_transfer_context(btif_gattc_upstreams_evt, BTA_GATTC_BTH_SCAN_RD_EVT,
906c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji        (char*) &btif_scan_track_cb, sizeof(btgatt_batch_track_cb_t), NULL);
907c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
90816fe0822ccd3eb6f66d3afd9965d25a0a0cb4c30Prerepa Viswanadham    if (data_len > 0)
909cceb430489a70add1b996d54289867c17f4ac0fdPavlin Radoslavov        osi_free_and_reset((void **)&btif_scan_track_cb.read_reports.p_rep_data);
910c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji}
911c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
9126975b4d711142b885af479721cada448952c6b41Andre Eisenbachstatic void bta_scan_results_cb (tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
913ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
914ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_cb_t btif_cb;
915ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    uint8_t len;
916ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
917ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    switch (event)
918ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    {
919ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_DM_INQ_RES_EVT:
920ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
921ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            bdcpy(btif_cb.bd_addr.address, p_data->inq_res.bd_addr);
922ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            btif_cb.device_type = p_data->inq_res.device_type;
923ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            btif_cb.rssi = p_data->inq_res.rssi;
924ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            btif_cb.addr_type = p_data->inq_res.ble_addr_type;
9257fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Batta            btif_cb.flag = p_data->inq_res.flag;
926ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            if (p_data->inq_res.p_eir)
927ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            {
928ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                memcpy(btif_cb.value, p_data->inq_res.p_eir, 62);
929a50fc88c9f784a2422ceac014fea47ac1717647bZach Johnson                if (BTM_CheckEirData(p_data->inq_res.p_eir, BTM_EIR_COMPLETE_LOCAL_NAME_TYPE,
930ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                                      &len))
931ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                {
932ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                    p_data->inq_res.remt_name_not_required  = TRUE;
933ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                }
934ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            }
935ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
936ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        break;
937ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
938ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        case BTA_DM_INQ_CMPL_EVT:
939ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        {
940e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati            BTIF_TRACE_DEBUG("%s  BLE observe complete. Num Resp %d",
941ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                              __FUNCTION__,p_data->inq_cmpl.num_resps);
942ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta            return;
943ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        }
944ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
945ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        default:
946e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati        BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event);
947ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        return;
948ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    }
949ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_transfer_context(btif_gattc_upstreams_evt, BTIF_GATT_OBSERVE_EVT,
950ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                                 (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
951ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
952ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
953f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Callojistatic void bta_track_adv_event_cb(tBTA_DM_BLE_TRACK_ADV_DATA *p_track_adv_data)
9541acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji{
955f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji    btgatt_track_adv_info_t btif_scan_track_cb;
956f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji    BTIF_TRACE_DEBUG("%s",__FUNCTION__);
957f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji    btif_gatt_move_track_adv_data(&btif_scan_track_cb,
958f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji                (btgatt_track_adv_info_t*)p_track_adv_data);
959f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji
9601acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji    btif_transfer_context(btif_gattc_upstreams_evt, BTA_GATTC_ADV_VSC_EVT,
961f538707fe64c62b1dbb8e4210e4a1bfa0bab2b56Satya Calloji                          (char*) &btif_scan_track_cb, sizeof(btgatt_track_adv_info_t), NULL);
9621acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji}
9631acb61ce065053f91a0f8d43e8328c9eeec4b5edSatya Calloji
964ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic void btm_read_rssi_cb (tBTM_RSSI_RESULTS *p_result)
965ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
966ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_cb_t btif_cb;
967ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
968ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    bdcpy(btif_cb.bd_addr.address, p_result->rem_bda);
969ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_cb.rssi = p_result->rssi;
970ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_cb.status = p_result->status;
971ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_cb.client_if = rssi_request_client_if;
972ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_transfer_context(btif_gattc_upstreams_evt, BTIF_GATTC_RSSI_EVT,
973ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta                                 (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
974ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
975ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
976da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowskistatic void bta_scan_param_setup_cb(tGATT_IF client_if, tBTM_STATUS status) {
977da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski  CLI_CBACK_IN_JNI(scan_parameter_setup_completed_cb, client_if,
978da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                   btif_gattc_translate_btm_status(status));
979979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach}
980979e3421c8111a56ebfcf176f6383df58eed52eaAndre Eisenbach
981da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowskistatic void bta_scan_filt_cfg_cb(tBTA_DM_BLE_PF_ACTION action,
982da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                 tBTA_DM_BLE_SCAN_COND_OP cfg_op,
983da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
984da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                 tBTA_STATUS status,
985da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                 tBTA_DM_BLE_REF_VALUE ref_value) {
986da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski  CLI_CBACK_IN_JNI(scan_filter_cfg_cb, action, ref_value, status, cfg_op,
987da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                   avbl_space);
9881a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji}
9891a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji
9901a9247a1229aa65b3d1dce16426177bc5828e54dSatya Callojistatic void bta_scan_filt_param_setup_cb(UINT8 action_type,
991da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                         tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
992da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                         tBTA_DM_BLE_REF_VALUE ref_value,
993da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                         tBTA_STATUS status) {
994da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski  CLI_CBACK_IN_JNI(scan_filter_param_cb, action_type, ref_value, status,
995da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                   avbl_space);
9961a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji}
9971a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji
9981a9247a1229aa65b3d1dce16426177bc5828e54dSatya Callojistatic void bta_scan_filt_status_cb(UINT8 action, tBTA_STATUS status,
999da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski                                    tBTA_DM_BLE_REF_VALUE ref_value) {
1000da5b59b5bf9cb34574c16ba784c1484055fcb1e3Jakub Pawlowski  CLI_CBACK_IN_JNI(scan_filter_status_cb, action, ref_value, status);
1001b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach}
1002ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1003ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/*******************************************************************************
1004ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta**  Client API Functions
1005ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta********************************************************************************/
1006ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1007c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowskistatic void btif_gattc_register_app_impl(tBT_UUID uuid) {
1008c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  btif_gattc_incr_app_count();
1009c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  BTA_GATTC_AppRegister(&uuid, bta_gattc_cback);
1010ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1011ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1012c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowskistatic bt_status_t btif_gattc_register_app(bt_uuid_t *uuid) {
1013c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  CHECK_BTGATT_INIT();
1014c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski
1015c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  tBT_UUID bt_uuid;
1016c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  btif_to_bta_uuid(&bt_uuid, uuid);
1017c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  return do_in_jni_thread(Bind(&btif_gattc_register_app_impl, bt_uuid));
1018c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski}
1019c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski
1020c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowskistatic void btif_gattc_unregister_app_impl(int client_if) {
1021c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  btif_gattc_clear_clientif(client_if, TRUE);
1022c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  btif_gattc_decr_app_count();
1023c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  BTA_GATTC_AppDeregister(client_if);
1024c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski}
1025c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski
1026c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowskistatic bt_status_t btif_gattc_unregister_app(int client_if) {
1027c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  CHECK_BTGATT_INIT();
1028c8b5185a5d4c4c9c15f3ec5df4acd37c1d46f1f1Jakub Pawlowski  return do_in_jni_thread(Bind(&btif_gattc_unregister_app_impl, client_if));
1029ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1030ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1031955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowskistatic bt_status_t btif_gattc_scan(bool start) {
1032955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski  CHECK_BTGATT_INIT();
1033955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski  if (start) {
1034955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski    btif_gattc_init_dev_cb();
1035955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski    return do_in_jni_thread(Bind(&BTA_DmBleObserve, TRUE, 0,
1036955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski                                 (tBTA_DM_SEARCH_CBACK *)bta_scan_results_cb));
1037955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski  } else {
1038955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski    return do_in_jni_thread(Bind(&BTA_DmBleObserve, FALSE, 0, nullptr));
1039955ff4e88ef7391632e19d1b0234cae40b6f42c1Jakub Pawlowski  }
1040ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1041ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
104226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowskistatic void btif_gattc_open_impl(int client_if, BD_ADDR address,
104326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski                                 bool is_direct, int transport_p) {
104426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  // Ensure device is in inquiry database
104526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  int addr_type = 0;
104626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  int device_type = 0;
104726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  tBTA_GATT_TRANSPORT transport = (tBTA_GATT_TRANSPORT)BTA_GATT_TRANSPORT_LE;
104826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski
104926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  if (btif_get_address_type(address, &addr_type) &&
105026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      btif_get_device_type(address, &device_type) &&
105126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      device_type != BT_DEVICE_TYPE_BREDR) {
105226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    BTA_DmAddBleDevice(address, addr_type, device_type);
105326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  }
105426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski
105526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  // Check for background connections
105626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  if (!is_direct) {
105726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    // Check for privacy 1.0 and 1.1 controller and do not start background
105826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    // connection if RPA offloading is not supported, since it will not
105926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    // connect after change of random address
106026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    if (!controller_get_interface()->supports_ble_privacy() &&
106126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        (addr_type == BLE_ADDR_RANDOM) &&
106226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        BTM_BLE_IS_RESOLVE_BDA(address)) {
106326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      tBTM_BLE_VSC_CB vnd_capabilities;
106426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      BTM_BleGetVendorCapabilities(&vnd_capabilities);
106526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      if (!vnd_capabilities.rpa_offloading) {
106626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        HAL_CBACK(bt_gatt_callbacks, client->open_cb, 0, BT_STATUS_UNSUPPORTED,
106726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski                  client_if, (bt_bdaddr_t*) &address);
106826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        return;
106926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      }
107026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    }
107126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    BTA_DmBleSetBgConnType(BTM_BLE_CONN_AUTO, NULL);
107226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  }
107326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski
107426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  // Determine transport
107526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  if (transport_p != GATT_TRANSPORT_AUTO) {
107626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    transport = transport_p;
107726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  } else {
107826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    switch (device_type) {
107926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      case BT_DEVICE_TYPE_BREDR:
108026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        transport = BTA_GATT_TRANSPORT_BR_EDR;
108126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        break;
108226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski
108326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      case BT_DEVICE_TYPE_BLE:
108426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        transport = BTA_GATT_TRANSPORT_LE;
108526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        break;
108626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski
108726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      case BT_DEVICE_TYPE_DUMO:
108826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        if (transport == GATT_TRANSPORT_LE)
108926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski          transport = BTA_GATT_TRANSPORT_LE;
109026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        else
109126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski          transport = BTA_GATT_TRANSPORT_BR_EDR;
109226e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski        break;
109326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski    }
109426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  }
109526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski
109626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  // Connect!
109726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  BTIF_TRACE_DEBUG("%s Transport=%d, device type=%d", __func__, transport,
109826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski                   device_type);
109926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  BTA_GATTC_Open(client_if, address, is_direct, transport);
110026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski}
110126e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski
11027fa4fba6f59f97df00aff07dbe8fb21b114b3c2cGanesh Ganapathi Battastatic bt_status_t btif_gattc_open(int client_if, const bt_bdaddr_t *bd_addr,
110326e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski                                   bool is_direct, int transport) {
110426e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  CHECK_BTGATT_INIT();
110526e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  // Closure will own this value and free it.
110626e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  uint8_t *address = new BD_ADDR;
110726e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  bdcpy(address, bd_addr->address);
110826e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski  return do_in_jni_thread(
110926e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski      Bind(&btif_gattc_open_impl, client_if, base::Owned(address), is_direct,
111026e51cb18509e7e04755b4fa4250c60f105ab9d2Jakub Pawlowski           transport));
1111ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1112ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1113b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowskistatic void btif_gattc_close_impl(int client_if, BD_ADDR address,
1114b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski                                  int conn_id) {
1115b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  // Disconnect established connections
1116b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  if (conn_id != 0)
1117b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski    BTA_GATTC_Close(conn_id);
1118b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  else
1119b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski    BTA_GATTC_CancelOpen(client_if, address, TRUE);
1120b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski
1121b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  // Cancel pending background connections (remove from whitelist)
1122b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  BTA_GATTC_CancelOpen(client_if, address, FALSE);
1123b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski}
1124b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski
1125b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowskistatic bt_status_t btif_gattc_close(int client_if, const bt_bdaddr_t *bd_addr,
1126b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski                                    int conn_id) {
1127b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  CHECK_BTGATT_INIT();
1128b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  // Closure will own this value and free it.
1129b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  uint8_t *address = new BD_ADDR;
1130b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  bdcpy(address, bd_addr->address);
1131b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski  return do_in_jni_thread(
1132b454953bb6620cbafba86351b91d58b47dda107dJakub Pawlowski      Bind(&btif_gattc_close_impl, client_if, base::Owned(address), conn_id));
1133ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1134ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1135144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowskistatic bt_status_t btif_gattc_listen(int client_if, bool start) {
1136144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowski  CHECK_BTGATT_INIT();
1137144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowski#if (defined(BLE_PERIPHERAL_MODE_SUPPORT) && \
1138144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowski     (BLE_PERIPHERAL_MODE_SUPPORT == TRUE))
1139144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowski  return do_in_jni_thread(Bind(&BTA_GATTC_Listen, client_if, start, nullptr));
1140144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowski#else
1141144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowski  return do_in_jni_thread(Bind(&BTA_GATTC_Broadcast, client_if, start));
1142144998f68990205ba711e701be6be8325dd6e820Jakub Pawlowski#endif
11435c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach}
11445c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach
11451ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowskistatic void btif_gattc_set_adv_data_impl(btif_adv_data_t *p_adv_data) {
11461ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  const int cbindex = CLNT_IF_IDX;
11471ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  if (cbindex >= 0 && btif_gattc_copy_datacb(cbindex, p_adv_data, false)) {
11481ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    btgatt_multi_adv_common_data *p_multi_adv_data_cb =
11491ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski        btif_obtain_multi_adv_data_cb();
11501ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    if (!p_adv_data->set_scan_rsp) {
11511ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski      BTA_DmBleSetAdvConfig(p_multi_adv_data_cb->inst_cb[cbindex].mask,
11521ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski                            &p_multi_adv_data_cb->inst_cb[cbindex].data,
11531ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski                            bta_gattc_set_adv_data_cback);
11541ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    } else {
11551ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski      BTA_DmBleSetScanRsp(p_multi_adv_data_cb->inst_cb[cbindex].mask,
11561ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski                          &p_multi_adv_data_cb->inst_cb[cbindex].data,
11571ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski                          bta_gattc_set_adv_data_cback);
11581ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    }
11591ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  } else {
11601ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    BTIF_TRACE_ERROR("%s: failed to get instance data cbindex: %d", __func__,
11611ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski                     cbindex);
11621ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  }
11631ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski}
11641ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski
11651ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowskistatic bt_status_t btif_gattc_set_adv_data(
11661ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    int client_if, bool set_scan_rsp, bool include_name, bool include_txpower,
11671ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    int min_interval, int max_interval, int appearance,
11681ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    uint16_t manufacturer_len, char *manufacturer_data,
11691ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    uint16_t service_data_len, char *service_data, uint16_t service_uuid_len,
11701ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski    char *service_uuid) {
11711ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  CHECK_BTGATT_INIT();
11721ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski
11731ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  btif_adv_data_t *adv_data = new btif_adv_data_t;
1174eeeac99328c23304ab24698331b6600f3b545700Andre Eisenbach
11751ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  btif_gattc_adv_data_packager(
11761ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski      client_if, set_scan_rsp, include_name, include_txpower, min_interval,
11771ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski      max_interval, appearance, manufacturer_len, manufacturer_data,
11781ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski      service_data_len, service_data, service_uuid_len, service_uuid, adv_data);
1179eeeac99328c23304ab24698331b6600f3b545700Andre Eisenbach
11801ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski  return do_in_jni_thread(
11811ce0819a83f47f3bec3c16c46befd1e7faddf0ffJakub Pawlowski      Bind(&btif_gattc_set_adv_data_impl, base::Owned(adv_data)));
11825c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach}
11835c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach
1184140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowskistatic bt_status_t btif_gattc_refresh(int client_if,
1185140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski                                      const bt_bdaddr_t *bd_addr) {
1186140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski  CHECK_BTGATT_INIT();
1187140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski  // Closure will own this value and free it.
1188140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski  uint8_t *address = new BD_ADDR;
1189140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski  bdcpy(address, bd_addr->address);
1190140645f6b8d87464c08f082bd14740eecab23f71Jakub Pawlowski  return do_in_jni_thread(Bind(&BTA_GATTC_Refresh, base::Owned(address)));
1191ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1192ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1193d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowskistatic bt_status_t btif_gattc_search_service(int conn_id,
1194d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski                                             bt_uuid_t *filter_uuid) {
1195d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski  CHECK_BTGATT_INIT();
1196d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski
1197d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski  if (filter_uuid) {
1198d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski    tBT_UUID *uuid = new tBT_UUID;
1199d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski    btif_to_bta_uuid(uuid, filter_uuid);
1200d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski    return do_in_jni_thread(
1201d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski        Bind(&BTA_GATTC_ServiceSearchRequest, conn_id, base::Owned(uuid)));
1202d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski  } else {
1203d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski    return do_in_jni_thread(
1204d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski        Bind(&BTA_GATTC_ServiceSearchRequest, conn_id, nullptr));
1205d05e50e7df462c928041bf565821d77fb493bc28Jakub Pawlowski  }
1206ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1207ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
120861a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowskivoid btif_gattc_get_gatt_db_impl(int conn_id) {
120961a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski  btgatt_db_element_t *db = NULL;
121061a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski  int count = 0;
121161a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski  BTA_GATTC_GetGattDb(conn_id, 0x0000, 0xFFFF, &db, &count);
1212533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski
121361a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski  HAL_CBACK(bt_gatt_callbacks, client->get_gatt_db_cb, conn_id, db, count);
121461a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski  osi_free(db);
121561a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski}
121661a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski
121761a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowskistatic bt_status_t btif_gattc_get_gatt_db(int conn_id) {
121861a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski  CHECK_BTGATT_INIT();
121961a98132c39d3181a0ea23988ac36fbfef8194b4Jakub Pawlowski  return do_in_jni_thread(Bind(&btif_gattc_get_gatt_db_impl, conn_id));
1220533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski}
1221533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski
122261a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowskistatic bt_status_t btif_gattc_read_char(int conn_id, uint16_t handle,
122361a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski                                        int auth_req) {
122461a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski  CHECK_BTGATT_INIT();
122561a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski  return do_in_jni_thread(
122661a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski      Bind(&BTA_GATTC_ReadCharacteristic, conn_id, handle, auth_req));
1227ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1228ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
122961a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowskistatic bt_status_t btif_gattc_read_char_descr(int conn_id, uint16_t handle,
123061a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski                                              int auth_req) {
123161a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski  CHECK_BTGATT_INIT();
123261a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski  return do_in_jni_thread(
123361a112e488a7686e5cc9680434c42895ef9db878Jakub Pawlowski      Bind(&BTA_GATTC_ReadCharDescr, conn_id, handle, auth_req));
1234ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1235ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
123639a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowskistatic bt_status_t btif_gattc_write_char(int conn_id, uint16_t handle,
123739a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski                                         int write_type, int len, int auth_req,
123839a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski                                         char *p_value) {
123939a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  CHECK_BTGATT_INIT();
124039a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski
124139a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  len = len > BTGATT_MAX_ATTR_LEN ? BTGATT_MAX_ATTR_LEN : len;
124239a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  // callback will own this value and free it.
124339a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  UINT8 *value = new UINT8(len);
124439a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  memcpy(value, p_value, len);
124539a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski
124639a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharValue, conn_id, handle,
124739a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski                               write_type, len, base::Owned(value), auth_req));
1248ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1249ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
12509dc998503590163068845827d951fc2f05a17bdaJakub Pawlowskistatic bt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle,
125139a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski                                               int write_type, int len,
125239a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski                                               int auth_req, char *p_value) {
125339a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  len = len > BTGATT_MAX_ATTR_LEN ? BTGATT_MAX_ATTR_LEN : len;
125439a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski
125539a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  // callback will own this value and free it
125639a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  // TODO(jpawlowski): This one is little hacky because of unfmt type,
125739a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  // make it accept len an val like BTA_GATTC_WriteCharValue
125839a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  tBTA_GATT_UNFMT *value = (tBTA_GATT_UNFMT *)new UINT8(sizeof(UINT16) + len);
125939a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  value->len = len;
126039a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  value->p_value = ((UINT8 *)value) + 2;
126139a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  memcpy(value->p_value, p_value, len);
126239a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski
126339a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski  return do_in_jni_thread(Bind(&BTA_GATTC_WriteCharDescr, conn_id, handle,
126439a33612889a562da5c919f14df24707ba3e6007Jakub Pawlowski                               write_type, Owned(value), auth_req));
1265ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1266ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1267a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowskistatic bt_status_t btif_gattc_execute_write(int conn_id, int execute) {
1268a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski  CHECK_BTGATT_INIT();
1269a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski  return do_in_jni_thread(
1270a684a52231bf0422d991fb16e4dcfc88e4584680Jakub Pawlowski      Bind(&BTA_GATTC_ExecuteWrite, conn_id, (uint8_t)execute));
1271ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1272ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1273ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowskistatic void btif_gattc_reg_for_notification_impl(tBTA_GATTC_IF client_if,
1274ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski                                          const BD_ADDR bda, UINT16 handle) {
1275ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  tBTA_GATT_STATUS status = BTA_GATTC_RegisterForNotifications(
1276ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski      client_if, const_cast<UINT8 *>(bda), handle);
1277ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski
1278ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  //TODO(jpawlowski): conn_id is currently unused
1279ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb,
1280ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski            /* conn_id */ 0, 1, status, handle);
1281ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1282ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1283ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowskistatic bt_status_t btif_gattc_reg_for_notification(int client_if,
1284ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski                                                   const bt_bdaddr_t *bd_addr,
1285ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski                                                   uint16_t handle) {
1286ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  CHECK_BTGATT_INIT();
1287ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski
1288ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  uint8_t *address = new BD_ADDR;
1289ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  bdcpy(address, bd_addr->address);
1290ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  return do_in_jni_thread(
1291ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski      Bind(base::IgnoreResult(&btif_gattc_reg_for_notification_impl), client_if,
1292ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski           base::Owned(address), handle));
1293ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski}
1294ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski
1295ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowskistatic void btif_gattc_dereg_for_notification_impl(tBTA_GATTC_IF client_if,
1296ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski                                            const BD_ADDR bda, UINT16 handle) {
1297ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  tBTA_GATT_STATUS status = BTA_GATTC_DeregisterForNotifications(
1298ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski      client_if, const_cast<UINT8 *>(bda), handle);
1299ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski
1300ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  //TODO(jpawlowski): conn_id is currently unused
1301ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb,
1302ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski            /* conn_id */ 0, 0, status, handle);
1303ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski}
1304ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski
1305ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowskistatic bt_status_t btif_gattc_dereg_for_notification(int client_if,
1306ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski                                                     const bt_bdaddr_t *bd_addr,
1307ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski                                                     uint16_t handle) {
1308ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  CHECK_BTGATT_INIT();
1309ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski
1310ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  uint8_t *address = new BD_ADDR;
1311ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  bdcpy(address, bd_addr->address);
1312ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski  return do_in_jni_thread(
1313ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski      Bind(base::IgnoreResult(&btif_gattc_dereg_for_notification_impl),
1314ca9d889000b087ddb9bedaa716176be986be158fJakub Pawlowski           client_if, base::Owned(address), handle));
1315ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1316ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1317c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowskistatic bt_status_t btif_gattc_read_remote_rssi(int client_if,
1318c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski                                               const bt_bdaddr_t *bd_addr) {
1319c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  CHECK_BTGATT_INIT();
1320c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  rssi_request_client_if = client_if;
1321c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  // Closure will own this value and free it.
1322c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  uint8_t *address = new BD_ADDR;
1323c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  bdcpy(address, bd_addr->address);
1324c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  return do_in_jni_thread(Bind(base::IgnoreResult(&BTM_ReadRSSI),
1325c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski                               base::Owned(address),
1326c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski                               (tBTM_CMPL_CB *)btm_read_rssi_cb));
1327ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1328ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1329c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowskistatic bt_status_t btif_gattc_configure_mtu(int conn_id, int mtu) {
1330c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  CHECK_BTGATT_INIT();
1331c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski  return do_in_jni_thread(
1332c9fe4b6f62c95b195fa99c4fbb75863e547929bfJakub Pawlowski      Bind(base::IgnoreResult(&BTA_GATTC_ConfigureMTU), conn_id, mtu));
13339426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach}
13349426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach
13357cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowskivoid btif_gattc_conn_parameter_update_impl(const BD_ADDR addr, int min_interval,
13367cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski                                           int max_interval, int latency,
13377cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski                                           int timeout) {
13387cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski  if (BTA_DmGetConnectionState(const_cast<UINT8 *>(addr)))
13397cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski    BTA_DmBleUpdateConnectionParams(const_cast<UINT8 *>(addr), min_interval,
13407cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski                                    max_interval, latency, timeout);
13417cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski  else
13427cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski    BTA_DmSetBlePrefConnParams(const_cast<UINT8 *>(addr), min_interval,
13437cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski                               max_interval, latency, timeout);
13447cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski}
13457cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski
13467cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowskistatic bt_status_t btif_gattc_conn_parameter_update(const bt_bdaddr_t *bd_addr,
13477cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski                                                    int min_interval,
13487cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski                                                    int max_interval,
13497cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski                                                    int latency, int timeout) {
13507cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski  CHECK_BTGATT_INIT();
13517cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski  return do_in_jni_thread(
13527cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski      Bind(base::IgnoreResult(&btif_gattc_conn_parameter_update_impl),
13537cb29a38027f9cb24fc30eefb389f848cfc17082Jakub Pawlowski           bd_addr->address, min_interval, max_interval, latency, timeout));
135452a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach}
135552a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach
13561a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowskistatic void btif_gattc_scan_filter_param_setup_impl(
13571a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski    int client_if, uint8_t action, int filt_index,
13581a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski    tBTA_DM_BLE_PF_FILT_PARAMS *adv_filt_param) {
13591a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  if (1 == adv_filt_param->dely_mode)
13601a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski    BTA_DmBleTrackAdvertiser(client_if, bta_track_adv_event_cb);
13611a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  BTA_DmBleScanFilterSetup(action, filt_index, adv_filt_param, NULL,
13621a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski                           bta_scan_filt_param_setup_cb, client_if);
13631a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski}
13641a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski
13651a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowskistatic bt_status_t btif_gattc_scan_filter_param_setup(
13661a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski    btgatt_filt_param_setup_t filt_param) {
13671a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  CHECK_BTGATT_INIT();
13681a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  BTIF_TRACE_DEBUG("%s", __FUNCTION__);
13691a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski
13701a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  tBTA_DM_BLE_PF_FILT_PARAMS *adv_filt_param = new tBTA_DM_BLE_PF_FILT_PARAMS;
13711a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->feat_seln = filt_param.feat_seln;
13721a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->list_logic_type = filt_param.list_logic_type;
13731a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->filt_logic_type = filt_param.filt_logic_type;
13741a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->rssi_high_thres = filt_param.rssi_high_thres;
13751a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->rssi_low_thres = filt_param.rssi_low_thres;
13761a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->dely_mode = filt_param.dely_mode;
13771a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->found_timeout = filt_param.found_timeout;
13781a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->lost_timeout = filt_param.lost_timeout;
13791a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->found_timeout_cnt = filt_param.found_timeout_cnt;
13801a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  adv_filt_param->num_of_tracking_entries = filt_param.num_of_tracking_entries;
13811a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski
13821a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski  return do_in_jni_thread(
13831a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski      Bind(base::IgnoreResult(&btif_gattc_scan_filter_param_setup_impl),
13841a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski           filt_param.client_if, filt_param.action, filt_param.filt_index,
13851a9e2ac4dab5a74139613f4ff5dde1b979522f0eJakub Pawlowski           base::Owned(adv_filt_param)));
1386b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach}
1387b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach
1388904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowskivoid btif_gattc_scan_filter_add_srvc_uuid(tBT_UUID uuid,
1389904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          tBTA_DM_BLE_PF_COND_MASK *p_uuid_mask,
1390904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          int action, int filt_type,
1391904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          int filt_index, int client_if) {
1392904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  tBTA_DM_BLE_PF_COND_PARAM cond;
1393904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  memset(&cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1394904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1395904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.srvc_uuid.p_target_addr = NULL;
1396904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.srvc_uuid.cond_logic = BTA_DM_BLE_PF_LOGIC_AND;
1397904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.srvc_uuid.uuid = uuid;
1398904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.srvc_uuid.p_uuid_mask = p_uuid_mask;
1399904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1400904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  BTA_DmBleCfgFilterCondition(action, filt_type, filt_index, &cond,
1401904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                              &bta_scan_filt_cfg_cb, client_if);
1402904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski}
1403904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1404904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowskivoid btif_gattc_scan_filter_add_local_name(uint8_t *data, int data_len,
1405904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                           int action, int filt_type,
1406904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                           int filt_index, int client_if) {
1407904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  tBTA_DM_BLE_PF_COND_PARAM cond;
1408904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  memset(&cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1409904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1410904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.local_name.data_len = data_len;
1411904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.local_name.p_data = data;
1412904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  BTA_DmBleCfgFilterCondition(action, filt_type, filt_index, &cond,
1413904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                              &bta_scan_filt_cfg_cb, client_if);
1414904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski}
1415904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1416904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowskivoid btif_gattc_scan_filter_add_manu_data(int company_id, int company_id_mask,
1417904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          uint8_t *pattern, int pattern_len,
1418904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          uint8_t *pattern_mask, int action,
1419904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          int filt_type, int filt_index,
1420904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          int client_if) {
1421904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  tBTA_DM_BLE_PF_COND_PARAM cond;
1422904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  memset(&cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1423904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1424904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.manu_data.company_id = company_id;
1425904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.manu_data.company_id_mask = company_id_mask ? company_id_mask : 0xFFFF;
1426904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.manu_data.data_len = pattern_len;
1427904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.manu_data.p_pattern = pattern;
1428904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.manu_data.p_pattern_mask = pattern_mask;
1429904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  BTA_DmBleCfgFilterCondition(action, filt_type, filt_index, &cond,
1430904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                              &bta_scan_filt_cfg_cb, client_if);
1431904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski}
1432904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1433904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowskivoid btif_gattc_scan_filter_add_data_pattern(uint8_t *pattern, int pattern_len,
1434904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          uint8_t *pattern_mask, int action,
1435904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          int filt_type, int filt_index,
1436904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                          int client_if) {
1437904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  tBTA_DM_BLE_PF_COND_PARAM cond;
1438904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  memset(&cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1439904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1440904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.srvc_data.data_len = pattern_len;
1441904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.srvc_data.p_pattern = pattern;
1442904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  cond.srvc_data.p_pattern_mask = pattern_mask;
1443904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  BTA_DmBleCfgFilterCondition(action, filt_type, filt_index, &cond,
1444904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                              &bta_scan_filt_cfg_cb, client_if);
1445904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski}
1446904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1447904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowskistatic bt_status_t btif_gattc_scan_filter_add_remove(
1448904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    int client_if, int action, int filt_type, int filt_index, int company_id,
1449904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    int company_id_mask, const bt_uuid_t *p_uuid, const bt_uuid_t *p_uuid_mask,
1450904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    const bt_bdaddr_t *bd_addr, char addr_type, int data_len, char *p_data,
1451904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    int mask_len, char *p_mask) {
1452904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  CHECK_BTGATT_INIT();
1453904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  BTIF_TRACE_DEBUG("%s, %d, %d", __FUNCTION__, action, filt_type);
1454904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1455904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  /* If data is passed, both mask and data have to be the same length */
1456904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  if (data_len != mask_len && NULL != p_data && NULL != p_mask)
1457904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    return BT_STATUS_PARM_INVALID;
1458904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1459904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  switch (filt_type) {
1460904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    case BTA_DM_BLE_PF_ADDR_FILTER:  // 0
1461904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    {
1462904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      tBTA_DM_BLE_PF_COND_PARAM *cond = new tBTA_DM_BLE_PF_COND_PARAM;
1463904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      memset(cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1464904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1465904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      bdcpy(cond->target_addr.bda, bd_addr->address);
1466904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      cond->target_addr.type = addr_type;
1467904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return do_in_jni_thread(Bind(&BTA_DmBleCfgFilterCondition, action,
1468904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   filt_type, filt_index, base::Owned(cond),
1469904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   &bta_scan_filt_cfg_cb, client_if));
1470904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    }
1471904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1472904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    case BTA_DM_BLE_PF_SRVC_DATA:  // 1
1473904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return do_in_jni_thread(Bind(&BTA_DmBleCfgFilterCondition, action,
1474904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   filt_type, filt_index, nullptr,
1475904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   &bta_scan_filt_cfg_cb, client_if));
1476904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1477904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    case BTA_DM_BLE_PF_SRVC_UUID:  // 2
1478904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    {
1479904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      tBT_UUID bt_uuid;
1480904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      btif_to_bta_uuid(&bt_uuid, p_uuid);
1481904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1482904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      if (p_uuid_mask != NULL) {
1483904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski        tBTA_DM_BLE_PF_COND_MASK *uuid_mask = new tBTA_DM_BLE_PF_COND_MASK;
1484904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski        btif_to_bta_uuid_mask(uuid_mask, p_uuid_mask);
1485904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski        return do_in_jni_thread(Bind(&btif_gattc_scan_filter_add_srvc_uuid,
1486904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                     bt_uuid, base::Owned(uuid_mask), action,
1487904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                     filt_type, filt_index, client_if));
1488904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      }
1489904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1490904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return do_in_jni_thread(Bind(&btif_gattc_scan_filter_add_srvc_uuid,
1491904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   bt_uuid, nullptr, action, filt_type,
1492904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   filt_index, client_if));
1493904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    }
1494904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1495904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    case BTA_DM_BLE_PF_SRVC_SOL_UUID:  // 3
1496904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    {
1497904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      tBTA_DM_BLE_PF_COND_PARAM *cond = new tBTA_DM_BLE_PF_COND_PARAM;
1498904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      memset(cond, 0, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
1499904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1500904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      cond->solicitate_uuid.p_target_addr = NULL;
1501904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      cond->solicitate_uuid.cond_logic = BTA_DM_BLE_PF_LOGIC_AND;
1502904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      btif_to_bta_uuid(&cond->solicitate_uuid.uuid, p_uuid);
1503904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1504904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return do_in_jni_thread(Bind(&BTA_DmBleCfgFilterCondition, action,
1505904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   filt_type, filt_index, base::Owned(cond),
1506904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   &bta_scan_filt_cfg_cb, client_if));
1507904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    }
1508904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1509904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    case BTA_DM_BLE_PF_LOCAL_NAME:  // 4
1510904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    {
1511904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      uint8_t *data = new uint8_t[data_len];
1512904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      memcpy(data, p_data, data_len);
1513904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return do_in_jni_thread(Bind(&btif_gattc_scan_filter_add_local_name,
1514904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   base::Owned(data), data_len, action,
1515904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski                                   filt_type, filt_index, client_if));
1516904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    }
1517904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1518904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    case BTA_DM_BLE_PF_MANU_DATA:  // 5
15191a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    {
1520904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      uint8_t *data = new uint8_t[data_len];
1521904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      memcpy(data, p_data, data_len);
1522904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1523904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      uint8_t *mask = new uint8_t[data_len];
1524904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      memcpy(mask, p_mask, data_len);
1525904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return do_in_jni_thread(
1526904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski          Bind(&btif_gattc_scan_filter_add_manu_data, company_id,
1527904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski               company_id_mask, base::Owned(data), data_len, base::Owned(mask),
1528904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski               action, filt_type, filt_index, client_if));
15291a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    }
1530904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1531904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:  // 6
1532904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    {
1533904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      uint8_t *data = new uint8_t[data_len];
1534904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      memcpy(data, p_data, data_len);
1535904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1536904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      uint8_t *mask = new uint8_t[data_len];
1537904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      memcpy(mask, p_mask, data_len);
1538904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1539904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return do_in_jni_thread(Bind(
1540904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski          &btif_gattc_scan_filter_add_data_pattern, base::Owned(data), data_len,
1541904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski          base::Owned(mask), action, filt_type, filt_index, client_if));
1542904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    }
1543904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski
1544904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski    default:
1545904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      LOG_ERROR(LOG_TAG, "%s: Unknown filter type (%d)!", __func__, action);
1546904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski      return (bt_status_t)BTA_GATT_OK;
1547904aefe1a9c2808a7460ebb9896391acdaa39f4eJakub Pawlowski  }
1548b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach}
1549b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach
155071d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowskistatic bt_status_t btif_gattc_scan_filter_clear(int client_if, int filter_index) {
155171d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski  CHECK_BTGATT_INIT();
155271d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski  BTIF_TRACE_DEBUG("%s: filter_index: %d", __FUNCTION__, filter_index);
15531a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji
155471d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski  return do_in_jni_thread(Bind(&BTA_DmBleCfgFilterCondition,
155571d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski                               BTA_DM_BLE_SCAN_COND_CLEAR,
155671d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski                               BTA_DM_BLE_PF_TYPE_ALL, filter_index, nullptr,
155771d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski                               &bta_scan_filt_cfg_cb, client_if));
15581a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji}
15591a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji
156071d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowskistatic bt_status_t btif_gattc_scan_filter_enable(int client_if, bool enable) {
156171d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski  CHECK_BTGATT_INIT();
156271d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski  BTIF_TRACE_DEBUG("%s: enable: %d", __FUNCTION__, enable);
15631a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji
156471d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski  uint8_t action = enable ? 1: 0;
156571d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski
156671d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski  return do_in_jni_thread(Bind(&BTA_DmEnableScanFilter, action,
156771d4e33a08a5eaf458c4cd3de1ca65a542be81e3Jakub Pawlowski                               &bta_scan_filt_status_cb, client_if));
1568b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach}
1569b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach
15704c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowskistatic bt_status_t btif_gattc_set_scan_parameters(int client_if,
15714c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowski                                                  int scan_interval,
15724c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowski                                                  int scan_window) {
15734c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowski  CHECK_BTGATT_INIT();
15744c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowski  return do_in_jni_thread(
15754c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowski      Bind(BTA_DmSetBleScanParams, client_if, scan_interval, scan_window,
15764c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowski           BTM_BLE_SCAN_MODE_ACTI,
15774c634eeafc79e68b40ff1ade0d96ba7b1c34f85fJakub Pawlowski           (tBLE_SCAN_PARAM_SETUP_CBACK)bta_scan_param_setup_cb));
15787d208f286865ff58ba5e79299c42b9686cca25cbPrerepa Viswanadham}
15797d208f286865ff58ba5e79299c42b9686cca25cbPrerepa Viswanadham
1580ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic int btif_gattc_get_device_type( const bt_bdaddr_t *bd_addr )
1581ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
1582ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    int device_type = 0;
1583ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    char bd_addr_str[18] = {0};
1584ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
15858a6a89faa942aed4f176b0c98402d01c8bdd6aa6Sharvil Nanavati    bdaddr_to_string(bd_addr, bd_addr_str, sizeof(bd_addr_str));
15869d52f88bfc07556cb01ab3055f5b1242c9b467aaSharvil Nanavati    if (btif_config_get_int(bd_addr_str, "DevType", &device_type))
1587ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta        return device_type;
1588ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    return 0;
1589ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1590ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
15913a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowskistatic void btif_gattc_multi_adv_enable_impl(int client_if, int min_interval,
15923a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                                             int max_interval, int adv_type,
15933a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                                             int chnl_map, int tx_power,
15943a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                                             int timeout_s) {
15953a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  tBTA_BLE_ADV_PARAMS param;
15963a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  param.adv_int_min = min_interval;
15973a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  param.adv_int_max = max_interval;
15983a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  param.adv_type = adv_type;
15993a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  param.channel_map = chnl_map;
16003a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  param.adv_filter_policy = 0;
16013a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  param.tx_power = tx_power;
16023a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski
16033a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  int cbindex = -1;
16043a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  int arrindex = btif_multi_adv_add_instid_map(client_if, INVALID_ADV_INST, true);
16053a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  if (arrindex >= 0)
16063a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    cbindex = btif_gattc_obtain_idx_for_datacb(client_if, CLNT_IF_IDX);
16073a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski
16083a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  if (cbindex >= 0 && arrindex >= 0) {
16093a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    btgatt_multi_adv_common_data *p_multi_adv_data_cb =
16103a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski        btif_obtain_multi_adv_data_cb();
16113a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    memcpy(&p_multi_adv_data_cb->inst_cb[cbindex].param, &param,
16123a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski           sizeof(tBTA_BLE_ADV_PARAMS));
16133a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    p_multi_adv_data_cb->inst_cb[cbindex].timeout_s = timeout_s;
16143a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    BTIF_TRACE_DEBUG("%s, client_if value: %d", __FUNCTION__,
16153a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                     p_multi_adv_data_cb->clntif_map[arrindex + arrindex]);
16163a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    BTA_BleEnableAdvInstance(
16173a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski        &(p_multi_adv_data_cb->inst_cb[cbindex].param),
16183a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski        bta_gattc_multi_adv_cback,
16193a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski        &(p_multi_adv_data_cb->clntif_map[arrindex + arrindex]));
16203a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  } else {
16213a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    // let the error propagate up from BTA layer
16223a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    BTIF_TRACE_ERROR("%s invalid index arrindex: %d, cbindex: %d",
16233a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                     __func__, arrindex, cbindex);
16243a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski    BTA_BleEnableAdvInstance(&param, bta_gattc_multi_adv_cback, NULL);
16253a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  }
16263a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski}
16273a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski
16283a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowskistatic bt_status_t btif_gattc_multi_adv_enable(int client_if, int min_interval,
16293a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                                               int max_interval, int adv_type,
16303a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                                               int chnl_map, int tx_power,
16313a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                                               int timeout_s) {
16323a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  CHECK_BTGATT_INIT();
16333a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski  return do_in_jni_thread(Bind(btif_gattc_multi_adv_enable_impl, client_if,
16343a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                               min_interval, max_interval, adv_type, chnl_map,
16353a70173f66b9ca3c5ad6260ca963180c479c5d0dJakub Pawlowski                               tx_power, timeout_s));
1636a6ce7751d84218c193eb90d390aef23217b1737eWei Wang}
1637a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
16385dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowskistatic void btif_gattc_multi_adv_update_impl(int client_if, int min_interval,
16395dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                                             int max_interval, int adv_type,
16405dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                                             int chnl_map, int tx_power) {
16415dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  tBTA_BLE_ADV_PARAMS param;
16425dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  param.adv_int_min = min_interval;
16435dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  param.adv_int_max = max_interval;
16445dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  param.adv_type = adv_type;
16455dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  param.channel_map = chnl_map;
16465dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  param.adv_filter_policy = 0;
16475dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  param.tx_power = tx_power;
16485dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski
16495dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  int inst_id = btif_multi_adv_instid_for_clientif(client_if);
16505dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  int cbindex = btif_gattc_obtain_idx_for_datacb(client_if, CLNT_IF_IDX);
16515dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  if (inst_id >= 0 && cbindex >= 0) {
16525dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski    btgatt_multi_adv_common_data *p_multi_adv_data_cb =
16535dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski        btif_obtain_multi_adv_data_cb();
16545dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski    memcpy(&p_multi_adv_data_cb->inst_cb[cbindex].param, &param,
16555dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski           sizeof(tBTA_BLE_ADV_PARAMS));
16565dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski    BTA_BleUpdateAdvInstParam((UINT8)inst_id,
16575dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                              &(p_multi_adv_data_cb->inst_cb[cbindex].param));
16585dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  } else {
16595dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski    BTIF_TRACE_ERROR("%s invalid index in BTIF_GATTC_UPDATE_ADV", __FUNCTION__);
16605dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  }
16615dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski}
1662a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
16635dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowskistatic bt_status_t btif_gattc_multi_adv_update(int client_if, int min_interval,
16645dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                                               int max_interval, int adv_type,
16655dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                                               int chnl_map, int tx_power,
16665dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                                               int timeout_s) {
16675dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  CHECK_BTGATT_INIT();
16685dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski  return do_in_jni_thread(Bind(btif_gattc_multi_adv_update_impl, client_if,
16695dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                               min_interval, max_interval, adv_type, chnl_map,
16705dfe8ba500ad0594c787a0b905369f36de7da38bJakub Pawlowski                               tx_power));
1671a6ce7751d84218c193eb90d390aef23217b1737eWei Wang}
1672a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
1673ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowskistatic void btif_gattc_multi_adv_setdata_impl(btif_adv_data_t *p_adv_data) {
1674ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  int cbindex =
1675ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski      btif_gattc_obtain_idx_for_datacb(p_adv_data->client_if, CLNT_IF_IDX);
1676ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  int inst_id = btif_multi_adv_instid_for_clientif(p_adv_data->client_if);
1677ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  if (inst_id >= 0 && cbindex >= 0 &&
1678ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski      btif_gattc_copy_datacb(cbindex, p_adv_data, true)) {
1679ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski    btgatt_multi_adv_common_data *p_multi_adv_data_cb =
1680ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski        btif_obtain_multi_adv_data_cb();
1681ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski    BTA_BleCfgAdvInstData((UINT8)inst_id, p_adv_data->set_scan_rsp,
1682ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski                          p_multi_adv_data_cb->inst_cb[cbindex].mask,
1683ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski                          &p_multi_adv_data_cb->inst_cb[cbindex].data);
1684ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  } else {
1685ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski    BTIF_TRACE_ERROR(
1686ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski        "%s: failed to get invalid instance data: inst_id:%d cbindex:%d",
1687ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski        __func__, inst_id, cbindex);
1688ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  }
1689ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski}
1690a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
1691ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowskistatic bt_status_t btif_gattc_multi_adv_setdata(
1692ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski    int client_if, bool set_scan_rsp, bool include_name, bool incl_txpower,
1693ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski    int appearance, int manufacturer_len, char *manufacturer_data,
1694ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski    int service_data_len, char *service_data, int service_uuid_len,
1695ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski    char *service_uuid) {
1696ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  CHECK_BTGATT_INIT();
16970d45f25e4102b14d942efa530f0e6a1a6c19787aIan Coolidge
1698ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  btif_adv_data_t *multi_adv_data_inst = new btif_adv_data_t;
1699a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
1700ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  const int min_interval = 0;
1701ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  const int max_interval = 0;
1702a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
1703ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  btif_gattc_adv_data_packager(client_if, set_scan_rsp, include_name,
1704ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski                               incl_txpower, min_interval, max_interval,
1705ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski                               appearance, manufacturer_len, manufacturer_data,
1706ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski                               service_data_len, service_data, service_uuid_len,
1707ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski                               service_uuid, multi_adv_data_inst);
1708ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski
1709ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski  return do_in_jni_thread(Bind(&btif_gattc_multi_adv_setdata_impl,
1710ed8aefe6134359cc70b127a23bac3a6d4c24065eJakub Pawlowski                               base::Owned(multi_adv_data_inst)));
1711a6ce7751d84218c193eb90d390aef23217b1737eWei Wang}
1712a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
1713772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowskistatic void btif_gattc_multi_adv_disable_impl(int client_if) {
1714772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski  int inst_id = btif_multi_adv_instid_for_clientif(client_if);
1715772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski  if (inst_id >= 0)
1716772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski    BTA_BleDisableAdvInstance((UINT8)inst_id);
1717772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski  else
1718772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski    BTIF_TRACE_ERROR("%s invalid instance ID", __func__);
1719772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski}
1720a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
1721772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowskistatic bt_status_t btif_gattc_multi_adv_disable(int client_if) {
1722772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski  CHECK_BTGATT_INIT();
1723772fc669dcf1221df03377e5c16507f2f7caa91bJakub Pawlowski  return do_in_jni_thread(Bind(btif_gattc_multi_adv_disable_impl, client_if));
1724a6ce7751d84218c193eb90d390aef23217b1737eWei Wang}
1725a6ce7751d84218c193eb90d390aef23217b1737eWei Wang
17262af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowskistatic bt_status_t btif_gattc_cfg_storage(int client_if,
17272af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                                          int batch_scan_full_max,
17282af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                                          int batch_scan_trunc_max,
17292af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                                          int batch_scan_notify_threshold) {
17302af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  CHECK_BTGATT_INIT();
17312af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  return do_in_jni_thread(
17322af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski      Bind(BTA_DmBleSetStorageParams, batch_scan_full_max, batch_scan_trunc_max,
17332af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski           batch_scan_notify_threshold,
17342af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski           (tBTA_BLE_SCAN_SETUP_CBACK *)bta_batch_scan_setup_cb,
17352af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski           (tBTA_BLE_SCAN_THRESHOLD_CBACK *)bta_batch_scan_threshold_cb,
17362af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski           (tBTA_BLE_SCAN_REP_CBACK *)bta_batch_scan_reports_cb,
17372af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski           (tBTA_DM_BLE_REF_VALUE)client_if));
1738c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji}
1739c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
17402af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowskistatic bt_status_t btif_gattc_enb_batch_scan(int client_if, int scan_mode,
17412af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                                             int scan_interval, int scan_window,
17422af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                                             int addr_type, int discard_rule) {
17432af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  CHECK_BTGATT_INIT();
17442af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  return do_in_jni_thread(Bind(BTA_DmBleEnableBatchScan, scan_mode,
17452af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                               scan_interval, scan_window, discard_rule,
17462af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                               addr_type, client_if));
1747c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji}
1748c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
17492af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowskistatic bt_status_t btif_gattc_dis_batch_scan(int client_if) {
17502af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  CHECK_BTGATT_INIT();
17512af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  return do_in_jni_thread(Bind(BTA_DmBleDisableBatchScan, client_if));
1752c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji}
1753c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
17542af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowskistatic bt_status_t btif_gattc_read_batch_scan_reports(int client_if,
17552af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski                                                      int scan_mode) {
17562af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  CHECK_BTGATT_INIT();
17572af2129df720baee246d4ff9a0f1a02884da856eJakub Pawlowski  return do_in_jni_thread(Bind(BTA_DmBleReadScanReports, scan_mode, client_if));
1758c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji}
1759c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji
1760ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battaextern bt_status_t btif_gattc_test_command_impl(int command, btgatt_test_params_t* params);
1761ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1762ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battastatic bt_status_t btif_gattc_test_command(int command, btgatt_test_params_t* params)
1763ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{
1764ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    return btif_gattc_test_command_impl(command, params);
1765ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta}
1766ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1767ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battaconst btgatt_client_interface_t btgattClientInterface = {
1768ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_register_app,
1769ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_unregister_app,
1770ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_scan,
1771ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_open,
1772ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_close,
17735c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    btif_gattc_listen,
1774ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_refresh,
1775ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_search_service,
1776ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_read_char,
1777ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_write_char,
1778ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_read_char_descr,
1779ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_write_char_descr,
1780ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_execute_write,
1781ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_reg_for_notification,
1782ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_dereg_for_notification,
1783ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_read_remote_rssi,
17841a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    btif_gattc_scan_filter_param_setup,
17851a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    btif_gattc_scan_filter_add_remove,
1786b203d478f4835f5e35217874a1787e1914328f7cAndre Eisenbach    btif_gattc_scan_filter_clear,
17871a9247a1229aa65b3d1dce16426177bc5828e54dSatya Calloji    btif_gattc_scan_filter_enable,
1788ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta    btif_gattc_get_device_type,
17895c44e45473e5fc2fa89411ab1add7dbfc979f1f8Andre Eisenbach    btif_gattc_set_adv_data,
17909426d530e9bbc5d3ffae55515388d49185c61325Andre Eisenbach    btif_gattc_configure_mtu,
179152a2cd609897c04bb6440e14ef2ec8871143d028Andre Eisenbach    btif_gattc_conn_parameter_update,
17927d208f286865ff58ba5e79299c42b9686cca25cbPrerepa Viswanadham    btif_gattc_set_scan_parameters,
1793a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_gattc_multi_adv_enable,
1794a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_gattc_multi_adv_update,
1795a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_gattc_multi_adv_setdata,
1796a6ce7751d84218c193eb90d390aef23217b1737eWei Wang    btif_gattc_multi_adv_disable,
1797c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_gattc_cfg_storage,
1798c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_gattc_enb_batch_scan,
1799c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_gattc_dis_batch_scan,
1800c4e2596a112a0dd63ac681b1226548c0f95e828cSatya Calloji    btif_gattc_read_batch_scan_reports,
1801533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski    btif_gattc_test_command,
1802533fdbf46fb623aefbe4d0107b5cccd41aec097aJakub Pawlowski    btif_gattc_get_gatt_db
1803ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta};
1804ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta
1805ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta#endif
1806