• 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 
17 #include "usbd_bulk_callback.h"
18 #include <hdf_base.h>
19 #include <hdf_log.h>
20 #include <hdf_sbuf_ipc.h>
21 #include "usb_errors.h"
22 
23 #define HDF_LOG_TAG USBD_BULK_CALLBACK
24 
25 namespace OHOS::USB {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int32_t UsbdBulkCallBack::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
27     MessageOption &option)
28 {
29     HDF_LOGI("%{public}s:%{public}d OnRemoteRequest entry! code:%{public}d", __func__, __LINE__, code);
30     switch (code) {
31         case CMD_USBD_BULK_CALLBACK_WRITE: {
32             if (data.ReadInterfaceToken() != GetObjectDescriptor()) {
33                 HDF_LOGE("%{public}s: checkout interface descriptor failed!", __func__);
34                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
35             }
36             int32_t status;
37             int32_t actLength;
38             if (!data.ReadInt32(status)) {
39                 HDF_LOGE("%{public}s:%{public}d get status error", __func__, __LINE__);
40                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
41             }
42             if (!data.ReadInt32(actLength)) {
43                 HDF_LOGE("%{public}s:%{public}d get actLength error", __func__, __LINE__);
44                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
45             }
46             HDF_LOGI("%{public}s:%{public}d status:%{public}d actLength:%{public}d", __func__, __LINE__, status,
47                      actLength);
48             OnBulkWriteCallback(status, actLength);
49             break;
50         }
51         case CMD_USBD_BULK_CALLBACK_READ: {
52             if (data.ReadInterfaceToken() != GetObjectDescriptor()) {
53                 HDF_LOGE("%{public}s: checkout interface descriptor failed!", __func__);
54                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
55             }
56             int32_t status;
57             int32_t actLength;
58             if (!data.ReadInt32(status)) {
59                 HDF_LOGE("%{public}s:%{public}d get status error", __func__, __LINE__);
60                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
61             }
62             if (!data.ReadInt32(actLength)) {
63                 HDF_LOGE("%{public}s:%{public}d get actLength error", __func__, __LINE__);
64                 return UEC_SERVICE_WRITE_PARCEL_ERROR;
65             }
66             HDF_LOGI("%{public}s:%{public}d status:%{public}d actLength:%{public}d", __func__, __LINE__, status,
67                      actLength);
68             OnBulkReadCallback(status, actLength);
69             break;
70         }
71         default: {
72             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
73         }
74     }
75     return UEC_OK;
76 }
77 } // namespace OHOS::USB
78