142103316Sopenharmony_ci/*
242103316Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
342103316Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
442103316Sopenharmony_ci * you may not use this file except in compliance with the License.
542103316Sopenharmony_ci * You may obtain a copy of the License at
642103316Sopenharmony_ci *
742103316Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
842103316Sopenharmony_ci *
942103316Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1042103316Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1142103316Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1242103316Sopenharmony_ci * See the License for the specific language governing permissions and
1342103316Sopenharmony_ci * limitations under the License.
1442103316Sopenharmony_ci */
1542103316Sopenharmony_ci
1642103316Sopenharmony_ci#ifndef USBMGR_USB_SERVER_PROXY_H
1742103316Sopenharmony_ci#define USBMGR_USB_SERVER_PROXY_H
1842103316Sopenharmony_ci
1942103316Sopenharmony_ci#include <map>
2042103316Sopenharmony_ci#include <string>
2142103316Sopenharmony_ci#include "iremote_proxy.h"
2242103316Sopenharmony_ci#include "iusb_srv.h"
2342103316Sopenharmony_ci#include "nocopyable.h"
2442103316Sopenharmony_ci#include "usb_device.h"
2542103316Sopenharmony_ci#include "usb_interface_type.h"
2642103316Sopenharmony_ci#include "usb_service_ipc_interface_code.h"
2742103316Sopenharmony_ci
2842103316Sopenharmony_cinamespace OHOS {
2942103316Sopenharmony_cinamespace USB {
3042103316Sopenharmony_ciclass UsbServerProxy : public IRemoteProxy<IUsbSrv> {
3142103316Sopenharmony_cipublic:
3242103316Sopenharmony_ci    explicit UsbServerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IUsbSrv>(impl) {}
3342103316Sopenharmony_ci    ~UsbServerProxy() = default;
3442103316Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(UsbServerProxy);
3542103316Sopenharmony_ci
3642103316Sopenharmony_ci    int32_t GetDevices(std::vector<UsbDevice> &deviceList) override;
3742103316Sopenharmony_ci    int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) override;
3842103316Sopenharmony_ci    int32_t ResetDevice(uint8_t busNum, uint8_t devAddr) override;
3942103316Sopenharmony_ci    bool HasRight(std::string deviceName) override;
4042103316Sopenharmony_ci    int32_t RequestRight(std::string deviceName) override;
4142103316Sopenharmony_ci    int32_t RemoveRight(std::string deviceName) override;
4242103316Sopenharmony_ci    int32_t GetCurrentFunctions(int32_t &funcs) override;
4342103316Sopenharmony_ci    int32_t SetCurrentFunctions(int32_t funcs) override;
4442103316Sopenharmony_ci    int32_t UsbFunctionsFromString(std::string_view funcs) override;
4542103316Sopenharmony_ci    std::string UsbFunctionsToString(int32_t funcs) override;
4642103316Sopenharmony_ci    int32_t GetPorts(std::vector<UsbPort> &ports) override;
4742103316Sopenharmony_ci    int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes) override;
4842103316Sopenharmony_ci    int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) override;
4942103316Sopenharmony_ci
5042103316Sopenharmony_ci    int32_t ClaimInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t force) override;
5142103316Sopenharmony_ci    int32_t UsbAttachKernelDriver(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid) override;
5242103316Sopenharmony_ci    int32_t UsbDetachKernelDriver(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid) override;
5342103316Sopenharmony_ci    int32_t ReleaseInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid) override;
5442103316Sopenharmony_ci    int32_t BulkTransferRead(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe,
5542103316Sopenharmony_ci        std::vector<uint8_t> &bufferData, int32_t timeOut) override;
5642103316Sopenharmony_ci    int32_t BulkTransferReadwithLength(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe,
5742103316Sopenharmony_ci        int32_t length, std::vector<uint8_t> &bufferData, int32_t timeOut) override;
5842103316Sopenharmony_ci    int32_t BulkTransferWrite(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe,
5942103316Sopenharmony_ci        const std::vector<uint8_t> &bufferData, int32_t timeOut) override;
6042103316Sopenharmony_ci
6142103316Sopenharmony_ci    int32_t ControlTransfer(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbCtrlTransfer &ctrl,
6242103316Sopenharmony_ci        std::vector<uint8_t> &bufferData) override;
6342103316Sopenharmony_ci    int32_t UsbControlTransfer(const HDI::Usb::V1_0::UsbDev &dev,
6442103316Sopenharmony_ci        const HDI::Usb::V1_1::UsbCtrlTransferParams &ctrlParams, std::vector<uint8_t> &bufferData) override;
6542103316Sopenharmony_ci    int32_t SetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t configIndex) override;
6642103316Sopenharmony_ci    int32_t GetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t &configIndex) override;
6742103316Sopenharmony_ci    int32_t SetInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t altIndex) override;
6842103316Sopenharmony_ci    int32_t GetRawDescriptor(uint8_t busNum, uint8_t devAddr, std::vector<uint8_t> &bufferData) override;
6942103316Sopenharmony_ci    int32_t GetFileDescriptor(uint8_t busNum, uint8_t devAddr, int32_t &fd) override;
7042103316Sopenharmony_ci    int32_t RequestQueue(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe,
7142103316Sopenharmony_ci        const std::vector<uint8_t> &clientData, const std::vector<uint8_t> &bufferData) override;
7242103316Sopenharmony_ci    int32_t RequestWait(const HDI::Usb::V1_0::UsbDev &dev, int32_t timeOut, std::vector<uint8_t> &clientData,
7342103316Sopenharmony_ci        std::vector<uint8_t> &bufferData) override;
7442103316Sopenharmony_ci    int32_t RequestCancel(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t endpointId) override;
7542103316Sopenharmony_ci    int32_t Close(uint8_t busNum, uint8_t devAddr) override;
7642103316Sopenharmony_ci
7742103316Sopenharmony_ci    int32_t RegBulkCallback(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe,
7842103316Sopenharmony_ci        const sptr<IRemoteObject> &cb) override;
7942103316Sopenharmony_ci    int32_t UnRegBulkCallback(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe) override;
8042103316Sopenharmony_ci    int32_t BulkRead(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe,
8142103316Sopenharmony_ci        sptr<Ashmem> &ashmem) override;
8242103316Sopenharmony_ci    int32_t BulkWrite(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe,
8342103316Sopenharmony_ci        sptr<Ashmem> &ashmem) override;
8442103316Sopenharmony_ci    int32_t BulkCancel(const HDI::Usb::V1_0::UsbDev &dev, const HDI::Usb::V1_0::UsbPipe &pipe) override;
8542103316Sopenharmony_ci    int32_t AddRight(const std::string &bundleName, const std::string &deviceName) override;
8642103316Sopenharmony_ci    int32_t AddAccessRight(const std::string &tokenId, const std::string &deviceName) override;
8742103316Sopenharmony_ci    int32_t ManageGlobalInterface(bool disable) override;
8842103316Sopenharmony_ci    int32_t ManageDevice(int32_t vendorId, int32_t productId, bool disable) override;
8942103316Sopenharmony_ci    int32_t ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable) override;
9042103316Sopenharmony_ci    int32_t ClearHalt(uint8_t busNum, uint8_t devAddr, uint8_t interfaceId, uint8_t endpointId) override;
9142103316Sopenharmony_ci    int32_t GetDeviceSpeed(uint8_t busNum, uint8_t devAddr, uint8_t &speed) override;
9242103316Sopenharmony_ci    int32_t GetInterfaceActiveStatus(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, bool &unactivated) override;
9342103316Sopenharmony_ciprivate:
9442103316Sopenharmony_ci    static inline BrokerDelegator<UsbServerProxy> delegator_;
9542103316Sopenharmony_ci    int32_t ParseUsbPort(MessageParcel &reply, std::vector<UsbPort> &result);
9642103316Sopenharmony_ci    int32_t SetDeviceMessage(MessageParcel &data, uint8_t busNum, uint8_t devAddr);
9742103316Sopenharmony_ci    int32_t SetBufferMessage(MessageParcel &data, const std::vector<uint8_t> &bufferData);
9842103316Sopenharmony_ci    int32_t GetBufferMessage(MessageParcel &data, std::vector<uint8_t> &bufferData);
9942103316Sopenharmony_ci    int32_t GetDeviceListMessageParcel(MessageParcel &data, std::vector<UsbDevice> &deviceList);
10042103316Sopenharmony_ci    int32_t GetDeviceMessageParcel(MessageParcel &data, UsbDevice &devInfo);
10142103316Sopenharmony_ci    int32_t GetDeviceConfigsMessageParcel(MessageParcel &data, std::vector<USBConfig> &configs);
10242103316Sopenharmony_ci    int32_t GetDeviceInterfacesMessageParcel(MessageParcel &data, std::vector<UsbInterface> &interfaces);
10342103316Sopenharmony_ci    int32_t GetDeviceEndpointsMessageParcel(MessageParcel &data, std::vector<USBEndpoint> &eps);
10442103316Sopenharmony_ci
10542103316Sopenharmony_ci    bool ReadFileDescriptor(MessageParcel &data, int &fd);
10642103316Sopenharmony_ci};
10742103316Sopenharmony_ci} // namespace USB
10842103316Sopenharmony_ci} // namespace OHOS
10942103316Sopenharmony_ci
11042103316Sopenharmony_ci#endif // USBMGR_USB_SERVER_PROXY_H
111