1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "usbd_callback_stub.h"
17 #include "hilog_wrapper.h"
18 #include "usb_errors.h"
19 #include "struct_parcel.h"
20
21 namespace OHOS::USB {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int32_t UsbdStubCallBack::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
23 MessageOption &option)
24 {
25 switch (code) {
26 case CMD_USBD_TRANSFER_CALLBACK_WRITE: {
27 TransferWriteCallback(code, data);
28 break;
29 }
30 case CMD_USBD_TRANSFER_CALLBACK_READ: {
31 TransferReadCallback(code, data);
32 break;
33 }
34 default: {
35 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
36 }
37 }
38 return UEC_OK;
39 }
40
TransferWriteCallback(uint32_t code,OHOS::MessageParcel & data)41 int32_t UsbdStubCallBack::TransferWriteCallback(uint32_t code, OHOS::MessageParcel &data)
42 {
43 int32_t status;
44 int32_t actLength;
45 uint64_t userData;
46 std::shared_ptr<UsbIsoVecParcel> usbIsoVecParcel(data.ReadParcelable<UsbIsoVecParcel>());
47 if (usbIsoVecParcel == nullptr) {
48 USB_HILOGE(MODULE_USB_INNERKIT, "get usbIsoVecParcel error");
49 return UEC_SERVICE_WRITE_PARCEL_ERROR;
50 }
51 if (!data.ReadInt32(status)) {
52 USB_HILOGE(MODULE_USB_INNERKIT, "get status error");
53 return UEC_SERVICE_WRITE_PARCEL_ERROR;
54 }
55 if (!data.ReadInt32(actLength)) {
56 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error");
57 return UEC_SERVICE_WRITE_PARCEL_ERROR;
58 }
59 if (!data.ReadUint64(userData)) {
60 USB_HILOGE(MODULE_USB_INNERKIT, "get userData error");
61 return UEC_SERVICE_WRITE_PARCEL_ERROR;
62 }
63 USB_HILOGI(MODULE_USB_INNERKIT, "%{public}d TransferReadCallback status:%{public}d actLength:%{public}d",
64 __LINE__, status, actLength);
65 return OnTransferWriteCallback(status, actLength, usbIsoVecParcel->isoInfoVec, userData);
66 }
67
TransferReadCallback(uint32_t code,OHOS::MessageParcel & data)68 int32_t UsbdStubCallBack::TransferReadCallback(uint32_t code, OHOS::MessageParcel &data)
69 {
70 int32_t status;
71 int32_t actLength;
72 uint64_t userData;
73 std::shared_ptr<UsbIsoVecParcel> usbIsoVecParcel(data.ReadParcelable<UsbIsoVecParcel>());
74 if (usbIsoVecParcel == nullptr) {
75 USB_HILOGE(MODULE_USB_INNERKIT, "get usbIsoVecParcel error");
76 return UEC_SERVICE_WRITE_PARCEL_ERROR;
77 }
78 if (!data.ReadInt32(status)) {
79 USB_HILOGE(MODULE_USB_INNERKIT, "get status error");
80 return UEC_SERVICE_WRITE_PARCEL_ERROR;
81 }
82 if (!data.ReadInt32(actLength)) {
83 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error");
84 return UEC_SERVICE_WRITE_PARCEL_ERROR;
85 }
86 if (!data.ReadUint64(userData)) {
87 USB_HILOGE(MODULE_USB_INNERKIT, "get userData error");
88 return UEC_SERVICE_WRITE_PARCEL_ERROR;
89 }
90 USB_HILOGI(MODULE_USB_INNERKIT, "%{public}d TransferReadCallback status:%{public}d actLength:%{public}d",
91 __LINE__, status, actLength);
92 return OnTransferReadCallback(status, actLength, usbIsoVecParcel->isoInfoVec, userData);
93 }
94 } // namespace OHOS::USB
95