• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #pragma once
16 #include <cstdint>
17 
18 #include "pw_bluetooth_sapphire/internal/host/hci-spec/constants.h"
19 
20 namespace bt::gap {
21 
22 // Builds and returns the HCI event mask based on our supported host side
23 // features and controller capabilities. This is used to mask events that we
24 // do not know how to handle.
BuildEventMask()25 constexpr uint64_t BuildEventMask() {
26   uint64_t event_mask = 0;
27 
28 #define ENABLE_EVT(event) \
29   event_mask |= static_cast<uint64_t>(hci_spec::EventMask::event)
30 
31   // Enable events that are needed for basic functionality. (alphabetic)
32   ENABLE_EVT(kAuthenticationCompleteEvent);
33   ENABLE_EVT(kConnectionCompleteEvent);
34   ENABLE_EVT(kConnectionRequestEvent);
35   ENABLE_EVT(kDataBufferOverflowEvent);
36   ENABLE_EVT(kDisconnectionCompleteEvent);
37   ENABLE_EVT(kEncryptionChangeEvent);
38   ENABLE_EVT(kEncryptionKeyRefreshCompleteEvent);
39   ENABLE_EVT(kExtendedInquiryResultEvent);
40   ENABLE_EVT(kHardwareErrorEvent);
41   ENABLE_EVT(kInquiryCompleteEvent);
42   ENABLE_EVT(kInquiryResultEvent);
43   ENABLE_EVT(kInquiryResultWithRSSIEvent);
44   ENABLE_EVT(kIOCapabilityRequestEvent);
45   ENABLE_EVT(kIOCapabilityResponseEvent);
46   ENABLE_EVT(kLEMetaEvent);
47   ENABLE_EVT(kLinkKeyRequestEvent);
48   ENABLE_EVT(kLinkKeyNotificationEvent);
49   ENABLE_EVT(kRemoteOOBDataRequestEvent);
50   ENABLE_EVT(kRemoteNameRequestCompleteEvent);
51   ENABLE_EVT(kReadRemoteSupportedFeaturesCompleteEvent);
52   ENABLE_EVT(kReadRemoteVersionInformationCompleteEvent);
53   ENABLE_EVT(kReadRemoteExtendedFeaturesCompleteEvent);
54   ENABLE_EVT(kRoleChangeEvent);
55   ENABLE_EVT(kSimplePairingCompleteEvent);
56   ENABLE_EVT(kSynchronousConnectionCompleteEvent);
57   ENABLE_EVT(kUserConfirmationRequestEvent);
58   ENABLE_EVT(kUserPasskeyRequestEvent);
59   ENABLE_EVT(kUserPasskeyNotificationEvent);
60 
61 #undef ENABLE_EVT
62 
63   return event_mask;
64 }
65 
66 // Builds and returns the LE event mask based on our supported host side
67 // features and controller capabilities. This is used to mask LE events that
68 // we do not know how to handle.
BuildLEEventMask()69 constexpr uint64_t BuildLEEventMask() {
70   uint64_t event_mask = 0;
71 
72 #define ENABLE_EVT(event) \
73   event_mask |= static_cast<uint64_t>(hci_spec::LEEventMask::event)
74 
75   ENABLE_EVT(kLEAdvertisingReport);
76   ENABLE_EVT(kLEConnectionComplete);
77   ENABLE_EVT(kLEConnectionUpdateComplete);
78   ENABLE_EVT(kLEExtendedAdvertisingSetTerminated);
79   ENABLE_EVT(kLELongTermKeyRequest);
80   ENABLE_EVT(kLEReadRemoteFeaturesComplete);
81 
82 #undef ENABLE_EVT
83 
84   return event_mask;
85 }
86 
87 }  // namespace bt::gap
88