• 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 #ifndef USBMGR_INNERKITS_IUSB_SRV_H
17 #define USBMGR_INNERKITS_IUSB_SRV_H
18 
19 #include "iremote_broker.h"
20 #include "iremote_object.h"
21 #include "usb_device.h"
22 #include "usb_param.h"
23 #include "usb_port.h"
24 namespace OHOS {
25 namespace USB {
26 class IUsbSrv : public IRemoteBroker {
27 public:
28     enum {
29         USB_FUN_HAS_RIGHT = 0,
30         USB_FUN_REQUEST_RIGHT,
31         USB_FUN_REMOVE_RIGHT,
32         USB_FUN_OPEN_DEVICE,
33         USB_FUN_GET_DEVICE,
34         USB_FUN_GET_DEVICES,
35         USB_FUN_GET_CURRENT_FUNCTIONS,
36         USB_FUN_SET_CURRENT_FUNCTIONS,
37         USB_FUN_USB_FUNCTIONS_FROM_STRING,
38         USB_FUN_USB_FUNCTIONS_TO_STRING,
39         USB_FUN_CLAIM_INTERFACE,
40         USB_FUN_RELEASE_INTERFACE,
41         USB_FUN_BULK_TRANSFER_READ,
42         USB_FUN_BULK_TRANSFER_WRITE,
43         USB_FUN_CONTROL_TRANSFER,
44         USB_FUN_SET_ACTIVE_CONFIG,
45         USB_FUN_GET_ACTIVE_CONFIG,
46         USB_FUN_SET_INTERFACE,
47         USB_FUN_GET_PORTS,
48         USB_FUN_GET_SUPPORTED_MODES,
49         USB_FUN_SET_PORT_ROLE,
50         USB_FUN_REQUEST_QUEUE,
51         USB_FUN_REQUEST_WAIT,
52         USB_FUN_REQUEST_CANCEL,
53         USB_FUN_GET_DESCRIPTOR,
54         USB_FUN_GET_FILEDESCRIPTOR,
55         USB_FUN_CLOSE_DEVICE,
56         USB_FUN_BULK_AYSNC_READ,
57         USB_FUN_BULK_AYSNC_WRITE,
58         USB_FUN_BULK_AYSNC_CANCEL,
59         USB_FUN_REG_BULK_CALLBACK,
60         USB_FUN_UNREG_BULK_CALLBACK,
61     };
62 
63     virtual int32_t OpenDevice(uint8_t busNum, uint8_t devAddr) = 0;
64     virtual int32_t HasRight(std::string deviceName) = 0;
65     virtual int32_t RequestRight(std::string deviceName) = 0;
66     virtual int32_t RemoveRight(std::string deviceName) = 0;
67     virtual int32_t GetDevices(std::vector<UsbDevice> &deviceList) = 0;
68     virtual int32_t GetCurrentFunctions(int32_t &funcs) = 0;
69     virtual int32_t SetCurrentFunctions(int32_t funcs) = 0;
70     virtual int32_t UsbFunctionsFromString(std::string funcs) = 0;
71     virtual std::string UsbFunctionsToString(int32_t funcs) = 0;
72     virtual int32_t GetPorts(std::vector<UsbPort> &ports) = 0;
73     virtual int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes) = 0;
74     virtual int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) = 0;
75     virtual int32_t ReleaseInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid) = 0;
76     virtual int32_t ClaimInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t force) = 0;
77     virtual int32_t BulkTransferRead(const UsbDev &dev, const UsbPipe &pipe, std::vector<uint8_t> &bufferData,
78                 int32_t timeOut) = 0;
79     virtual int32_t BulkTransferWrite(const UsbDev &dev, const UsbPipe &pipe, const std::vector<uint8_t> &bufferData,
80                 int32_t timeOut) = 0;
81     virtual int32_t ControlTransfer(const UsbDev &dev, const UsbCtrlTransfer &ctrl,
82                 std::vector<uint8_t> &bufferData) = 0;
83     virtual int32_t SetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t configId) = 0;
84     virtual int32_t GetActiveConfig(uint8_t busNum, uint8_t devAddr, uint8_t &configId) = 0;
85     virtual int32_t SetInterface(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t altIndex) = 0;
86     virtual int32_t GetRawDescriptor(uint8_t busNum, uint8_t devAddr, std::vector<uint8_t> &bufferData) = 0;
87     virtual int32_t GetFileDescriptor(uint8_t busNum, uint8_t devAddr, int32_t &fd) = 0;
88     virtual int32_t RequestQueue(const UsbDev &dev, const UsbPipe &pipe, const std::vector<uint8_t> &clientData,
89                 const std::vector<uint8_t> &bufferData) = 0;
90     virtual int32_t RequestWait(const UsbDev &dev, int32_t timeOut, std::vector<uint8_t> &clientData,
91                 std::vector<uint8_t> &bufferData) = 0;
92     virtual int32_t RequestCancel(uint8_t busNum, uint8_t devAddr, uint8_t interfaceid, uint8_t endpointId) = 0;
93     virtual int32_t Close(uint8_t busNum, uint8_t devAddr) = 0;
94 
95     virtual int32_t RegBulkCallback(const UsbDev &devInfo, const UsbPipe &pipe, const sptr<IRemoteObject> &cb) = 0;
96     virtual int32_t UnRegBulkCallback(const UsbDev &devInfo, const UsbPipe &pipe) = 0;
97     virtual int32_t BulkRead(const UsbDev &devInfo, const UsbPipe &pipe, sptr<Ashmem> &ashmem) = 0;
98     virtual int32_t BulkWrite(const UsbDev &devInfo, const UsbPipe &pipe, sptr<Ashmem> &ashmem) = 0;
99     virtual int32_t BulkCancel(const UsbDev &devInfo, const UsbPipe &pipe) = 0;
100 
101 public:
102     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.usb.IUsbSrv");
103 };
104 } // namespace USB
105 } // namespace OHOS
106 
107 #endif // USBMGR_INNERKITS_IUSB_SRV_H
108