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 #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 = 2; 52 const int32_t HDC = 4; 53 const int32_t MTP = 8; 54 const int32_t PTP = 16; 55 const int32_t RNDIS = 32; 56 const int32_t MIDI = 64; 57 const int32_t AUDIO_SOURCE = 128; 58 const int32_t NCM = 256; 59 60 struct USBAsyncContext { 61 napi_env env; 62 napi_async_work work; 63 64 napi_deferred deferred; 65 napi_status status; 66 }; 67 68 struct USBRightAsyncContext : USBAsyncContext { 69 std::string deviceName; 70 bool hasRight = false; 71 }; 72 73 struct USBFunctionAsyncContext : USBAsyncContext { 74 int32_t functions; 75 }; 76 77 struct USBPortRoleAsyncContext : USBAsyncContext { 78 int32_t portId; 79 int32_t powerRole; 80 int32_t dataRole; 81 }; 82 83 struct USBControlTransferAsyncContext : USBAsyncContext { 84 USBDevicePipe pipe; 85 int32_t request; 86 int32_t target; 87 int32_t reqType; 88 int32_t directon; 89 int32_t value; 90 int32_t index; 91 uint8_t *buffer; 92 uint32_t bufferLength; 93 int32_t timeOut = 0; 94 }; 95 96 struct USBBulkTransferAsyncContext : USBAsyncContext { 97 uint8_t *buffer; 98 uint32_t bufferLength; 99 int32_t timeOut = 0; 100 USBDevicePipe pipe; 101 USBEndpoint endpoint; 102 }; 103 104 struct USBQueueAsyncContext : USBAsyncContext { 105 UsbRequest req; 106 uint8_t *buffer; 107 uint32_t bufferLength; 108 }; 109 } // namespace USB 110 } // namespace OHOS 111 #endif // USB_ASYNC_CONTEXT_H