1 /*
2 * Copyright (c) 2021 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_bulk_callback.h"
17
18 #include "hilog_wrapper.h"
19 #include "usb_errors.h"
20
21 namespace OHOS::USB {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int32_t UsbdBulkCallBack::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
23 MessageOption &option)
24 {
25 switch (code) {
26 case CMD_USBD_BULK_CALLBACK_WRITE: {
27 int32_t status;
28 int32_t actLength;
29 if (!data.ReadInt32(status)) {
30 USB_HILOGE(MODULE_USB_INNERKIT, "get status error");
31 return UEC_SERVICE_WRITE_PARCEL_ERROR;
32 }
33 if (!data.ReadInt32(actLength)) {
34 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error");
35 return UEC_SERVICE_WRITE_PARCEL_ERROR;
36 }
37
38 USB_HILOGI(MODULE_USB_INNERKIT, "status:%{public}d actLength:%{public}d", status, actLength);
39 OnBulkWriteCallback(status, actLength);
40 break;
41 }
42 case CMD_USBD_BULK_CALLBACK_READ: {
43 int32_t status;
44 int32_t actLength;
45 if (!data.ReadInt32(status)) {
46 USB_HILOGE(MODULE_USB_INNERKIT, "get status error code=%{public}u", code);
47 return UEC_SERVICE_WRITE_PARCEL_ERROR;
48 }
49 if (!data.ReadInt32(actLength)) {
50 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error code=%{public}u", code);
51 return UEC_SERVICE_WRITE_PARCEL_ERROR;
52 }
53
54 USB_HILOGI(MODULE_USB_INNERKIT, "%{public}d status:%{public}d actLength:%{public}d", __LINE__, status,
55 actLength);
56 OnBulkReadCallback(status, actLength);
57 break;
58 }
59 default: {
60 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
61 }
62 }
63 return UEC_OK;
64 }
65 } // namespace OHOS::USB
66