• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef USB_ASYNC_CONTEXT_H
16 #define USB_ASYNC_CONTEXT_H
17 
18 #include "napi/native_api.h"
19 #include "napi/native_node_api.h"
20 #include "usb_device_pipe.h"
21 #include "usb_endpoint.h"
22 #include "usb_request.h"
23 
24 namespace OHOS {
25 namespace USB {
26 const int32_t NONE = 0;
27 const int32_t SOURCE = 1;
28 const int32_t SINK = 2;
29 
30 const int32_t HOST = 1;
31 const int32_t DEVICE = 2;
32 
33 const int32_t UFP = 1;
34 const int32_t DFP = 2;
35 const int32_t DRP = 3;
36 const int32_t NUM_MODES = 4;
37 
38 const int32_t USB_REQUEST_TARGET_DEVICE = 0;
39 const int32_t USB_REQUEST_TARGET_INTERFACE = 1;
40 const int32_t USB_REQUEST_TARGET_ENDPOINT = 2;
41 const int32_t USB_REQUEST_TARGET_OTHER = 3;
42 
43 const int32_t USB_REQUEST_TYPE_STANDARD = 0;
44 const int32_t USB_REQUEST_TYPE_CLASS = 1;
45 const int32_t USB_REQUEST_TYPE_VENDOR = 2;
46 
47 const int32_t USB_REQUEST_DIR_TO_DEVICE = 0;
48 const int32_t USB_REQUEST_DIR_FROM_DEVICE = 0x80;
49 
50 const int32_t ACM = 1;
51 const int32_t ECM = 1 << 1;
52 const int32_t HDC = 1 << 2;
53 const int32_t MTP = 1 << 3;
54 const int32_t PTP = 1 << 4;
55 const int32_t RNDIS = 1 << 5;
56 const int32_t MIDI = 1 << 6;
57 const int32_t AUDIO_SOURCE = 1 << 7;
58 const int32_t NCM = 1 << 8;
59 const int32_t STORAGE = 1 << 9;
60 
61 struct USBAsyncContext {
62     napi_env env;
63     napi_async_work work;
64 
65     napi_deferred deferred;
66     napi_status status;
67 };
68 
69 struct USBRightAsyncContext : USBAsyncContext {
70     std::string deviceName;
71     bool hasRight = false;
72 };
73 
74 struct USBFunctionAsyncContext : USBAsyncContext {
75     int32_t functions;
76 };
77 
78 struct USBPortRoleAsyncContext : USBAsyncContext {
79     int32_t portId;
80     int32_t powerRole;
81     int32_t dataRole;
82 };
83 
84 struct USBControlTransferAsyncContext : USBAsyncContext {
85     USBDevicePipe pipe;
86     int32_t request;
87     int32_t target;
88     uint32_t reqType;
89     int32_t directon;
90     int32_t value;
91     int32_t index;
92     uint8_t *buffer;
93     uint32_t bufferLength;
94     uint32_t dataSize;
95     int32_t timeOut = 0;
96 };
97 
98 struct USBBulkTransferAsyncContext : USBAsyncContext {
99     uint8_t *buffer;
100     uint32_t bufferLength;
101     uint32_t dataSize;
102     int32_t timeOut = 0;
103     USBDevicePipe pipe;
104     USBEndpoint endpoint;
105 };
106 } // namespace USB
107 } // namespace OHOS
108 #endif // USB_ASYNC_CONTEXT_H
109