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 #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 #include "usb_service_ipc_interface_code.h" 26 27 namespace OHOS { 28 namespace USB { 29 class UsbServerProxy : public IRemoteProxy<IUsbSrv> { 30 public: UsbServerProxy(const sptr<IRemoteObject> & impl)31 explicit UsbServerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IUsbSrv>(impl) {} 32 ~UsbServerProxy() = default; 33 DISALLOW_COPY_AND_MOVE(UsbServerProxy); 34 35 int32_t GetDevices(std::vector<UsbDevice> &deviceList) override; 36 int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) override; 37 bool HasRight(std::string deviceName) override; 38 int32_t RequestRight(std::string deviceName) override; 39 int32_t RemoveRight(std::string deviceName) override; 40 int32_t GetCurrentFunctions(int32_t &funcs) override; 41 int32_t SetCurrentFunctions(int32_t funcs) override; 42 int32_t UsbFunctionsFromString(std::string_view funcs) override; 43 std::string UsbFunctionsToString(int32_t funcs) override; 44 int32_t GetPorts(std::vector<UsbPort> &ports) override; 45 int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes) override; 46 int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) override; 47 48 int32_t ClaimInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t force) override; 49 int32_t ReleaseInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid) override; 50 int32_t BulkTransferRead(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 51 std::vector<uint8_t> &bufferData, int32_t timeOut) override; 52 int32_t BulkTransferWrite(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 53 const std::vector<uint8_t> &bufferData, int32_t timeOut) override; 54 55 int32_t ControlTransfer(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbCtrlTransfer &ctrl, 56 std::vector<uint8_t> &bufferData) override; 57 int32_t SetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t configIndex) override; 58 int32_t GetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t &configIndex) override; 59 int32_t SetInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t altIndex) override; 60 int32_t GetRawDescriptor(uint8_t busNum, uint8_t devAddr, std::vector<uint8_t> &bufferData) override; 61 int32_t GetFileDescriptor(uint8_t busNum, uint8_t devAddr, int32_t &fd) override; 62 int32_t RequestQueue(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 63 const std::vector<uint8_t> &clientData, const std::vector<uint8_t> &bufferData) override; 64 int32_t RequestWait(const HDI::Usb::V1_0::UsbDev &dev, int32_t timeOut, std::vector<uint8_t> &clientData, 65 std::vector<uint8_t> &bufferData) override; 66 int32_t RequestCancel(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t endpointId) override; 67 int32_t Close(uint8_t busNum, uint8_t devAddr) override; 68 69 int32_t RegBulkCallback(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 70 const sptr<IRemoteObject> &cb) override; 71 int32_t UnRegBulkCallback(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe) override; 72 int32_t BulkRead(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 73 sptr<Ashmem> &ashmem) override; 74 int32_t BulkWrite(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 75 sptr<Ashmem> &ashmem) override; 76 int32_t BulkCancel(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe) override; 77 int32_t AddRight(const std::string &bundleName, const std::string &deviceName) override; 78 79 private: 80 static inline BrokerDelegator<UsbServerProxy> delegator_; 81 int32_t ParseUsbPort(MessageParcel &reply, std::vector<UsbPort> &result); 82 int32_t SetDeviceMessage(MessageParcel &data, uint8_t busNum, uint8_t devAddr); 83 int32_t SetBufferMessage(MessageParcel &data, const std::vector<uint8_t> &bufferData); 84 int32_t GetBufferMessage(MessageParcel &data, std::vector<uint8_t> &bufferData); 85 int32_t GetDeviceListMessageParcel(MessageParcel &data, std::vector<UsbDevice> &deviceList); 86 int32_t GetDeviceMessageParcel(MessageParcel &data, UsbDevice &devInfo); 87 int32_t GetDeviceConfigsMessageParcel(MessageParcel &data, std::vector<USBConfig> &configs); 88 int32_t GetDeviceInterfacesMessageParcel(MessageParcel &data, std::vector<UsbInterface> &interfaces); 89 int32_t GetDeviceEndpointsMessageParcel(MessageParcel &data, std::vector<USBEndpoint> &eps); 90 }; 91 } // namespace USB 92 } // namespace OHOS 93 94 #endif // USBMGR_USB_SERVER_PROXY_H 95