1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <memory> 19 20 #include <stdint.h> 21 22 #include "common/libs/usbforward/protocol.h" 23 #include "host/commands/virtual_usb_manager/vadb/usb_cmd.h" 24 #include "host/commands/virtual_usb_manager/usbip/device.h" 25 26 namespace vadb { 27 // Execute control transfer. 28 class USBCmdControlTransfer : public USBCommand { 29 public: 30 USBCmdControlTransfer(uint8_t bus_id, uint8_t dev_id, uint8_t type, 31 uint8_t request, uint16_t value, uint16_t index, 32 uint32_t timeout, std::vector<uint8_t> data, 33 usbip::Device::AsyncTransferReadyCB callback); 34 35 ~USBCmdControlTransfer() override = default; 36 37 // Return usbforward command this instance is executing. Command()38 usb_forward::Command Command() override { 39 return usb_forward::CmdControlTransfer; 40 } 41 42 // Send request body to the server. 43 // Return false, if communication failed. 44 bool OnRequest(const cvd::SharedFD& data) override; 45 46 // Receive response data from the server. 47 // Return false, if communication failed. 48 bool OnResponse(bool is_success, const cvd::SharedFD& data) override; 49 50 private: 51 usb_forward::ControlTransfer req_; 52 std::vector<uint8_t> data_; 53 usbip::Device::AsyncTransferReadyCB callback_; 54 55 USBCmdControlTransfer(const USBCmdControlTransfer& other) = delete; 56 USBCmdControlTransfer& operator=(const USBCmdControlTransfer& other) = delete; 57 }; 58 } // namespace vadb 59