• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_srv_client.h"
17 #include "datetime_ex.h"
18 #include "if_system_ability_manager.h"
19 #include "ipc_skeleton.h"
20 #include "iservice_registry.h"
21 #include "string_ex.h"
22 #include "system_ability_definition.h"
23 #include "usb_common.h"
24 #include "usb_device.h"
25 #include "usb_errors.h"
26 #include "timer.h"
27 #include "v1_2/iusb_interface.h"
28 #include "usbd_callback_server.h"
29 #include "usb_bulk_trans_data.h"
30 using namespace OHOS::HDI::Usb::V1_2;
31 namespace OHOS {
32 namespace USB {
33 constexpr uint32_t WAIT_SERVICE_LOAD = 500;
34 #ifdef USB_MANAGER_FEATURE_HOST
35 constexpr int32_t READ_BUF_SIZE = 8192;
36 constexpr int32_t PARAM_ERROR = 401;
37 #endif // USB_MANAGER_FEATURE_HOST
38 [[ maybe_unused ]] constexpr int32_t CAPABILITY_NOT_SUPPORT = 801;
UsbSrvClient()39 UsbSrvClient::UsbSrvClient()
40 {
41     Connect();
42     serialRemote = new SerialDeathMonitor();
43 }
~UsbSrvClient()44 UsbSrvClient::~UsbSrvClient()
45 {
46     USB_HILOGE(MODULE_USB_INNERKIT, "~UsbSrvClient!");
47 }
48 
GetInstance()49 UsbSrvClient& UsbSrvClient::GetInstance()
50 {
51     static UsbSrvClient instance;
52     return instance;
53 }
54 
Connect()55 int32_t UsbSrvClient::Connect()
56 {
57     std::lock_guard<std::mutex> lock(mutex_);
58     if (proxy_ != nullptr) {
59         return UEC_OK;
60     }
61     return ConnectUnLocked();
62 }
63 
ConnectUnLocked()64 int32_t UsbSrvClient::ConnectUnLocked()
65 {
66     sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
67     if (sm == nullptr) {
68         USB_HILOGE(MODULE_USB_INNERKIT, "fail to get SystemAbilityManager");
69         return UEC_INTERFACE_GET_SYSTEM_ABILITY_MANAGER_FAILED;
70     }
71     sptr<IRemoteObject> remoteObject = sm->CheckSystemAbility(USB_SYSTEM_ABILITY_ID);
72     if (remoteObject == nullptr) {
73         USB_HILOGE(MODULE_USB_INNERKIT, "GetSystemAbility failed.");
74         return UEC_INTERFACE_GET_USB_SERVICE_FAILED;
75     }
76     proxy_ = iface_cast<IUsbServer>(remoteObject);
77     USB_HILOGI(MODULE_USB_INNERKIT, "Connect UsbService ok.");
78     sptr<IRemoteObject> deathObject = proxy_->AsObject();
79     if (deathObject == nullptr) {
80         USB_HILOGI(MODULE_USB_INNERKIT, "deathObject is null.");
81         return UEC_INTERFACE_DEAD_OBJECT;
82     }
83     deathRecipient_  = new UsbSrvDeathRecipient();
84     deathObject->AddDeathRecipient(deathRecipient_);
85     return UEC_OK;
86 }
87 
ResetProxy(const wptr<IRemoteObject> & remote)88 void UsbSrvClient::ResetProxy(const wptr<IRemoteObject> &remote)
89 {
90     std::lock_guard<std::mutex> lock(mutex_);
91     RETURN_IF(proxy_ == nullptr);
92     auto serviceRemote = proxy_->AsObject();
93     if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
94         serviceRemote->RemoveDeathRecipient(deathRecipient_);
95         proxy_ = nullptr;
96 
97         std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_SERVICE_LOAD));
98         ConnectUnLocked();
99     } else {
100         USB_HILOGW(MODULE_USB_INNERKIT, "serviceRemote is null or serviceRemote != promote");
101     }
102 }
103 
OnRemoteDied(const wptr<IRemoteObject> & remote)104 void UsbSrvClient::UsbSrvDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
105 {
106     if (remote == nullptr) {
107         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvDeathRecipient::OnRemoteDied failed, remote is nullptr.");
108         return;
109     }
110     USB_HILOGI(MODULE_USB_INNERKIT, "UsbSrvDeathRecipient::Recv death notice.");
111     UsbSrvClient::GetInstance().ResetProxy(remote);
112 }
113 
114 #ifdef USB_MANAGER_FEATURE_HOST
OpenDevice(const UsbDevice & device,USBDevicePipe & pipe)115 int32_t UsbSrvClient::OpenDevice(const UsbDevice &device, USBDevicePipe &pipe)
116 {
117     USB_HILOGI(MODULE_USB_INNERKIT, "Calling OpenDevice Start!");
118     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
119     int32_t ret = proxy_->OpenDevice(device.GetBusNum(), device.GetDevAddr());
120     if (ret != UEC_OK) {
121         USB_HILOGE(MODULE_USB_INNERKIT, "OpenDevice failed with ret = %{public}d !", ret);
122         return ret;
123     }
124 
125     pipe.SetBusNum(device.GetBusNum());
126     pipe.SetDevAddr(device.GetDevAddr());
127     return UEC_OK;
128 }
129 
ResetDevice(USBDevicePipe & pipe)130 int32_t UsbSrvClient::ResetDevice(USBDevicePipe &pipe)
131 {
132     USB_HILOGI(MODULE_USB_INNERKIT, "Calling ResetDevice Start!");
133     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
134     int32_t ret = proxy_->ResetDevice(pipe.GetBusNum(), pipe.GetDevAddr());
135     if (ret != UEC_OK) {
136         USB_HILOGE(MODULE_USB_INNERKIT, "ResetDevice failed with ret = %{public}d !", ret);
137         return ret;
138     }
139 
140     return UEC_OK;
141 }
142 
HasRight(std::string deviceName)143 bool UsbSrvClient::HasRight(std::string deviceName)
144 {
145     USB_HILOGI(MODULE_USB_INNERKIT, "Calling HasRight Start!");
146     RETURN_IF_WITH_RET(Connect() != UEC_OK, false);
147     bool hasRight = false;
148     proxy_->HasRight(deviceName, hasRight);
149     return hasRight;
150 }
151 
RequestRight(std::string deviceName)152 int32_t UsbSrvClient::RequestRight(std::string deviceName)
153 {
154     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
155     int32_t ret = proxy_->RequestRight(deviceName);
156     if (ret != UEC_OK) {
157         USB_HILOGE(MODULE_USB_INNERKIT, "Calling RequestRight failed with ret = %{public}d !", ret);
158     }
159     return ret;
160 }
161 
RemoveRight(std::string deviceName)162 int32_t UsbSrvClient::RemoveRight(std::string deviceName)
163 {
164     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
165     int32_t ret = proxy_->RemoveRight(deviceName);
166     if (ret != UEC_OK) {
167         USB_HILOGE(MODULE_USB_INNERKIT, "Calling RemoveRight failed with ret = %{public}d !", ret);
168     }
169     return ret;
170 }
171 
GetDevices(std::vector<UsbDevice> & deviceList)172 int32_t UsbSrvClient::GetDevices(std::vector<UsbDevice> &deviceList)
173 {
174     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
175     int32_t ret = proxy_->GetDevices(deviceList);
176     if (ret != UEC_OK) {
177         USB_HILOGE(MODULE_USB_INNERKIT, "GetDevices failed ret = %{public}d!", ret);
178         return ret;
179     }
180     USB_HILOGI(MODULE_USB_INNERKIT, "GetDevices deviceList size = %{public}zu!", deviceList.size());
181     return ret;
182 }
183 
ClaimInterface(USBDevicePipe & pipe,const UsbInterface & interface,bool force)184 int32_t UsbSrvClient::ClaimInterface(USBDevicePipe &pipe, const UsbInterface &interface, bool force)
185 {
186     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
187     int32_t ret = proxy_->ClaimInterface(pipe.GetBusNum(), pipe.GetDevAddr(), interface.GetId(), force);
188     if (ret != UEC_OK) {
189         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
190     }
191     return ret;
192 }
193 
UsbAttachKernelDriver(USBDevicePipe & pipe,const UsbInterface & interface)194 int32_t UsbSrvClient::UsbAttachKernelDriver(USBDevicePipe &pipe, const UsbInterface &interface)
195 {
196     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
197     int32_t ret = proxy_->UsbAttachKernelDriver(pipe.GetBusNum(), pipe.GetDevAddr(), interface.GetId());
198     if (ret != UEC_OK) {
199         USB_HILOGE(MODULE_USB_INNERKIT, "UsbAttachKernelDriver failed width ret = %{public}d !", ret);
200     }
201     return ret;
202 }
203 
UsbDetachKernelDriver(USBDevicePipe & pipe,const UsbInterface & interface)204 int32_t UsbSrvClient::UsbDetachKernelDriver(USBDevicePipe &pipe, const UsbInterface &interface)
205 {
206     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
207     int32_t ret = proxy_->UsbDetachKernelDriver(pipe.GetBusNum(), pipe.GetDevAddr(), interface.GetId());
208     if (ret != UEC_OK) {
209         USB_HILOGE(MODULE_USB_INNERKIT, "UsbDetachKernelDriver failed width ret = %{public}d !", ret);
210     }
211     return ret;
212 }
213 
ReleaseInterface(USBDevicePipe & pipe,const UsbInterface & interface)214 int32_t UsbSrvClient::ReleaseInterface(USBDevicePipe &pipe, const UsbInterface &interface)
215 {
216     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
217     int32_t ret = proxy_->ReleaseInterface(pipe.GetBusNum(), pipe.GetDevAddr(), interface.GetId());
218     if (ret != UEC_OK) {
219         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
220     }
221     return ret;
222 }
223 
BulkTransfer(USBDevicePipe & pipe,const USBEndpoint & endpoint,std::vector<uint8_t> & bufferData,int32_t timeOut)224 int32_t UsbSrvClient::BulkTransfer(
225     USBDevicePipe &pipe, const USBEndpoint &endpoint, std::vector<uint8_t> &bufferData, int32_t timeOut)
226 {
227     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
228     int32_t ret = UEC_INTERFACE_INVALID_VALUE;
229     if (USB_ENDPOINT_DIR_IN == endpoint.GetDirection()) {
230         int32_t length = bufferData.size() > 0 ? static_cast<int32_t>(bufferData.size()) : READ_BUF_SIZE;
231         bufferData.clear();
232         UsbBulkTransData bulkData;
233         ret = proxy_->BulkTransferReadwithLength(pipe.GetBusNum(), pipe.GetDevAddr(),
234             endpoint, length, bulkData, timeOut);
235         bufferData.swap(bulkData.data_);
236     } else if (USB_ENDPOINT_DIR_OUT == endpoint.GetDirection()) {
237         UsbBulkTransData bulkData (bufferData);
238         ret = proxy_->BulkTransferWrite(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint, bulkData, timeOut);
239     }
240     if (ret != UEC_OK) {
241         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
242     }
243     return ret;
244 }
245 
UsbCtrlTransferChange(const HDI::Usb::V1_0::UsbCtrlTransfer & param,UsbCtlSetUp & ctlSetup)246 void UsbSrvClient::UsbCtrlTransferChange(const HDI::Usb::V1_0::UsbCtrlTransfer &param, UsbCtlSetUp &ctlSetup)
247 {
248     ctlSetup.reqType = param.requestType;
249     ctlSetup.reqCmd = param.requestCmd;
250     ctlSetup.value = param.value;
251     ctlSetup.index = param.index;
252     ctlSetup.length = param.timeout;
253     return;
254 }
255 
ControlTransfer(USBDevicePipe & pipe,const UsbCtrlTransfer & ctrl,std::vector<uint8_t> & bufferData)256 int32_t UsbSrvClient::ControlTransfer(
257     USBDevicePipe &pipe, const UsbCtrlTransfer &ctrl, std::vector<uint8_t> &bufferData)
258 {
259     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
260     UsbCtlSetUp ctlSetup;
261     UsbCtrlTransferChange(ctrl, ctlSetup);
262     if ((static_cast<uint32_t>(ctlSetup.reqType) & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_IN) {
263         bufferData.clear();
264     }
265     int32_t ret = proxy_->ControlTransfer(pipe.GetBusNum(), pipe.GetDevAddr(), ctlSetup, bufferData);
266     if (ret != UEC_OK) {
267         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
268     }
269 
270     return ret;
271 }
272 
UsbCtrlTransferChange(const HDI::Usb::V1_2::UsbCtrlTransferParams & param,UsbCtlSetUp & ctlSetup)273 void UsbSrvClient::UsbCtrlTransferChange(const HDI::Usb::V1_2::UsbCtrlTransferParams &param, UsbCtlSetUp &ctlSetup)
274 {
275     ctlSetup.reqType = param.requestType;
276     ctlSetup.reqCmd = param.requestCmd;
277     ctlSetup.value = param.value;
278     ctlSetup.index = param.index;
279     ctlSetup.length = param.length;
280     ctlSetup.timeout = param.timeout;
281     return;
282 }
283 
UsbControlTransfer(USBDevicePipe & pipe,const HDI::Usb::V1_2::UsbCtrlTransferParams & ctrlParams,std::vector<uint8_t> & bufferData)284 int32_t UsbSrvClient::UsbControlTransfer(USBDevicePipe &pipe, const HDI::Usb::V1_2::UsbCtrlTransferParams &ctrlParams,
285     std::vector<uint8_t> &bufferData)
286 {
287     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
288     UsbCtlSetUp ctlSetup;
289     UsbCtrlTransferChange(ctrlParams, ctlSetup);
290     if ((static_cast<uint32_t>(ctlSetup.reqType) & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_IN) {
291         bufferData.clear();
292     }
293     int32_t ret = proxy_->UsbControlTransfer(pipe.GetBusNum(), pipe.GetDevAddr(), ctlSetup, bufferData);
294     if (ret != UEC_OK) {
295         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
296     }
297 
298     return ret;
299 }
300 
SetConfiguration(USBDevicePipe & pipe,const USBConfig & config)301 int32_t UsbSrvClient::SetConfiguration(USBDevicePipe &pipe, const USBConfig &config)
302 {
303     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
304     int32_t ret = proxy_->SetActiveConfig(pipe.GetBusNum(), pipe.GetDevAddr(), config.GetId());
305     return ret;
306 }
307 
SetInterface(USBDevicePipe & pipe,const UsbInterface & interface)308 int32_t UsbSrvClient::SetInterface(USBDevicePipe &pipe, const UsbInterface &interface)
309 {
310     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
311     return proxy_->SetInterface(
312         pipe.GetBusNum(), pipe.GetDevAddr(), interface.GetId(), interface.GetAlternateSetting());
313 }
314 
GetRawDescriptors(USBDevicePipe & pipe,std::vector<uint8_t> & bufferData)315 int32_t UsbSrvClient::GetRawDescriptors(USBDevicePipe &pipe, std::vector<uint8_t> &bufferData)
316 {
317     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
318     int32_t ret = proxy_->GetRawDescriptor(pipe.GetBusNum(), pipe.GetDevAddr(), bufferData);
319     if (ret != UEC_OK) {
320         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
321     }
322     return ret;
323 }
324 
GetFileDescriptor(USBDevicePipe & pipe,int32_t & fd)325 int32_t UsbSrvClient::GetFileDescriptor(USBDevicePipe &pipe, int32_t &fd)
326 {
327     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
328     int32_t ret = proxy_->GetFileDescriptor(pipe.GetBusNum(), pipe.GetDevAddr(), fd);
329     if (ret != UEC_OK) {
330         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
331     }
332     return ret;
333 }
334 
Close(const USBDevicePipe & pipe)335 bool UsbSrvClient::Close(const USBDevicePipe &pipe)
336 {
337     RETURN_IF_WITH_RET(proxy_ == nullptr, false);
338     int32_t ret = proxy_->Close(pipe.GetBusNum(), pipe.GetDevAddr());
339     return (ret == UEC_OK);
340 }
341 
PipeRequestWait(USBDevicePipe & pipe,int64_t timeOut,UsbRequest & req)342 int32_t UsbSrvClient::PipeRequestWait(USBDevicePipe &pipe, int64_t timeOut, UsbRequest &req)
343 {
344     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
345     std::vector<uint8_t> clientData;
346     std::vector<uint8_t> bufferData;
347     int32_t ret = proxy_->RequestWait(pipe.GetBusNum(), pipe.GetDevAddr(), timeOut, clientData, bufferData);
348     if (ret != UEC_OK) {
349         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d.", ret);
350         return ret;
351     }
352 
353     req.SetPipe(pipe);
354     req.SetClientData(clientData);
355     req.SetReqData(bufferData);
356     return ret;
357 }
358 
RequestInitialize(UsbRequest & request)359 int32_t UsbSrvClient::RequestInitialize(UsbRequest &request)
360 {
361     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
362     const USBDevicePipe &pipe = request.GetPipe();
363     const USBEndpoint &endpoint = request.GetEndpoint();
364     return proxy_->ClaimInterface(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint.GetInterfaceId(), CLAIM_FORCE_1);
365 }
366 
RequestFree(UsbRequest & request)367 int32_t UsbSrvClient::RequestFree(UsbRequest &request)
368 {
369     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
370     const USBDevicePipe &pipe = request.GetPipe();
371     const USBEndpoint &ep = request.GetEndpoint();
372     return proxy_->RequestCancel(pipe.GetBusNum(), pipe.GetDevAddr(), ep.GetInterfaceId(), ep.GetAddress());
373 }
374 
RequestAbort(UsbRequest & request)375 int32_t UsbSrvClient::RequestAbort(UsbRequest &request)
376 {
377     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
378     const USBDevicePipe &pipe = request.GetPipe();
379     const USBEndpoint &ep = request.GetEndpoint();
380     return proxy_->RequestCancel(pipe.GetBusNum(), pipe.GetDevAddr(), ep.GetInterfaceId(), ep.GetAddress());
381 }
382 
RequestQueue(UsbRequest & request)383 int32_t UsbSrvClient::RequestQueue(UsbRequest &request)
384 {
385     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
386     const USBDevicePipe &pipe = request.GetPipe();
387     const USBEndpoint &ep = request.GetEndpoint();
388     return proxy_->RequestQueue(pipe.GetBusNum(), pipe.GetDevAddr(), ep, request.GetClientData(), request.GetReqData());
389 }
390 
UsbCancelTransfer(USBDevicePipe & pipe,int32_t & endpoint)391 int32_t UsbSrvClient::UsbCancelTransfer(USBDevicePipe &pipe, int32_t &endpoint)
392 {
393     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
394     int32_t ret = proxy_->UsbCancelTransfer(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint);
395     if (ret!= UEC_OK) {
396         USB_HILOGE(MODULE_USB_INNERKIT, "UsbCancelTransfer failed with ret = %{public}d!", ret);
397     }
398     return ret;
399 }
400 
UsbTransInfoChange(const HDI::Usb::V1_2::USBTransferInfo & param,UsbTransInfo & info)401 void UsbSrvClient::UsbTransInfoChange(const HDI::Usb::V1_2::USBTransferInfo &param, UsbTransInfo &info)
402 {
403     info.endpoint = param.endpoint;
404     info.flags = param.flags;
405     info.type = param.type;
406     info.timeOut = param.timeOut;
407     info.length = param.length;
408     info.userData = param.userData;
409     info.numIsoPackets = param.numIsoPackets;
410     return;
411 }
412 
UsbSubmitTransfer(USBDevicePipe & pipe,HDI::Usb::V1_2::USBTransferInfo & info,const TransferCallback & cb,sptr<Ashmem> & ashmem)413 int32_t UsbSrvClient::UsbSubmitTransfer(USBDevicePipe &pipe, HDI::Usb::V1_2::USBTransferInfo &info,
414     const TransferCallback &cb, sptr<Ashmem> &ashmem)
415 {
416     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
417     if (cb == nullptr) {
418         return PARAM_ERROR;
419     }
420     sptr<UsbdCallBackServer> callBackService = new UsbdCallBackServer(cb);
421     UsbTransInfo param;
422     UsbTransInfoChange(info, param);
423     int32_t fd = ashmem->GetAshmemFd();
424     int32_t memSize = ashmem->GetAshmemSize();
425     int32_t ret = proxy_->UsbSubmitTransfer(pipe.GetBusNum(), pipe.GetDevAddr(), param, callBackService, fd, memSize);
426     if (ret != UEC_OK) {
427         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSubmitTransfer failed with ret = %{public}d", ret);
428     }
429     return ret;
430 }
431 
RegBulkCallback(USBDevicePipe & pipe,const USBEndpoint & endpoint,const sptr<IRemoteObject> & cb)432 int32_t UsbSrvClient::RegBulkCallback(USBDevicePipe &pipe, const USBEndpoint &endpoint, const sptr<IRemoteObject> &cb)
433 {
434     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
435     int32_t ret = proxy_->RegBulkCallback(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint, cb);
436     if (ret != UEC_OK) {
437         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
438     }
439     return ret;
440 }
441 
UnRegBulkCallback(USBDevicePipe & pipe,const USBEndpoint & endpoint)442 int32_t UsbSrvClient::UnRegBulkCallback(USBDevicePipe &pipe, const USBEndpoint &endpoint)
443 {
444     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
445     int32_t ret = proxy_->UnRegBulkCallback(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint);
446     if (ret != UEC_OK) {
447         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
448     }
449     return ret;
450 }
451 
BulkRead(USBDevicePipe & pipe,const USBEndpoint & endpoint,sptr<Ashmem> & ashmem)452 int32_t UsbSrvClient::BulkRead(USBDevicePipe &pipe, const USBEndpoint &endpoint, sptr<Ashmem> &ashmem)
453 {
454     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
455     int32_t fd = ashmem->GetAshmemFd();
456     int32_t memSize = ashmem->GetAshmemSize();
457     int32_t ret = proxy_->BulkRead(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint, fd, memSize);
458     if (ret != UEC_OK) {
459         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
460     }
461     return ret;
462 }
463 
BulkWrite(USBDevicePipe & pipe,const USBEndpoint & endpoint,sptr<Ashmem> & ashmem)464 int32_t UsbSrvClient::BulkWrite(USBDevicePipe &pipe, const USBEndpoint &endpoint, sptr<Ashmem> &ashmem)
465 {
466     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
467     int32_t fd = ashmem->GetAshmemFd();
468     int32_t memSize = ashmem->GetAshmemSize();
469     int32_t ret = proxy_->BulkWrite(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint, fd, memSize);
470     if (ret != UEC_OK) {
471         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
472     }
473     return ret;
474 }
475 
BulkCancel(USBDevicePipe & pipe,const USBEndpoint & endpoint)476 int32_t UsbSrvClient::BulkCancel(USBDevicePipe &pipe, const USBEndpoint &endpoint)
477 {
478     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
479     int32_t ret = proxy_->BulkCancel(pipe.GetBusNum(), pipe.GetDevAddr(), endpoint);
480     if (ret != UEC_OK) {
481         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
482     }
483     return ret;
484 }
485 
AddRight(const std::string & bundleName,const std::string & deviceName)486 int32_t UsbSrvClient::AddRight(const std::string &bundleName, const std::string &deviceName)
487 {
488     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
489     USB_HILOGI(MODULE_USB_INNERKIT, "Calling AddRight");
490     int32_t ret = proxy_->AddRight(bundleName, deviceName);
491     if (ret != UEC_OK) {
492         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
493     }
494     return ret;
495 }
496 
AddAccessRight(const std::string & tokenId,const std::string & deviceName)497 int32_t UsbSrvClient::AddAccessRight(const std::string &tokenId, const std::string &deviceName)
498 {
499     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
500     USB_HILOGI(MODULE_USB_INNERKIT, "Calling AddAccessRight");
501     int32_t ret = proxy_->AddAccessRight(tokenId, deviceName);
502     if (ret != UEC_OK) {
503         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
504     }
505     return ret;
506 }
507 
ManageGlobalInterface(bool disable)508 int32_t UsbSrvClient::ManageGlobalInterface(bool disable)
509 {
510     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
511     int32_t ret = proxy_->ManageGlobalInterface(disable);
512     if (ret != UEC_OK) {
513         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
514     }
515     return ret;
516 }
517 
ManageDevice(int32_t vendorId,int32_t productId,bool disable)518 int32_t UsbSrvClient::ManageDevice(int32_t vendorId, int32_t productId, bool disable)
519 {
520     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
521     int32_t ret = proxy_->ManageDevice(vendorId, productId, disable);
522     if (ret != UEC_OK) {
523         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
524     }
525     return ret;
526 }
UsbDeviceTypeChange(const std::vector<UsbDeviceType> & disableType,std::vector<UsbDeviceTypeInfo> & deviceTypes)527 void UsbSrvClient::UsbDeviceTypeChange(const std::vector<UsbDeviceType> &disableType,
528     std::vector<UsbDeviceTypeInfo> &deviceTypes)
529 {
530     for (size_t i = 0; i < disableType.size(); i++) {
531         UsbDeviceTypeInfo info;
532         info.baseClass = disableType[i].baseClass;
533         info.subClass = disableType[i].subClass;
534         info.protocol = disableType[i].protocol;
535         info.isDeviceType = disableType[i].isDeviceType;
536         deviceTypes.push_back(info);
537     }
538     return;
539 }
ManageInterfaceType(const std::vector<UsbDeviceType> & disableType,bool disable)540 int32_t UsbSrvClient::ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
541 {
542     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
543     std::vector<UsbDeviceTypeInfo> disableDevType;
544     UsbDeviceTypeChange(disableType, disableDevType);
545     int32_t ret = proxy_->ManageInterfaceType(disableDevType, disable);
546     if (ret != UEC_OK) {
547         USB_HILOGE(MODULE_USB_INNERKIT, "failed width ret = %{public}d !", ret);
548     }
549     return ret;
550 }
551 
ClearHalt(USBDevicePipe & pipe,const USBEndpoint & ep)552 int32_t UsbSrvClient::ClearHalt(USBDevicePipe &pipe, const USBEndpoint &ep)
553 {
554     RETURN_IF_WITH_RET(proxy_ == nullptr, UEC_INTERFACE_NO_INIT);
555     int32_t ret = proxy_->ClearHalt(pipe.GetBusNum(), pipe.GetDevAddr(), ep.GetInterfaceId(), ep.GetAddress());
556     if (ret != UEC_OK) {
557         USB_HILOGE(MODULE_USB_INNERKIT, "ClearHalt failed ret = %{public}d !", ret);
558     }
559     return ret;
560 }
561 
GetDeviceSpeed(USBDevicePipe & pipe,uint8_t & speed)562 int32_t UsbSrvClient::GetDeviceSpeed(USBDevicePipe &pipe, uint8_t &speed)
563 {
564     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
565     int32_t ret = proxy_->GetDeviceSpeed(pipe.GetBusNum(), pipe.GetDevAddr(), speed);
566     if (ret != UEC_OK) {
567         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
568     }
569     USB_HILOGE(MODULE_USB_INNERKIT, "GetDeviceSpeed speed = %{public}u!", speed);
570     return ret;
571 }
572 
GetInterfaceActiveStatus(USBDevicePipe & pipe,const UsbInterface & interface,bool & unactivated)573 int32_t UsbSrvClient::GetInterfaceActiveStatus(USBDevicePipe &pipe, const UsbInterface &interface, bool &unactivated)
574 {
575     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
576     int32_t ret = proxy_->GetInterfaceActiveStatus(pipe.GetBusNum(), pipe.GetDevAddr(), interface.GetId(), unactivated);
577     if (ret != UEC_OK) {
578         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
579     }
580     return ret;
581 }
582 #else
OpenDevice(const UsbDevice & device,USBDevicePipe & pipe)583 int32_t UsbSrvClient::OpenDevice(const UsbDevice &device, USBDevicePipe &pipe)
584 {
585     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
586     return CAPABILITY_NOT_SUPPORT;
587 }
588 
ResetDevice(USBDevicePipe & pipe)589 int32_t UsbSrvClient::ResetDevice(USBDevicePipe &pipe)
590 {
591     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
592     return CAPABILITY_NOT_SUPPORT;
593 }
594 
HasRight(std::string deviceName)595 bool UsbSrvClient::HasRight(std::string deviceName)
596 {
597     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
598     return false;
599 }
600 
RequestRight(std::string deviceName)601 int32_t UsbSrvClient::RequestRight(std::string deviceName)
602 {
603     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
604     return CAPABILITY_NOT_SUPPORT;
605 }
606 
RemoveRight(std::string deviceName)607 int32_t UsbSrvClient::RemoveRight(std::string deviceName)
608 {
609     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
610     return CAPABILITY_NOT_SUPPORT;
611 }
612 
GetDevices(std::vector<UsbDevice> & deviceList)613 int32_t UsbSrvClient::GetDevices(std::vector<UsbDevice> &deviceList)
614 {
615     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
616     return CAPABILITY_NOT_SUPPORT;
617 }
618 
ClaimInterface(USBDevicePipe & pipe,const UsbInterface & interface,bool force)619 int32_t UsbSrvClient::ClaimInterface(USBDevicePipe &pipe, const UsbInterface &interface, bool force)
620 {
621     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
622     return CAPABILITY_NOT_SUPPORT;
623 }
624 
UsbAttachKernelDriver(USBDevicePipe & pipe,const UsbInterface & interface)625 int32_t UsbSrvClient::UsbAttachKernelDriver(USBDevicePipe &pipe, const UsbInterface &interface)
626 {
627     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
628     return CAPABILITY_NOT_SUPPORT;
629 }
630 
UsbDetachKernelDriver(USBDevicePipe & pipe,const UsbInterface & interface)631 int32_t UsbSrvClient::UsbDetachKernelDriver(USBDevicePipe &pipe, const UsbInterface &interface)
632 {
633     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
634     return CAPABILITY_NOT_SUPPORT;
635 }
636 
ReleaseInterface(USBDevicePipe & pipe,const UsbInterface & interface)637 int32_t UsbSrvClient::ReleaseInterface(USBDevicePipe &pipe, const UsbInterface &interface)
638 {
639     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
640     return CAPABILITY_NOT_SUPPORT;
641 }
642 
BulkTransfer(USBDevicePipe & pipe,const USBEndpoint & endpoint,std::vector<uint8_t> & bufferData,int32_t timeOut)643 int32_t UsbSrvClient::BulkTransfer(
644     USBDevicePipe &pipe, const USBEndpoint &endpoint, std::vector<uint8_t> &bufferData, int32_t timeOut)
645 {
646     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
647     return CAPABILITY_NOT_SUPPORT;
648 }
649 
ControlTransfer(USBDevicePipe & pipe,const UsbCtrlTransfer & ctrl,std::vector<uint8_t> & bufferData)650 int32_t UsbSrvClient::ControlTransfer(
651     USBDevicePipe &pipe, const UsbCtrlTransfer &ctrl, std::vector<uint8_t> &bufferData)
652 {
653     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
654     return CAPABILITY_NOT_SUPPORT;
655 }
656 
UsbControlTransfer(USBDevicePipe & pipe,const HDI::Usb::V1_2::UsbCtrlTransferParams & ctrlParams,std::vector<uint8_t> & bufferData)657 int32_t UsbSrvClient::UsbControlTransfer(USBDevicePipe &pipe, const HDI::Usb::V1_2::UsbCtrlTransferParams &ctrlParams,
658     std::vector<uint8_t> &bufferData)
659 {
660     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
661     return CAPABILITY_NOT_SUPPORT;
662 }
663 
SetConfiguration(USBDevicePipe & pipe,const USBConfig & config)664 int32_t UsbSrvClient::SetConfiguration(USBDevicePipe &pipe, const USBConfig &config)
665 {
666     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
667     return CAPABILITY_NOT_SUPPORT;
668 }
669 
SetInterface(USBDevicePipe & pipe,const UsbInterface & interface)670 int32_t UsbSrvClient::SetInterface(USBDevicePipe &pipe, const UsbInterface &interface)
671 {
672     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
673     return CAPABILITY_NOT_SUPPORT;
674 }
675 
GetRawDescriptors(USBDevicePipe & pipe,std::vector<uint8_t> & bufferData)676 int32_t UsbSrvClient::GetRawDescriptors(USBDevicePipe &pipe, std::vector<uint8_t> &bufferData)
677 {
678     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
679     return CAPABILITY_NOT_SUPPORT;
680 }
681 
GetFileDescriptor(USBDevicePipe & pipe,int32_t & fd)682 int32_t UsbSrvClient::GetFileDescriptor(USBDevicePipe &pipe, int32_t &fd)
683 {
684     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
685     return CAPABILITY_NOT_SUPPORT;
686 }
687 
Close(const USBDevicePipe & pipe)688 bool UsbSrvClient::Close(const USBDevicePipe &pipe)
689 {
690     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
691     return false;
692 }
693 
PipeRequestWait(USBDevicePipe & pipe,int64_t timeOut,UsbRequest & req)694 int32_t UsbSrvClient::PipeRequestWait(USBDevicePipe &pipe, int64_t timeOut, UsbRequest &req)
695 {
696     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
697     return CAPABILITY_NOT_SUPPORT;
698 }
699 
RequestInitialize(UsbRequest & request)700 int32_t UsbSrvClient::RequestInitialize(UsbRequest &request)
701 {
702     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
703     return CAPABILITY_NOT_SUPPORT;
704 }
705 
RequestFree(UsbRequest & request)706 int32_t UsbSrvClient::RequestFree(UsbRequest &request)
707 {
708     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
709     return CAPABILITY_NOT_SUPPORT;
710 }
711 
RequestAbort(UsbRequest & request)712 int32_t UsbSrvClient::RequestAbort(UsbRequest &request)
713 {
714     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
715     return CAPABILITY_NOT_SUPPORT;
716 }
717 
RequestQueue(UsbRequest & request)718 int32_t UsbSrvClient::RequestQueue(UsbRequest &request)
719 {
720     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
721     return CAPABILITY_NOT_SUPPORT;
722 }
723 
UsbCancelTransfer(USBDevicePipe & pipe,int32_t & endpoint)724 int32_t UsbSrvClient::UsbCancelTransfer(USBDevicePipe &pipe, int32_t &endpoint)
725 {
726     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
727     return CAPABILITY_NOT_SUPPORT;
728 }
729 
UsbSubmitTransfer(USBDevicePipe & pipe,HDI::Usb::V1_2::USBTransferInfo & info,const TransferCallback & cb,sptr<Ashmem> & ashmem)730 int32_t UsbSrvClient::UsbSubmitTransfer(USBDevicePipe &pipe, HDI::Usb::V1_2::USBTransferInfo &info,
731     const TransferCallback &cb, sptr<Ashmem> &ashmem)
732 {
733     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
734     return CAPABILITY_NOT_SUPPORT;
735 }
736 
RegBulkCallback(USBDevicePipe & pipe,const USBEndpoint & endpoint,const sptr<IRemoteObject> & cb)737 int32_t UsbSrvClient::RegBulkCallback(USBDevicePipe &pipe, const USBEndpoint &endpoint, const sptr<IRemoteObject> &cb)
738 {
739     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
740     return CAPABILITY_NOT_SUPPORT;
741 }
742 
UnRegBulkCallback(USBDevicePipe & pipe,const USBEndpoint & endpoint)743 int32_t UsbSrvClient::UnRegBulkCallback(USBDevicePipe &pipe, const USBEndpoint &endpoint)
744 {
745     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
746     return CAPABILITY_NOT_SUPPORT;
747 }
748 
BulkRead(USBDevicePipe & pipe,const USBEndpoint & endpoint,sptr<Ashmem> & ashmem)749 int32_t UsbSrvClient::BulkRead(USBDevicePipe &pipe, const USBEndpoint &endpoint, sptr<Ashmem> &ashmem)
750 {
751     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
752     return CAPABILITY_NOT_SUPPORT;
753 }
754 
BulkWrite(USBDevicePipe & pipe,const USBEndpoint & endpoint,sptr<Ashmem> & ashmem)755 int32_t UsbSrvClient::BulkWrite(USBDevicePipe &pipe, const USBEndpoint &endpoint, sptr<Ashmem> &ashmem)
756 {
757     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
758     return CAPABILITY_NOT_SUPPORT;
759 }
760 
BulkCancel(USBDevicePipe & pipe,const USBEndpoint & endpoint)761 int32_t UsbSrvClient::BulkCancel(USBDevicePipe &pipe, const USBEndpoint &endpoint)
762 {
763     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
764     return CAPABILITY_NOT_SUPPORT;
765 }
766 
AddRight(const std::string & bundleName,const std::string & deviceName)767 int32_t UsbSrvClient::AddRight(const std::string &bundleName, const std::string &deviceName)
768 {
769     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
770     return CAPABILITY_NOT_SUPPORT;
771 }
772 
AddAccessRight(const std::string & tokenId,const std::string & deviceName)773 int32_t UsbSrvClient::AddAccessRight(const std::string &tokenId, const std::string &deviceName)
774 {
775     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
776     return CAPABILITY_NOT_SUPPORT;
777 }
778 
ManageGlobalInterface(bool disable)779 int32_t UsbSrvClient::ManageGlobalInterface(bool disable)
780 {
781     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
782     return CAPABILITY_NOT_SUPPORT;
783 }
784 
ManageDevice(int32_t vendorId,int32_t productId,bool disable)785 int32_t UsbSrvClient::ManageDevice(int32_t vendorId, int32_t productId, bool disable)
786 {
787     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
788     return CAPABILITY_NOT_SUPPORT;
789 }
790 
ManageInterfaceType(const std::vector<UsbDeviceType> & disableType,bool disable)791 int32_t UsbSrvClient::ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
792 {
793     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
794     return CAPABILITY_NOT_SUPPORT;
795 }
796 
ClearHalt(USBDevicePipe & pipe,const USBEndpoint & ep)797 int32_t UsbSrvClient::ClearHalt(USBDevicePipe &pipe, const USBEndpoint &ep)
798 {
799     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
800     return CAPABILITY_NOT_SUPPORT;
801 }
802 
GetDeviceSpeed(USBDevicePipe & pipe,uint8_t & speed)803 int32_t UsbSrvClient::GetDeviceSpeed(USBDevicePipe &pipe, uint8_t &speed)
804 {
805     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
806     return CAPABILITY_NOT_SUPPORT;
807 }
808 
GetInterfaceActiveStatus(USBDevicePipe & pipe,const UsbInterface & interface,bool & unactivated)809 int32_t UsbSrvClient::GetInterfaceActiveStatus(USBDevicePipe &pipe, const UsbInterface &interface, bool &unactivated)
810 {
811     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
812     return CAPABILITY_NOT_SUPPORT;
813 }
814 #endif // USB_MANAGER_FEATURE_HOST
815 
816 #ifdef USB_MANAGER_FEATURE_DEVICE
GetCurrentFunctions(int32_t & funcs)817 int32_t UsbSrvClient::GetCurrentFunctions(int32_t &funcs)
818 {
819     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
820     int32_t ret = proxy_->GetCurrentFunctions(funcs);
821     if (ret != UEC_OK) {
822         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
823         return ret;
824     }
825     USB_HILOGI(MODULE_USB_INNERKIT, " Calling GetCurrentFunctions Success!");
826     USB_HILOGI(MODULE_USB_INNERKIT, "GetCurrentFunctions funcs = %{public}d!", funcs);
827     return ret;
828 }
829 
SetCurrentFunctions(int32_t funcs)830 int32_t UsbSrvClient::SetCurrentFunctions(int32_t funcs)
831 {
832     USB_HILOGI(MODULE_USB_INNERKIT, "SetCurrentFunctions funcs = %{public}d!", funcs);
833     RETURN_IF_WITH_RET(Connect() != UEC_OK, false);
834     int32_t ret = proxy_->SetCurrentFunctions(funcs);
835     if (ret != UEC_OK) {
836         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
837         return ret;
838     }
839     USB_HILOGI(MODULE_USB_INNERKIT, " Calling SetCurrentFunctions Success!");
840     return ret;
841 }
842 
UsbFunctionsFromString(std::string_view funcs)843 int32_t UsbSrvClient::UsbFunctionsFromString(std::string_view funcs)
844 {
845     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
846     int32_t funcResult = 0;
847     std::string funcsStr(funcs);
848     int32_t ret = proxy_->UsbFunctionsFromString(funcsStr, funcResult);
849     if (ret != UEC_OK) {
850         USB_HILOGE(MODULE_USB_INNERKIT, "UsbFunctionsFromString failed ret = %{public}d!", ret);
851         return ret;
852     }
853     USB_HILOGI(MODULE_USB_INNERKIT, " Calling UsbFunctionsFromString Success!");
854     return funcResult;
855 }
856 
UsbFunctionsToString(int32_t funcs)857 std::string UsbSrvClient::UsbFunctionsToString(int32_t funcs)
858 {
859     std::string result;
860     RETURN_IF_WITH_RET(Connect() != UEC_OK, result);
861     int32_t ret = proxy_->UsbFunctionsToString(funcs, result);
862     if (ret != UEC_OK) {
863         USB_HILOGE(MODULE_USB_INNERKIT, "UsbFunctionsToString failed ret = %{public}d!", ret);
864         return "";
865     }
866     USB_HILOGI(MODULE_USB_INNERKIT, " Calling UsbFunctionsToString Success!");
867     return result;
868 }
869 
GetAccessoryList(std::vector<USBAccessory> & accessList)870 int32_t UsbSrvClient::GetAccessoryList(std::vector<USBAccessory> &accessList)
871 {
872     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
873     int32_t ret = proxy_->GetAccessoryList(accessList);
874     if (ret != UEC_OK) {
875         USB_HILOGE(MODULE_USB_INNERKIT, "GetAccessoryList failed ret = %{public}d!", ret);
876         return ret;
877     }
878     USB_HILOGI(MODULE_USB_INNERKIT, "GetAccessoryList accessList size = %{public}zu!", accessList.size());
879     return ret;
880 }
881 
OpenAccessory(const USBAccessory & access,int32_t & fd)882 int32_t UsbSrvClient::OpenAccessory(const USBAccessory &access, int32_t &fd)
883 {
884     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
885     int32_t ret = proxy_->OpenAccessory(access, fd);
886     if (ret != UEC_OK) {
887         USB_HILOGE(MODULE_USB_INNERKIT, "OpenAccessory ret = %{public}d!", ret);
888     }
889     return ret;
890 }
891 
AddAccessoryRight(const uint32_t tokenId,const USBAccessory & access)892 int32_t UsbSrvClient::AddAccessoryRight(const uint32_t tokenId, const USBAccessory &access)
893 {
894     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
895     int32_t ret = proxy_->AddAccessoryRight(tokenId, access);
896     if (ret != UEC_OK) {
897         USB_HILOGE(MODULE_USB_INNERKIT, "AddAccessoryRight ret = %{public}d!", ret);
898     }
899     return ret;
900 }
901 
HasAccessoryRight(const USBAccessory & access,bool & result)902 int32_t UsbSrvClient::HasAccessoryRight(const USBAccessory &access, bool &result)
903 {
904     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
905     return proxy_->HasAccessoryRight(access, result);
906 }
907 
RequestAccessoryRight(const USBAccessory & access,bool & result)908 int32_t UsbSrvClient::RequestAccessoryRight(const USBAccessory &access, bool &result)
909 {
910     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
911     int32_t ret = proxy_->RequestAccessoryRight(access, result);
912     if (ret != UEC_OK) {
913         USB_HILOGE(MODULE_USB_INNERKIT, "RequestAccessoryRight ret = %{public}d!", ret);
914     }
915     return ret;
916 }
917 
CancelAccessoryRight(const USBAccessory & access)918 int32_t UsbSrvClient::CancelAccessoryRight(const USBAccessory &access)
919 {
920     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
921     int32_t ret = proxy_->CancelAccessoryRight(access);
922     if (ret != UEC_OK) {
923         USB_HILOGE(MODULE_USB_INNERKIT, "CancelAccessoryRight ret = %{public}d!", ret);
924     }
925     return ret;
926 }
927 
CloseAccessory(const int32_t fd)928 int32_t UsbSrvClient::CloseAccessory(const int32_t fd)
929 {
930     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
931     int32_t ret = proxy_->CloseAccessory(fd);
932     if (ret != UEC_OK) {
933         USB_HILOGE(MODULE_USB_INNERKIT, "CloseAccessory ret = %{public}d!", ret);
934     }
935     return ret;
936 }
937 #else
GetCurrentFunctions(int32_t & funcs)938 int32_t UsbSrvClient::GetCurrentFunctions(int32_t &funcs)
939 {
940     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
941     return CAPABILITY_NOT_SUPPORT;
942 }
943 
SetCurrentFunctions(int32_t funcs)944 int32_t UsbSrvClient::SetCurrentFunctions(int32_t funcs)
945 {
946     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
947     return CAPABILITY_NOT_SUPPORT;
948 }
949 
UsbFunctionsFromString(std::string_view funcs)950 int32_t UsbSrvClient::UsbFunctionsFromString(std::string_view funcs)
951 {
952     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
953     return CAPABILITY_NOT_SUPPORT;
954 }
955 
UsbFunctionsToString(int32_t funcs)956 std::string UsbSrvClient::UsbFunctionsToString(int32_t funcs)
957 {
958     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
959     return "";
960 }
961 
GetAccessoryList(std::vector<USBAccessory> & accessList)962 int32_t UsbSrvClient::GetAccessoryList(std::vector<USBAccessory> &accessList)
963 {
964     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
965     return CAPABILITY_NOT_SUPPORT;
966 }
967 
OpenAccessory(const USBAccessory & access,int32_t & fd)968 int32_t UsbSrvClient::OpenAccessory(const USBAccessory &access, int32_t &fd)
969 {
970     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
971     return CAPABILITY_NOT_SUPPORT;
972 }
973 
AddAccessoryRight(const uint32_t tokenId,const USBAccessory & access)974 int32_t UsbSrvClient::AddAccessoryRight(const uint32_t tokenId, const USBAccessory &access)
975 {
976     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
977     return CAPABILITY_NOT_SUPPORT;
978 }
979 
HasAccessoryRight(const USBAccessory & access,bool & result)980 int32_t UsbSrvClient::HasAccessoryRight(const USBAccessory &access, bool &result)
981 {
982     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
983     return CAPABILITY_NOT_SUPPORT;
984 }
985 
RequestAccessoryRight(const USBAccessory & access,bool & result)986 int32_t UsbSrvClient::RequestAccessoryRight(const USBAccessory &access, bool &result)
987 {
988     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
989     return CAPABILITY_NOT_SUPPORT;
990 }
991 
CancelAccessoryRight(const USBAccessory & access)992 int32_t UsbSrvClient::CancelAccessoryRight(const USBAccessory &access)
993 {
994     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
995     return CAPABILITY_NOT_SUPPORT;
996 }
997 
CloseAccessory(const int32_t fd)998 int32_t UsbSrvClient::CloseAccessory(const int32_t fd)
999 {
1000     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
1001     return CAPABILITY_NOT_SUPPORT;
1002 }
1003 #endif // USB_MANAGER_FEATURE_DEVICE
1004 
1005 #ifdef USB_MANAGER_FEATURE_PORT
GetPorts(std::vector<UsbPort> & usbports)1006 int32_t UsbSrvClient::GetPorts(std::vector<UsbPort> &usbports)
1007 {
1008     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1009     USB_HILOGI(MODULE_USB_INNERKIT, " Calling GetPorts");
1010     int32_t ret = proxy_->GetPorts(usbports);
1011     if (ret != UEC_OK) {
1012         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
1013     }
1014     return ret;
1015 }
1016 
GetSupportedModes(int32_t portId,int32_t & result)1017 int32_t UsbSrvClient::GetSupportedModes(int32_t portId, int32_t &result)
1018 {
1019     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1020     USB_HILOGI(MODULE_USB_INNERKIT, " Calling GetSupportedModes");
1021     int32_t ret = proxy_->GetSupportedModes(portId, result);
1022     if (ret != UEC_OK) {
1023         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
1024     }
1025     return ret;
1026 }
1027 
SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)1028 int32_t UsbSrvClient::SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole)
1029 {
1030     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1031     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SetPortRole");
1032     int32_t ret = proxy_->SetPortRole(portId, powerRole, dataRole);
1033     if (ret != UEC_OK) {
1034         USB_HILOGE(MODULE_USB_INNERKIT, "failed ret = %{public}d!", ret);
1035     }
1036     return ret;
1037 }
1038 #else
GetPorts(std::vector<UsbPort> & usbports)1039 int32_t UsbSrvClient::GetPorts(std::vector<UsbPort> &usbports)
1040 {
1041     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
1042     return CAPABILITY_NOT_SUPPORT;
1043 }
1044 
GetSupportedModes(int32_t portId,int32_t & result)1045 int32_t UsbSrvClient::GetSupportedModes(int32_t portId, int32_t &result)
1046 {
1047     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
1048     return CAPABILITY_NOT_SUPPORT;
1049 }
1050 
SetPortRole(int32_t portId,int32_t powerRole,int32_t dataRole)1051 int32_t UsbSrvClient::SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole)
1052 {
1053     USB_HILOGW(MODULE_USB_INNERKIT, "%{public}s: Capability not supported.", __FUNCTION__);
1054     return CAPABILITY_NOT_SUPPORT;
1055 }
1056 #endif // USB_MANAGER_FEATURE_PORT
1057 
SerialOpen(int32_t portId)1058 int32_t UsbSrvClient::SerialOpen(int32_t portId)
1059 {
1060     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SerialOpen");
1061     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1062     int32_t ret = proxy_->SerialOpen(portId, serialRemote);
1063     if (ret != UEC_OK) {
1064         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::SerialOpen failed ret = %{public}d!", ret);
1065     }
1066     return ret;
1067 }
1068 
SerialClose(int32_t portId)1069 int32_t UsbSrvClient::SerialClose(int32_t portId)
1070 {
1071     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SerialClose");
1072     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1073     int32_t ret = proxy_->SerialClose(portId);
1074     if (ret != UEC_OK) {
1075         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::SerialClose failed ret = %{public}d!", ret);
1076     }
1077     return ret;
1078 }
1079 
SerialRead(int32_t portId,std::vector<uint8_t> & data,uint32_t bufferSize,uint32_t & actualSize,uint32_t timeout)1080 int32_t UsbSrvClient::SerialRead(int32_t portId, std::vector<uint8_t> &data,
1081     uint32_t bufferSize, uint32_t &actualSize, uint32_t timeout)
1082 {
1083     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SerialRead");
1084     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1085     int32_t ret = proxy_->SerialRead(portId, data, bufferSize, actualSize, timeout);
1086     if (ret != UEC_OK) {
1087         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::SerialRead failed ret = %{public}d!", ret);
1088     }
1089     return ret;
1090 }
1091 
SerialWrite(int32_t portId,const std::vector<uint8_t> & data,uint32_t bufferSize,uint32_t & actualSize,uint32_t timeout)1092 int32_t UsbSrvClient::SerialWrite(int32_t portId, const std::vector<uint8_t>& data,
1093     uint32_t bufferSize, uint32_t &actualSize, uint32_t timeout)
1094 {
1095     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SerialWrite");
1096     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1097     int32_t ret = proxy_->SerialWrite(portId, data, bufferSize, actualSize, timeout);
1098     if (ret != UEC_OK) {
1099         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::SerialWrite failed ret = %{public}d!", ret);
1100     }
1101     return ret;
1102 }
1103 
SerialGetAttribute(int32_t portId,UsbSerialAttr & attribute)1104 int32_t UsbSrvClient::SerialGetAttribute(int32_t portId, UsbSerialAttr& attribute)
1105 {
1106     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SerialGetAttribute");
1107     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1108     int32_t ret = proxy_->SerialGetAttribute(portId, attribute);
1109     if (ret != UEC_OK) {
1110         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::SerialGetAttribute failed ret = %{public}d!", ret);
1111     }
1112     return ret;
1113 }
1114 
SerialSetAttribute(int32_t portId,const UsbSerialAttr & attribute)1115 int32_t UsbSrvClient::SerialSetAttribute(int32_t portId,
1116     const UsbSerialAttr& attribute)
1117 {
1118     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SerialSetAttribute");
1119     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1120     int32_t ret = proxy_->SerialSetAttribute(portId, attribute);
1121     if (ret != UEC_OK) {
1122         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::SerialSetAttribute failed ret = %{public}d!", ret);
1123     }
1124     return ret;
1125 }
1126 
SerialGetPortList(std::vector<UsbSerialPort> & serialPortList)1127 int32_t UsbSrvClient::SerialGetPortList(
1128     std::vector<UsbSerialPort>& serialPortList)
1129 {
1130     USB_HILOGI(MODULE_USB_INNERKIT, "Calling SerialGetPortList");
1131     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1132     int32_t ret = proxy_->SerialGetPortList(serialPortList);
1133     if (ret != UEC_OK) {
1134         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::SerialGetPortList failed ret = %{public}d!", ret);
1135     }
1136     return ret;
1137 }
1138 
HasSerialRight(int32_t portId,bool & hasRight)1139 int32_t UsbSrvClient::HasSerialRight(int32_t portId, bool &hasRight)
1140 {
1141     USB_HILOGI(MODULE_USB_INNERKIT, "Calling HasSerialRight");
1142     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1143     int32_t ret = proxy_->HasSerialRight(portId, hasRight);
1144     if (ret != UEC_OK) {
1145         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::HasSerialRight failed ret = %{public}d!", ret);
1146         return ret;
1147     }
1148     return UEC_OK;
1149 }
1150 
CancelSerialRight(int32_t portId)1151 int32_t UsbSrvClient::CancelSerialRight(int32_t portId)
1152 {
1153     USB_HILOGI(MODULE_USB_INNERKIT, "Calling CancelSerialRight");
1154     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1155     int32_t ret = proxy_->CancelSerialRight(portId);
1156     if (ret != UEC_OK) {
1157         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::CancelSerialRight failed ret = %{public}d !", ret);
1158     }
1159     return ret;
1160 }
1161 
RequestSerialRight(int32_t portId,bool & hasRight)1162 int32_t UsbSrvClient::RequestSerialRight(int32_t portId, bool &hasRight)
1163 {
1164     USB_HILOGI(MODULE_USB_INNERKIT, "Calling RequestSerialRight");
1165     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1166     int32_t ret = proxy_->RequestSerialRight(portId, hasRight);
1167     if (ret != UEC_OK) {
1168         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::RequestSerialRight failed ret = %{public}d !", ret);
1169     }
1170     return ret;
1171 }
1172 
AddSerialRight(uint32_t tokenId,int32_t portId)1173 int32_t UsbSrvClient::AddSerialRight(uint32_t tokenId, int32_t portId)
1174 {
1175     USB_HILOGI(MODULE_USB_INNERKIT, "Calling AddSerialRight");
1176     RETURN_IF_WITH_RET(Connect() != UEC_OK, UEC_INTERFACE_NO_INIT);
1177     int32_t ret = proxy_->AddSerialRight(tokenId, portId);
1178     if (ret != UEC_OK) {
1179         USB_HILOGE(MODULE_USB_INNERKIT, "UsbSrvClient::AddSerialRight failed ret = %{public}d!", ret);
1180     }
1181     return ret;
1182 }
1183 } // namespace USB
1184 } // namespace OHOS
1185