1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdint> 20 21 #include "hci/acl_manager/le_acl_connection.h" 22 #include "hci/hci_packets.h" 23 #include "os/handler.h" 24 25 namespace bluetooth { 26 namespace l2cap { 27 namespace le { 28 namespace internal { 29 class Link; 30 } 31 32 /** 33 * Proxy for L2CAP user to get some link layer properties (connection handle, role), and set link layer options 34 * (connection parameter update, set PHY). Only few special L2CAP users need to use it, including Security Manager, 35 * Hearing Aid Profile, HID Profile, and Java API. 36 * Note: Setting link layer options applies to the LINK, not single CHANNEL. 37 */ 38 class LinkOptions { 39 public: 40 /** 41 * Get LL Role. Most applications should NOT know its LL role. 42 */ 43 hci::Role GetRole() const; 44 45 /** 46 * Get ACL Handle. Most applications should NOT know its ACL handle. 47 */ 48 uint16_t GetHandle() const; 49 50 /** 51 * Return Local address used for initiation of this connection. 52 */ 53 hci::AddressWithType GetLocalAddress() const; 54 55 /** 56 * Update the LE link layer connection parameters. 57 * Depending on the link role and supported features, may directly send HCI command to update link, or send L2CAP 58 * request to advise the remote. The updated connection parameters are still determined by controller. It's a link 59 * layer change for performance tuning, and no host layer change should be observable by user. 60 * Parameters are defined in Core spec HCI 7.8.18. 61 * @return true iff the request is sent to controller through HCI or remote through L2CAP 62 * (Use it only if you know what you are doing!) 63 */ 64 bool UpdateConnectionParameter(uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency, 65 uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length); 66 67 /** 68 * Set PHY preference. The PHY is determined by the controller. 69 * No host layer change should be observable by user. 70 * Parameters are defined in Core spec HCI 7.8.49. 71 * @return true iff the request is sent to controller through HCI 72 * (Use it only if you know what you are doing!) 73 */ 74 bool SetPhy(uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint16_t phy_options); 75 76 LinkOptions(hci::acl_manager::LeAclConnection* acl_connection, internal::Link* link, os::Handler* l2cap_handler); 77 78 private: 79 hci::acl_manager::LeAclConnection* acl_connection_ = nullptr; 80 internal::Link* link_ = nullptr; 81 os::Handler* l2cap_handler_ = nullptr; 82 }; 83 84 } // namespace le 85 } // namespace l2cap 86 } // namespace bluetooth 87