bt_avctp/
lib.rs

1// Copyright 2019 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#![recursion_limit = "128"]
6
7use std::result;
8use thiserror::Error;
9
10mod avc;
11mod avctp;
12
13pub use crate::avctp::{
14    Command as AvctpCommand, CommandStream as AvctpCommandStream, MessageType as AvctpMessageType,
15    PacketType as AvctpPacketType, Peer as AvctpPeer,
16};
17
18pub use crate::avc::{
19    Command as AvcCommand, CommandResponse as AvcCommandResponse,
20    CommandStream as AvcCommandStream, CommandType as AvcCommandType, OpCode as AvcOpCode,
21    PacketType as AvcPacketType, Peer as AvcPeer, ResponseType as AvcResponseType,
22};
23
24/// The error type of the AVCTP library.
25#[derive(Error, Debug, PartialEq)]
26pub enum Error {
27    /// The value that was sent on the wire was out of range.
28    #[error("Value was out of range")]
29    OutOfRange,
30
31    /// The profile identifier sent was returned as invalid by the peer.
32    #[error("Invalid profile id")]
33    InvalidProfileId,
34
35    /// The header was invalid when parsing a message from the peer.
36    #[error("Invalid Header for a AVCTP message")]
37    InvalidHeader,
38
39    /// The body format was invalid when parsing a message from the peer.
40    #[error("Failed to parse AVCTP message contents")]
41    InvalidMessage,
42
43    /// The remote end failed to respond to this command in time.
44    #[error("Command timed out")]
45    Timeout,
46
47    /// The distant peer has disconnected.
48    #[error("Peer has disconnected")]
49    PeerDisconnected,
50
51    /// Sent if a Command Future is polled after it's already completed
52    #[error("Command Response has already been received")]
53    AlreadyReceived,
54
55    /// Encountered an IO error reading from the peer.
56    #[error("Encountered an IO error reading from the peer: {}", _0)]
57    PeerRead(zx::Status),
58
59    /// Encountered an IO error reading from the peer.
60    #[error("Encountered an IO error writing to the peer: {}", _0)]
61    PeerWrite(zx::Status),
62
63    /// A message couldn't be encoded.
64    #[error("Encountered an error encoding a message")]
65    Encoding,
66
67    /// An error has been detected, and the request that is being handled
68    /// should be rejected with the error code given.
69    #[error("Invalid request detected")]
70    RequestInvalid,
71
72    /// The response command type is not valid.
73    #[error("Command type is not a response")]
74    ResponseTypeInvalid,
75
76    /// The response command was unexpected
77    #[error("Response command type is unexpected")]
78    UnexpectedResponse,
79
80    #[doc(hidden)]
81    #[error("__Nonexhaustive error should never be created.")]
82    __Nonexhaustive,
83}
84
85/// Result type for AVCTP, using avctp::Error
86pub(crate) type Result<T> = result::Result<T, Error>;