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 #include "usb_device_pipe.h"
17 #include "iusb_srv.h"
18 #include "usb_common.h"
19 #include "usb_device.h"
20 #include "usb_errors.h"
21 #include "usb_request.h"
22 #include "usb_srv_client.h"
23
24 using namespace OHOS::HDI::Usb::V1_0;
25 namespace OHOS {
26 namespace USB {
USBDevicePipe()27 USBDevicePipe::USBDevicePipe() {}
USBDevicePipe(uint8_t busNum,uint8_t devAddr)28 USBDevicePipe::USBDevicePipe(uint8_t busNum, uint8_t devAddr)
29 : busNum_(busNum), devAddr_(devAddr)
30 {
31 }
32
Close()33 int32_t USBDevicePipe::Close()
34 {
35 int32_t ret = ERR_OK;
36 bool bSuccess = UsbSrvClient::GetInstance().Close(*this);
37 if (!bSuccess) {
38 ret = ERR_INVALID_VALUE;
39 }
40 return ret;
41 }
42
ClaimInterface(const UsbInterface & interface,bool force)43 int32_t USBDevicePipe::ClaimInterface(const UsbInterface &interface, bool force)
44 {
45 return UsbSrvClient::GetInstance().ClaimInterface(*this, interface, force);
46 }
47
ReleaseInterface(const UsbInterface & interface)48 int32_t USBDevicePipe::ReleaseInterface(const UsbInterface &interface)
49 {
50 return UsbSrvClient::GetInstance().ReleaseInterface(*this, interface);
51 }
52
BulkTransfer(const USBEndpoint & endpoint,std::vector<uint8_t> & bufferData,int32_t timeOut)53 int32_t USBDevicePipe::BulkTransfer(const USBEndpoint &endpoint, std::vector<uint8_t> &bufferData, int32_t timeOut)
54 {
55 return UsbSrvClient::GetInstance().BulkTransfer(*this, endpoint, bufferData, timeOut);
56 }
57
ControlTransfer(const UsbCtrlTransfer & ctrl,std::vector<uint8_t> & bufferData)58 int32_t USBDevicePipe::ControlTransfer(const UsbCtrlTransfer &ctrl, std::vector<uint8_t> &bufferData)
59 {
60 return UsbSrvClient::GetInstance().ControlTransfer(*this, ctrl, bufferData);
61 }
62
SetConfiguration(const USBConfig & config)63 int32_t USBDevicePipe::SetConfiguration(const USBConfig &config)
64 {
65 return UsbSrvClient::GetInstance().SetConfiguration(*this, config);
66 }
67
SetInterface(const UsbInterface & interface)68 int32_t USBDevicePipe::SetInterface(const UsbInterface &interface)
69 {
70 return UsbSrvClient::GetInstance().SetInterface(*this, interface);
71 }
72
SetBusNum(uint8_t busNum)73 void USBDevicePipe::SetBusNum(uint8_t busNum)
74 {
75 this->busNum_ = busNum;
76 }
77
SetDevAddr(uint8_t devAddr)78 void USBDevicePipe::SetDevAddr(uint8_t devAddr)
79 {
80 this->devAddr_ = devAddr;
81 }
82
GetBusNum() const83 uint8_t USBDevicePipe::GetBusNum() const
84 {
85 return busNum_;
86 }
87
GetDevAddr() const88 uint8_t USBDevicePipe::GetDevAddr() const
89 {
90 return devAddr_;
91 }
92 } // namespace USB
93 } // namespace OHOS
94