1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef USB_DEVICE_PIPE_H
17 #define USB_DEVICE_PIPE_H
18 
19 #include "usb_config.h"
20 #include "v1_1/usb_types.h"
21 
22 namespace OHOS {
23 namespace USB {
24 class USBDevicePipe {
25 public:
26     USBDevicePipe();
~USBDevicePipe()27     ~USBDevicePipe() {}
28     USBDevicePipe(uint8_t busNum, uint8_t devAddr);
29     int32_t ClaimInterface(const UsbInterface &interface, bool force);
30     int32_t ReleaseInterface(const UsbInterface &interface);
31     int32_t BulkTransfer(const USBEndpoint &endpoint, std::vector<uint8_t> &bufferData, int32_t timeOut);
32     int32_t ControlTransfer(const HDI::Usb::V1_0::UsbCtrlTransfer &ctrl, std::vector<uint8_t> &bufferData);
33     int32_t UsbControlTransfer(
34         const HDI::Usb::V1_1::UsbCtrlTransferParams &ctrlParams, std::vector<uint8_t> &bufferData);
35     int32_t SetConfiguration(const USBConfig &config);
36     int32_t SetInterface(const UsbInterface &interface);
37     int32_t Close();
38 
39     void SetBusNum(uint8_t busNum);
40     void SetDevAddr(uint8_t devAddr);
41     uint8_t GetBusNum() const;
42     uint8_t GetDevAddr() const;
43 
44 private:
45     uint8_t busNum_ = UINT8_MAX;
46     uint8_t devAddr_ = UINT8_MAX;
47 };
48 } // namespace USB
49 } // namespace OHOS
50 
51 #endif // USB_DEVICE_PIPE_H
52