1 /****************************************************************************** 2 * 3 * Copyright 2018 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #pragma once 20 21 #include <set> 22 23 #include "types/ble_address_with_type.h" 24 #include "types/raw_address.h" 25 26 /* Must be provided by stack to connection manager, so it can dump nice client names in dumpsys */ 27 std::string get_client_name(uint8_t gatt_if); 28 29 /* connection_manager takes care of all the low-level details of LE connection 30 * initiation. It accept requests from multiple subsystems to connect to 31 * devices, and multiplex them into acceptlist add/remove, and scan parameter 32 * changes. 33 * 34 * There is no code for app_id generation. GATT clients use their GATT_IF, and 35 * L2CAP layer uses CONN_MGR_ID_L2CAP as fixed app_id. In case any further 36 * subsystems also use connection_manager, we should consider adding a proper 37 * mechanism for app_id generation. 38 */ 39 namespace connection_manager { 40 41 using tAPP_ID = uint8_t; 42 43 /* Mark device as using targeted announcements. 44 * 45 * @return true if device added to the list, false otherwise */ 46 bool background_connect_targeted_announcement_add(tAPP_ID app_id, const RawAddress& address); 47 48 /* Add a background connect request. 49 * 50 * @return true if device added to the list, false otherwise */ 51 bool background_connect_add(tAPP_ID app_id, const RawAddress& address); 52 53 /* Remove a background connection request. 54 * 55 * @return true if the request is removed, false otherwise. 56 */ 57 bool background_connect_remove(tAPP_ID app_id, const RawAddress& address); 58 59 bool remove_unconditional(const RawAddress& address); 60 61 void reset(bool after_reset); 62 63 void on_app_deregistered(tAPP_ID app_id); 64 void on_connection_complete(const RawAddress& address); 65 66 std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& remote_bda); 67 68 /* Add a direct connect request. 69 * 70 * @return true if device added to the list, false otherwise */ 71 bool direct_connect_add(tAPP_ID app_id, const RawAddress& address, 72 tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC); 73 /* Remove a direct connection request. 74 * 75 * @return true if the request is removed, false otherwise. 76 */ 77 bool direct_connect_remove(tAPP_ID app_id, const RawAddress& address, 78 bool connection_timeout = false); 79 80 void dump(int fd); 81 82 /* This callback will be executed when direct connect attempt fails due to 83 * timeout. It must be implemented by users of connection_manager */ 84 void on_connection_timed_out(uint8_t app_id, const RawAddress& address); 85 void on_connection_timed_out_from_shim(const RawAddress& address); 86 87 bool is_background_connection(const RawAddress& address); 88 89 } // namespace connection_manager 90