1 /*
2 * Copyright 2022 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 "model/controller/link_layer_controller.h"
18
19 enum : unsigned {
20 CONNECTABLE = 0x1,
21 SCANNABLE = 0x2,
22 DIRECTED = 0x4,
23 HIGH_DUTY_CYCLE = 0x8,
24 LEGACY = 0x10,
25 ANONYMOUS = 0x20,
26 TX_POWER = 0x40,
27 };
28
29 [[maybe_unused]] static bluetooth::hci::AdvertisingEventProperties
30 MakeAdvertisingEventProperties(unsigned mask = 0) {
31 bluetooth::hci::AdvertisingEventProperties properties;
32 properties.connectable_ = (mask & CONNECTABLE) != 0;
33 properties.scannable_ = (mask & SCANNABLE) != 0;
34 properties.directed_ = (mask & DIRECTED) != 0;
35 properties.high_duty_cycle_ = (mask & HIGH_DUTY_CYCLE) != 0;
36 properties.legacy_ = (mask & LEGACY) != 0;
37 properties.anonymous_ = (mask & ANONYMOUS) != 0;
38 properties.tx_power_ = (mask & TX_POWER) != 0;
39 return properties;
40 }
41
MakeEnabledSet(uint8_t advertising_handle,uint16_t duration,uint8_t max_extended_advertising_events)42 [[maybe_unused]] static bluetooth::hci::EnabledSet MakeEnabledSet(
43 uint8_t advertising_handle, uint16_t duration,
44 uint8_t max_extended_advertising_events) {
45 bluetooth::hci::EnabledSet set;
46 set.advertising_handle_ = advertising_handle;
47 set.duration_ = duration;
48 set.max_extended_advertising_events_ = max_extended_advertising_events;
49 return set;
50 }
51
52 [[maybe_unused]] static bluetooth::hci::InitiatingPhyParameters
MakeInitiatingPhyParameters(uint16_t scan_interval,uint16_t scan_window,uint16_t connection_interval_min,uint16_t connection_interval_max,uint16_t max_latency,uint16_t supervision_timeout,uint16_t min_ce_length,uint16_t max_ce_length)53 MakeInitiatingPhyParameters(uint16_t scan_interval, uint16_t scan_window,
54 uint16_t connection_interval_min,
55 uint16_t connection_interval_max,
56 uint16_t max_latency, uint16_t supervision_timeout,
57 uint16_t min_ce_length, uint16_t max_ce_length) {
58 bluetooth::hci::InitiatingPhyParameters parameters;
59 parameters.scan_interval_ = scan_interval;
60 parameters.scan_window_ = scan_window;
61 parameters.connection_interval_min_ = connection_interval_min;
62 parameters.connection_interval_max_ = connection_interval_max;
63 parameters.max_latency_ = max_latency;
64 parameters.supervision_timeout_ = supervision_timeout;
65 parameters.min_ce_length_ = min_ce_length;
66 parameters.max_ce_length_ = max_ce_length;
67 return parameters;
68 }
69