19ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// 29ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// Copyright (C) 2015 Google, Inc. 39ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// 49ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// Licensed under the Apache License, Version 2.0 (the "License"); 59ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// you may not use this file except in compliance with the License. 69ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// You may obtain a copy of the License at: 79ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// 89ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// http://www.apache.org/licenses/LICENSE-2.0 99ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// 109ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// Unless required by applicable law or agreed to in writing, software 119ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// distributed under the License is distributed on an "AS IS" BASIS, 129ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// See the License for the specific language governing permissions and 149ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// limitations under the License. 159ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// 169ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 179ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray#include "service/hal/fake_bluetooth_gatt_interface.h" 189ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 199ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguraynamespace bluetooth { 209ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguraynamespace hal { 219ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguraynamespace { 229ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 239e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray// The global test handler instances. We have to have globals since the HAL 249e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray// interface methods all have to be global and their signatures don't allow us 259e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray// to pass in user_data. 2674ef54b440dc50bb25f587783d80fe5a37070e4aJakub Pawlowskistd::shared_ptr<BleAdvertiserInterface> g_advertiser_handler; 2783f1d967df168f862cf733cabbab76f7c52587f4Jakub Pawlowskistd::shared_ptr<BleScannerInterface> g_scanner_handler; 289e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguraystd::shared_ptr<FakeBluetoothGattInterface::TestClientHandler> g_client_handler; 299e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguraystd::shared_ptr<FakeBluetoothGattInterface::TestServerHandler> g_server_handler; 309ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 3196ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t FakeRegisterClient(const bt_uuid_t& app_uuid) { 32911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_client_handler) return g_client_handler->RegisterClient(app_uuid); 339ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 349ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray return BT_STATUS_FAIL; 359ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} 369ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 379ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguraybt_status_t FakeUnregisterClient(int client_if) { 38911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_client_handler) return g_client_handler->UnregisterClient(client_if); 399ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 409ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray return BT_STATUS_FAIL; 419ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} 429ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 43a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskibt_status_t FakeConnect(int client_if, const RawAddress& bd_addr, 445120fedf20eb29fa65cef561c475d18d51197b25Jack He bool is_direct, int transport, bool opportunistic, 455120fedf20eb29fa65cef561c475d18d51197b25Jack He int phy) { 46ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski if (g_client_handler) 47ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski return g_client_handler->Connect(client_if, bd_addr, is_direct, transport); 48ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski 49ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski return BT_STATUS_FAIL; 50ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski} 51ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski 52a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowskibt_status_t FakeDisconnect(int client_if, const RawAddress& bd_addr, 53ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski int conn_id) { 54ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski if (g_client_handler) 55ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski return g_client_handler->Disconnect(client_if, bd_addr, conn_id); 56ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski 57ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski return BT_STATUS_FAIL; 58ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski} 59ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski 6096ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowskibt_status_t FakeRegisterServer(const bt_uuid_t& app_uuid) { 61911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_server_handler) return g_server_handler->RegisterServer(app_uuid); 629e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 639e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray return BT_STATUS_FAIL; 649e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray} 659e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 669e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguraybt_status_t FakeUnregisterServer(int server_if) { 67911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_server_handler) return g_server_handler->UnregisterServer(server_if); 68d1ed1f53a5c0cce5ecb8d784acf5bef53211a20fArman Uguray 69d1ed1f53a5c0cce5ecb8d784acf5bef53211a20fArman Uguray return BT_STATUS_FAIL; 70d1ed1f53a5c0cce5ecb8d784acf5bef53211a20fArman Uguray} 71d1ed1f53a5c0cce5ecb8d784acf5bef53211a20fArman Uguray 72b324a8d0b719065cec10379ad6855852724d9004Pavlin Radoslavovbt_status_t FakeAddService(int server_if, 73b324a8d0b719065cec10379ad6855852724d9004Pavlin Radoslavov std::vector<btgatt_db_element_t> service) { 7478a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray if (g_server_handler) 75a641b6fa2a25e1b5382945d13c4fa49d36084a78Jakub Pawlowski return g_server_handler->AddService(server_if, std::move(service)); 7678a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray 7778a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray return BT_STATUS_FAIL; 7878a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray} 7978a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray 8078a44cdb25616892087af2c92abd382878c2ccb4Arman Uguraybt_status_t FakeDeleteService(int server_if, int srvc_handle) { 8178a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray if (g_server_handler) 8278a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray return g_server_handler->DeleteService(server_if, srvc_handle); 8378a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray 8478a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray return BT_STATUS_FAIL; 8578a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray} 8678a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray 87911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonbt_status_t FakeSendIndication(int server_if, int attribute_handle, int conn_id, 88b324a8d0b719065cec10379ad6855852724d9004Pavlin Radoslavov int confirm, std::vector<uint8_t> value) { 89cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray if (g_server_handler) 90cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray return g_server_handler->SendIndication(server_if, attribute_handle, 91ec79baaaed83529dae14d492ea2f73aedee9e4d0Jakub Pawlowski conn_id, confirm, std::move(value)); 92cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray 93cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray return BT_STATUS_FAIL; 94cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray} 95cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray 96b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguraybt_status_t FakeSendResponse(int conn_id, int trans_id, int status, 9796ac0a3c16a4a9f98169baf158bae16528cde79bJakub Pawlowski const btgatt_response_t& response) { 98b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray if (g_server_handler) 99b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray return g_server_handler->SendResponse(conn_id, trans_id, status, response); 100b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray 101b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray return BT_STATUS_FAIL; 102b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray} 103b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray 104c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowskibtgatt_client_interface_t fake_btgattc_iface = { 105911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeRegisterClient, 106911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeUnregisterClient, 107911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeConnect, 108911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeDisconnect, 109911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // refresh 110911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // search_service 11145aebe75f75c1f93c396118bc39748fc0f4054c7Jakub Pawlowski nullptr, // discover_service_by_uuid 112911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // read_characteristic 1137dd34f52bc950bae2fb1b30b17da0ff34ee016aaJakub Pawlowski nullptr, // read_using_characteristic_uuid 114911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // write_characteristic 115911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // read_descriptor 116911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // write_descriptor 117911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // execute_write 118911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // register_for_notification 119911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // deregister_for_notification 120911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // read_remote_rssi 121911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // get_device_type 122911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // configure_mtu 123911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // conn_parameter_update 124eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski nullptr, // set_phy 125eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski nullptr, // read_phy 126911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // test_command 127911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // get_gatt_db 1289e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray}; 1299e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 1309e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguraybtgatt_server_interface_t fake_btgatts_iface = { 131911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeRegisterServer, 132911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeUnregisterServer, 133911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // connect 134911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // disconnect 135911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeAddService, 136911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson nullptr, // stop_service 137911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeDeleteService, 138911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeSendIndication, 139911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FakeSendResponse, 140eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski nullptr, // set_phy 141eafd45d08653bb1621c82a2f3cf922a43a0b1bc5Jakub Pawlowski nullptr, // read_phy 1429ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray}; 1439ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 1449ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} // namespace 1459ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 1469ded7b6175825afdac0e2cebef8755e4d7b03103Arman UgurayFakeBluetoothGattInterface::FakeBluetoothGattInterface( 14774ef54b440dc50bb25f587783d80fe5a37070e4aJakub Pawlowski std::shared_ptr<BleAdvertiserInterface> advertiser_handler, 14883f1d967df168f862cf733cabbab76f7c52587f4Jakub Pawlowski std::shared_ptr<BleScannerInterface> scanner_handler, 1499e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray std::shared_ptr<TestClientHandler> client_handler, 1509e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray std::shared_ptr<TestServerHandler> server_handler) 15174ef54b440dc50bb25f587783d80fe5a37070e4aJakub Pawlowski : client_handler_(client_handler) { 15267d5a2523314d9757b2472c3e828dbc1015df4feJakub Pawlowski CHECK(!g_advertiser_handler); 153c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski CHECK(!g_scanner_handler); 1549e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray CHECK(!g_client_handler); 1559e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray CHECK(!g_server_handler); 1569ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 1579ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray // We allow passing NULL. In this case all calls we fail by default. 158911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (advertiser_handler) g_advertiser_handler = advertiser_handler; 15967d5a2523314d9757b2472c3e828dbc1015df4feJakub Pawlowski 160911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (scanner_handler) g_scanner_handler = scanner_handler; 161c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski 162911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (client_handler) g_client_handler = client_handler; 1639e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 164911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (server_handler) g_server_handler = server_handler; 1659ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} 1669ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 1679ded7b6175825afdac0e2cebef8755e4d7b03103Arman UgurayFakeBluetoothGattInterface::~FakeBluetoothGattInterface() { 168911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_advertiser_handler) g_advertiser_handler = nullptr; 16967d5a2523314d9757b2472c3e828dbc1015df4feJakub Pawlowski 170911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_scanner_handler) g_scanner_handler = nullptr; 171c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski 172911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_client_handler) g_client_handler = nullptr; 1739e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 174911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson if (g_server_handler) g_server_handler = nullptr; 1759ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} 1769ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 1779ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// The methods below can be used to notify observers with certain events and 1789ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray// given parameters. 179c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowskivoid FakeBluetoothGattInterface::NotifyScanResultCallback( 180a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bda, int rssi, std::vector<uint8_t> adv_data) { 181c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski FOR_EACH_OBSERVER(ScannerObserver, scanner_observers_, 182c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski ScanResultCallback(this, bda, rssi, adv_data)); 183c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski} 184c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski 1859ded7b6175825afdac0e2cebef8755e4d7b03103Arman Ugurayvoid FakeBluetoothGattInterface::NotifyRegisterClientCallback( 186911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson int status, int client_if, const bt_uuid_t& app_uuid) { 1879ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray FOR_EACH_OBSERVER(ClientObserver, client_observers_, 188d1ed1f53a5c0cce5ecb8d784acf5bef53211a20fArman Uguray RegisterClientCallback(this, status, client_if, app_uuid)); 189d1ed1f53a5c0cce5ecb8d784acf5bef53211a20fArman Uguray} 190d1ed1f53a5c0cce5ecb8d784acf5bef53211a20fArman Uguray 191911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonvoid FakeBluetoothGattInterface::NotifyConnectCallback(int conn_id, int status, 192911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson int client_if, 193a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski const RawAddress& bda) { 194ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski FOR_EACH_OBSERVER(ClientObserver, client_observers_, 195ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski ConnectCallback(this, conn_id, status, client_if, bda)); 196ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski} 197ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski 198ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowskivoid FakeBluetoothGattInterface::NotifyDisconnectCallback( 199a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski int conn_id, int status, int client_if, const RawAddress& bda) { 200ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski FOR_EACH_OBSERVER(ClientObserver, client_observers_, 201ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski DisconnectCallback(this, conn_id, status, client_if, bda)); 202ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski} 203ce021ddaafea0cdb78005fe08bc8510f9c75aca4Jakub Pawlowski 2049e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Ugurayvoid FakeBluetoothGattInterface::NotifyRegisterServerCallback( 205911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson int status, int server_if, const bt_uuid_t& app_uuid) { 2069e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray FOR_EACH_OBSERVER(ServerObserver, server_observers_, 2079e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray RegisterServerCallback(this, status, server_if, app_uuid)); 2089e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray} 2099e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 210b10f96fa25266b69d0d31af166e93afe14134be7Arman Ugurayvoid FakeBluetoothGattInterface::NotifyServerConnectionCallback( 211a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski int conn_id, int server_if, int connected, const RawAddress& bda) { 212b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray FOR_EACH_OBSERVER( 213b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray ServerObserver, server_observers_, 214b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray ConnectionCallback(this, conn_id, server_if, connected, bda)); 215b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray} 216b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray 21778a44cdb25616892087af2c92abd382878c2ccb4Arman Ugurayvoid FakeBluetoothGattInterface::NotifyServiceAddedCallback( 218b324a8d0b719065cec10379ad6855852724d9004Pavlin Radoslavov int status, int server_if, std::vector<btgatt_db_element_t> service) { 219911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FOR_EACH_OBSERVER(ServerObserver, server_observers_, 220911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson ServiceAddedCallback(this, status, server_if, service)); 22178a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray} 22278a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray 223a641b6fa2a25e1b5382945d13c4fa49d36084a78Jakub Pawlowskivoid FakeBluetoothGattInterface::NotifyRequestReadCharacteristicCallback( 224a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski int conn_id, int trans_id, const RawAddress& bda, int attr_handle, 225a641b6fa2a25e1b5382945d13c4fa49d36084a78Jakub Pawlowski int offset, bool is_long) { 226d9b0552a7f75737b5c8c60cb87f892b1b9323acfArman Uguray FOR_EACH_OBSERVER( 227d9b0552a7f75737b5c8c60cb87f892b1b9323acfArman Uguray ServerObserver, server_observers_, 228911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson RequestReadCharacteristicCallback(this, conn_id, trans_id, bda, 229911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson attr_handle, offset, is_long)); 230d9b0552a7f75737b5c8c60cb87f892b1b9323acfArman Uguray} 231d9b0552a7f75737b5c8c60cb87f892b1b9323acfArman Uguray 232a641b6fa2a25e1b5382945d13c4fa49d36084a78Jakub Pawlowskivoid FakeBluetoothGattInterface::NotifyRequestReadDescriptorCallback( 233a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski int conn_id, int trans_id, const RawAddress& bda, int attr_handle, 234a641b6fa2a25e1b5382945d13c4fa49d36084a78Jakub Pawlowski int offset, bool is_long) { 23578a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray FOR_EACH_OBSERVER( 23678a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray ServerObserver, server_observers_, 237911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson RequestReadDescriptorCallback(this, conn_id, trans_id, bda, attr_handle, 238911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson offset, is_long)); 23978a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray} 24078a44cdb25616892087af2c92abd382878c2ccb4Arman Uguray 241a641b6fa2a25e1b5382945d13c4fa49d36084a78Jakub Pawlowskivoid FakeBluetoothGattInterface::NotifyRequestWriteCharacteristicCallback( 242a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski int conn_id, int trans_id, const RawAddress& bda, int attr_handle, 243b324a8d0b719065cec10379ad6855852724d9004Pavlin Radoslavov int offset, bool need_rsp, bool is_prep, std::vector<uint8_t> value) { 244911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson FOR_EACH_OBSERVER(ServerObserver, server_observers_, 245911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson RequestWriteCharacteristicCallback( 246911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson this, conn_id, trans_id, bda, attr_handle, offset, 247911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson need_rsp, is_prep, value)); 248b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray} 249b10f96fa25266b69d0d31af166e93afe14134be7Arman Uguray 250a641b6fa2a25e1b5382945d13c4fa49d36084a78Jakub Pawlowskivoid FakeBluetoothGattInterface::NotifyRequestWriteDescriptorCallback( 251a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski int conn_id, int trans_id, const RawAddress& bda, int attr_handle, 252b324a8d0b719065cec10379ad6855852724d9004Pavlin Radoslavov int offset, bool need_rsp, bool is_prep, std::vector<uint8_t> value) { 2534ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray FOR_EACH_OBSERVER( 2544ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray ServerObserver, server_observers_, 255911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson RequestWriteDescriptorCallback(this, conn_id, trans_id, bda, attr_handle, 256911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson offset, need_rsp, is_prep, value)); 2574ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray} 2584ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray 2594ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Ugurayvoid FakeBluetoothGattInterface::NotifyRequestExecWriteCallback( 260a484a888196ddf8bcbf1ad3226d6451bc735a94bJakub Pawlowski int conn_id, int trans_id, const RawAddress& bda, int exec_write) { 2614ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray FOR_EACH_OBSERVER( 2624ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray ServerObserver, server_observers_, 2634ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray RequestExecWriteCallback(this, conn_id, trans_id, bda, exec_write)); 2644ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray} 2654ebcbd9ede4006500c3ead0685befe0a8e4aadc2Arman Uguray 266911d1ae03efec2d54c3b1b605589d790d1745488Myles Watsonvoid FakeBluetoothGattInterface::NotifyIndicationSentCallback(int conn_id, 267911d1ae03efec2d54c3b1b605589d790d1745488Myles Watson int status) { 268cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray FOR_EACH_OBSERVER(ServerObserver, server_observers_, 269cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray IndicationSentCallback(this, conn_id, status)); 270cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray} 271cd644e3c54a4321b7626b52531c59f88e24e87beArman Uguray 272c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowskivoid FakeBluetoothGattInterface::AddScannerObserver(ScannerObserver* observer) { 273c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski CHECK(observer); 274c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski scanner_observers_.AddObserver(observer); 275c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski} 276c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski 277c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowskivoid FakeBluetoothGattInterface::RemoveScannerObserver( 278c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski ScannerObserver* observer) { 279c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski CHECK(observer); 280c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski scanner_observers_.RemoveObserver(observer); 281c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski} 282c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski 2839ded7b6175825afdac0e2cebef8755e4d7b03103Arman Ugurayvoid FakeBluetoothGattInterface::AddClientObserver(ClientObserver* observer) { 2849ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray CHECK(observer); 2859ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray client_observers_.AddObserver(observer); 2869ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} 2879ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 2889ded7b6175825afdac0e2cebef8755e4d7b03103Arman Ugurayvoid FakeBluetoothGattInterface::RemoveClientObserver( 2899ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray ClientObserver* observer) { 2909ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray CHECK(observer); 2919ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray client_observers_.RemoveObserver(observer); 2929ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} 2939ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 2949e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Ugurayvoid FakeBluetoothGattInterface::AddServerObserver(ServerObserver* observer) { 2959e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray CHECK(observer); 2969e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray server_observers_.AddObserver(observer); 2979e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray} 2989e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 2999e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Ugurayvoid FakeBluetoothGattInterface::RemoveServerObserver( 3009e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray ServerObserver* observer) { 3019e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray CHECK(observer); 3029e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray server_observers_.RemoveObserver(observer); 3039e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray} 3049e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 30574ef54b440dc50bb25f587783d80fe5a37070e4aJakub PawlowskiBleAdvertiserInterface* FakeBluetoothGattInterface::GetAdvertiserHALInterface() 30674ef54b440dc50bb25f587783d80fe5a37070e4aJakub Pawlowski const { 30774ef54b440dc50bb25f587783d80fe5a37070e4aJakub Pawlowski return g_advertiser_handler.get(); 30867d5a2523314d9757b2472c3e828dbc1015df4feJakub Pawlowski} 30967d5a2523314d9757b2472c3e828dbc1015df4feJakub Pawlowski 31083f1d967df168f862cf733cabbab76f7c52587f4Jakub PawlowskiBleScannerInterface* FakeBluetoothGattInterface::GetScannerHALInterface() 31183f1d967df168f862cf733cabbab76f7c52587f4Jakub Pawlowski const { 31283f1d967df168f862cf733cabbab76f7c52587f4Jakub Pawlowski return g_scanner_handler.get(); 313c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski} 314c3f6a51615c4f26bce0b8b6e16757610dbd0b45bJakub Pawlowski 3159ded7b6175825afdac0e2cebef8755e4d7b03103Arman Ugurayconst btgatt_client_interface_t* 3169ded7b6175825afdac0e2cebef8755e4d7b03103Arman UgurayFakeBluetoothGattInterface::GetClientHALInterface() const { 3179ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray return &fake_btgattc_iface; 3189ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} 3199ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray 3209e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Ugurayconst btgatt_server_interface_t* 3219e5205368d61adf11e75c9e2bd9f6ff26b375bacArman UgurayFakeBluetoothGattInterface::GetServerHALInterface() const { 3229e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray return &fake_btgatts_iface; 3239e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray} 3249e5205368d61adf11e75c9e2bd9f6ff26b375bacArman Uguray 3259ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} // namespace hal 3269ded7b6175825afdac0e2cebef8755e4d7b03103Arman Uguray} // namespace bluetooth 327