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 <stddef.h> 17 18 namespace bt::hci { 19 20 // Represents the controller data buffer settings for one of the BR/EDR, LE, or 21 // SCO transports. 22 class DataBufferInfo { 23 public: 24 // Initialize fields to non-zero values. 25 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) DataBufferInfo(size_t max_data_length,size_t max_num_packets)26 DataBufferInfo(size_t max_data_length, size_t max_num_packets) 27 : max_data_length_(max_data_length), max_num_packets_(max_num_packets) {} 28 29 // The default constructor sets all fields to zero. This can be used to 30 // represent a data buffer that does not exist (e.g. the controller has a 31 // single shared buffer and no dedicated LE buffer). 32 DataBufferInfo() = default; 33 34 // The maximum length (in octets) of the data portion of each HCI 35 // packet that the controller is able to accept. max_data_length()36 size_t max_data_length() const { return max_data_length_; } 37 38 // Returns the total number of HCI packets that can be stored in the 39 // data buffer represented by this object. max_num_packets()40 size_t max_num_packets() const { return max_num_packets_; } 41 42 // Returns true if both fields are set to non-zero. IsAvailable()43 bool IsAvailable() const { return max_data_length_ && max_num_packets_; } 44 45 // Comparison operators. 46 bool operator==(const DataBufferInfo& other) const { 47 return max_data_length_ == other.max_data_length_ && 48 max_num_packets_ == other.max_num_packets_; 49 } 50 bool operator!=(const DataBufferInfo& other) const { 51 return !(*this == other); 52 } 53 54 private: 55 size_t max_data_length_ = 0u; 56 size_t max_num_packets_ = 0u; 57 }; 58 59 } // namespace bt::hci 60