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#include "ipc_types.h"
1742103316Sopenharmony_ci#include "message_parcel.h"
1842103316Sopenharmony_ci#include "securec.h"
1942103316Sopenharmony_ci#include "string_ex.h"
2042103316Sopenharmony_ci#include "usb_common.h"
2142103316Sopenharmony_ci#include "usb_errors.h"
2242103316Sopenharmony_ci#include "usb_request.h"
2342103316Sopenharmony_ci#include "usb_server_proxy.h"
2442103316Sopenharmony_ci#include "v1_1/iusb_interface.h"
2542103316Sopenharmony_ci
2642103316Sopenharmony_ciusing namespace OHOS::HDI::Usb::V1_1;
2742103316Sopenharmony_cinamespace OHOS {
2842103316Sopenharmony_cinamespace USB {
2942103316Sopenharmony_ci
3042103316Sopenharmony_ciconstexpr int32_t MAX_DEVICE_NUM = 127;
3142103316Sopenharmony_ciconstexpr int32_t MAX_CONFIG_NUM  = 100;
3242103316Sopenharmony_ciconstexpr int32_t MAX_INTERFACE_NUM = 100;
3342103316Sopenharmony_ciconstexpr int32_t MAX_ENDPOINT_NUM = 32;
3442103316Sopenharmony_ciconstexpr int32_t MAX_PORT_NUM = 100;
3542103316Sopenharmony_ci
3642103316Sopenharmony_ciint32_t UsbServerProxy::SetDeviceMessage(MessageParcel &data, uint8_t busNum, uint8_t devAddr)
3742103316Sopenharmony_ci{
3842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, busNum, UEC_SERVICE_WRITE_PARCEL_ERROR);
3942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, devAddr, UEC_SERVICE_WRITE_PARCEL_ERROR);
4042103316Sopenharmony_ci    return UEC_OK;
4142103316Sopenharmony_ci}
4242103316Sopenharmony_ci
4342103316Sopenharmony_ciint32_t UsbServerProxy::SetBufferMessage(MessageParcel &data, const std::vector<uint8_t> &bufferData)
4442103316Sopenharmony_ci{
4542103316Sopenharmony_ci    uint32_t length = bufferData.size();
4642103316Sopenharmony_ci    const uint8_t *ptr = bufferData.data();
4742103316Sopenharmony_ci    if (!ptr) {
4842103316Sopenharmony_ci        length = 0;
4942103316Sopenharmony_ci    }
5042103316Sopenharmony_ci
5142103316Sopenharmony_ci    if (!data.WriteUint32(length)) {
5242103316Sopenharmony_ci        USB_HILOGE(MODULE_USBD, "write length failed:%{public}u", length);
5342103316Sopenharmony_ci        return UEC_SERVICE_WRITE_PARCEL_ERROR;
5442103316Sopenharmony_ci    }
5542103316Sopenharmony_ci    if ((ptr) && (length > 0) && !data.WriteBuffer(reinterpret_cast<const void *>(ptr), length)) {
5642103316Sopenharmony_ci        USB_HILOGE(MODULE_USBD, "write buffer failed length:%{public}u", length);
5742103316Sopenharmony_ci        return UEC_SERVICE_WRITE_PARCEL_ERROR;
5842103316Sopenharmony_ci    }
5942103316Sopenharmony_ci
6042103316Sopenharmony_ci    USB_HILOGI(MODULE_USBD, "success length:%{public}u", length);
6142103316Sopenharmony_ci    return UEC_OK;
6242103316Sopenharmony_ci}
6342103316Sopenharmony_ci
6442103316Sopenharmony_ciint32_t UsbServerProxy::GetBufferMessage(MessageParcel &data, std::vector<uint8_t> &bufferData)
6542103316Sopenharmony_ci{
6642103316Sopenharmony_ci    uint32_t dataSize = 0;
6742103316Sopenharmony_ci    bufferData.clear();
6842103316Sopenharmony_ci    if (!data.ReadUint32(dataSize)) {
6942103316Sopenharmony_ci        USB_HILOGE(MODULE_USBD, "read dataSize failed");
7042103316Sopenharmony_ci        return UEC_SERVICE_READ_PARCEL_ERROR;
7142103316Sopenharmony_ci    }
7242103316Sopenharmony_ci    if (dataSize == 0) {
7342103316Sopenharmony_ci        USB_HILOGI(MODULE_USBD, "invalid size:%{public}u", dataSize);
7442103316Sopenharmony_ci        return UEC_OK;
7542103316Sopenharmony_ci    }
7642103316Sopenharmony_ci
7742103316Sopenharmony_ci    const uint8_t *readData = data.ReadUnpadBuffer(dataSize);
7842103316Sopenharmony_ci    if (readData == nullptr) {
7942103316Sopenharmony_ci        USB_HILOGE(MODULE_USBD, "failed size:%{public}u", dataSize);
8042103316Sopenharmony_ci        return UEC_SERVICE_READ_PARCEL_ERROR;
8142103316Sopenharmony_ci    }
8242103316Sopenharmony_ci    std::vector<uint8_t> tdata(readData, readData + dataSize);
8342103316Sopenharmony_ci    bufferData.swap(tdata);
8442103316Sopenharmony_ci    return UEC_OK;
8542103316Sopenharmony_ci}
8642103316Sopenharmony_ci
8742103316Sopenharmony_ciint32_t UsbServerProxy::GetDevices(std::vector<UsbDevice> &deviceList)
8842103316Sopenharmony_ci{
8942103316Sopenharmony_ci    int32_t ret;
9042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
9142103316Sopenharmony_ci    if (remote == nullptr) {
9242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "remote is failed");
9342103316Sopenharmony_ci        return ERR_INVALID_VALUE;
9442103316Sopenharmony_ci    }
9542103316Sopenharmony_ci    MessageParcel data;
9642103316Sopenharmony_ci    MessageParcel reply;
9742103316Sopenharmony_ci    MessageOption option;
9842103316Sopenharmony_ci
9942103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
10042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
10142103316Sopenharmony_ci        return ERR_INVALID_VALUE;
10242103316Sopenharmony_ci    }
10342103316Sopenharmony_ci
10442103316Sopenharmony_ci    ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_DEVICES), data, reply, option);
10542103316Sopenharmony_ci    if (ret != UEC_OK) {
10642103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "failed code: %{public}d", ret);
10742103316Sopenharmony_ci        return ret;
10842103316Sopenharmony_ci    }
10942103316Sopenharmony_ci    ret = GetDeviceListMessageParcel(reply, deviceList);
11042103316Sopenharmony_ci    return ret;
11142103316Sopenharmony_ci}
11242103316Sopenharmony_ci
11342103316Sopenharmony_ciint32_t UsbServerProxy::GetDeviceListMessageParcel(MessageParcel &data, std::vector<UsbDevice> &deviceList)
11442103316Sopenharmony_ci{
11542103316Sopenharmony_ci    int32_t count;
11642103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, count, UEC_SERVICE_READ_PARCEL_ERROR);
11742103316Sopenharmony_ci    if (count > MAX_DEVICE_NUM) {
11842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "the maximum number of devices is exceeded!");
11942103316Sopenharmony_ci        return ERR_INVALID_VALUE;
12042103316Sopenharmony_ci    }
12142103316Sopenharmony_ci
12242103316Sopenharmony_ci    for (int32_t i = 0; i < count; ++i) {
12342103316Sopenharmony_ci        UsbDevice devInfo;
12442103316Sopenharmony_ci        GetDeviceMessageParcel(data, devInfo);
12542103316Sopenharmony_ci        deviceList.push_back(devInfo);
12642103316Sopenharmony_ci    }
12742103316Sopenharmony_ci    return UEC_OK;
12842103316Sopenharmony_ci}
12942103316Sopenharmony_ci
13042103316Sopenharmony_ciint32_t UsbServerProxy::GetDeviceMessageParcel(MessageParcel &data, UsbDevice &devInfo)
13142103316Sopenharmony_ci{
13242103316Sopenharmony_ci    int32_t tmp;
13342103316Sopenharmony_ci    uint8_t tui8;
13442103316Sopenharmony_ci    uint16_t tui16;
13542103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
13642103316Sopenharmony_ci    devInfo.SetBusNum(tmp);
13742103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
13842103316Sopenharmony_ci    devInfo.SetDevAddr(tmp);
13942103316Sopenharmony_ci
14042103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
14142103316Sopenharmony_ci    devInfo.SetVendorId(tmp);
14242103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
14342103316Sopenharmony_ci    devInfo.SetProductId(tmp);
14442103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
14542103316Sopenharmony_ci    devInfo.SetClass(tmp);
14642103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
14742103316Sopenharmony_ci    devInfo.SetSubclass(tmp);
14842103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
14942103316Sopenharmony_ci    devInfo.SetProtocol(tmp);
15042103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Uint8, tui8, UEC_SERVICE_READ_PARCEL_ERROR);
15142103316Sopenharmony_ci    devInfo.SetiManufacturer(tui8);
15242103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Uint8, tui8, UEC_SERVICE_READ_PARCEL_ERROR);
15342103316Sopenharmony_ci    devInfo.SetiProduct(tui8);
15442103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Uint8, tui8, UEC_SERVICE_READ_PARCEL_ERROR);
15542103316Sopenharmony_ci    devInfo.SetiSerialNumber(tui8);
15642103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Uint8, tui8, UEC_SERVICE_READ_PARCEL_ERROR);
15742103316Sopenharmony_ci    devInfo.SetbMaxPacketSize0(tui8);
15842103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Uint16, tui16, UEC_SERVICE_READ_PARCEL_ERROR);
15942103316Sopenharmony_ci    devInfo.SetbcdUSB(tui16);
16042103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Uint16, tui16, UEC_SERVICE_READ_PARCEL_ERROR);
16142103316Sopenharmony_ci    devInfo.SetbcdDevice(tui16);
16242103316Sopenharmony_ci    std::u16string tstr;
16342103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, String16, tstr, UEC_SERVICE_READ_PARCEL_ERROR);
16442103316Sopenharmony_ci    devInfo.SetName(Str16ToStr8(tstr));
16542103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, String16, tstr, UEC_SERVICE_READ_PARCEL_ERROR);
16642103316Sopenharmony_ci    devInfo.SetManufacturerName(Str16ToStr8(tstr));
16742103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, String16, tstr, UEC_SERVICE_READ_PARCEL_ERROR);
16842103316Sopenharmony_ci    devInfo.SetProductName(Str16ToStr8(tstr));
16942103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, String16, tstr, UEC_SERVICE_READ_PARCEL_ERROR);
17042103316Sopenharmony_ci    devInfo.SetVersion(Str16ToStr8(tstr));
17142103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, String16, tstr, UEC_SERVICE_READ_PARCEL_ERROR);
17242103316Sopenharmony_ci    devInfo.SetmSerial(Str16ToStr8(tstr));
17342103316Sopenharmony_ci
17442103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_INNERKIT, "devName:%{public}s Bus:%{public}d dev:%{public}d ", devInfo.GetName().c_str(),
17542103316Sopenharmony_ci        devInfo.GetBusNum(), devInfo.GetDevAddr());
17642103316Sopenharmony_ci    std::vector<USBConfig> configs;
17742103316Sopenharmony_ci    GetDeviceConfigsMessageParcel(data, configs);
17842103316Sopenharmony_ci    devInfo.SetConfigs(configs);
17942103316Sopenharmony_ci    return UEC_OK;
18042103316Sopenharmony_ci}
18142103316Sopenharmony_ci
18242103316Sopenharmony_ciint32_t UsbServerProxy::GetDeviceConfigsMessageParcel(MessageParcel &data, std::vector<USBConfig> &configs)
18342103316Sopenharmony_ci{
18442103316Sopenharmony_ci    uint32_t configCount;
18542103316Sopenharmony_ci    uint8_t tui8;
18642103316Sopenharmony_ci    std::u16string tstr;
18742103316Sopenharmony_ci    data.ReadUint32(configCount);
18842103316Sopenharmony_ci
18942103316Sopenharmony_ci    int32_t tmp;
19042103316Sopenharmony_ci    uint32_t attributes;
19142103316Sopenharmony_ci    if (configCount > MAX_CONFIG_NUM) {
19242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "the maximum number of configurations is exceeded!");
19342103316Sopenharmony_ci        return ERR_INVALID_VALUE;
19442103316Sopenharmony_ci    }
19542103316Sopenharmony_ci    for (uint32_t i = 0; i < configCount; ++i) {
19642103316Sopenharmony_ci        USBConfig config;
19742103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
19842103316Sopenharmony_ci        config.SetId(tmp);
19942103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Uint32, attributes, UEC_SERVICE_READ_PARCEL_ERROR);
20042103316Sopenharmony_ci        config.SetAttribute(attributes);
20142103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
20242103316Sopenharmony_ci        config.SetMaxPower(tmp);
20342103316Sopenharmony_ci
20442103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Uint8, tui8, UEC_SERVICE_READ_PARCEL_ERROR);
20542103316Sopenharmony_ci        config.SetiConfiguration(tui8);
20642103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, String16, tstr, UEC_SERVICE_READ_PARCEL_ERROR);
20742103316Sopenharmony_ci        config.SetName(Str16ToStr8(tstr));
20842103316Sopenharmony_ci
20942103316Sopenharmony_ci        std::vector<UsbInterface> interfaces;
21042103316Sopenharmony_ci        if (int32_t ret = GetDeviceInterfacesMessageParcel(data, interfaces); ret != UEC_OK) {
21142103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceInterfacesMessageParcel failed ret:%{public}d", ret);
21242103316Sopenharmony_ci            return ret;
21342103316Sopenharmony_ci        }
21442103316Sopenharmony_ci
21542103316Sopenharmony_ci        config.SetInterfaces(interfaces);
21642103316Sopenharmony_ci        configs.push_back(config);
21742103316Sopenharmony_ci        USB_HILOGI(MODULE_USB_SERVICE, "devInfo=%{public}s", config.ToString().c_str());
21842103316Sopenharmony_ci    }
21942103316Sopenharmony_ci
22042103316Sopenharmony_ci    return UEC_OK;
22142103316Sopenharmony_ci}
22242103316Sopenharmony_ci
22342103316Sopenharmony_ciint32_t UsbServerProxy::GetDeviceInterfacesMessageParcel(MessageParcel &data, std::vector<UsbInterface> &interfaces)
22442103316Sopenharmony_ci{
22542103316Sopenharmony_ci    int32_t tmp;
22642103316Sopenharmony_ci    int32_t interfaceCount;
22742103316Sopenharmony_ci    uint8_t tui8;
22842103316Sopenharmony_ci    std::u16string tstr;
22942103316Sopenharmony_ci    data.ReadInt32(tmp);
23042103316Sopenharmony_ci    interfaceCount = tmp;
23142103316Sopenharmony_ci    if (interfaceCount > MAX_INTERFACE_NUM) {
23242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "the maximum number of interfaces is exceeded!");
23342103316Sopenharmony_ci        return ERR_INVALID_VALUE;
23442103316Sopenharmony_ci    }
23542103316Sopenharmony_ci    for (int32_t i = 0; i < interfaceCount; ++i) {
23642103316Sopenharmony_ci        UsbInterface interface;
23742103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
23842103316Sopenharmony_ci        interface.SetId(tmp);
23942103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
24042103316Sopenharmony_ci        interface.SetClass(tmp);
24142103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
24242103316Sopenharmony_ci        interface.SetSubClass(tmp);
24342103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
24442103316Sopenharmony_ci        interface.SetAlternateSetting(tmp);
24542103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
24642103316Sopenharmony_ci        interface.SetProtocol(tmp);
24742103316Sopenharmony_ci
24842103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Uint8, tui8, UEC_SERVICE_READ_PARCEL_ERROR);
24942103316Sopenharmony_ci        interface.SetiInterface(tui8);
25042103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, String16, tstr, UEC_SERVICE_READ_PARCEL_ERROR);
25142103316Sopenharmony_ci        interface.SetName(Str16ToStr8(tstr));
25242103316Sopenharmony_ci
25342103316Sopenharmony_ci        std::vector<USBEndpoint> eps;
25442103316Sopenharmony_ci        if (int32_t ret = GetDeviceEndpointsMessageParcel(data, eps); ret != UEC_OK) {
25542103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "GetDeviceEndpointsMessageParcel failed ret:%{public}d", ret);
25642103316Sopenharmony_ci            return ret;
25742103316Sopenharmony_ci        }
25842103316Sopenharmony_ci
25942103316Sopenharmony_ci        for (size_t j = 0; j < eps.size(); ++j) {
26042103316Sopenharmony_ci            eps[j].SetInterfaceId(interface.GetId());
26142103316Sopenharmony_ci        }
26242103316Sopenharmony_ci        interface.SetEndpoints(eps);
26342103316Sopenharmony_ci        interfaces.push_back(interface);
26442103316Sopenharmony_ci        USB_HILOGI(MODULE_USB_SERVICE, "devInfo=%{public}s", interface.ToString().c_str());
26542103316Sopenharmony_ci    }
26642103316Sopenharmony_ci    return UEC_OK;
26742103316Sopenharmony_ci}
26842103316Sopenharmony_ci
26942103316Sopenharmony_ciint32_t UsbServerProxy::GetDeviceEndpointsMessageParcel(MessageParcel &data, std::vector<USBEndpoint> &eps)
27042103316Sopenharmony_ci{
27142103316Sopenharmony_ci    int32_t tmp;
27242103316Sopenharmony_ci    int32_t epCount;
27342103316Sopenharmony_ci    uint32_t attributes;
27442103316Sopenharmony_ci    uint32_t address;
27542103316Sopenharmony_ci    READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
27642103316Sopenharmony_ci    epCount = tmp;
27742103316Sopenharmony_ci    if (epCount > MAX_ENDPOINT_NUM) {
27842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "the maximum number of endpoints is exceeded!");
27942103316Sopenharmony_ci        return ERR_INVALID_VALUE;
28042103316Sopenharmony_ci    }
28142103316Sopenharmony_ci    for (int32_t i = 0; i < epCount; ++i) {
28242103316Sopenharmony_ci        USBEndpoint ep;
28342103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Uint32, address, UEC_SERVICE_READ_PARCEL_ERROR);
28442103316Sopenharmony_ci        ep.SetAddr(address);
28542103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Uint32, attributes, UEC_SERVICE_READ_PARCEL_ERROR);
28642103316Sopenharmony_ci        ep.SetAttr(attributes);
28742103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
28842103316Sopenharmony_ci        ep.SetInterval(tmp);
28942103316Sopenharmony_ci        READ_PARCEL_WITH_RET(data, Int32, tmp, UEC_SERVICE_READ_PARCEL_ERROR);
29042103316Sopenharmony_ci        ep.SetMaxPacketSize(tmp);
29142103316Sopenharmony_ci        eps.push_back(ep);
29242103316Sopenharmony_ci        USB_HILOGI(MODULE_USB_SERVICE, "devInfo=%{public}s", ep.ToString().c_str());
29342103316Sopenharmony_ci    }
29442103316Sopenharmony_ci    return UEC_OK;
29542103316Sopenharmony_ci}
29642103316Sopenharmony_ci
29742103316Sopenharmony_ciint32_t UsbServerProxy::OpenDevice(uint8_t busNum, uint8_t devAddr)
29842103316Sopenharmony_ci{
29942103316Sopenharmony_ci    MessageParcel data;
30042103316Sopenharmony_ci    MessageParcel reply;
30142103316Sopenharmony_ci    MessageOption option;
30242103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
30342103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
30442103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
30542103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
30642103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
30742103316Sopenharmony_ci    }
30842103316Sopenharmony_ci
30942103316Sopenharmony_ci    int32_t ret = SetDeviceMessage(data, busNum, devAddr);
31042103316Sopenharmony_ci    if (ret != UEC_OK) {
31142103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SetDeviceMessage failed, ret:%{public}d", ret);
31242103316Sopenharmony_ci        return ret;
31342103316Sopenharmony_ci    }
31442103316Sopenharmony_ci
31542103316Sopenharmony_ci    ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_OPEN_DEVICE), data, reply, option);
31642103316Sopenharmony_ci    if (ret != UEC_OK) {
31742103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
31842103316Sopenharmony_ci    }
31942103316Sopenharmony_ci    return ret;
32042103316Sopenharmony_ci}
32142103316Sopenharmony_ci
32242103316Sopenharmony_ciint32_t UsbServerProxy::ResetDevice(uint8_t busNum, uint8_t devAddr)
32342103316Sopenharmony_ci{
32442103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
32542103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
32642103316Sopenharmony_ci    MessageParcel data;
32742103316Sopenharmony_ci    MessageParcel reply;
32842103316Sopenharmony_ci    MessageOption option;
32942103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
33042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
33142103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
33242103316Sopenharmony_ci    }
33342103316Sopenharmony_ci
33442103316Sopenharmony_ci    int32_t ret = SetDeviceMessage(data, busNum, devAddr);
33542103316Sopenharmony_ci    if (ret != UEC_OK) {
33642103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SetDeviceMessage failed, ret:%{public}d", ret);
33742103316Sopenharmony_ci        return ret;
33842103316Sopenharmony_ci    }
33942103316Sopenharmony_ci
34042103316Sopenharmony_ci    ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_RESET_DEVICE), data, reply, option);
34142103316Sopenharmony_ci    if (ret != UEC_OK) {
34242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
34342103316Sopenharmony_ci    }
34442103316Sopenharmony_ci    return ret;
34542103316Sopenharmony_ci}
34642103316Sopenharmony_ci
34742103316Sopenharmony_cibool UsbServerProxy::HasRight(std::string deviceName)
34842103316Sopenharmony_ci{
34942103316Sopenharmony_ci    MessageParcel data;
35042103316Sopenharmony_ci    MessageOption option;
35142103316Sopenharmony_ci    MessageParcel reply;
35242103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
35342103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, false);
35442103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
35542103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
35642103316Sopenharmony_ci        return false;
35742103316Sopenharmony_ci    }
35842103316Sopenharmony_ci
35942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String16, Str8ToStr16(deviceName), false);
36042103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_HAS_RIGHT), data, reply, option);
36142103316Sopenharmony_ci    if (ret != UEC_OK) {
36242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
36342103316Sopenharmony_ci        return false;
36442103316Sopenharmony_ci    }
36542103316Sopenharmony_ci
36642103316Sopenharmony_ci    bool result = false;
36742103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Bool, result, false);
36842103316Sopenharmony_ci
36942103316Sopenharmony_ci    return result;
37042103316Sopenharmony_ci}
37142103316Sopenharmony_ci
37242103316Sopenharmony_ciint32_t UsbServerProxy::RequestRight(std::string deviceName)
37342103316Sopenharmony_ci{
37442103316Sopenharmony_ci    MessageParcel reply;
37542103316Sopenharmony_ci    MessageOption option;
37642103316Sopenharmony_ci    MessageParcel data;
37742103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
37842103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
37942103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
38042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
38142103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
38242103316Sopenharmony_ci    }
38342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String16, Str8ToStr16(deviceName), UEC_INTERFACE_WRITE_PARCEL_ERROR);
38442103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_REQUEST_RIGHT),
38542103316Sopenharmony_ci        data, reply, option);
38642103316Sopenharmony_ci    if (ret != UEC_OK) {
38742103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
38842103316Sopenharmony_ci        return ret;
38942103316Sopenharmony_ci    }
39042103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
39142103316Sopenharmony_ci    return ret;
39242103316Sopenharmony_ci}
39342103316Sopenharmony_ci
39442103316Sopenharmony_ciint32_t UsbServerProxy::RemoveRight(std::string deviceName)
39542103316Sopenharmony_ci{
39642103316Sopenharmony_ci    MessageParcel reply;
39742103316Sopenharmony_ci    MessageOption option;
39842103316Sopenharmony_ci    MessageParcel data;
39942103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
40042103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
40142103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
40242103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
40342103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
40442103316Sopenharmony_ci    }
40542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String16, Str8ToStr16(deviceName), UEC_INTERFACE_WRITE_PARCEL_ERROR);
40642103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_REMOVE_RIGHT),
40742103316Sopenharmony_ci        data, reply, option);
40842103316Sopenharmony_ci    if (ret != UEC_OK) {
40942103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
41042103316Sopenharmony_ci        return ret;
41142103316Sopenharmony_ci    }
41242103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
41342103316Sopenharmony_ci    return ret;
41442103316Sopenharmony_ci}
41542103316Sopenharmony_ci
41642103316Sopenharmony_ciint32_t UsbServerProxy::GetCurrentFunctions(int32_t &funcs)
41742103316Sopenharmony_ci{
41842103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
41942103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
42042103316Sopenharmony_ci
42142103316Sopenharmony_ci    MessageParcel data;
42242103316Sopenharmony_ci    MessageParcel reply;
42342103316Sopenharmony_ci    MessageOption option;
42442103316Sopenharmony_ci
42542103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
42642103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
42742103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
42842103316Sopenharmony_ci    }
42942103316Sopenharmony_ci
43042103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_CURRENT_FUNCTIONS),
43142103316Sopenharmony_ci        data, reply, option);
43242103316Sopenharmony_ci    if (ret != UEC_OK) {
43342103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
43442103316Sopenharmony_ci        return ret;
43542103316Sopenharmony_ci    }
43642103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, funcs, UEC_INTERFACE_READ_PARCEL_ERROR);
43742103316Sopenharmony_ci    return ret;
43842103316Sopenharmony_ci}
43942103316Sopenharmony_ci
44042103316Sopenharmony_ciint32_t UsbServerProxy::SetCurrentFunctions(int32_t funcs)
44142103316Sopenharmony_ci{
44242103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
44342103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
44442103316Sopenharmony_ci
44542103316Sopenharmony_ci    MessageOption option;
44642103316Sopenharmony_ci    MessageParcel data;
44742103316Sopenharmony_ci    MessageParcel reply;
44842103316Sopenharmony_ci
44942103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
45042103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
45142103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
45242103316Sopenharmony_ci    }
45342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, funcs, UEC_INTERFACE_WRITE_PARCEL_ERROR);
45442103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_SET_CURRENT_FUNCTIONS),
45542103316Sopenharmony_ci        data, reply, option);
45642103316Sopenharmony_ci    if (ret != UEC_OK) {
45742103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
45842103316Sopenharmony_ci    }
45942103316Sopenharmony_ci    return ret;
46042103316Sopenharmony_ci}
46142103316Sopenharmony_ci
46242103316Sopenharmony_ciint32_t UsbServerProxy::UsbFunctionsFromString(std::string_view funcs)
46342103316Sopenharmony_ci{
46442103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
46542103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
46642103316Sopenharmony_ci    MessageOption option;
46742103316Sopenharmony_ci    MessageParcel data;
46842103316Sopenharmony_ci    MessageParcel reply;
46942103316Sopenharmony_ci
47042103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
47142103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
47242103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
47342103316Sopenharmony_ci    }
47442103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String, std::string {funcs}, UEC_INTERFACE_WRITE_PARCEL_ERROR);
47542103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_USB_FUNCTIONS_FROM_STRING),
47642103316Sopenharmony_ci        data, reply, option);
47742103316Sopenharmony_ci    if (ret != UEC_OK) {
47842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
47942103316Sopenharmony_ci        return UEC_INTERFACE_INVALID_VALUE;
48042103316Sopenharmony_ci    }
48142103316Sopenharmony_ci    int32_t result = 0;
48242103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, result, INVALID_USB_INT_VALUE);
48342103316Sopenharmony_ci    return result;
48442103316Sopenharmony_ci}
48542103316Sopenharmony_ci
48642103316Sopenharmony_cistd::string UsbServerProxy::UsbFunctionsToString(int32_t funcs)
48742103316Sopenharmony_ci{
48842103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
48942103316Sopenharmony_ci
49042103316Sopenharmony_ci    MessageParcel data;
49142103316Sopenharmony_ci    MessageOption option;
49242103316Sopenharmony_ci    MessageParcel reply;
49342103316Sopenharmony_ci
49442103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, INVALID_STRING_VALUE);
49542103316Sopenharmony_ci
49642103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
49742103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
49842103316Sopenharmony_ci        return INVALID_STRING_VALUE;
49942103316Sopenharmony_ci    }
50042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, funcs, INVALID_STRING_VALUE);
50142103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_USB_FUNCTIONS_TO_STRING),
50242103316Sopenharmony_ci        data, reply, option);
50342103316Sopenharmony_ci    if (ret != UEC_OK) {
50442103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
50542103316Sopenharmony_ci        return INVALID_STRING_VALUE;
50642103316Sopenharmony_ci    }
50742103316Sopenharmony_ci    std::string result;
50842103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, String, result, INVALID_STRING_VALUE);
50942103316Sopenharmony_ci    return result;
51042103316Sopenharmony_ci}
51142103316Sopenharmony_ci
51242103316Sopenharmony_ciint32_t UsbServerProxy::GetPorts(std::vector<UsbPort> &ports)
51342103316Sopenharmony_ci{
51442103316Sopenharmony_ci    MessageOption option;
51542103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
51642103316Sopenharmony_ci
51742103316Sopenharmony_ci    MessageParcel data;
51842103316Sopenharmony_ci    MessageParcel reply;
51942103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
52042103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
52142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
52242103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
52342103316Sopenharmony_ci    }
52442103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_PORTS), data, reply, option);
52542103316Sopenharmony_ci    if (ret != UEC_OK) {
52642103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
52742103316Sopenharmony_ci        return ret;
52842103316Sopenharmony_ci    }
52942103316Sopenharmony_ci    int32_t size;
53042103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, size, UEC_INTERFACE_READ_PARCEL_ERROR);
53142103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_INNERKIT, "GetPorts size %{public}d", size);
53242103316Sopenharmony_ci    if (size > MAX_PORT_NUM) {
53342103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "the maximum number of ports is exceeded!");
53442103316Sopenharmony_ci        return ERR_INVALID_VALUE;
53542103316Sopenharmony_ci    }
53642103316Sopenharmony_ci    for (int32_t i = 0; i < size; ++i) {
53742103316Sopenharmony_ci        USB_HILOGI(MODULE_USB_INNERKIT, "ParseUsbPort : %{public}d", i);
53842103316Sopenharmony_ci        ret = ParseUsbPort(reply, ports);
53942103316Sopenharmony_ci        if (ret) {
54042103316Sopenharmony_ci            return ret;
54142103316Sopenharmony_ci        }
54242103316Sopenharmony_ci    }
54342103316Sopenharmony_ci    return ret;
54442103316Sopenharmony_ci}
54542103316Sopenharmony_ci
54642103316Sopenharmony_ciint32_t UsbServerProxy::ParseUsbPort(MessageParcel &reply, std::vector<UsbPort> &ports)
54742103316Sopenharmony_ci{
54842103316Sopenharmony_ci    UsbPort port;
54942103316Sopenharmony_ci    UsbPortStatus status;
55042103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, port.id, UEC_INTERFACE_READ_PARCEL_ERROR);
55142103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_INNERKIT, "UsbServerProxy::port->id %{public}d", port.id);
55242103316Sopenharmony_ci    port.supportedModes = reply.ReadInt32();
55342103316Sopenharmony_ci    status.currentMode = reply.ReadInt32();
55442103316Sopenharmony_ci    status.currentPowerRole = reply.ReadInt32();
55542103316Sopenharmony_ci    status.currentDataRole = reply.ReadInt32();
55642103316Sopenharmony_ci    port.usbPortStatus = status;
55742103316Sopenharmony_ci    USB_HILOGI(MODULE_USB_INNERKIT, "UsbServerProxy::port.usbPortStatus.currentMode %{public}d",
55842103316Sopenharmony_ci        port.usbPortStatus.currentMode);
55942103316Sopenharmony_ci    ports.push_back(port);
56042103316Sopenharmony_ci    return UEC_OK;
56142103316Sopenharmony_ci}
56242103316Sopenharmony_ci
56342103316Sopenharmony_ciint32_t UsbServerProxy::GetSupportedModes(int32_t portId, int32_t &supportedModes)
56442103316Sopenharmony_ci{
56542103316Sopenharmony_ci    MessageParcel data;
56642103316Sopenharmony_ci    MessageParcel reply;
56742103316Sopenharmony_ci    MessageOption option;
56842103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
56942103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
57042103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
57142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
57242103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
57342103316Sopenharmony_ci    }
57442103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, portId, UEC_INTERFACE_WRITE_PARCEL_ERROR);
57542103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_SUPPORTED_MODES),
57642103316Sopenharmony_ci        data, reply, option);
57742103316Sopenharmony_ci    if (ret) {
57842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
57942103316Sopenharmony_ci        return ret;
58042103316Sopenharmony_ci    }
58142103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, supportedModes, UEC_INTERFACE_READ_PARCEL_ERROR);
58242103316Sopenharmony_ci    return ret;
58342103316Sopenharmony_ci}
58442103316Sopenharmony_ci
58542103316Sopenharmony_ciint32_t UsbServerProxy::SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole)
58642103316Sopenharmony_ci{
58742103316Sopenharmony_ci    MessageParcel data;
58842103316Sopenharmony_ci    MessageParcel reply;
58942103316Sopenharmony_ci    MessageOption option;
59042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
59142103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
59242103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
59342103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
59442103316Sopenharmony_ci        return UEC_INTERFACE_WRITE_PARCEL_ERROR;
59542103316Sopenharmony_ci    }
59642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, portId, UEC_INTERFACE_WRITE_PARCEL_ERROR);
59742103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, powerRole, UEC_INTERFACE_WRITE_PARCEL_ERROR);
59842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, dataRole, UEC_INTERFACE_WRITE_PARCEL_ERROR);
59942103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_SET_PORT_ROLE),
60042103316Sopenharmony_ci        data, reply, option);
60142103316Sopenharmony_ci    if (ret) {
60242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
60342103316Sopenharmony_ci        return ret;
60442103316Sopenharmony_ci    }
60542103316Sopenharmony_ci    return ret;
60642103316Sopenharmony_ci}
60742103316Sopenharmony_ci
60842103316Sopenharmony_ciint32_t UsbServerProxy::ClaimInterface(uint8_t busNum, uint8_t devAddr, uint8_t interface, uint8_t force)
60942103316Sopenharmony_ci{
61042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
61142103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
61242103316Sopenharmony_ci    MessageParcel data;
61342103316Sopenharmony_ci    MessageParcel reply;
61442103316Sopenharmony_ci    MessageOption option;
61542103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
61642103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
61742103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
61842103316Sopenharmony_ci    }
61942103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
62042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interface, UEC_SERVICE_WRITE_PARCEL_ERROR);
62142103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, force, UEC_SERVICE_WRITE_PARCEL_ERROR);
62242103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_CLAIM_INTERFACE),
62342103316Sopenharmony_ci        data, reply, option);
62442103316Sopenharmony_ci    if (ret != UEC_OK) {
62542103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
62642103316Sopenharmony_ci        return ret;
62742103316Sopenharmony_ci    }
62842103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
62942103316Sopenharmony_ci    return ret;
63042103316Sopenharmony_ci}
63142103316Sopenharmony_ci
63242103316Sopenharmony_ciint32_t UsbServerProxy::UsbAttachKernelDriver(uint8_t busNum, uint8_t devAddr, uint8_t interface)
63342103316Sopenharmony_ci{
63442103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
63542103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
63642103316Sopenharmony_ci    MessageParcel data;
63742103316Sopenharmony_ci    MessageParcel reply;
63842103316Sopenharmony_ci    MessageOption option;
63942103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
64042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
64142103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
64242103316Sopenharmony_ci    }
64342103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
64442103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interface, UEC_SERVICE_WRITE_PARCEL_ERROR);
64542103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_ATTACH_KERNEL_DRIVER),
64642103316Sopenharmony_ci        data, reply, option);
64742103316Sopenharmony_ci    if (ret != UEC_OK) {
64842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
64942103316Sopenharmony_ci        return ret;
65042103316Sopenharmony_ci    }
65142103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
65242103316Sopenharmony_ci    return ret;
65342103316Sopenharmony_ci}
65442103316Sopenharmony_ci
65542103316Sopenharmony_ciint32_t UsbServerProxy::UsbDetachKernelDriver(uint8_t busNum, uint8_t devAddr, uint8_t interface)
65642103316Sopenharmony_ci{
65742103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
65842103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
65942103316Sopenharmony_ci    MessageParcel data;
66042103316Sopenharmony_ci    MessageParcel reply;
66142103316Sopenharmony_ci    MessageOption option;
66242103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
66342103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
66442103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
66542103316Sopenharmony_ci    }
66642103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
66742103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interface, UEC_SERVICE_WRITE_PARCEL_ERROR);
66842103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_DETACH_KERNEL_DRIVER),
66942103316Sopenharmony_ci        data, reply, option);
67042103316Sopenharmony_ci    if (ret != UEC_OK) {
67142103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
67242103316Sopenharmony_ci        return ret;
67342103316Sopenharmony_ci    }
67442103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
67542103316Sopenharmony_ci    return ret;
67642103316Sopenharmony_ci}
67742103316Sopenharmony_ci
67842103316Sopenharmony_ciint32_t UsbServerProxy::ReleaseInterface(uint8_t busNum, uint8_t devAddr, uint8_t interface)
67942103316Sopenharmony_ci{
68042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
68142103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
68242103316Sopenharmony_ci    MessageParcel data;
68342103316Sopenharmony_ci    MessageParcel reply;
68442103316Sopenharmony_ci    MessageOption option;
68542103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
68642103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
68742103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
68842103316Sopenharmony_ci    }
68942103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
69042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interface, UEC_SERVICE_WRITE_PARCEL_ERROR);
69142103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_RELEASE_INTERFACE),
69242103316Sopenharmony_ci        data, reply, option);
69342103316Sopenharmony_ci    if (ret != UEC_OK) {
69442103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
69542103316Sopenharmony_ci        return ret;
69642103316Sopenharmony_ci    }
69742103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
69842103316Sopenharmony_ci    return ret;
69942103316Sopenharmony_ci}
70042103316Sopenharmony_ciint32_t UsbServerProxy::BulkTransferRead(
70142103316Sopenharmony_ci    const UsbDev &dev, const UsbPipe &pipe, std::vector<uint8_t> &bufferData, int32_t timeOut)
70242103316Sopenharmony_ci{
70342103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
70442103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
70542103316Sopenharmony_ci    MessageParcel data;
70642103316Sopenharmony_ci    MessageParcel reply;
70742103316Sopenharmony_ci    MessageOption option;
70842103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
70942103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
71042103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
71142103316Sopenharmony_ci    }
71242103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
71342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
71442103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
71542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, timeOut, UEC_SERVICE_WRITE_PARCEL_ERROR);
71642103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_BULK_TRANSFER_READ),
71742103316Sopenharmony_ci        data, reply, option);
71842103316Sopenharmony_ci    if (ret != UEC_OK) {
71942103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
72042103316Sopenharmony_ci        return ret;
72142103316Sopenharmony_ci    }
72242103316Sopenharmony_ci    ret = GetBufferMessage(reply, bufferData);
72342103316Sopenharmony_ci    if (ret != UEC_OK) {
72442103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "get buffer is failed, error code: %{public}d", ret);
72542103316Sopenharmony_ci        return ret;
72642103316Sopenharmony_ci    }
72742103316Sopenharmony_ci    USB_HILOGI(MODULE_USBD, "Set buffer message. length = %{public}zu", bufferData.size());
72842103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
72942103316Sopenharmony_ci    return ret;
73042103316Sopenharmony_ci}
73142103316Sopenharmony_ci
73242103316Sopenharmony_ciint32_t UsbServerProxy::BulkTransferReadwithLength(const UsbDev &dev, const UsbPipe &pipe,
73342103316Sopenharmony_ci    int32_t length, std::vector<uint8_t> &bufferData, int32_t timeOut)
73442103316Sopenharmony_ci{
73542103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
73642103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
73742103316Sopenharmony_ci    MessageParcel data;
73842103316Sopenharmony_ci    MessageParcel reply;
73942103316Sopenharmony_ci    MessageOption option;
74042103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
74142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
74242103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
74342103316Sopenharmony_ci    }
74442103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
74542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
74642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
74742103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, length, UEC_SERVICE_WRITE_PARCEL_ERROR);
74842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, timeOut, UEC_SERVICE_WRITE_PARCEL_ERROR);
74942103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_BULK_TRANSFER_READ_WITH_LENGTH),
75042103316Sopenharmony_ci        data, reply, option);
75142103316Sopenharmony_ci    if (ret != UEC_OK) {
75242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
75342103316Sopenharmony_ci        return ret;
75442103316Sopenharmony_ci    }
75542103316Sopenharmony_ci    ret = GetBufferMessage(reply, bufferData);
75642103316Sopenharmony_ci    if (ret != UEC_OK) {
75742103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_INNERKIT, "get buffer is failed, error code: %{public}d", ret);
75842103316Sopenharmony_ci        return ret;
75942103316Sopenharmony_ci    }
76042103316Sopenharmony_ci    USB_HILOGI(MODULE_USBD, "Set buffer message. length = %{public}zu", bufferData.size());
76142103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
76242103316Sopenharmony_ci    return ret;
76342103316Sopenharmony_ci}
76442103316Sopenharmony_ci
76542103316Sopenharmony_ciint32_t UsbServerProxy::BulkTransferWrite(
76642103316Sopenharmony_ci    const UsbDev &dev, const UsbPipe &pipe, const std::vector<uint8_t> &bufferData, int32_t timeOut)
76742103316Sopenharmony_ci{
76842103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
76942103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
77042103316Sopenharmony_ci    MessageParcel data;
77142103316Sopenharmony_ci    MessageParcel reply;
77242103316Sopenharmony_ci    MessageOption option;
77342103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
77442103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
77542103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
77642103316Sopenharmony_ci    }
77742103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
77842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
77942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
78042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, timeOut, UEC_SERVICE_WRITE_PARCEL_ERROR);
78142103316Sopenharmony_ci    int32_t ret = SetBufferMessage(data, bufferData);
78242103316Sopenharmony_ci    if (UEC_OK != ret) {
78342103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SetBufferMessage ret:%{public}d", ret);
78442103316Sopenharmony_ci        return ret;
78542103316Sopenharmony_ci    }
78642103316Sopenharmony_ci    ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_BULK_TRANSFER_WRITE),
78742103316Sopenharmony_ci        data, reply, option);
78842103316Sopenharmony_ci    if (UEC_OK != ret) {
78942103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SendRequest ret:%{public}d", ret);
79042103316Sopenharmony_ci        return ret;
79142103316Sopenharmony_ci    }
79242103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
79342103316Sopenharmony_ci    return ret;
79442103316Sopenharmony_ci}
79542103316Sopenharmony_ci
79642103316Sopenharmony_ciint32_t UsbServerProxy::ControlTransfer(
79742103316Sopenharmony_ci    const UsbDev &dev, const UsbCtrlTransfer &ctrl, std::vector<uint8_t> &bufferData)
79842103316Sopenharmony_ci{
79942103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
80042103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
80142103316Sopenharmony_ci    MessageParcel data;
80242103316Sopenharmony_ci    MessageParcel reply;
80342103316Sopenharmony_ci    MessageOption option;
80442103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
80542103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
80642103316Sopenharmony_ci        return UEC_SERVICE_INNER_ERR;
80742103316Sopenharmony_ci    }
80842103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
80942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrl.requestType, UEC_SERVICE_WRITE_PARCEL_ERROR);
81042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrl.requestCmd, UEC_SERVICE_WRITE_PARCEL_ERROR);
81142103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrl.value, UEC_SERVICE_WRITE_PARCEL_ERROR);
81242103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrl.index, UEC_SERVICE_WRITE_PARCEL_ERROR);
81342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrl.timeout, UEC_SERVICE_WRITE_PARCEL_ERROR);
81442103316Sopenharmony_ci    int32_t ret = SetBufferMessage(data, bufferData);
81542103316Sopenharmony_ci    if (UEC_OK != ret) {
81642103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write failed! len:%{public}d", ret);
81742103316Sopenharmony_ci        return ret;
81842103316Sopenharmony_ci    }
81942103316Sopenharmony_ci
82042103316Sopenharmony_ci    uint32_t reqType = static_cast<uint32_t>(ctrl.requestType);
82142103316Sopenharmony_ci    bool isWrite = ((reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_OUT);
82242103316Sopenharmony_ci    ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_CONTROL_TRANSFER), data, reply, option);
82342103316Sopenharmony_ci    if (ret != UEC_OK) {
82442103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "USB_FUN_CONTROL_TRANSFER ret:%{public}d", ret);
82542103316Sopenharmony_ci        return ret;
82642103316Sopenharmony_ci    }
82742103316Sopenharmony_ci    if (!isWrite) {
82842103316Sopenharmony_ci        ret = GetBufferMessage(reply, bufferData);
82942103316Sopenharmony_ci        if (UEC_OK != ret) {
83042103316Sopenharmony_ci            USB_HILOGE(MODULE_USBD, "Get buffer message error. ret = %{public}d", ret);
83142103316Sopenharmony_ci            return ret;
83242103316Sopenharmony_ci        }
83342103316Sopenharmony_ci        USB_HILOGI(MODULE_USBD, "Get buffer message. length = %{public}zu", bufferData.size());
83442103316Sopenharmony_ci    }
83542103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
83642103316Sopenharmony_ci    return ret;
83742103316Sopenharmony_ci}
83842103316Sopenharmony_ci
83942103316Sopenharmony_ciint32_t UsbServerProxy::UsbControlTransfer(
84042103316Sopenharmony_ci    const UsbDev &dev, const UsbCtrlTransferParams &ctrlParams, std::vector<uint8_t> &bufferData)
84142103316Sopenharmony_ci{
84242103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
84342103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
84442103316Sopenharmony_ci    MessageParcel data;
84542103316Sopenharmony_ci    MessageParcel reply;
84642103316Sopenharmony_ci    MessageOption option;
84742103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
84842103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
84942103316Sopenharmony_ci        return UEC_SERVICE_INNER_ERR;
85042103316Sopenharmony_ci    }
85142103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
85242103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrlParams.requestType, UEC_SERVICE_WRITE_PARCEL_ERROR);
85342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrlParams.requestCmd, UEC_SERVICE_WRITE_PARCEL_ERROR);
85442103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrlParams.value, UEC_SERVICE_WRITE_PARCEL_ERROR);
85542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrlParams.index, UEC_SERVICE_WRITE_PARCEL_ERROR);
85642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrlParams.length, UEC_SERVICE_WRITE_PARCEL_ERROR);
85742103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, ctrlParams.timeout, UEC_SERVICE_WRITE_PARCEL_ERROR);
85842103316Sopenharmony_ci    int32_t ret = SetBufferMessage(data, bufferData);
85942103316Sopenharmony_ci    if (UEC_OK != ret) {
86042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write failed! len:%{public}d", ret);
86142103316Sopenharmony_ci        return ret;
86242103316Sopenharmony_ci    }
86342103316Sopenharmony_ci
86442103316Sopenharmony_ci    uint32_t reqType = static_cast<uint32_t>(ctrlParams.requestType);
86542103316Sopenharmony_ci    bool isWrite = ((reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_OUT);
86642103316Sopenharmony_ci    ret = remote->SendRequest(
86742103316Sopenharmony_ci        static_cast<int32_t>(UsbInterfaceCode::USB_FUN_USB_CONTROL_TRANSFER), data, reply, option);
86842103316Sopenharmony_ci    if (ret != UEC_OK) {
86942103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "USB_FUN_USB_CONTROL_TRANSFER ret:%{public}d", ret);
87042103316Sopenharmony_ci        return ret;
87142103316Sopenharmony_ci    }
87242103316Sopenharmony_ci    if (!isWrite) {
87342103316Sopenharmony_ci        ret = GetBufferMessage(reply, bufferData);
87442103316Sopenharmony_ci        if (UEC_OK != ret) {
87542103316Sopenharmony_ci            USB_HILOGE(MODULE_USBD, "Get buffer message error. ret = %{public}d", ret);
87642103316Sopenharmony_ci            return ret;
87742103316Sopenharmony_ci        }
87842103316Sopenharmony_ci        USB_HILOGI(MODULE_USBD, "Get buffer message. length = %{public}zu", bufferData.size());
87942103316Sopenharmony_ci    }
88042103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
88142103316Sopenharmony_ci    return ret;
88242103316Sopenharmony_ci}
88342103316Sopenharmony_ci
88442103316Sopenharmony_ciint32_t UsbServerProxy::SetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t configIndex)
88542103316Sopenharmony_ci{
88642103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
88742103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
88842103316Sopenharmony_ci    MessageParcel data;
88942103316Sopenharmony_ci    MessageParcel reply;
89042103316Sopenharmony_ci    MessageOption option;
89142103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
89242103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
89342103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
89442103316Sopenharmony_ci    }
89542103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
89642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, configIndex, UEC_SERVICE_WRITE_PARCEL_ERROR);
89742103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_SET_ACTIVE_CONFIG),
89842103316Sopenharmony_ci        data, reply, option);
89942103316Sopenharmony_ci    if (UEC_OK != ret) {
90042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "USB_FUN_SET_ACTIVE_CONFIG ret:%{public}d", ret);
90142103316Sopenharmony_ci        return ret;
90242103316Sopenharmony_ci    }
90342103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
90442103316Sopenharmony_ci    return ret;
90542103316Sopenharmony_ci}
90642103316Sopenharmony_ciint32_t UsbServerProxy::GetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t &configIndex)
90742103316Sopenharmony_ci{
90842103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
90942103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
91042103316Sopenharmony_ci    MessageParcel data;
91142103316Sopenharmony_ci    MessageParcel reply;
91242103316Sopenharmony_ci    MessageOption option;
91342103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
91442103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
91542103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
91642103316Sopenharmony_ci    }
91742103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
91842103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_ACTIVE_CONFIG),
91942103316Sopenharmony_ci        data, reply, option);
92042103316Sopenharmony_ci    if (ret != UEC_OK) {
92142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "USB_FUN_GET_ACTIVE_CONFIG ret:%{public}d", ret);
92242103316Sopenharmony_ci        return ret;
92342103316Sopenharmony_ci    }
92442103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Uint8, configIndex, UEC_SERVICE_WRITE_PARCEL_ERROR);
92542103316Sopenharmony_ci    return ret;
92642103316Sopenharmony_ci}
92742103316Sopenharmony_ciint32_t UsbServerProxy::SetInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t altIndex)
92842103316Sopenharmony_ci{
92942103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
93042103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
93142103316Sopenharmony_ci    MessageParcel data;
93242103316Sopenharmony_ci    MessageParcel reply;
93342103316Sopenharmony_ci    MessageOption option;
93442103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
93542103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
93642103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
93742103316Sopenharmony_ci    }
93842103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
93942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interfaceid, UEC_SERVICE_WRITE_PARCEL_ERROR);
94042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, altIndex, UEC_SERVICE_WRITE_PARCEL_ERROR);
94142103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_SET_INTERFACE),
94242103316Sopenharmony_ci        data, reply, option);
94342103316Sopenharmony_ci    if (UEC_OK != ret) {
94442103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "USB_FUN_SET_INTERFACE ret:%{public}d", ret);
94542103316Sopenharmony_ci        return ret;
94642103316Sopenharmony_ci    }
94742103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
94842103316Sopenharmony_ci    return ret;
94942103316Sopenharmony_ci}
95042103316Sopenharmony_ciint32_t UsbServerProxy::GetRawDescriptor(uint8_t busNum, uint8_t devAddr, std::vector<uint8_t> &bufferData)
95142103316Sopenharmony_ci{
95242103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
95342103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
95442103316Sopenharmony_ci    MessageParcel data;
95542103316Sopenharmony_ci    MessageParcel reply;
95642103316Sopenharmony_ci    MessageOption option;
95742103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
95842103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
95942103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
96042103316Sopenharmony_ci    }
96142103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
96242103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_DESCRIPTOR),
96342103316Sopenharmony_ci        data, reply, option);
96442103316Sopenharmony_ci    if (ret == UEC_OK) {
96542103316Sopenharmony_ci        ret = GetBufferMessage(reply, bufferData);
96642103316Sopenharmony_ci        if (UEC_OK != ret) {
96742103316Sopenharmony_ci            USB_HILOGE(MODULE_INNERKIT, "get failed ret:%{public}d", ret);
96842103316Sopenharmony_ci        }
96942103316Sopenharmony_ci    }
97042103316Sopenharmony_ci    return ret;
97142103316Sopenharmony_ci}
97242103316Sopenharmony_ci
97342103316Sopenharmony_ciint32_t UsbServerProxy::GetFileDescriptor(uint8_t busNum, uint8_t devAddr, int32_t &fd)
97442103316Sopenharmony_ci{
97542103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
97642103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
97742103316Sopenharmony_ci    MessageParcel data;
97842103316Sopenharmony_ci    MessageParcel reply;
97942103316Sopenharmony_ci    MessageOption option;
98042103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
98142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
98242103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
98342103316Sopenharmony_ci    }
98442103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
98542103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_FILEDESCRIPTOR),
98642103316Sopenharmony_ci        data, reply, option);
98742103316Sopenharmony_ci    if (ret == UEC_OK) {
98842103316Sopenharmony_ci        fd = -1;
98942103316Sopenharmony_ci        if (!ReadFileDescriptor(reply, fd)) {
99042103316Sopenharmony_ci            USB_HILOGW(MODULE_USB_SERVICE, "%{public}s: read fd failed!", __func__);
99142103316Sopenharmony_ci            return UEC_INTERFACE_READ_PARCEL_ERROR;
99242103316Sopenharmony_ci        }
99342103316Sopenharmony_ci    }
99442103316Sopenharmony_ci    return ret;
99542103316Sopenharmony_ci}
99642103316Sopenharmony_ci
99742103316Sopenharmony_ciint32_t UsbServerProxy::RequestQueue(const UsbDev &dev, const UsbPipe &pipe, const std::vector<uint8_t> &clientData,
99842103316Sopenharmony_ci    const std::vector<uint8_t> &bufferData)
99942103316Sopenharmony_ci{
100042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
100142103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
100242103316Sopenharmony_ci    MessageParcel data;
100342103316Sopenharmony_ci    MessageParcel reply;
100442103316Sopenharmony_ci    MessageOption option;
100542103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
100642103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "get descriptor failed!");
100742103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
100842103316Sopenharmony_ci    }
100942103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
101042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
101142103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
101242103316Sopenharmony_ci
101342103316Sopenharmony_ci    int32_t ret = UsbServerProxy::SetBufferMessage(data, clientData);
101442103316Sopenharmony_ci    if (UEC_OK != ret) {
101542103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "set clientData failed ret:%{public}d", ret);
101642103316Sopenharmony_ci        return ERR_INVALID_VALUE;
101742103316Sopenharmony_ci    }
101842103316Sopenharmony_ci
101942103316Sopenharmony_ci    ret = UsbServerProxy::SetBufferMessage(data, bufferData);
102042103316Sopenharmony_ci    if (UEC_OK != ret) {
102142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "setBuffer failed ret:%{public}d", ret);
102242103316Sopenharmony_ci        return ERR_INVALID_VALUE;
102342103316Sopenharmony_ci    }
102442103316Sopenharmony_ci
102542103316Sopenharmony_ci    ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_REQUEST_QUEUE), data, reply, option);
102642103316Sopenharmony_ci    if (ret != UEC_OK) {
102742103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
102842103316Sopenharmony_ci        return ret;
102942103316Sopenharmony_ci    }
103042103316Sopenharmony_ci    return ret;
103142103316Sopenharmony_ci}
103242103316Sopenharmony_ci
103342103316Sopenharmony_ciint32_t UsbServerProxy::RequestWait(
103442103316Sopenharmony_ci    const UsbDev &dev, int32_t timeOut, std::vector<uint8_t> &clientData, std::vector<uint8_t> &bufferData)
103542103316Sopenharmony_ci{
103642103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
103742103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
103842103316Sopenharmony_ci    MessageParcel data;
103942103316Sopenharmony_ci    MessageParcel reply;
104042103316Sopenharmony_ci    MessageOption option;
104142103316Sopenharmony_ci
104242103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
104342103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "get descriptor failed!");
104442103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
104542103316Sopenharmony_ci    }
104642103316Sopenharmony_ci
104742103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
104842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, timeOut, UEC_SERVICE_WRITE_PARCEL_ERROR);
104942103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_REQUEST_WAIT),
105042103316Sopenharmony_ci        data, reply, option);
105142103316Sopenharmony_ci    if (ret != UEC_OK) {
105242103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "queue failed! ret:%{public}d", ret);
105342103316Sopenharmony_ci        return ret;
105442103316Sopenharmony_ci    }
105542103316Sopenharmony_ci
105642103316Sopenharmony_ci    ret = UsbServerProxy::GetBufferMessage(reply, clientData);
105742103316Sopenharmony_ci    if (ret != UEC_OK) {
105842103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "get clientData failed! ret:%{public}d", ret);
105942103316Sopenharmony_ci        return ret;
106042103316Sopenharmony_ci    }
106142103316Sopenharmony_ci
106242103316Sopenharmony_ci    ret = UsbServerProxy::GetBufferMessage(reply, bufferData);
106342103316Sopenharmony_ci    if (ret != UEC_OK) {
106442103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "get buffer failed! ret:%{public}d", ret);
106542103316Sopenharmony_ci        return ret;
106642103316Sopenharmony_ci    }
106742103316Sopenharmony_ci
106842103316Sopenharmony_ci    return ret;
106942103316Sopenharmony_ci}
107042103316Sopenharmony_ci
107142103316Sopenharmony_ciint32_t UsbServerProxy::RequestCancel(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t endpointId)
107242103316Sopenharmony_ci{
107342103316Sopenharmony_ci    int32_t ret;
107442103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
107542103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
107642103316Sopenharmony_ci    MessageParcel data;
107742103316Sopenharmony_ci    MessageParcel reply;
107842103316Sopenharmony_ci    MessageOption option;
107942103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
108042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "get descriptor failed!");
108142103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
108242103316Sopenharmony_ci    }
108342103316Sopenharmony_ci
108442103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
108542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interfaceid, UEC_SERVICE_WRITE_PARCEL_ERROR);
108642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
108742103316Sopenharmony_ci    ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_REQUEST_CANCEL), data, reply, option);
108842103316Sopenharmony_ci    if (ret != UEC_OK) {
108942103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "request cancel failed!");
109042103316Sopenharmony_ci    }
109142103316Sopenharmony_ci
109242103316Sopenharmony_ci    return ret;
109342103316Sopenharmony_ci}
109442103316Sopenharmony_ci
109542103316Sopenharmony_ciint32_t UsbServerProxy::Close(uint8_t busNum, uint8_t devAddr)
109642103316Sopenharmony_ci{
109742103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
109842103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
109942103316Sopenharmony_ci    MessageOption option;
110042103316Sopenharmony_ci    MessageParcel data;
110142103316Sopenharmony_ci    MessageParcel reply;
110242103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
110342103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "get descriptor failed!");
110442103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
110542103316Sopenharmony_ci    }
110642103316Sopenharmony_ci
110742103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
110842103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_CLOSE_DEVICE),
110942103316Sopenharmony_ci        data, reply, option);
111042103316Sopenharmony_ci    if (ret != UEC_OK) {
111142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "queue failed!");
111242103316Sopenharmony_ci        return ret;
111342103316Sopenharmony_ci    }
111442103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
111542103316Sopenharmony_ci    return ret;
111642103316Sopenharmony_ci}
111742103316Sopenharmony_ci
111842103316Sopenharmony_ciint32_t UsbServerProxy::RegBulkCallback(const UsbDev &dev, const UsbPipe &pipe, const sptr<IRemoteObject> &cb)
111942103316Sopenharmony_ci{
112042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
112142103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
112242103316Sopenharmony_ci    MessageParcel data;
112342103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
112442103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
112542103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
112642103316Sopenharmony_ci    }
112742103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
112842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
112942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
113042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, RemoteObject, cb, UEC_SERVICE_WRITE_PARCEL_ERROR);
113142103316Sopenharmony_ci    MessageOption option;
113242103316Sopenharmony_ci    MessageParcel reply;
113342103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_REG_BULK_CALLBACK),
113442103316Sopenharmony_ci        data, reply, option);
113542103316Sopenharmony_ci    if (ret != UEC_OK) {
113642103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
113742103316Sopenharmony_ci        return ret;
113842103316Sopenharmony_ci    }
113942103316Sopenharmony_ci    return ret;
114042103316Sopenharmony_ci}
114142103316Sopenharmony_ci
114242103316Sopenharmony_ciint32_t UsbServerProxy::UnRegBulkCallback(const UsbDev &dev, const UsbPipe &pipe)
114342103316Sopenharmony_ci{
114442103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
114542103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
114642103316Sopenharmony_ci    MessageParcel data;
114742103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
114842103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
114942103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
115042103316Sopenharmony_ci    }
115142103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
115242103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
115342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
115442103316Sopenharmony_ci    MessageOption option;
115542103316Sopenharmony_ci    MessageParcel reply;
115642103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_UNREG_BULK_CALLBACK),
115742103316Sopenharmony_ci        data, reply, option);
115842103316Sopenharmony_ci    if (ret != UEC_OK) {
115942103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
116042103316Sopenharmony_ci        return ret;
116142103316Sopenharmony_ci    }
116242103316Sopenharmony_ci    return ret;
116342103316Sopenharmony_ci}
116442103316Sopenharmony_ci
116542103316Sopenharmony_ciint32_t UsbServerProxy::BulkRead(const UsbDev &dev, const UsbPipe &pipe, sptr<Ashmem> &ashmem)
116642103316Sopenharmony_ci{
116742103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
116842103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
116942103316Sopenharmony_ci    MessageParcel data;
117042103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
117142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
117242103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
117342103316Sopenharmony_ci    }
117442103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
117542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
117642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
117742103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Ashmem, ashmem, UEC_SERVICE_WRITE_PARCEL_ERROR);
117842103316Sopenharmony_ci    MessageOption option;
117942103316Sopenharmony_ci    MessageParcel reply;
118042103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_BULK_AYSNC_READ),
118142103316Sopenharmony_ci        data, reply, option);
118242103316Sopenharmony_ci    if (ret != UEC_OK) {
118342103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
118442103316Sopenharmony_ci        return ret;
118542103316Sopenharmony_ci    }
118642103316Sopenharmony_ci    return ret;
118742103316Sopenharmony_ci}
118842103316Sopenharmony_ci
118942103316Sopenharmony_ciint32_t UsbServerProxy::BulkWrite(const UsbDev &dev, const UsbPipe &pipe, sptr<Ashmem> &ashmem)
119042103316Sopenharmony_ci{
119142103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
119242103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
119342103316Sopenharmony_ci    MessageParcel data;
119442103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
119542103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
119642103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
119742103316Sopenharmony_ci    }
119842103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
119942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
120042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
120142103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Ashmem, ashmem, UEC_SERVICE_WRITE_PARCEL_ERROR);
120242103316Sopenharmony_ci    MessageOption option;
120342103316Sopenharmony_ci    MessageParcel reply;
120442103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_BULK_AYSNC_WRITE),
120542103316Sopenharmony_ci        data, reply, option);
120642103316Sopenharmony_ci    if (ret != UEC_OK) {
120742103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
120842103316Sopenharmony_ci        return ret;
120942103316Sopenharmony_ci    }
121042103316Sopenharmony_ci    return ret;
121142103316Sopenharmony_ci}
121242103316Sopenharmony_ci
121342103316Sopenharmony_ciint32_t UsbServerProxy::BulkCancel(const UsbDev &dev, const UsbPipe &pipe)
121442103316Sopenharmony_ci{
121542103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
121642103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
121742103316Sopenharmony_ci    MessageParcel data;
121842103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
121942103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
122042103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
122142103316Sopenharmony_ci    }
122242103316Sopenharmony_ci    SetDeviceMessage(data, dev.busNum, dev.devAddr);
122342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.intfId, UEC_SERVICE_WRITE_PARCEL_ERROR);
122442103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, pipe.endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
122542103316Sopenharmony_ci    MessageOption option;
122642103316Sopenharmony_ci    MessageParcel reply;
122742103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_BULK_AYSNC_CANCEL),
122842103316Sopenharmony_ci        data, reply, option);
122942103316Sopenharmony_ci    if (ret != UEC_OK) {
123042103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "SendRequest failed!");
123142103316Sopenharmony_ci        return ret;
123242103316Sopenharmony_ci    }
123342103316Sopenharmony_ci    return ret;
123442103316Sopenharmony_ci}
123542103316Sopenharmony_ci
123642103316Sopenharmony_ciint32_t UsbServerProxy::AddRight(const std::string &bundleName, const std::string &deviceName)
123742103316Sopenharmony_ci{
123842103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
123942103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
124042103316Sopenharmony_ci
124142103316Sopenharmony_ci    MessageParcel data;
124242103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
124342103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
124442103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
124542103316Sopenharmony_ci    }
124642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String, bundleName, UEC_SERVICE_WRITE_PARCEL_ERROR);
124742103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String, deviceName, UEC_SERVICE_WRITE_PARCEL_ERROR);
124842103316Sopenharmony_ci
124942103316Sopenharmony_ci    MessageOption option;
125042103316Sopenharmony_ci    MessageParcel reply;
125142103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_ADD_RIGHT), data, reply, option);
125242103316Sopenharmony_ci    if (ret != UEC_OK) {
125342103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
125442103316Sopenharmony_ci    }
125542103316Sopenharmony_ci    return ret;
125642103316Sopenharmony_ci}
125742103316Sopenharmony_ci
125842103316Sopenharmony_ciint32_t UsbServerProxy::AddAccessRight(const std::string &tokenId, const std::string &deviceName)
125942103316Sopenharmony_ci{
126042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
126142103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
126242103316Sopenharmony_ci
126342103316Sopenharmony_ci    MessageParcel data;
126442103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
126542103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
126642103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
126742103316Sopenharmony_ci    }
126842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String, tokenId, UEC_SERVICE_WRITE_PARCEL_ERROR);
126942103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, String, deviceName, UEC_SERVICE_WRITE_PARCEL_ERROR);
127042103316Sopenharmony_ci
127142103316Sopenharmony_ci    MessageOption option;
127242103316Sopenharmony_ci    MessageParcel reply;
127342103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_ADD_ACCESS_RIGHT),
127442103316Sopenharmony_ci        data, reply, option);
127542103316Sopenharmony_ci    if (ret != UEC_OK) {
127642103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
127742103316Sopenharmony_ci    }
127842103316Sopenharmony_ci    return ret;
127942103316Sopenharmony_ci}
128042103316Sopenharmony_ci
128142103316Sopenharmony_ciint32_t UsbServerProxy::ManageGlobalInterface(bool disable)
128242103316Sopenharmony_ci{
128342103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
128442103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
128542103316Sopenharmony_ci
128642103316Sopenharmony_ci    MessageParcel data;
128742103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
128842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
128942103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
129042103316Sopenharmony_ci    }
129142103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Bool, disable, UEC_SERVICE_WRITE_PARCEL_ERROR);
129242103316Sopenharmony_ci
129342103316Sopenharmony_ci    MessageOption option;
129442103316Sopenharmony_ci    MessageParcel reply;
129542103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_DISABLE_GLOBAL_INTERFACE),
129642103316Sopenharmony_ci        data, reply, option);
129742103316Sopenharmony_ci    if (ret != UEC_OK) {
129842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
129942103316Sopenharmony_ci    }
130042103316Sopenharmony_ci    return ret;
130142103316Sopenharmony_ci}
130242103316Sopenharmony_ci
130342103316Sopenharmony_ciint32_t UsbServerProxy::ManageDevice(int32_t vendorId, int32_t productId, bool disable)
130442103316Sopenharmony_ci{
130542103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
130642103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
130742103316Sopenharmony_ci
130842103316Sopenharmony_ci    MessageParcel data;
130942103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
131042103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
131142103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
131242103316Sopenharmony_ci    }
131342103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, vendorId, UEC_SERVICE_WRITE_PARCEL_ERROR);
131442103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, productId, UEC_SERVICE_WRITE_PARCEL_ERROR);
131542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Bool, disable, UEC_SERVICE_WRITE_PARCEL_ERROR);
131642103316Sopenharmony_ci
131742103316Sopenharmony_ci    MessageOption option;
131842103316Sopenharmony_ci    MessageParcel reply;
131942103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_DISABLE_DEVICE),
132042103316Sopenharmony_ci        data, reply, option);
132142103316Sopenharmony_ci    if (ret != UEC_OK) {
132242103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
132342103316Sopenharmony_ci    }
132442103316Sopenharmony_ci    return ret;
132542103316Sopenharmony_ci}
132642103316Sopenharmony_ci
132742103316Sopenharmony_ciint32_t UsbServerProxy::ManageInterfaceType(const std::vector<UsbDeviceType> &disableType, bool disable)
132842103316Sopenharmony_ci{
132942103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
133042103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_INTERFACE_INVALID_VALUE);
133142103316Sopenharmony_ci
133242103316Sopenharmony_ci    MessageParcel data;
133342103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
133442103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "write descriptor failed!");
133542103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
133642103316Sopenharmony_ci    }
133742103316Sopenharmony_ci    int32_t size = (int32_t)disableType.size();
133842103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Int32, size, UEC_SERVICE_WRITE_PARCEL_ERROR);
133942103316Sopenharmony_ci
134042103316Sopenharmony_ci    for (const auto &type : disableType) {
134142103316Sopenharmony_ci        WRITE_PARCEL_WITH_RET(data, Int32, type.baseClass, UEC_SERVICE_WRITE_PARCEL_ERROR);
134242103316Sopenharmony_ci        WRITE_PARCEL_WITH_RET(data, Int32, type.subClass, UEC_SERVICE_WRITE_PARCEL_ERROR);
134342103316Sopenharmony_ci        WRITE_PARCEL_WITH_RET(data, Int32, type.protocol, UEC_SERVICE_WRITE_PARCEL_ERROR);
134442103316Sopenharmony_ci        WRITE_PARCEL_WITH_RET(data, Bool, type.isDeviceType, UEC_SERVICE_WRITE_PARCEL_ERROR);
134542103316Sopenharmony_ci    }
134642103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Bool, disable, UEC_SERVICE_WRITE_PARCEL_ERROR);
134742103316Sopenharmony_ci
134842103316Sopenharmony_ci    MessageOption option;
134942103316Sopenharmony_ci    MessageParcel reply;
135042103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_DISABLE_INTERFACE_TYPE),
135142103316Sopenharmony_ci        data, reply, option);
135242103316Sopenharmony_ci    if (ret != UEC_OK) {
135342103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "SendRequest is failed, error code: %{public}d", ret);
135442103316Sopenharmony_ci    }
135542103316Sopenharmony_ci    return ret;
135642103316Sopenharmony_ci}
135742103316Sopenharmony_ci
135842103316Sopenharmony_ciint32_t UsbServerProxy::ClearHalt(uint8_t busNum, uint8_t devAddr, uint8_t interfaceId, uint8_t endpointId)
135942103316Sopenharmony_ci{
136042103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
136142103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
136242103316Sopenharmony_ci    MessageParcel data;
136342103316Sopenharmony_ci    MessageParcel reply;
136442103316Sopenharmony_ci    MessageOption option;
136542103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
136642103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
136742103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
136842103316Sopenharmony_ci    }
136942103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
137042103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interfaceId, UEC_SERVICE_WRITE_PARCEL_ERROR);
137142103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, endpointId, UEC_SERVICE_WRITE_PARCEL_ERROR);
137242103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_CLEAR_HALT), data, reply, option);
137342103316Sopenharmony_ci    if (ret != UEC_OK) {
137442103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "ClearHalt is failed, error code: %{public}d", ret);
137542103316Sopenharmony_ci        return ret;
137642103316Sopenharmony_ci    }
137742103316Sopenharmony_ci    READ_PARCEL_WITH_RET(reply, Int32, ret, UEC_INTERFACE_READ_PARCEL_ERROR);
137842103316Sopenharmony_ci    return ret;
137942103316Sopenharmony_ci}
138042103316Sopenharmony_ci
138142103316Sopenharmony_ciint32_t UsbServerProxy::GetDeviceSpeed(uint8_t busNum, uint8_t devAddr, uint8_t &speed)
138242103316Sopenharmony_ci{
138342103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
138442103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
138542103316Sopenharmony_ci    MessageParcel data;
138642103316Sopenharmony_ci    MessageParcel reply;
138742103316Sopenharmony_ci    MessageOption option;
138842103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
138942103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
139042103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
139142103316Sopenharmony_ci    }
139242103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
139342103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_DEVICE_SPEED),
139442103316Sopenharmony_ci        data, reply, option);
139542103316Sopenharmony_ci    if (ret == UEC_OK) {
139642103316Sopenharmony_ci        READ_PARCEL_WITH_RET(reply, Uint8, speed, UEC_INTERFACE_READ_PARCEL_ERROR);
139742103316Sopenharmony_ci    }
139842103316Sopenharmony_ci    USB_HILOGE(MODULE_INNERKIT, "GetDeviceSpeed speed:%{public}u", speed);
139942103316Sopenharmony_ci    return ret;
140042103316Sopenharmony_ci}
140142103316Sopenharmony_ci
140242103316Sopenharmony_ciint32_t UsbServerProxy::GetInterfaceActiveStatus(uint8_t busNum, uint8_t devAddr,
140342103316Sopenharmony_ci    uint8_t interfaceid,  bool &unactivated)
140442103316Sopenharmony_ci{
140542103316Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
140642103316Sopenharmony_ci    RETURN_IF_WITH_RET(remote == nullptr, UEC_SERVICE_INNER_ERR);
140742103316Sopenharmony_ci    MessageParcel data;
140842103316Sopenharmony_ci    MessageParcel reply;
140942103316Sopenharmony_ci    MessageOption option;
141042103316Sopenharmony_ci    if (!data.WriteInterfaceToken(UsbServerProxy::GetDescriptor())) {
141142103316Sopenharmony_ci        USB_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
141242103316Sopenharmony_ci        return ERR_ENOUGH_DATA;
141342103316Sopenharmony_ci    }
141442103316Sopenharmony_ci    SetDeviceMessage(data, busNum, devAddr);
141542103316Sopenharmony_ci    WRITE_PARCEL_WITH_RET(data, Uint8, interfaceid, UEC_SERVICE_WRITE_PARCEL_ERROR);
141642103316Sopenharmony_ci    int32_t ret = remote->SendRequest(static_cast<int32_t>(UsbInterfaceCode::USB_FUN_GET_DRIVER_ACTIVE_STATUS),
141742103316Sopenharmony_ci        data, reply, option);
141842103316Sopenharmony_ci    if (ret == UEC_OK) {
141942103316Sopenharmony_ci        READ_PARCEL_WITH_RET(reply, Bool, unactivated, UEC_INTERFACE_READ_PARCEL_ERROR);
142042103316Sopenharmony_ci    }
142142103316Sopenharmony_ci    return ret;
142242103316Sopenharmony_ci}
142342103316Sopenharmony_cibool UsbServerProxy::ReadFileDescriptor(MessageParcel &data, int &fd)
142442103316Sopenharmony_ci{
142542103316Sopenharmony_ci    fd = -1;
142642103316Sopenharmony_ci    bool fdValid = false;
142742103316Sopenharmony_ci    if (!data.ReadBool(fdValid)) {
142842103316Sopenharmony_ci        USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: failed to read fdValid", __func__);
142942103316Sopenharmony_ci        return false;
143042103316Sopenharmony_ci    }
143142103316Sopenharmony_ci
143242103316Sopenharmony_ci    if (fdValid) {
143342103316Sopenharmony_ci        fd = data.ReadFileDescriptor();
143442103316Sopenharmony_ci        if (fd < 0) {
143542103316Sopenharmony_ci            USB_HILOGE(MODULE_USB_SERVICE, "%{public}s: failed to read fd", __func__);
143642103316Sopenharmony_ci            return false;
143742103316Sopenharmony_ci        }
143842103316Sopenharmony_ci    }
143942103316Sopenharmony_ci    return true;
144042103316Sopenharmony_ci}
144142103316Sopenharmony_ci} // namespace USB
144242103316Sopenharmony_ci} // namespace OHOS
1443