1 // Copyright 2019 The Chromium OS 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 use crate::usb::xhci::scatter_gather_buffer::Error as BufferError; 6 use crate::usb::xhci::xhci_transfer::Error as XhciTransferError; 7 use crate::utils::Error as UtilsError; 8 9 use base::TubeError; 10 use std::fmt::{self, Display}; 11 use usb_util::Error as UsbUtilError; 12 13 #[derive(Debug)] 14 pub enum Error { 15 AddToEventLoop(UtilsError), 16 StartAsyncJobQueue(UtilsError), 17 QueueAsyncJob(UtilsError), 18 CreateLibUsbContext(UsbUtilError), 19 GetActiveConfig(UsbUtilError), 20 SetActiveConfig(UsbUtilError), 21 SetInterfaceAltSetting(UsbUtilError), 22 ClearHalt(UsbUtilError), 23 CreateTransfer(UsbUtilError), 24 Reset(UsbUtilError), 25 GetEndpointType, 26 CreateControlTube(TubeError), 27 SetupControlTube(TubeError), 28 ReadControlTube(TubeError), 29 WriteControlTube(TubeError), 30 GetXhciTransferType(XhciTransferError), 31 TransferComplete(XhciTransferError), 32 ReadBuffer(BufferError), 33 WriteBuffer(BufferError), 34 BufferLen(BufferError), 35 /// Cannot get interface descriptor for (interface, altsetting). 36 GetInterfaceDescriptor((u8, u8)), 37 GetEndpointDescriptor(u8), 38 BadXhciTransferState, 39 BadBackendProviderState, 40 } 41 42 impl Display for Error { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 44 use self::Error::*; 45 46 match self { 47 AddToEventLoop(e) => write!(f, "failed to add to event loop: {}", e), 48 StartAsyncJobQueue(e) => write!(f, "failed to start async job queue: {}", e), 49 QueueAsyncJob(e) => write!(f, "failed to queue async job: {}", e), 50 CreateLibUsbContext(e) => write!(f, "failed to create libusb context: {:?}", e), 51 GetActiveConfig(e) => write!(f, "failed to get active config: {:?}", e), 52 SetActiveConfig(e) => write!(f, "failed to set active config: {:?}", e), 53 SetInterfaceAltSetting(e) => write!(f, "failed to set interface alt setting: {:?}", e), 54 ClearHalt(e) => write!(f, "failed to clear halt: {:?}", e), 55 CreateTransfer(e) => write!(f, "failed to create transfer: {:?}", e), 56 Reset(e) => write!(f, "failed to reset: {:?}", e), 57 GetEndpointType => write!(f, "failed to get endpoint type"), 58 CreateControlTube(e) => write!(f, "failed to create contro tube: {}", e), 59 SetupControlTube(e) => write!(f, "failed to setup control tube: {}", e), 60 ReadControlTube(e) => write!(f, "failed to read control tube: {}", e), 61 WriteControlTube(e) => write!(f, "failed to write control tube: {}", e), 62 GetXhciTransferType(e) => write!(f, "failed to get xhci transfer type: {}", e), 63 TransferComplete(e) => write!(f, "xhci transfer completed: {}", e), 64 ReadBuffer(e) => write!(f, "failed to read buffer: {}", e), 65 WriteBuffer(e) => write!(f, "failed to write buffer: {}", e), 66 BufferLen(e) => write!(f, "failed to get buffer length: {}", e), 67 GetInterfaceDescriptor((i, alt_setting)) => write!( 68 f, 69 "failed to get interface descriptor for interface {}, alt setting {}", 70 i, alt_setting 71 ), 72 GetEndpointDescriptor(ep_idx) => { 73 write!(f, "failed to get endpoint descriptor for ep: {}", ep_idx) 74 } 75 BadXhciTransferState => write!(f, "xhci transfer is in a bad state"), 76 BadBackendProviderState => write!(f, "backend provider is in a bad state"), 77 } 78 } 79 } 80 81 pub type Result<T> = std::result::Result<T, Error>; 82