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