1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef USBMGR_USB_SERVER_PROXY_H 17 #define USBMGR_USB_SERVER_PROXY_H 18 19 #include <map> 20 #include <string> 21 #include "iremote_proxy.h" 22 #include "iusb_srv.h" 23 #include "nocopyable.h" 24 #include "usb_device.h" 25 26 namespace OHOS { 27 namespace USB { 28 class UsbServerProxy : public IRemoteProxy<IUsbSrv> { 29 public: UsbServerProxy(const sptr<IRemoteObject> & impl)30 explicit UsbServerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IUsbSrv>(impl) {} 31 ~UsbServerProxy() = default; 32 DISALLOW_COPY_AND_MOVE(UsbServerProxy); 33 34 int32_t GetDevices(std::vector<UsbDevice> &deviceList) override; 35 int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) override; 36 bool HasRight(std::string deviceName) override; 37 int32_t RequestRight(std::string deviceName) override; 38 int32_t RemoveRight(std::string deviceName) override; 39 int32_t GetCurrentFunctions(int32_t &funcs) override; 40 int32_t SetCurrentFunctions(int32_t funcs) override; 41 int32_t UsbFunctionsFromString(std::string_view funcs) override; 42 std::string UsbFunctionsToString(int32_t funcs) override; 43 int32_t GetPorts(std::vector<UsbPort> &ports) override; 44 int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes) override; 45 int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) override; 46 47 int32_t ClaimInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t force) override; 48 int32_t ReleaseInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid) override; 49 int32_t BulkTransferRead(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 50 std::vector<uint8_t> &bufferData, int32_t timeOut) override; 51 int32_t BulkTransferWrite(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 52 const std::vector<uint8_t> &bufferData, int32_t timeOut) override; 53 54 int32_t ControlTransfer(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbCtrlTransfer &ctrl, 55 std::vector<uint8_t> &bufferData) override; 56 int32_t SetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t configIndex) override; 57 int32_t GetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t &configIndex) override; 58 int32_t SetInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t altIndex) override; 59 int32_t GetRawDescriptor(uint8_t busNum, uint8_t devAddr, std::vector<uint8_t> &bufferData) override; 60 int32_t GetFileDescriptor(uint8_t busNum, uint8_t devAddr, int32_t &fd) override; 61 int32_t RequestQueue(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 62 const std::vector<uint8_t> &clientData, const std::vector<uint8_t> &bufferData) override; 63 int32_t RequestWait(const HDI::Usb::V1_0::UsbDev &dev, int32_t timeOut, std::vector<uint8_t> &clientData, 64 std::vector<uint8_t> &bufferData) override; 65 int32_t RequestCancel(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t endpointId) override; 66 int32_t Close(uint8_t busNum, uint8_t devAddr) override; 67 68 int32_t RegBulkCallback(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 69 const sptr<IRemoteObject> &cb) override; 70 int32_t UnRegBulkCallback(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe) override; 71 int32_t BulkRead(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 72 sptr<Ashmem> &ashmem) override; 73 int32_t BulkWrite(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 74 sptr<Ashmem> &ashmem) override; 75 int32_t BulkCancel(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe) override; 76 int32_t AddRight(const std::string &bundleName, const std::string &deviceName) override; 77 78 private: 79 static inline BrokerDelegator<UsbServerProxy> delegator_; 80 int32_t ParseUsbPort(MessageParcel &reply, std::vector<UsbPort> &result); 81 int32_t SetDeviceMessage(MessageParcel &data, uint8_t busNum, uint8_t devAddr); 82 int32_t SetBufferMessage(MessageParcel &data, const std::vector<uint8_t> &bufferData); 83 int32_t GetBufferMessage(MessageParcel &data, std::vector<uint8_t> &bufferData); 84 int32_t GetDeviceListMessageParcel(MessageParcel &data, std::vector<UsbDevice> &deviceList); 85 int32_t GetDeviceMessageParcel(MessageParcel &data, UsbDevice &devInfo); 86 int32_t GetDeviceConfigsMessageParcel(MessageParcel &data, std::vector<USBConfig> &configs); 87 int32_t GetDeviceInterfacesMessageParcel(MessageParcel &data, std::vector<UsbInterface> &interfaces); 88 int32_t GetDeviceEndpointsMessageParcel(MessageParcel &data, std::vector<USBEndpoint> &eps); 89 }; 90 } // namespace USB 91 } // namespace OHOS 92 93 #endif // USBMGR_USB_SERVER_PROXY_H 94