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