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 /* connection_manager takes care of all the low-level details of LE connection 27 * initiation. It accept requests from multiple subsystems to connect to 28 * devices, and multiplex them into acceptlist add/remove, and scan parameter 29 * changes. 30 * 31 * There is no code for app_id generation. GATT clients use their GATT_IF, and 32 * L2CAP layer uses CONN_MGR_ID_L2CAP as fixed app_id. In case any further 33 * subsystems also use connection_manager, we should consider adding a proper 34 * mechanism for app_id generation. 35 */ 36 namespace connection_manager { 37 38 using tAPP_ID = uint8_t; 39 40 /* for background connection */ 41 bool background_connect_targeted_announcement_add(tAPP_ID app_id, const RawAddress& address); 42 bool background_connect_add(tAPP_ID app_id, const RawAddress& address); 43 bool background_connect_remove(tAPP_ID app_id, const RawAddress& address); 44 bool remove_unconditional(const RawAddress& address); 45 46 void reset(bool after_reset); 47 48 void on_app_deregistered(tAPP_ID app_id); 49 void on_connection_complete(const RawAddress& address); 50 51 std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& remote_bda); 52 53 /* create_le_connection is adding device directly to AclManager, and relying on it's "direct 54 * connect" implementation. 55 * direct_connect_add method is doing multiplexing of apps request, and 56 * sending the request to AclManager, but it lacks some extra checks and lookups. Currently these 57 * methods are exclusive, if you try to use both you will get some bad behavior. These should be 58 * merged into one. */ 59 bool create_le_connection(uint8_t /* id */, const RawAddress& bd_addr, 60 tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC); 61 bool direct_connect_add(tAPP_ID app_id, const RawAddress& address); 62 bool direct_connect_remove(tAPP_ID app_id, const RawAddress& address, 63 bool connection_timeout = false); 64 65 void dump(int fd); 66 67 /* This callback will be executed when direct connect attempt fails due to 68 * timeout. It must be implemented by users of connection_manager */ 69 void on_connection_timed_out(uint8_t app_id, const RawAddress& address); 70 void on_connection_timed_out_from_shim(const RawAddress& address); 71 72 bool is_background_connection(const RawAddress& address); 73 74 } // namespace connection_manager 75