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_INNERKITS_IUSB_SRV_H 17 #define USBMGR_INNERKITS_IUSB_SRV_H 18 19 #include "iremote_broker.h" 20 #include "iremote_object.h" 21 #include "usb_device.h" 22 #include "usb_port.h" 23 #include "v1_0/usb_types.h" 24 25 namespace OHOS { 26 namespace USB { 27 class IUsbSrv : public IRemoteBroker { 28 public: 29 enum { 30 USB_FUN_HAS_RIGHT = 0, 31 USB_FUN_REQUEST_RIGHT, 32 USB_FUN_REMOVE_RIGHT, 33 USB_FUN_OPEN_DEVICE, 34 USB_FUN_GET_DEVICE, 35 USB_FUN_GET_DEVICES, 36 USB_FUN_GET_CURRENT_FUNCTIONS, 37 USB_FUN_SET_CURRENT_FUNCTIONS, 38 USB_FUN_USB_FUNCTIONS_FROM_STRING, 39 USB_FUN_USB_FUNCTIONS_TO_STRING, 40 USB_FUN_CLAIM_INTERFACE, 41 USB_FUN_RELEASE_INTERFACE, 42 USB_FUN_BULK_TRANSFER_READ, 43 USB_FUN_BULK_TRANSFER_WRITE, 44 USB_FUN_CONTROL_TRANSFER, 45 USB_FUN_SET_ACTIVE_CONFIG, 46 USB_FUN_GET_ACTIVE_CONFIG, 47 USB_FUN_SET_INTERFACE, 48 USB_FUN_GET_PORTS, 49 USB_FUN_GET_SUPPORTED_MODES, 50 USB_FUN_SET_PORT_ROLE, 51 USB_FUN_REQUEST_QUEUE, 52 USB_FUN_REQUEST_WAIT, 53 USB_FUN_REQUEST_CANCEL, 54 USB_FUN_GET_DESCRIPTOR, 55 USB_FUN_GET_FILEDESCRIPTOR, 56 USB_FUN_CLOSE_DEVICE, 57 USB_FUN_BULK_AYSNC_READ, 58 USB_FUN_BULK_AYSNC_WRITE, 59 USB_FUN_BULK_AYSNC_CANCEL, 60 USB_FUN_REG_BULK_CALLBACK, 61 USB_FUN_UNREG_BULK_CALLBACK, 62 USB_FUN_ADD_RIGHT, 63 }; 64 65 virtual int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) = 0; 66 virtual bool HasRight(std::string deviceName) = 0; 67 virtual int32_t RequestRight(std::string deviceName) = 0; 68 virtual int32_t RemoveRight(std::string deviceName) = 0; 69 virtual int32_t GetDevices(std::vector<UsbDevice> &deviceList) = 0; 70 virtual int32_t GetCurrentFunctions(int32_t &funcs) = 0; 71 virtual int32_t SetCurrentFunctions(int32_t funcs) = 0; 72 virtual int32_t UsbFunctionsFromString(std::string_view funcs) = 0; 73 virtual std::string UsbFunctionsToString(int32_t funcs) = 0; 74 virtual int32_t GetPorts(std::vector<UsbPort> &ports) = 0; 75 virtual int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes) = 0; 76 virtual int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) = 0; 77 virtual int32_t ReleaseInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid) = 0; 78 virtual int32_t ClaimInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t force) = 0; 79 virtual int32_t BulkTransferRead(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 80 std::vector<uint8_t> &bufferData, int32_t timeOut) = 0; 81 virtual int32_t BulkTransferWrite(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 82 const std::vector<uint8_t> &bufferData, int32_t timeOut) = 0; 83 virtual int32_t ControlTransfer(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbCtrlTransfer &ctrl, 84 std::vector<uint8_t> &bufferData) = 0; 85 virtual int32_t SetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t configId) = 0; 86 virtual int32_t GetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t &configId) = 0; 87 virtual int32_t SetInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t altIndex) = 0; 88 virtual int32_t GetRawDescriptor(uint8_t busNum, uint8_t devAddr, std::vector<uint8_t> &bufferData) = 0; 89 virtual int32_t GetFileDescriptor(uint8_t busNum, uint8_t devAddr, int32_t &fd) = 0; 90 virtual int32_t RequestQueue(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe, 91 const std::vector<uint8_t> &clientData, const std::vector<uint8_t> &bufferData) = 0; 92 virtual int32_t RequestWait(const HDI::Usb::V1_0::UsbDev &dev, int32_t timeOut, std::vector<uint8_t> &clientData, 93 std::vector<uint8_t> &bufferData) = 0; 94 virtual int32_t RequestCancel(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t endpointId) = 0; 95 virtual int32_t Close(uint8_t busNum, uint8_t devAddr) = 0; 96 97 virtual int32_t RegBulkCallback(const HDI::Usb::V1_0::UsbDev &devInfo, const HDI::Usb::V1_0::UsbPipe &pipe, 98 const sptr<IRemoteObject> &cb) = 0; 99 virtual int32_t UnRegBulkCallback(const HDI::Usb::V1_0::UsbDev &devInfo, const HDI::Usb::V1_0::UsbPipe &pipe) = 0; 100 virtual int32_t BulkRead(const HDI::Usb::V1_0::UsbDev &devInfo, const HDI::Usb::V1_0::UsbPipe &pipe, 101 sptr<Ashmem> &ashmem) = 0; 102 virtual int32_t BulkWrite(const HDI::Usb::V1_0::UsbDev &devInfo, const HDI::Usb::V1_0::UsbPipe &pipe, 103 sptr<Ashmem> &ashmem) = 0; 104 virtual int32_t BulkCancel(const HDI::Usb::V1_0::UsbDev &devInfo, const HDI::Usb::V1_0::UsbPipe &pipe) = 0; 105 virtual int32_t AddRight(const std::string &bundleName, const std::string &deviceName) = 0; 106 107 public: 108 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.usb.IUsbSrv"); 109 }; 110 } // namespace USB 111 } // namespace OHOS 112 113 #endif // USBMGR_INNERKITS_IUSB_SRV_H 114