| // Copyright 2026 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| use bt_common::PeerId; |
| use thiserror::Error; |
| |
| /// Spec-defined configurations. |
| /// Defined in Section 4.4 of Basic Audio Profile 1.0.1 |
| /// TODO: Add the remaining configurations |
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| pub enum Configuration { |
| /// Configuration 1: Mono Audio Sink (typically 1 Sink ASE) |
| MonoAudioSink, |
| /// Configuration 3: Conversational (typically 1 Sink and 1 Source ASE) |
| Conversational, |
| // TODO: Add more configurations from spec. |
| } |
| |
| /// Codec capability settings. |
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| pub enum CodecCapabilitySetting { |
| /// LC3 48 kHz, 10 ms |
| Lc3_48_2, |
| /// LC3 16 kHz, 10 ms |
| Lc3_16_2, |
| // TODO: Add more settings from spec. |
| } |
| |
| /// A valid pair of configuration and codec setting supported by a peer. |
| #[derive(Debug, Clone, PartialEq, Eq)] |
| pub struct SupportedConfiguration { |
| pub configuration: Configuration, |
| pub codec_setting: CodecCapabilitySetting, |
| } |
| |
| /// Centralized Error enum for the library. |
| #[derive(Debug, Error)] |
| pub enum Error { |
| /// An error occurred in the underlying GATT interaction. |
| #[error("GATT error: {0}")] |
| Gatt(#[from] bt_gatt::types::Error), |
| |
| /// An error occurred in the ASCS client. |
| #[error("ASCS error: {0}")] |
| Ascs(#[from] bt_ascs::Error), |
| |
| /// The requested peer was not found in the manager. |
| #[error("Peer {0:?} not found")] |
| PeerNotFound(PeerId), |
| |
| /// The peer already exists in the manager, and can't be added. |
| #[error("Peer {0:?} already exists")] |
| PeerAlreadyExists(PeerId), |
| |
| /// The operation requested is invalid in the current state. |
| #[error("Invalid state: {0}")] |
| InvalidState(String), |
| |
| /// The configuration requested is not valid according to the spec. |
| #[error("Invalid configuration: {0}")] |
| InvalidConfiguration(String), |
| |
| /// The peer rejected the operation (e.g. QoS or Codec configuration |
| /// rejected). |
| #[error("Peer rejected operation: {0}")] |
| PeerRejected(String), |
| |
| /// An internal error occurred. |
| #[error("Internal error: {0}")] |
| Internal(String), |
| } |
| |
| #[cfg(test)] |
| mod tests { |
| use super::*; |
| |
| #[test] |
| fn test_supported_configuration() { |
| let config = Configuration::MonoAudioSink; |
| let setting = CodecCapabilitySetting::Lc3_48_2; |
| let supported = SupportedConfiguration { configuration: config, codec_setting: setting }; |
| assert_eq!(supported.configuration, Configuration::MonoAudioSink); |
| assert_eq!(supported.codec_setting, CodecCapabilitySetting::Lc3_48_2); |
| } |
| } |