1 /* 2 * Copyright 2021 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 #pragma once 18 19 #include "stack/include/bt_types.h" 20 #include "stack/include/hcidefs.h" 21 22 #define BD_FEATURES_LEN 8 23 typedef uint8_t 24 BD_FEATURES[BD_FEATURES_LEN]; /* LMP features supported by device */ 25 26 // Bit order [0]:0-7 [1]:8-15 ... [7]:56-63 bd_features_text(const BD_FEATURES & features)27inline std::string bd_features_text(const BD_FEATURES& features) { 28 uint8_t len = BD_FEATURES_LEN; 29 char buf[255]; 30 char* pbuf = buf; 31 const uint8_t* b = features; 32 while (len--) { 33 pbuf += sprintf(pbuf, "0x%02x ", *b++); 34 } 35 return std::string(buf); 36 } 37 38 /** 39 * Create a bitmask of packet types from the remote feature 40 */ 41 class PeerPacketTypes { 42 public: 43 struct { 44 uint16_t supported{0}; 45 uint16_t unsupported{0}; 46 } acl{.supported = (HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1)}, sco{}; 47 PeerPacketTypes(const BD_FEATURES & features)48 PeerPacketTypes(const BD_FEATURES& features) { 49 /* 3 and 5 slot packets? */ 50 if (HCI_3_SLOT_PACKETS_SUPPORTED(features)) 51 acl.supported |= (HCI_PKT_TYPES_MASK_DH3 | HCI_PKT_TYPES_MASK_DM3); 52 53 if (HCI_5_SLOT_PACKETS_SUPPORTED(features)) 54 acl.supported |= HCI_PKT_TYPES_MASK_DH5 | HCI_PKT_TYPES_MASK_DM5; 55 56 /* 2 and 3 MPS support? */ 57 if (!HCI_EDR_ACL_2MPS_SUPPORTED(features)) 58 /* Not supported. Add 'not_supported' mask for all 2MPS packet types */ 59 acl.unsupported |= 60 (HCI_PKT_TYPES_MASK_NO_2_DH1 | HCI_PKT_TYPES_MASK_NO_2_DH3 | 61 HCI_PKT_TYPES_MASK_NO_2_DH5); 62 63 if (!HCI_EDR_ACL_3MPS_SUPPORTED(features)) 64 /* Not supported. Add 'not_supported' mask for all 3MPS packet types */ 65 acl.unsupported |= 66 (HCI_PKT_TYPES_MASK_NO_3_DH1 | HCI_PKT_TYPES_MASK_NO_3_DH3 | 67 HCI_PKT_TYPES_MASK_NO_3_DH5); 68 69 /* EDR 3 and 5 slot support? */ 70 if (HCI_EDR_ACL_2MPS_SUPPORTED(features) || 71 HCI_EDR_ACL_3MPS_SUPPORTED(features)) { 72 if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(features)) 73 /* Not supported. Add 'not_supported' mask for all 3-slot EDR packet 74 * types 75 */ 76 acl.unsupported |= 77 (HCI_PKT_TYPES_MASK_NO_2_DH3 | HCI_PKT_TYPES_MASK_NO_3_DH3); 78 79 if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(features)) 80 /* Not supported. Add 'not_supported' mask for all 5-slot EDR packet 81 * types 82 */ 83 acl.unsupported |= 84 (HCI_PKT_TYPES_MASK_NO_2_DH5 | HCI_PKT_TYPES_MASK_NO_3_DH5); 85 } 86 } 87 }; 88