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 #include "l2cap/le/link_options.h"
18 
19 #include <cstdint>
20 
21 #include "hci/hci_packets.h"
22 #include "l2cap/le/internal/link.h"
23 
24 namespace bluetooth {
25 namespace l2cap {
26 namespace le {
27 
LinkOptions(hci::acl_manager::LeAclConnection * acl_connection,internal::Link * link,os::Handler * l2cap_handler)28 LinkOptions::LinkOptions(hci::acl_manager::LeAclConnection* acl_connection, internal::Link* link,
29                          os::Handler* l2cap_handler)
30     : acl_connection_(acl_connection), link_(link), l2cap_handler_(l2cap_handler) {}
31 
GetRole() const32 hci::Role LinkOptions::GetRole() const {
33   return acl_connection_->GetRole();
34 }
35 
GetHandle() const36 uint16_t LinkOptions::GetHandle() const {
37   return acl_connection_->GetHandle();
38 }
39 
GetLocalAddress() const40 hci::AddressWithType LinkOptions::GetLocalAddress() const {
41   return acl_connection_->GetLocalAddress();
42 }
43 
UpdateConnectionParameter(uint16_t conn_interval_min,uint16_t conn_interval_max,uint16_t conn_latency,uint16_t supervision_timeout,uint16_t min_ce_length,uint16_t max_ce_length)44 bool LinkOptions::UpdateConnectionParameter(uint16_t conn_interval_min, uint16_t conn_interval_max,
45                                             uint16_t conn_latency, uint16_t supervision_timeout, uint16_t min_ce_length,
46                                             uint16_t max_ce_length) {
47   if (conn_interval_min < 0x0006 || conn_interval_min > 0x0C80 || conn_interval_max < 0x0006 ||
48       conn_interval_max > 0x0C80 || conn_latency > 0x01F3 || supervision_timeout < 0x000A ||
49       supervision_timeout > 0x0C80) {
50     LOG_ERROR("Invalid parameter");
51     return false;
52   }
53 
54   l2cap_handler_->Post(common::BindOnce(&internal::Link::SendConnectionParameterUpdate, common::Unretained(link_),
55                                         conn_interval_min, conn_interval_max, conn_latency, supervision_timeout,
56                                         min_ce_length, max_ce_length));
57 
58   return true;
59 }
60 
SetPhy(uint8_t all_phys,uint8_t tx_phys,uint8_t rx_phys,uint16_t phy_options)61 bool LinkOptions::SetPhy(uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint16_t phy_options) {
62   LOG_ERROR("Not implemented");
63   return false;
64 }
65 
66 }  // namespace le
67 }  // namespace l2cap
68 }  // namespace bluetooth
69