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_STUB_H 17 #define USBMGR_USB_SERVER_STUB_H 18 19 #include <vector> 20 #include "iremote_stub.h" 21 #include "iusb_srv.h" 22 #include "nocopyable.h" 23 #include "usb_device.h" 24 #include "usb_service_ipc_interface_code.h" 25 26 namespace OHOS { 27 namespace USB { 28 class UsbServerStub : public IRemoteStub<IUsbSrv> { 29 public: 30 DISALLOW_COPY_AND_MOVE(UsbServerStub); 31 32 UsbServerStub() = default; 33 virtual ~UsbServerStub() = default; 34 35 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 36 37 private: 38 bool StubHost(uint32_t code, int32_t &result, MessageParcel &data, MessageParcel &reply, MessageOption &option); 39 bool StubDevice(uint32_t code, int32_t &result, MessageParcel &data, MessageParcel &reply, MessageOption &option); 40 41 int32_t DoGetCurrentFunctions(MessageParcel &data, MessageParcel &reply, MessageOption &option); 42 int32_t DoSetCurrentFunctions(MessageParcel &data, MessageParcel &reply, MessageOption &option); 43 int32_t DoUsbFunctionsFromString(MessageParcel &data, MessageParcel &reply, MessageOption &option); 44 int32_t DoUsbFunctionsToString(MessageParcel &data, MessageParcel &reply, MessageOption &option); 45 46 int32_t DoOpenDevice(MessageParcel &data, MessageParcel &reply, MessageOption &option); 47 int32_t DoHasRight(MessageParcel &data, MessageParcel &reply, MessageOption &option); 48 int32_t DoRequestRight(MessageParcel &data, MessageParcel &reply, MessageOption &option); 49 int32_t DoRemoveRight(MessageParcel &data, MessageParcel &reply, MessageOption &option); 50 int32_t DoGetPorts(MessageParcel &data, MessageParcel &reply, MessageOption &option); 51 int32_t DoGetSupportedModes(MessageParcel &data, MessageParcel &reply, MessageOption &option); 52 int32_t DoSetPortRole(MessageParcel &data, MessageParcel &reply, MessageOption &option); 53 int32_t DoClaimInterface(MessageParcel &data, MessageParcel &reply, MessageOption &option); 54 int32_t DoReleaseInterface(MessageParcel &data, MessageParcel &reply, MessageOption &option); 55 int32_t DoBulkTransferRead(MessageParcel &data, MessageParcel &reply, MessageOption &option); 56 int32_t DoBulkTransferWrite(MessageParcel &data, MessageParcel &reply, MessageOption &option); 57 int32_t DoControlTransfer(MessageParcel &data, MessageParcel &reply, MessageOption &option); 58 int32_t DoSetActiveConfig(MessageParcel &data, MessageParcel &reply, MessageOption &option); 59 int32_t DoGetActiveConfig(MessageParcel &data, MessageParcel &reply, MessageOption &option); 60 int32_t DoSetInterface(MessageParcel &data, MessageParcel &reply, MessageOption &option); 61 int32_t DoGetRawDescriptor(MessageParcel &data, MessageParcel &reply, MessageOption &option); 62 int32_t DoGetFileDescriptor(MessageParcel &data, MessageParcel &reply, MessageOption &option); 63 int32_t DoRequestQueue(MessageParcel &data, MessageParcel &reply, MessageOption &option); 64 int32_t DoRequestWait(MessageParcel &data, MessageParcel &reply, MessageOption &option); 65 int32_t DoRequestCancel(MessageParcel &data, MessageParcel &reply, MessageOption &option); 66 67 int32_t DoClose(MessageParcel &data, MessageParcel &reply, MessageOption &option); 68 int32_t DoGetDevices(MessageParcel &data, MessageParcel &reply, MessageOption &option); 69 70 int32_t WriteUsbPort(MessageParcel &reply, const UsbPort &port); 71 72 int32_t GetDeviceMessage(MessageParcel &data, uint8_t &busNum, uint8_t &devAddr); 73 int32_t SetBufferMessage(MessageParcel &data, const std::vector<uint8_t> &bufferData); 74 int32_t GetBufferMessage(MessageParcel &data, std::vector<uint8_t> &bufferData); 75 int32_t SetDeviceListMessageParcel(std::vector<UsbDevice> &deviceList, MessageParcel &data); 76 int32_t SetDeviceMessageParcel(UsbDevice &devInfo, MessageParcel &data); 77 int32_t SetDeviceConfigsMessageParcel(std::vector<USBConfig> &configs, MessageParcel &data); 78 int32_t SetDeviceInterfacesMessageParcel(std::vector<UsbInterface> &interfaces, MessageParcel &data); 79 int32_t SetDeviceEndpointsMessageParcel(std::vector<USBEndpoint> &eps, MessageParcel &data); 80 81 int32_t DoRegBulkCallback(MessageParcel &data, MessageParcel &reply, MessageOption &option); 82 int32_t DoUnRegBulkCallback(MessageParcel &data, MessageParcel &reply, MessageOption &option); 83 int32_t DoBulkRead(MessageParcel &data, MessageParcel &reply, MessageOption &option); 84 int32_t DoBulkWrite(MessageParcel &data, MessageParcel &reply, MessageOption &option); 85 int32_t DoBulkCancel(MessageParcel &data, MessageParcel &reply, MessageOption &option); 86 int32_t DoAddRight(MessageParcel &data, MessageParcel &reply, MessageOption &option); 87 }; 88 } // namespace USB 89 } // namespace OHOS 90 91 #endif // USBMGR_USB_SERVER_STUB_H 92