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 <pw_bluetooth/hci_commands.emb.h> 17 18 #include "pw_bluetooth_sapphire/internal/host/hci-spec/constants.h" 19 20 namespace bt::sco { 21 22 // TODO(fxbug.dev/42062077): This type should be deleted as it duplicates 23 // `ScoPacketType` in hci-protocol.emb. This may involve migrating 24 // `ParameterSet` below to Emboss. 25 enum class ScoPacketTypeBits : uint16_t { 26 // SCO packet types 27 kHv1 = (1 << 0), 28 kHv2 = (1 << 1), 29 kHv3 = (1 << 2), 30 // eSCO packet types 31 kEv3 = (1 << 3), 32 kEv4 = (1 << 4), 33 kEv5 = (1 << 5), 34 kNot2Ev3 = (1 << 6), 35 kNot3Ev3 = (1 << 7), 36 kNot2Ev5 = (1 << 8), 37 kNot3Ev5 = (1 << 9), 38 }; 39 40 // Codec SCO parameter sets as defined in HFP specification (v1.8, section 5.7). 41 struct ParameterSet { 42 uint16_t packet_types; 43 uint32_t transmit_receive_bandwidth; 44 pw::bluetooth::emboss::CodingFormat transmit_receive_format; 45 uint16_t max_latency_ms; 46 hci_spec::ScoRetransmissionEffort retransmission_effort; 47 }; 48 49 constexpr ParameterSet kParameterSetT1{ 50 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kEv3) | 51 static_cast<uint8_t>(ScoPacketTypeBits::kNot2Ev5) | 52 static_cast<uint8_t>(ScoPacketTypeBits::kNot3Ev5), 53 .transmit_receive_bandwidth = 8000, 54 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::TRANSPARENT, 55 .max_latency_ms = 8, 56 .retransmission_effort = 57 hci_spec::ScoRetransmissionEffort::kQualityOptimized}; 58 59 constexpr ParameterSet kParameterSetT2{ 60 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kEv3) | 61 static_cast<uint8_t>(ScoPacketTypeBits::kNot2Ev5) | 62 static_cast<uint8_t>(ScoPacketTypeBits::kNot3Ev5), 63 .transmit_receive_bandwidth = 8000, 64 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::TRANSPARENT, 65 .max_latency_ms = 13, 66 .retransmission_effort = 67 hci_spec::ScoRetransmissionEffort::kQualityOptimized}; 68 69 constexpr ParameterSet kParameterSetS1{ 70 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kHv1) | 71 static_cast<uint8_t>(ScoPacketTypeBits::kHv2) | 72 static_cast<uint8_t>(ScoPacketTypeBits::kHv3) | 73 static_cast<uint8_t>(ScoPacketTypeBits::kEv3) | 74 static_cast<uint8_t>(ScoPacketTypeBits::kNot2Ev5) | 75 static_cast<uint8_t>(ScoPacketTypeBits::kNot3Ev5), 76 .transmit_receive_bandwidth = 8000, 77 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::CVSD, 78 .max_latency_ms = 7, 79 .retransmission_effort = 80 hci_spec::ScoRetransmissionEffort::kPowerOptimized}; 81 82 constexpr ParameterSet kParameterSetS2{ 83 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kEv3) | 84 static_cast<uint8_t>(ScoPacketTypeBits::kNot2Ev5) | 85 static_cast<uint8_t>(ScoPacketTypeBits::kNot3Ev5), 86 .transmit_receive_bandwidth = 8000, 87 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::CVSD, 88 .max_latency_ms = 7, 89 .retransmission_effort = 90 hci_spec::ScoRetransmissionEffort::kPowerOptimized}; 91 92 constexpr ParameterSet kParameterSetS3{ 93 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kEv3) | 94 static_cast<uint8_t>(ScoPacketTypeBits::kNot2Ev5) | 95 static_cast<uint8_t>(ScoPacketTypeBits::kNot3Ev5), 96 .transmit_receive_bandwidth = 8000, 97 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::CVSD, 98 .max_latency_ms = 10, 99 .retransmission_effort = 100 hci_spec::ScoRetransmissionEffort::kPowerOptimized}; 101 102 constexpr ParameterSet kParameterSetS4{ 103 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kEv3) | 104 static_cast<uint8_t>(ScoPacketTypeBits::kNot2Ev5) | 105 static_cast<uint8_t>(ScoPacketTypeBits::kNot3Ev5), 106 .transmit_receive_bandwidth = 8000, 107 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::CVSD, 108 .max_latency_ms = 12, 109 .retransmission_effort = 110 hci_spec::ScoRetransmissionEffort::kQualityOptimized}; 111 112 constexpr ParameterSet kParameterSetD0{ 113 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kHv1), 114 .transmit_receive_bandwidth = 8000, 115 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::CVSD, 116 .max_latency_ms = 0xFFFF, 117 .retransmission_effort = hci_spec::ScoRetransmissionEffort::kDontCare}; 118 119 constexpr ParameterSet kParameterSetD1{ 120 .packet_types = static_cast<uint8_t>(ScoPacketTypeBits::kHv3), 121 .transmit_receive_bandwidth = 8000, 122 .transmit_receive_format = pw::bluetooth::emboss::CodingFormat::CVSD, 123 .max_latency_ms = 0xFFFF, 124 .retransmission_effort = hci_spec::ScoRetransmissionEffort::kDontCare}; 125 126 } // namespace bt::sco 127