blob: 5c5fe07c7d5c8fbc33507fc259da927fd7841ec1 [file] [log] [blame]
Armando Miragliacd70cfa2018-06-04 15:24:09 +02001// Copyright 2018 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#ifndef PERMISSION_BROKER_USB_CONTROL_H_
6#define PERMISSION_BROKER_USB_CONTROL_H_
7
8#include <stdint.h>
9
10#include <memory>
11#include <vector>
12
13#include <libusb-1.0/libusb.h>
14
15#include <base/macros.h>
16#include <base/time/time.h>
17#include <brillo/dbus/dbus_object.h>
18
19#include "permission_broker/libusb_wrapper.h"
20
21namespace permission_broker {
22
23// This class encapsulates the logic used to interact with the VBUS subsystem to
24// control the power state of USB devices.
25class UsbControl {
26 public:
27 explicit UsbControl(std::unique_ptr<UsbDeviceManagerInterface> manager);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090028 UsbControl(const UsbControl&) = delete;
29 UsbControl& operator=(const UsbControl&) = delete;
30
Armando Miragliacd70cfa2018-06-04 15:24:09 +020031 ~UsbControl();
32
33 // Based on |vid| and |pid| of a USB device, this function determines if the
Garrick Evansd48463e2020-06-22 14:09:10 +090034 // device type can be controlled by the API. The UsbControl implements an
35 // allow/deny mechanism, meaning that if a device is *not* allowed, it
Armando Miragliacd70cfa2018-06-04 15:24:09 +020036 // cannot be controlled.
Garrick Evansd48463e2020-06-22 14:09:10 +090037 bool IsDeviceAllowed(uint16_t vid, uint16_t pid) const;
Armando Miragliacd70cfa2018-06-04 15:24:09 +020038 // When called, this function will find all the USB devices identified by
39 // |vid| and |pid| and will try to power-cycle them using the VBUS subsystem.
40 // The |delay| determines the delay between powering all the devices found on
41 // and powering them all off.
Tom Hughes4f300e52020-08-24 18:08:59 -070042 void PowerCycleUsbPorts(base::Callback<void(bool)> callback,
43 uint16_t vid,
44 uint16_t pid,
45 base::TimeDelta delay);
Armando Miragliacd70cfa2018-06-04 15:24:09 +020046
47 private:
48 std::unique_ptr<UsbDeviceManagerInterface> manager_ = nullptr;
Armando Miragliacd70cfa2018-06-04 15:24:09 +020049};
50
51} // namespace permission_broker
52
53#endif // PERMISSION_BROKER_USB_CONTROL_H_