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()25constexpr 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(kPINCodeRequestEvent); 50 ENABLE_EVT(kRemoteOOBDataRequestEvent); 51 ENABLE_EVT(kRemoteNameRequestCompleteEvent); 52 ENABLE_EVT(kReadRemoteSupportedFeaturesCompleteEvent); 53 ENABLE_EVT(kReadRemoteVersionInformationCompleteEvent); 54 ENABLE_EVT(kReadRemoteExtendedFeaturesCompleteEvent); 55 ENABLE_EVT(kRoleChangeEvent); 56 ENABLE_EVT(kSimplePairingCompleteEvent); 57 ENABLE_EVT(kSynchronousConnectionCompleteEvent); 58 ENABLE_EVT(kUserConfirmationRequestEvent); 59 ENABLE_EVT(kUserPasskeyRequestEvent); 60 ENABLE_EVT(kUserPasskeyNotificationEvent); 61 62 #undef ENABLE_EVT 63 64 return event_mask; 65 } 66 67 // Builds and returns the LE event mask based on our supported host side 68 // features and controller capabilities. This is used to mask LE events that 69 // we do not know how to handle. BuildLEEventMask()70constexpr uint64_t BuildLEEventMask() { 71 uint64_t event_mask = 0; 72 73 #define ENABLE_EVT(event) \ 74 event_mask |= static_cast<uint64_t>(hci_spec::LEEventMask::event) 75 76 ENABLE_EVT(kLEAdvertisingReport); 77 ENABLE_EVT(kLEConnectionComplete); 78 ENABLE_EVT(kLEConnectionUpdateComplete); 79 ENABLE_EVT(kLEEnhancedConnectionComplete); 80 ENABLE_EVT(kLEExtendedAdvertisingReport); 81 ENABLE_EVT(kLEExtendedAdvertisingSetTerminated); 82 ENABLE_EVT(kLECISRequest); 83 ENABLE_EVT(kLECISEstablished); 84 ENABLE_EVT(kLELongTermKeyRequest); 85 ENABLE_EVT(kLEReadRemoteFeaturesComplete); 86 87 #undef ENABLE_EVT 88 89 return event_mask; 90 } 91 92 } // namespace bt::gap 93