• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             if (data.ReadInterfaceToken() != GetObjectDescriptor()) {
28                 USB_HILOGE(MODULE_USB_INNERKIT, "check interface token failed, code=%{public}u", code);
29                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
30             }
31 
32             int32_t status;
33             int32_t actLength;
34             if (!data.ReadInt32(status)) {
35                 USB_HILOGE(MODULE_USB_INNERKIT, "get status error");
36                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
37             }
38             if (!data.ReadInt32(actLength)) {
39                 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error");
40                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
41             }
42 
43             USB_HILOGI(MODULE_USB_INNERKIT, "status:%{public}d actLength:%{public}d", status, actLength);
44             OnBulkWriteCallback(status, actLength);
45             break;
46         }
47         case CMD_USBD_BULK_CALLBACK_READ: {
48             if (data.ReadInterfaceToken() != GetObjectDescriptor()) {
49                 USB_HILOGE(MODULE_USB_INNERKIT, "check interface token failed, code=%{public}u", code);
50                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
51             }
52 
53             int32_t status;
54             int32_t actLength;
55             if (!data.ReadInt32(status)) {
56                 USB_HILOGE(MODULE_USB_INNERKIT, "get status error code=%{public}u", code);
57                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
58             }
59             if (!data.ReadInt32(actLength)) {
60                 USB_HILOGE(MODULE_USB_INNERKIT, "get actLength error code=%{public}u", code);
61                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
62             }
63 
64             USB_HILOGI(MODULE_USB_INNERKIT, "%{public}d status:%{public}d actLength:%{public}d", __LINE__, status,
65                 actLength);
66             OnBulkReadCallback(status, actLength);
67             break;
68         }
69         default: {
70             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
71         }
72     }
73     return UEC_OK;
74 }
75 } // namespace OHOS::USB
76