Home | History | Annotate | Download | only in usbip
      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 <cstdint>
     19 #include <functional>
     20 #include <map>
     21 #include <memory>
     22 #include <vector>
     23 
     24 #include "host/libs/usbip/messages.h"
     25 
     26 namespace vadb {
     27 namespace usbip {
     28 
     29 // The device descriptor of a USB device represents a USB device that is
     30 // available for import.
     31 class Device {
     32  public:
     33   // AsyncTransferReadyCB specifies a signature of a function that will be
     34   // called upon transfer completion (whether successful or failed). Parameters
     35   // supplied to the function are:
     36   // - operation status, indicated by boolean flag (true = success),
     37   // - vector containing transferred data (and actual size).
     38   using AsyncTransferReadyCB = std::function<void(bool, std::vector<uint8_t>)>;
     39 
     40   // Interface provides minimal description of device's interface.
     41   struct Interface {
     42     uint8_t iface_class;
     43     uint8_t iface_subclass;
     44     uint8_t iface_protocol;
     45   };
     46 
     47   // vendor_id and product_id identify device manufacturer and type.
     48   // dev_version describes device version (as BCD).
     49   uint16_t vendor_id;
     50   uint16_t product_id;
     51   uint16_t dev_version;
     52 
     53   // Class, Subclass and Protocol define device type.
     54   uint8_t dev_class;
     55   uint8_t dev_subclass;
     56   uint8_t dev_protocol;
     57 
     58   // Speed indicates device speed (see libusb_speed).
     59   uint8_t speed;
     60 
     61   // ConfigurationsCount and ConfigurationNumber describe total number of device
     62   // configurations and currently activated device configuration.
     63   size_t configurations_count;
     64   size_t configuration_number;
     65 
     66   // Interfaces returns a collection of device interfaces.
     67   std::vector<Interface> interfaces;
     68 
     69   // Attach request handler.
     70   std::function<bool()> handle_attach;
     71 
     72   // Device control request dispatcher.
     73   std::function<bool(const CmdRequest& request, uint32_t deadline,
     74                      std::vector<uint8_t> data, AsyncTransferReadyCB callback)>
     75       handle_control_transfer;
     76 
     77   // Device  data request dispatcher.
     78   std::function<bool(uint8_t endpoint, bool is_host_to_device,
     79                      uint32_t deadline, std::vector<uint8_t> data,
     80                      AsyncTransferReadyCB callback)>
     81       handle_data_transfer;
     82 };
     83 
     84 }  // namespace usbip
     85 }  // namespace vadb
     86