1 /*
2 * Copyright (c) 2024-2025 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 "napi/native_api.h"
17 #include "native_common.h"
18 #include "usb/usb_ddk_api.h"
19 #include "usb/usb_ddk_types.h"
20 #include "scsi_peripheral/scsi_peripheral_api.h"
21 #include "scsi_peripheral/scsi_peripheral_types.h"
22 #include "ddk/ddk_api.h"
23 #include <cstdlib>
24 #include <js_native_api_types.h>
25 #include <tuple>
26 #include <unistd.h>
27 #include "hilog/log.h"
28 #include "usb_serial/usb_serial_api.h"
29 #include <vector>
30 #include <string>
31
32 #define ENDPOINT 0
33 #define SLEEP 2
34 #define PARAM_8 8
35 #define USB_DDK_TEST_BUF_SIZE 100
36 #define USB_DDK_ENDPOINT_DIR_MASK 0x80
37 #define USB_DDK_DIR_IN 0x80
38 #define USB_DDK_ENDPOINT_XFERTYPE_MASK 0x03
39 #define USB_DDK_ENDPOINT_XFER_INT 0x03
40 #define PARAM_0 0
41 #define PARAM_1 1
42 #define PARAM_10 10
43 #define PARAM_32 32
44 #define PARAM_48 48
45 #define PARM_0 0
46 #define PARM_1 1
47 #define USB_SERIAL_TEST_BUF_SIZE 100
48 static uint8_t configIndex = 0;
49 static uint8_t interfaceIndex = 0;
50 static uint64_t interfaceHandle = 0;
51 static uint8_t settingIndex = 0;
52 static uint32_t timeout = 1000;
53 constexpr size_t MAX_USB_DEVICE_NUM = 128;
54 constexpr size_t DEVICE_MEM_MAP_SIZE = 10 * 1024; // 10K
55 constexpr size_t DEVICE_MEM_MAP_SIZE_50K = 50 * 1024; // 50K
56 constexpr size_t DEVICE_MEM_MAP_SIZE_128M = 128 * 1024 * 1024; // 128M
57 constexpr size_t DEVICE_MEM_MAP_MAX_SIZE = 1024 * 1024 * 10;
58 const uint64_t SCSI_DDK_INVALID_DEVICE_ID = 0xFFFFFFFFFFFFFFFF;
59 const uint32_t SIXTEEN_BIT = 16;
60 const uint32_t THIRTYTWO_BIT = 32;
61 const uint32_t BUS_NUM_MASK = 0xFFFF0000;
62 const uint32_t DEVICE_NUM_MASK = 0x0000FFFF;
63 const uint8_t CONTROL_READY_DATA = 10;
64 const uint8_t CONTROL_INQUIRY_DATA = 100;
65 const uint16_t ALLOCATIONLENGTH_DATA = 16;
66 const uint8_t READ10_DATA = 123;
67 constexpr uint8_t ONE_BYTE = 1;
68 constexpr uint8_t TWO_BYTE = 2;
69 constexpr uint8_t THREE_BYTE = 3;
70 constexpr uint8_t FOUR_BYTE = 4;
71 constexpr uint8_t FIVE_BYTE = 5;
72 constexpr uint8_t SIX_BYTE = 6;
73 constexpr uint8_t SEVEN_BYTE = 7;
74 constexpr uint8_t EIGHT_BYTE = 8;
75 constexpr uint8_t NINE_BYTE = 9;
76 constexpr uint16_t MAX_MEM_LEN = 256;
77 constexpr uint32_t TIMEOUT = 5000;
78 constexpr uint32_t TIMEOUT2 = 20000;
79 constexpr uint32_t TIMEOUT3 = -10;
80 constexpr uint8_t CDB_LENGTH_TEN = 10;
81 constexpr uint8_t TEMP_BUFFER_SIZE = 20;
82 constexpr uint8_t BASE_10 = 10;
83 constexpr uint8_t STATUS_MSG_LEN = 100;
84 constexpr uint8_t INTERFACE_INDEX2 = 5;
85
86 struct UsbSerial_Device {
87 int32_t fd = -1;
88 };
89
NewSerialDeviceHandle()90 static UsbSerial_Device *NewSerialDeviceHandle()
91 {
92 return new UsbSerial_Device;
93 }
94
DeleteUsbSerialDeviceHandle(UsbSerial_Device ** dev)95 static void DeleteUsbSerialDeviceHandle(UsbSerial_Device **dev)
96 {
97 if (*dev != nullptr) {
98 delete *dev;
99 *dev = nullptr;
100 }
101 }
102
103 struct ScsiPeripheral_Device {
104 int32_t devFd = -1;
105 int32_t memMapFd = -1;
106 int32_t lbLength = 0;
107 };
108
NewScsiPeripheralDevice()109 static ScsiPeripheral_Device *NewScsiPeripheralDevice()
110 {
111 return new ScsiPeripheral_Device;
112 }
113
DeleteScsiPeripheralDevice(ScsiPeripheral_Device ** dev)114 static void DeleteScsiPeripheralDevice(ScsiPeripheral_Device **dev)
115 {
116 if (*dev != nullptr) {
117 delete *dev;
118 *dev = nullptr;
119 }
120 }
121
ConvertDeviceId(uint64_t deviceId64)122 static uint64_t ConvertDeviceId(uint64_t deviceId64)
123 {
124 int32_t deviceId32 = static_cast<uint32_t>(deviceId64 >> THIRTYTWO_BIT);
125 uint32_t busNum = (deviceId32 & BUS_NUM_MASK) >> SIXTEEN_BIT;
126 uint32_t deviceNum = deviceId32 & DEVICE_NUM_MASK;
127 uint64_t deviceId = ((static_cast<uint64_t>(busNum) << THIRTYTWO_BIT) | deviceNum);
128
129 return deviceId;
130 }
131
GetDeviceId(napi_env env,napi_callback_info info)132 static uint64_t GetDeviceId(napi_env env, napi_callback_info info)
133 {
134 size_t argc = PARAM_1;
135 napi_value args[PARAM_1];
136 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
137
138 int64_t tmpDeviceId;
139 napi_get_value_int64(env, args[PARAM_0], &tmpDeviceId);
140 uint64_t deviceId = ConvertDeviceId(tmpDeviceId);
141 return deviceId;
142 }
143
AppendIntToString(char * buffer,int32_t ret)144 static void AppendIntToString(char *buffer, int32_t ret)
145 {
146 char temp[TEMP_BUFFER_SIZE];
147 int i = 0;
148
149 int isNegative = (ret < 0);
150 if (isNegative) {
151 ret = -ret;
152 }
153
154 do {
155 temp[i++] = '0' + (ret % BASE_10);
156 ret /= BASE_10;
157 } while (ret > 0);
158
159 if (isNegative) {
160 temp[i++] = '-';
161 }
162
163 for (int start = 0, end = i - 1; start < end; start++, end--) {
164 char t = temp[start];
165 temp[start] = temp[end];
166 temp[end] = t;
167 }
168
169 size_t bufferLen = strlen(buffer);
170 for (int j = 0; j < i; j++) {
171 buffer[bufferLen + j] = temp[j];
172 }
173 buffer[bufferLen + i] = '\0';
174 }
175
IsInterruptInEndpoint(const UsbEndpointDescriptor & epDesc)176 static bool IsInterruptInEndpoint(const UsbEndpointDescriptor &epDesc)
177 {
178 return (((epDesc.bEndpointAddress & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN) &&
179 ((epDesc.bmAttributes & USB_DDK_ENDPOINT_XFERTYPE_MASK) == USB_DDK_ENDPOINT_XFER_INT));
180 }
181
FindForEachInterface(const UsbDdkInterface & interface)182 static std::tuple<bool, uint8_t, uint8_t, uint16_t> FindForEachInterface(const UsbDdkInterface &interface)
183 {
184 struct UsbDdkInterfaceDescriptor *intDesc = interface.altsetting;
185 uint32_t numSetting = interface.numAltsetting;
186 for (uint32_t setIdx = PARAM_0; setIdx < numSetting; ++setIdx) {
187 uint32_t numEp = intDesc[setIdx].interfaceDescriptor.bNumEndpoints;
188 struct UsbDdkEndpointDescriptor *epDesc = intDesc[setIdx].endPoint;
189 for (uint32_t epIdx = PARAM_0; epIdx < numEp; ++epIdx) {
190 if (IsInterruptInEndpoint(epDesc[epIdx].endpointDescriptor)) {
191 return {true, intDesc[setIdx].interfaceDescriptor.bInterfaceNumber,
192 epDesc[epIdx].endpointDescriptor.bEndpointAddress,
193 epDesc[epIdx].endpointDescriptor.wMaxPacketSize};
194 }
195 }
196 }
197
198 return {false, {}, {}, {}};
199 }
200
GetEndpointInfo(const struct UsbDdkConfigDescriptor * config)201 static std::tuple<bool, uint8_t, uint8_t, uint16_t> GetEndpointInfo(const struct UsbDdkConfigDescriptor *config)
202 {
203 for (uint32_t intIdx = PARAM_0; intIdx < config->configDescriptor.bNumInterfaces; ++intIdx) {
204 auto result = FindForEachInterface(config->interface[intIdx]);
205 if (std::get<0>(result)) {
206 return result;
207 }
208 }
209 return {false, {}, {}, {}};
210 }
211
JsDeviceIdToNative(uint64_t deviceId)212 uint64_t JsDeviceIdToNative(uint64_t deviceId)
213 {
214 uint32_t busNum = (uint32_t)(deviceId >> PARAM_48);
215 uint32_t devNum = (uint32_t)((deviceId & 0x0000FFFF00000000) >> PARAM_32);
216 return (((static_cast<uint64_t>(busNum)) << PARAM_32) | devNum);
217 }
218
ParseConfiguration(uint64_t deviceId,std::tuple<bool,uint8_t,uint8_t,uint16_t> & source)219 static bool ParseConfiguration(uint64_t deviceId, std::tuple<bool, uint8_t, uint8_t, uint16_t> &source)
220 {
221 struct UsbDdkConfigDescriptor *config = nullptr;
222 int32_t ret = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
223 if (ret != PARAM_0) {
224 return false;
225 }
226 source = GetEndpointInfo(config);
227 if (!std::get<0>(source)) {
228 return false;
229 }
230 OH_Usb_FreeConfigDescriptor(config);
231 return true;
232 }
233
UsbInit(napi_env env,napi_callback_info info)234 static napi_value UsbInit(napi_env env, napi_callback_info info)
235 {
236 int32_t returnValue = OH_Usb_Init();
237 OH_Usb_Release();
238 napi_value result = nullptr;
239 napi_create_int32(env, returnValue, &result);
240 return result;
241 }
242
UsbRelease(napi_env env,napi_callback_info info)243 static napi_value UsbRelease(napi_env env, napi_callback_info info)
244 {
245 int32_t usbInitReturnValue = OH_Usb_Init();
246 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
247 OH_Usb_Release();
248 napi_value result = nullptr;
249 napi_create_int32(env, true, &result);
250 return result;
251 }
252
UsbReleaseResource(napi_env env,napi_callback_info info)253 static napi_value UsbReleaseResource(napi_env env, napi_callback_info info)
254 {
255 int32_t usbInitReturnValue = OH_Usb_Init();
256 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
257 int32_t returnValue = OH_Usb_ReleaseResource();
258 napi_value result = nullptr;
259 napi_create_int32(env, returnValue, &result);
260 return result;
261 }
262
UsbGetDeviceDescriptorOne(napi_env env,napi_callback_info info)263 static napi_value UsbGetDeviceDescriptorOne(napi_env env, napi_callback_info info)
264 {
265 size_t argc = PARAM_1;
266 napi_value args[PARAM_1] = {nullptr};
267 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
268 int64_t deviceId64;
269 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
270 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
271
272 int32_t usbInitReturnValue = OH_Usb_Init();
273 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
274 struct UsbDeviceDescriptor devDesc;
275 int32_t returnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
276 napi_value result = nullptr;
277 napi_create_int32(env, returnValue, &result);
278 return result;
279 }
280
UsbGetDeviceDescriptorTwo(napi_env env,napi_callback_info info)281 static napi_value UsbGetDeviceDescriptorTwo(napi_env env, napi_callback_info info)
282 {
283 size_t argc = PARAM_1;
284 napi_value args[PARAM_1] = {nullptr};
285 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
286 int64_t deviceId64;
287 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
288 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
289 int32_t usbInitReturnValue = OH_Usb_Init();
290 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
291 int32_t returnValue = OH_Usb_GetDeviceDescriptor(deviceId, nullptr);
292 napi_value result = nullptr;
293 napi_create_int32(env, returnValue, &result);
294 return result;
295 }
296
UsbGetConfigDescriptorOne(napi_env env,napi_callback_info info)297 static napi_value UsbGetConfigDescriptorOne(napi_env env, napi_callback_info info)
298 {
299 size_t argc = PARAM_1;
300 napi_value args[PARAM_1] = {nullptr};
301 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
302 int64_t deviceId64;
303 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
304 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
305 int32_t usbInitReturnValue = OH_Usb_Init();
306 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
307 struct UsbDdkConfigDescriptor *config = nullptr;
308 int32_t returnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
309 OH_Usb_FreeConfigDescriptor(config);
310 napi_value result = nullptr;
311 napi_create_int32(env, returnValue, &result);
312 return result;
313 }
314
UsbGetConfigDescriptorTwo(napi_env env,napi_callback_info info)315 static napi_value UsbGetConfigDescriptorTwo(napi_env env, napi_callback_info info)
316 {
317 struct UsbDdkConfigDescriptor *config = nullptr;
318 uint64_t errorId = PARAM_1;
319 int32_t returnValue = OH_Usb_GetConfigDescriptor(errorId, configIndex, &config);
320 OH_Usb_FreeConfigDescriptor(config);
321 napi_value result = nullptr;
322 napi_create_int32(env, returnValue, &result);
323 return result;
324 }
325
UsbGetConfigDescriptorThree(napi_env env,napi_callback_info info)326 static napi_value UsbGetConfigDescriptorThree(napi_env env, napi_callback_info info)
327 {
328 size_t argc = PARAM_1;
329 napi_value args[PARAM_1] = {nullptr};
330 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
331 int64_t deviceId64;
332 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
333 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
334 int32_t usbInitReturnValue = OH_Usb_Init();
335 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
336
337 int32_t returnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, nullptr);
338 napi_value result = nullptr;
339 napi_create_int32(env, returnValue, &result);
340 return result;
341 }
342
UsbFreeConfigDescriptor(napi_env env,napi_callback_info info)343 static napi_value UsbFreeConfigDescriptor(napi_env env, napi_callback_info info)
344 {
345 size_t argc = PARAM_1;
346 napi_value args[PARAM_1] = {nullptr};
347 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
348 int64_t deviceId64;
349 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
350 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
351 int32_t usbInitReturnValue = OH_Usb_Init();
352 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
353 struct UsbDdkConfigDescriptor *config = nullptr;
354 int32_t returnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
355 NAPI_ASSERT(env, returnValue == PARAM_0, "OH_Usb_GetConfigDescriptor failed");
356 OH_Usb_FreeConfigDescriptor(config);
357 napi_value result = nullptr;
358 napi_create_int32(env, true, &result);
359 return result;
360 }
361
UsbClaimInterfaceOne(napi_env env,napi_callback_info info)362 static napi_value UsbClaimInterfaceOne(napi_env env, napi_callback_info info)
363 {
364 size_t argc = PARAM_1;
365 napi_value args[PARAM_1] = {nullptr};
366 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
367 int64_t deviceId64;
368 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
369 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
370 int32_t usbInitReturnValue = OH_Usb_Init();
371 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
372 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
373 bool result1 = ParseConfiguration(deviceId, source);
374 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
375 uint8_t interface = std::get<1>(source);
376 int32_t returnValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
377 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
378 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
379 OH_Usb_Release();
380 napi_value result = nullptr;
381 napi_create_int32(env, returnValue, &result);
382 return result;
383 }
384
UsbClaimInterfaceTwo(napi_env env,napi_callback_info info)385 static napi_value UsbClaimInterfaceTwo(napi_env env, napi_callback_info info)
386 {
387 uint64_t errorId = PARAM_1;
388 int32_t returnValue = OH_Usb_ClaimInterface(errorId, interfaceIndex, &interfaceHandle);
389 napi_value result = nullptr;
390 napi_create_int32(env, returnValue, &result);
391 return result;
392 }
393
UsbClaimInterfaceThree(napi_env env,napi_callback_info info)394 static napi_value UsbClaimInterfaceThree(napi_env env, napi_callback_info info)
395 {
396 size_t argc = PARAM_1;
397 napi_value args[PARAM_1] = {nullptr};
398 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
399 int64_t deviceId64;
400 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
401 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
402 int32_t usbInitReturnValue = OH_Usb_Init();
403 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
404 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
405 bool result1 = ParseConfiguration(deviceId, source);
406 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
407 uint8_t interface = std::get<1>(source);
408 int32_t returnValue = OH_Usb_ClaimInterface(deviceId, interface, nullptr);
409 OH_Usb_Release();
410 napi_value result = nullptr;
411 napi_create_int32(env, returnValue, &result);
412 return result;
413 }
414
UsbReleaseInterface(napi_env env,napi_callback_info info)415 static napi_value UsbReleaseInterface(napi_env env, napi_callback_info info)
416 {
417 size_t argc = PARAM_1;
418 napi_value args[PARAM_1] = {nullptr};
419 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
420 int64_t deviceId64;
421 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
422 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
423 int32_t usbInitReturnValue = OH_Usb_Init();
424 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
425 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
426 bool result1 = ParseConfiguration(deviceId, source);
427 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
428 uint8_t interface = std::get<1>(source);
429 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
430 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
431 int32_t returnValue = OH_Usb_ReleaseInterface(interfaceHandle);
432 OH_Usb_Release();
433 napi_value result = nullptr;
434 napi_create_int32(env, returnValue, &result);
435 return result;
436 }
437
UsbSelectInterfaceSettingOne(napi_env env,napi_callback_info info)438 static napi_value UsbSelectInterfaceSettingOne(napi_env env, napi_callback_info info)
439 {
440 size_t argc = PARAM_1;
441 napi_value args[PARAM_1] = {nullptr};
442 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
443 int64_t deviceId64;
444 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
445 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
446 int32_t usbInitReturnValue = OH_Usb_Init();
447 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
448 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
449 bool result1 = ParseConfiguration(deviceId, source);
450 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
451 uint8_t interface = std::get<1>(source);
452 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
453 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
454 int32_t returnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
455 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
456 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
457 napi_value result = nullptr;
458 napi_create_int32(env, returnValue, &result);
459 return result;
460 }
461
UsbSelectInterfaceSettingTwo(napi_env env,napi_callback_info info)462 static napi_value UsbSelectInterfaceSettingTwo(napi_env env, napi_callback_info info)
463 {
464 size_t argc = PARAM_1;
465 napi_value args[PARAM_1] = {nullptr};
466 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
467 int64_t deviceId64;
468 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
469 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
470 int32_t usbInitReturnValue = OH_Usb_Init();
471 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
472 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
473 bool result1 = ParseConfiguration(deviceId, source);
474 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
475 uint8_t interface = std::get<1>(source);
476 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
477 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
478 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
479 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
480 OH_Usb_Release();
481 int32_t returnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
482 napi_value result = nullptr;
483 napi_create_int32(env, returnValue, &result);
484 return result;
485 }
486
UsbGetCurrentInterfaceSettingOne(napi_env env,napi_callback_info info)487 static napi_value UsbGetCurrentInterfaceSettingOne(napi_env env, napi_callback_info info)
488 {
489 size_t argc = PARAM_1;
490 napi_value args[PARAM_1] = {nullptr};
491 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
492 int64_t deviceId64;
493 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
494 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
495 int32_t usbInitReturnValue = OH_Usb_Init();
496 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
497 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
498 bool result1 = ParseConfiguration(deviceId, source);
499 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
500 uint8_t interface = std::get<1>(source);
501 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
502 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "OH_Usb_ClaimInterface failed");
503 int32_t usbSelectInterfaceSettingReturnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
504 NAPI_ASSERT(env, usbSelectInterfaceSettingReturnValue == PARAM_0, "OH_Usb_SelectInterfaceSetting failed");
505 int32_t returnValue = OH_Usb_GetCurrentInterfaceSetting(interfaceHandle, &settingIndex);
506 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
507 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
508 OH_Usb_Release();
509 napi_value result = nullptr;
510 napi_create_int32(env, returnValue, &result);
511 return result;
512 }
513
UsbGetCurrentInterfaceSettingTwo(napi_env env,napi_callback_info info)514 static napi_value UsbGetCurrentInterfaceSettingTwo(napi_env env, napi_callback_info info)
515 {
516 size_t argc = PARAM_1;
517 napi_value args[PARAM_1] = {nullptr};
518 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
519 int64_t deviceId64;
520 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
521 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
522 int32_t usbInitReturnValue = OH_Usb_Init();
523 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
524 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
525 bool result1 = ParseConfiguration(deviceId, source);
526 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
527 uint8_t interface = std::get<1>(source);
528 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
529 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "OH_Usb_ClaimInterface failed");
530 int32_t usbSelectInterfaceSettingReturnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
531 NAPI_ASSERT(env, usbSelectInterfaceSettingReturnValue == PARAM_0, "OH_Usb_SelectInterfaceSetting failed");
532 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
533 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
534 OH_Usb_Release();
535 int32_t returnValue = OH_Usb_GetCurrentInterfaceSetting(interfaceHandle, &settingIndex);
536 napi_value result = nullptr;
537 napi_create_int32(env, returnValue, &result);
538 return result;
539 }
540
UsbGetCurrentInterfaceSettingThree(napi_env env,napi_callback_info info)541 static napi_value UsbGetCurrentInterfaceSettingThree(napi_env env, napi_callback_info info)
542 {
543 size_t argc = PARAM_1;
544 napi_value args[PARAM_1] = {nullptr};
545 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
546 int64_t deviceId64;
547 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
548 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
549 int32_t usbInitReturnValue = OH_Usb_Init();
550 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
551 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
552 bool result1 = ParseConfiguration(deviceId, source);
553 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
554 uint8_t interface = std::get<1>(source);
555 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
556 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
557 int32_t usbSelectInterfaceSettingReturnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
558 NAPI_ASSERT(env, usbSelectInterfaceSettingReturnValue == PARAM_0, "Usb_ClaimInterface failed");
559 int32_t returnValue = OH_Usb_GetCurrentInterfaceSetting(interfaceHandle, nullptr);
560 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
561 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
562 OH_Usb_Release();
563 napi_value result = nullptr;
564 napi_create_int32(env, returnValue, &result);
565 return result;
566 }
567
UsbSendControlReadRequestOne(napi_env env,napi_callback_info info)568 static napi_value UsbSendControlReadRequestOne(napi_env env, napi_callback_info info)
569 {
570 size_t argc = PARAM_1;
571 napi_value args[PARAM_1] = {nullptr};
572 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
573 int64_t deviceId64;
574 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
575 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
576 int32_t usbInitReturnValue = OH_Usb_Init();
577 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
578 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
579 bool result1 = ParseConfiguration(deviceId, source);
580 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
581 uint8_t interface = std::get<1>(source);
582 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
583 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
584 struct UsbControlRequestSetup setup;
585 uint8_t data[USB_DDK_TEST_BUF_SIZE] = {PARAM_0};
586 uint32_t dataLen = USB_DDK_TEST_BUF_SIZE;
587 setup.bmRequestType = 0x80;
588 setup.bRequest = 0x06;
589 setup.wValue = (0x03 << PARAM_8) | 0x01;
590 setup.wIndex = 0x409;
591 setup.wLength = dataLen;
592 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, UINT32_MAX, data, &dataLen);
593 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
594 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
595 OH_Usb_Release();
596 napi_value result = nullptr;
597 napi_create_int32(env, returnValue, &result);
598 return result;
599 }
600
UsbSendControlReadRequestTwo(napi_env env,napi_callback_info info)601 static napi_value UsbSendControlReadRequestTwo(napi_env env, napi_callback_info info)
602 {
603 size_t argc = PARAM_1;
604 napi_value args[PARAM_1] = {nullptr};
605 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
606 int64_t deviceId64;
607 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
608 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
609 int32_t usbInitReturnValue = OH_Usb_Init();
610 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
611 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
612 bool result1 = ParseConfiguration(deviceId, source);
613 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
614 uint8_t interface = std::get<1>(source);
615 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
616 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
617 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
618 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
619 OH_Usb_Release();
620 struct UsbControlRequestSetup setup;
621 uint8_t data[USB_DDK_TEST_BUF_SIZE] = {PARAM_0};
622 uint32_t dataLen = USB_DDK_TEST_BUF_SIZE;
623 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, timeout, data, &dataLen);
624 napi_value result = nullptr;
625 napi_create_int32(env, returnValue, &result);
626 return result;
627 }
628
UsbSendControlReadRequestThree(napi_env env,napi_callback_info info)629 static napi_value UsbSendControlReadRequestThree(napi_env env, napi_callback_info info)
630 {
631 size_t argc = PARAM_1;
632 napi_value args[PARAM_1] = {nullptr};
633 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
634 int64_t deviceId64;
635 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
636 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
637 int32_t usbInitReturnValue = OH_Usb_Init();
638 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
639 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
640 bool result1 = ParseConfiguration(deviceId, source);
641 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
642 uint8_t interface = std::get<1>(source);
643 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
644 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
645 uint8_t data[USB_DDK_TEST_BUF_SIZE] = {PARAM_0};
646 uint32_t dataLen = USB_DDK_TEST_BUF_SIZE;
647 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, nullptr, timeout, data, &dataLen);
648 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
649 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
650 OH_Usb_Release();
651 napi_value result = nullptr;
652 napi_create_int32(env, returnValue, &result);
653 return result;
654 }
655
UsbSendControlReadRequestFour(napi_env env,napi_callback_info info)656 static napi_value UsbSendControlReadRequestFour(napi_env env, napi_callback_info info)
657 {
658 size_t argc = PARAM_1;
659 napi_value args[PARAM_1] = {nullptr};
660 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
661 int64_t deviceId64;
662 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
663 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
664 int32_t usbInitReturnValue = OH_Usb_Init();
665 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
666 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
667 bool result1 = ParseConfiguration(deviceId, source);
668 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
669 uint8_t interface = std::get<1>(source);
670 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
671 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
672 struct UsbControlRequestSetup setup;
673 uint32_t dataLen = PARAM_10;
674 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, timeout, nullptr, &dataLen);
675 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
676 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
677 OH_Usb_Release();
678 napi_value result = nullptr;
679 napi_create_int32(env, returnValue, &result);
680 return result;
681 }
682
UsbSendControlReadRequestFive(napi_env env,napi_callback_info info)683 static napi_value UsbSendControlReadRequestFive(napi_env env, napi_callback_info info)
684 {
685 size_t argc = PARAM_1;
686 napi_value args[PARAM_1] = {nullptr};
687 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
688 int64_t deviceId64;
689 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
690 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
691 int32_t usbInitReturnValue = OH_Usb_Init();
692 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
693 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
694 bool result1 = ParseConfiguration(deviceId, source);
695 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
696 uint8_t interface = std::get<1>(source);
697 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
698 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
699 struct UsbControlRequestSetup setup;
700 uint8_t data = PARAM_10;
701 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, timeout, &data, nullptr);
702 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
703 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
704 OH_Usb_Release();
705 napi_value result = nullptr;
706 napi_create_int32(env, returnValue, &result);
707 return result;
708 }
709
UsbSendControlWriteRequestOne(napi_env env,napi_callback_info info)710 static napi_value UsbSendControlWriteRequestOne(napi_env env, napi_callback_info info)
711 {
712 size_t argc = PARAM_1;
713 napi_value args[PARAM_1] = {nullptr};
714 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
715 int64_t deviceId64;
716 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
717 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
718 int32_t usbInitReturnValue = OH_Usb_Init();
719 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
720 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
721 bool result1 = ParseConfiguration(deviceId, source);
722 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
723 uint8_t interface = std::get<1>(source);
724 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
725 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
726 struct UsbControlRequestSetup setup = {PARAM_0};
727 uint8_t dataw[USB_DDK_TEST_BUF_SIZE] = {PARAM_0};
728 uint32_t dataLen = USB_DDK_TEST_BUF_SIZE;
729 setup.bmRequestType = 0x80;
730 setup.bRequest = 0x06;
731 setup.wValue = (0x03 << PARAM_8) | 0x01;
732 setup.wIndex = 0x409;
733 setup.wLength = dataLen;
734 int32_t returnValueR = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, timeout, dataw, &dataLen);
735 NAPI_ASSERT(env, returnValueR == PARAM_0, "OH_Usb_SendControlReadRequest failed");
736 struct UsbControlRequestSetup setupW = {PARAM_0};
737 setupW.bmRequestType = 0x00;
738 setupW.bRequest = 0x09;
739 setupW.wValue = (0x03 << PARAM_8) | 0x01;
740 setupW.wIndex = 0;
741 setupW.wLength = dataLen;
742 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, &setupW, timeout, dataw, dataLen);
743 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
744 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
745 OH_Usb_Release();
746 napi_value result = nullptr;
747 napi_create_int32(env, returnValue, &result);
748 return result;
749 }
750
UsbSendControlWriteRequestTwo(napi_env env,napi_callback_info info)751 static napi_value UsbSendControlWriteRequestTwo(napi_env env, napi_callback_info info)
752 {
753 size_t argc = PARAM_1;
754 napi_value args[PARAM_1] = {nullptr};
755 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
756 int64_t deviceId64;
757 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
758 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
759 int32_t usbInitReturnValue = OH_Usb_Init();
760 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
761 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
762 bool result1 = ParseConfiguration(deviceId, source);
763 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
764 uint8_t interface = std::get<1>(source);
765 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
766 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
767 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
768 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
769 OH_Usb_Release();
770 struct UsbControlRequestSetup setup;
771 uint8_t data = PARAM_10;
772 uint32_t dataLen = PARAM_10;
773 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, &setup, timeout, &data, dataLen);
774 napi_value result = nullptr;
775 napi_create_int32(env, returnValue, &result);
776 return result;
777 }
778
UsbSendControlWriteRequestThree(napi_env env,napi_callback_info info)779 static napi_value UsbSendControlWriteRequestThree(napi_env env, napi_callback_info info)
780 {
781 size_t argc = PARAM_1;
782 napi_value args[PARAM_1] = {nullptr};
783 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
784 int64_t deviceId64;
785 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
786 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
787 int32_t usbInitReturnValue = OH_Usb_Init();
788 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
789 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
790 bool result1 = ParseConfiguration(deviceId, source);
791 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
792 uint8_t interface = std::get<1>(source);
793 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
794 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
795 uint8_t data = PARAM_10;
796 uint32_t dataLen = PARAM_10;
797 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, nullptr, timeout, &data, dataLen);
798 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
799 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
800 OH_Usb_Release();
801 napi_value result = nullptr;
802 napi_create_int32(env, returnValue, &result);
803 return result;
804 }
805
UsbSendControlWriteRequestFour(napi_env env,napi_callback_info info)806 static napi_value UsbSendControlWriteRequestFour(napi_env env, napi_callback_info info)
807 {
808 size_t argc = PARAM_1;
809 napi_value args[PARAM_1] = {nullptr};
810 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
811 int64_t deviceId64;
812 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
813 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
814 int32_t usbInitReturnValue = OH_Usb_Init();
815 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
816 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
817 bool result1 = ParseConfiguration(deviceId, source);
818 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
819 uint8_t interface = std::get<1>(source);
820 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
821 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
822 struct UsbControlRequestSetup setup;
823 uint32_t dataLen = PARAM_10;
824 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, &setup, timeout, nullptr, dataLen);
825 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
826 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
827 OH_Usb_Release();
828 napi_value result = nullptr;
829 napi_create_int32(env, returnValue, &result);
830 return result;
831 }
832
UsbSendControlWriteRequestFive(napi_env env,napi_callback_info info)833 static napi_value UsbSendControlWriteRequestFive(napi_env env, napi_callback_info info)
834 {
835 size_t argc = PARAM_1;
836 napi_value args[PARAM_1] = {nullptr};
837 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
838 int64_t deviceId64;
839 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
840 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
841 int32_t usbInitReturnValue = OH_Usb_Init();
842 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
843 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
844 bool result1 = ParseConfiguration(deviceId, source);
845 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
846 uint8_t interface = std::get<1>(source);
847 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interfaceIndex, &interfaceHandle);
848 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
849 struct UsbControlRequestSetup setup;
850 uint8_t data = PARAM_10;
851 uint32_t dataLen = PARAM_10;
852 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, &setup, timeout, &data, dataLen);
853 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
854 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
855 OH_Usb_Release();
856 napi_value result = nullptr;
857 napi_create_int32(env, returnValue, &result);
858 return result;
859 }
860
UsbSendPipeRequestOne(napi_env env,napi_callback_info info)861 static napi_value UsbSendPipeRequestOne(napi_env env, napi_callback_info info)
862 {
863 size_t argc = PARAM_1;
864 napi_value args[PARAM_1] = {nullptr};
865 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
866 int64_t deviceId64;
867 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
868 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
869 int32_t usbInitReturnValue = OH_Usb_Init();
870 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
871 struct UsbDeviceDescriptor devDesc;
872 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
873 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
874 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
875 bool result1 = ParseConfiguration(deviceId, source);
876 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
877 uint8_t interface = std::get<1>(source);
878 uint8_t endpoint1 = std::get<2>(source);
879 uint16_t maxPktSize1 = std::get<3>(source);
880 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
881 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
882 struct UsbDeviceMemMap *devMemMap = nullptr;
883 size_t bufferLen = maxPktSize1;
884 int32_t usbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMemMap);
885 NAPI_ASSERT(env, usbCreateDeviceMemMapReturnValue == PARAM_0, "OH_Usb_CreateDeviceMemMap failed");
886 NAPI_ASSERT(env, devMemMap != nullptr, "OH_Usb_CreateDeviceMemMap failed");
887 struct UsbRequestPipe pipe;
888 pipe.interfaceHandle = interfaceHandle;
889 pipe.endpoint = endpoint1;
890 pipe.timeout = UINT32_MAX;
891 int32_t returnValue = OH_Usb_SendPipeRequest(&pipe, devMemMap);
892 OH_Usb_DestroyDeviceMemMap(devMemMap);
893 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
894 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
895 napi_value result = nullptr;
896 napi_create_int32(env, returnValue, &result);
897 return result;
898 }
899
UsbSendPipeRequestTwo(napi_env env,napi_callback_info info)900 static napi_value UsbSendPipeRequestTwo(napi_env env, napi_callback_info info)
901 {
902 size_t argc = PARAM_1;
903 napi_value args[PARAM_1] = {nullptr};
904 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
905 int64_t deviceId64;
906 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
907 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
908 int32_t usbInitReturnValue = OH_Usb_Init();
909 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
910 struct UsbDeviceDescriptor devDesc;
911 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
912 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
913 struct UsbDdkConfigDescriptor *config = nullptr;
914 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
915 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == PARAM_0, "OH_Usb_GetConfigDescriptor failed");
916 OH_Usb_FreeConfigDescriptor(config);
917 struct UsbDeviceMemMap *devMemMap = nullptr;
918 size_t bufferLen = PARAM_10;
919 int32_t usbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMemMap);
920 NAPI_ASSERT(env, usbCreateDeviceMemMapReturnValue == PARAM_0, "OH_Usb_CreateDeviceMemMap failed");
921 OH_Usb_Release();
922 struct UsbRequestPipe pipe;
923 pipe.interfaceHandle = interfaceHandle;
924 pipe.endpoint = ENDPOINT;
925 pipe.timeout = UINT32_MAX;
926 int32_t returnValue = OH_Usb_SendPipeRequest(&pipe, devMemMap);
927 OH_Usb_DestroyDeviceMemMap(devMemMap);
928 napi_value result = nullptr;
929 napi_create_int32(env, returnValue, &result);
930 return result;
931 }
932
UsbSendPipeRequestThree(napi_env env,napi_callback_info info)933 static napi_value UsbSendPipeRequestThree(napi_env env, napi_callback_info info)
934 {
935 size_t argc = PARAM_1;
936 napi_value args[PARAM_1] = {nullptr};
937 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
938 int64_t deviceId64;
939 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
940 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
941 int32_t usbInitReturnValue = OH_Usb_Init();
942 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
943 struct UsbDeviceDescriptor devDesc;
944 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
945 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
946 struct UsbDdkConfigDescriptor *config = nullptr;
947 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
948 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == PARAM_0, "OH_Usb_GetConfigDescriptor failed");
949 OH_Usb_FreeConfigDescriptor(config);
950 struct UsbDeviceMemMap *devMemMap = nullptr;
951 size_t bufferLen = PARAM_10;
952 int32_t usbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMemMap);
953 NAPI_ASSERT(env, usbCreateDeviceMemMapReturnValue == PARAM_0, "OH_Usb_CreateDeviceMemMap failed");
954 struct UsbRequestPipe pipe;
955 pipe.interfaceHandle = interfaceHandle;
956 pipe.endpoint = ENDPOINT;
957 pipe.timeout = UINT32_MAX;
958 int32_t returnValue = OH_Usb_SendPipeRequest(nullptr, devMemMap);
959 OH_Usb_DestroyDeviceMemMap(devMemMap);
960 napi_value result = nullptr;
961 napi_create_int32(env, returnValue, &result);
962 return result;
963 }
964
UsbSendPipeRequestFour(napi_env env,napi_callback_info info)965 static napi_value UsbSendPipeRequestFour(napi_env env, napi_callback_info info)
966 {
967 size_t argc = PARAM_1;
968 napi_value args[PARAM_1] = {nullptr};
969 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
970 int64_t deviceId64;
971 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
972 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
973 int32_t usbInitReturnValue = OH_Usb_Init();
974 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
975 struct UsbDeviceDescriptor devDesc;
976 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
977 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
978 struct UsbDdkConfigDescriptor *config = nullptr;
979 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
980 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == PARAM_0, "OH_Usb_GetConfigDescriptor failed");
981 OH_Usb_FreeConfigDescriptor(config);
982 struct UsbDeviceMemMap *devMemMap = nullptr;
983 size_t bufferLen = PARAM_10;
984 int32_t usbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMemMap);
985 NAPI_ASSERT(env, usbCreateDeviceMemMapReturnValue == PARAM_0, "OH_Usb_CreateDeviceMemMap failed");
986 struct UsbRequestPipe pipe;
987 pipe.interfaceHandle = interfaceHandle;
988 pipe.endpoint = ENDPOINT;
989 pipe.timeout = UINT32_MAX;
990 int32_t returnValue = OH_Usb_SendPipeRequest(&pipe, nullptr);
991 OH_Usb_DestroyDeviceMemMap(devMemMap);
992 napi_value result = nullptr;
993 napi_create_int32(env, returnValue, &result);
994 return result;
995 }
996
UsbCreateDeviceMemMapOne(napi_env env,napi_callback_info info)997 static napi_value UsbCreateDeviceMemMapOne(napi_env env, napi_callback_info info)
998 {
999 size_t argc = PARAM_1;
1000 napi_value args[PARAM_1] = {nullptr};
1001 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1002 int64_t deviceId64;
1003 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
1004 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
1005 int32_t usbInitReturnValue = OH_Usb_Init();
1006 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1007 struct UsbDeviceDescriptor devDesc;
1008 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
1009 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
1010 struct UsbDdkConfigDescriptor *config = nullptr;
1011 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
1012 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == PARAM_0, "OH_Usb_GetConfigDescriptor failed");
1013 OH_Usb_FreeConfigDescriptor(config);
1014 struct UsbDeviceMemMap *devMemMap = nullptr;
1015 size_t bufferLen = PARAM_10;
1016 int32_t returnValue = OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMemMap);
1017 OH_Usb_DestroyDeviceMemMap(devMemMap);
1018 napi_value result = nullptr;
1019 napi_create_int32(env, returnValue, &result);
1020 return result;
1021 }
1022
UsbCreateDeviceMemMapTwo(napi_env env,napi_callback_info info)1023 static napi_value UsbCreateDeviceMemMapTwo(napi_env env, napi_callback_info info)
1024 {
1025 size_t argc = PARAM_1;
1026 napi_value args[PARAM_1] = {nullptr};
1027 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1028 int64_t deviceId64;
1029 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
1030 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
1031 int32_t usbInitReturnValue = OH_Usb_Init();
1032 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1033 struct UsbDeviceDescriptor devDesc;
1034 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
1035 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
1036 struct UsbDdkConfigDescriptor *config = nullptr;
1037 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
1038 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == PARAM_0, "OH_Usb_GetConfigDescriptor failed");
1039 OH_Usb_FreeConfigDescriptor(config);
1040 size_t bufferLen = PARAM_10;
1041 int32_t returnValue = OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, nullptr);
1042 napi_value result = nullptr;
1043 napi_create_int32(env, returnValue, &result);
1044 return result;
1045 }
1046
UsbDestroyDeviceMemMap(napi_env env,napi_callback_info info)1047 static napi_value UsbDestroyDeviceMemMap(napi_env env, napi_callback_info info)
1048 {
1049 size_t argc = PARAM_1;
1050 napi_value args[PARAM_1] = {nullptr};
1051 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1052 int64_t deviceId64;
1053 napi_get_value_int64(env, args[PARAM_0], &deviceId64);
1054 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
1055 int32_t usbInitReturnValue = OH_Usb_Init();
1056 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1057 struct UsbDeviceDescriptor devDesc;
1058 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
1059 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
1060 struct UsbDdkConfigDescriptor *config = nullptr;
1061 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(deviceId, configIndex, &config);
1062 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == PARAM_0, "OH_Usb_GetConfigDescriptor failed");
1063 OH_Usb_FreeConfigDescriptor(config);
1064 struct UsbDeviceMemMap *devMemMap = nullptr;
1065 size_t bufferLen = PARAM_10;
1066 OH_Usb_CreateDeviceMemMap(deviceId, bufferLen, &devMemMap);
1067 OH_Usb_DestroyDeviceMemMap(devMemMap);
1068 napi_value result = nullptr;
1069 napi_create_int32(env, true, &result);
1070 return result;
1071 }
1072
UsbSendPipeRequestWithAshmemOne(napi_env env,napi_callback_info info)1073 static napi_value UsbSendPipeRequestWithAshmemOne(napi_env env, napi_callback_info info)
1074 {
1075 size_t argc = PARAM_1;
1076 napi_value args[PARAM_1] = {nullptr};
1077 NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
1078 int64_t deviceId64;
1079 NAPI_CALL(env, napi_get_value_int64(env, args[PARAM_0], &deviceId64));
1080 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
1081 int32_t usbInitReturnValue = OH_Usb_Init();
1082 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1083 struct UsbDeviceDescriptor devDesc;
1084 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
1085 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
1086 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
1087 bool result1 = ParseConfiguration(deviceId, source);
1088 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
1089 uint8_t interface = std::get<1>(source);
1090 uint8_t endpoint1 = std::get<2>(source);
1091 uint16_t maxPktSize1 = std::get<3>(source);
1092 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
1093 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
1094 size_t bufferLen = maxPktSize1;
1095 const uint8_t name[100] = "TestAshmem";
1096 DDK_Ashmem *ashmem = nullptr;
1097 int32_t createAshmemValue = OH_DDK_CreateAshmem(name, bufferLen, &ashmem);
1098 NAPI_ASSERT(env, createAshmemValue == PARAM_0, "OH_DDK_CreateAshmem failed");
1099 const uint8_t ashmemMapType = 0x03;
1100 int32_t mapAshmemValue = OH_DDK_MapAshmem(ashmem, ashmemMapType);
1101 NAPI_ASSERT(env, mapAshmemValue == PARAM_0, "OH_DDK_MapAshmem failed");
1102 struct UsbRequestPipe pipe;
1103 pipe.interfaceHandle = interfaceHandle;
1104 pipe.endpoint = endpoint1;
1105 pipe.timeout = UINT32_MAX;
1106 int32_t returnValue = OH_Usb_SendPipeRequestWithAshmem(&pipe, ashmem);
1107 OH_DDK_DestroyAshmem(ashmem);
1108 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
1109 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
1110 OH_Usb_Release();
1111 napi_value result = nullptr;
1112 NAPI_CALL(env, napi_create_int32(env, returnValue, &result));
1113 return result;
1114 }
1115
UsbSendPipeRequestWithAshmemTwo(napi_env env,napi_callback_info info)1116 static napi_value UsbSendPipeRequestWithAshmemTwo(napi_env env, napi_callback_info info)
1117 {
1118 size_t argc = PARAM_1;
1119 napi_value args[PARAM_1] = {nullptr};
1120 NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
1121 int32_t usbInitReturnValue = OH_Usb_Init();
1122 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1123 size_t bufferLen = PARAM_10;
1124 const uint8_t name[100] = "TestAshmem";
1125 DDK_Ashmem *ashmem = nullptr;
1126 int32_t createAshmemValue = OH_DDK_CreateAshmem(name, bufferLen, &ashmem);
1127 NAPI_ASSERT(env, createAshmemValue == PARAM_0, "OH_DDK_CreateAshmem failed");
1128 const uint8_t ashmemMapType = 0x03;
1129 int32_t mapAshmemValue = OH_DDK_MapAshmem(ashmem, ashmemMapType);
1130 NAPI_ASSERT(env, mapAshmemValue == PARAM_0, "OH_DDK_MapAshmem failed");
1131 int32_t returnValue = OH_Usb_SendPipeRequestWithAshmem(nullptr, ashmem);
1132 OH_DDK_DestroyAshmem(ashmem);
1133 OH_Usb_Release();
1134 napi_value result = nullptr;
1135 NAPI_CALL(env, napi_create_int32(env, returnValue, &result));
1136 return result;
1137 }
1138
UsbSendPipeRequestWithAshmemThree(napi_env env,napi_callback_info info)1139 static napi_value UsbSendPipeRequestWithAshmemThree(napi_env env, napi_callback_info info)
1140 {
1141 size_t argc = PARAM_1;
1142 napi_value args[PARAM_1] = {nullptr};
1143 NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
1144 int64_t deviceId64;
1145 NAPI_CALL(env, napi_get_value_int64(env, args[PARAM_0], &deviceId64));
1146 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
1147 int32_t usbInitReturnValue = OH_Usb_Init();
1148 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1149 struct UsbDeviceDescriptor devDesc;
1150 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
1151 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
1152 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
1153 bool result1 = ParseConfiguration(deviceId, source);
1154 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
1155 uint8_t interface = std::get<1>(source);
1156 uint8_t endpoint1 = std::get<2>(source);
1157 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
1158 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
1159 struct UsbRequestPipe pipe;
1160 pipe.interfaceHandle = interfaceHandle;
1161 pipe.endpoint = endpoint1;
1162 pipe.timeout = UINT32_MAX;
1163 int32_t returnValue = OH_Usb_SendPipeRequestWithAshmem(&pipe, nullptr);
1164 int32_t releaseValue = OH_Usb_ReleaseInterface(interfaceHandle);
1165 NAPI_ASSERT(env, releaseValue == PARAM_0, "OH_Usb_ReleaseInterface failed");
1166 OH_Usb_Release();
1167 napi_value result = nullptr;
1168 NAPI_CALL(env, napi_create_int32(env, returnValue, &result));
1169 return result;
1170 }
1171
UsbSendPipeRequestWithAshmemFour(napi_env env,napi_callback_info info)1172 static napi_value UsbSendPipeRequestWithAshmemFour(napi_env env, napi_callback_info info)
1173 {
1174 size_t argc = PARAM_1;
1175 napi_value args[PARAM_1] = {nullptr};
1176 NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
1177 int64_t deviceId64;
1178 NAPI_CALL(env, napi_get_value_int64(env, args[PARAM_0], &deviceId64));
1179 uint64_t deviceId = JsDeviceIdToNative(static_cast<uint64_t>(deviceId64));
1180 int32_t usbInitReturnValue = OH_Usb_Init();
1181 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1182 struct UsbDeviceDescriptor devDesc;
1183 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(deviceId, &devDesc);
1184 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == PARAM_0, "OH_Usb_GetDeviceDescriptor failed");
1185 std::tuple<bool, uint8_t, uint8_t, uint16_t> source;
1186 bool result1 = ParseConfiguration(deviceId, source);
1187 NAPI_ASSERT(env, result1 == true, "ParseConfiguration failed");
1188 uint8_t interface = std::get<1>(source);
1189 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(deviceId, interface, &interfaceHandle);
1190 NAPI_ASSERT(env, usbClaimInterfaceValue == PARAM_0, "Usb_ClaimInterface failed");
1191 OH_Usb_Release();
1192 size_t bufferLen = PARAM_10;
1193 const uint8_t name[100] = "TestAshmem";
1194 DDK_Ashmem *ashmem = nullptr;
1195 int32_t createAshmemValue = OH_DDK_CreateAshmem(name, bufferLen, &ashmem);
1196 NAPI_ASSERT(env, createAshmemValue == PARAM_0, "OH_DDK_CreateAshmem failed");
1197 const uint8_t ashmemMapType = 0x03;
1198 int32_t mapAshmemValue = OH_DDK_MapAshmem(ashmem, ashmemMapType);
1199 NAPI_ASSERT(env, mapAshmemValue == PARAM_0, "OH_DDK_MapAshmem failed");
1200 struct UsbRequestPipe pipe;
1201 pipe.interfaceHandle = interfaceHandle;
1202 pipe.endpoint = ENDPOINT;
1203 pipe.timeout = UINT32_MAX;
1204 int32_t returnValue = OH_Usb_SendPipeRequestWithAshmem(&pipe, ashmem);
1205 OH_DDK_DestroyAshmem(ashmem);
1206 napi_value result = nullptr;
1207 NAPI_CALL(env, napi_create_int32(env, returnValue, &result));
1208 return result;
1209 }
1210
UsbGetDevicesOne(napi_env env,napi_callback_info info)1211 static napi_value UsbGetDevicesOne(napi_env env, napi_callback_info info)
1212 {
1213 int32_t usbInitReturnValue = OH_Usb_Init();
1214 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1215 struct Usb_DeviceArray deviceArray;
1216 deviceArray.deviceIds = new uint64_t[MAX_USB_DEVICE_NUM];
1217 int32_t returnValue = OH_Usb_GetDevices(&deviceArray);
1218 OH_Usb_Release();
1219 delete[] deviceArray.deviceIds;
1220 napi_value result = nullptr;
1221 NAPI_CALL(env, napi_create_int32(env, returnValue, &result));
1222 return result;
1223 }
1224
UsbGetDevicesTwo(napi_env env,napi_callback_info info)1225 static napi_value UsbGetDevicesTwo(napi_env env, napi_callback_info info)
1226 {
1227 struct Usb_DeviceArray deviceArray;
1228 deviceArray.deviceIds = new uint64_t[MAX_USB_DEVICE_NUM];
1229 int32_t returnValue = OH_Usb_GetDevices(&deviceArray);
1230 delete[] deviceArray.deviceIds;
1231 napi_value result = nullptr;
1232 NAPI_CALL(env, napi_create_int32(env, returnValue, &result));
1233 return result;
1234 }
1235
UsbGetDevicesThree(napi_env env,napi_callback_info info)1236 static napi_value UsbGetDevicesThree(napi_env env, napi_callback_info info)
1237 {
1238 int32_t usbInitReturnValue = OH_Usb_Init();
1239 NAPI_ASSERT(env, usbInitReturnValue == PARAM_0, "OH_Usb_Init failed");
1240 int32_t returnValue = OH_Usb_GetDevices(nullptr);
1241 OH_Usb_Release();
1242 napi_value result = nullptr;
1243 NAPI_CALL(env, napi_create_int32(env, returnValue, &result));
1244 return result;
1245 }
1246
IsScsiDevice(napi_env env,napi_callback_info info)1247 static napi_value IsScsiDevice(napi_env env, napi_callback_info info)
1248 {
1249 uint64_t deviceId = GetDeviceId(env, info);
1250 int32_t ret = OH_ScsiPeripheral_Init();
1251 ScsiPeripheral_Device *dev = nullptr;
1252 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev);
1253 bool boolRet = ret == SCSIPERIPHERAL_DDK_SUCCESS ? true : false;
1254
1255 OH_ScsiPeripheral_Close(&dev);
1256 OH_ScsiPeripheral_Release();
1257 napi_value result = nullptr;
1258 napi_status status = napi_get_boolean(env, boolRet, &result);
1259 NAPI_CALL(env, status);
1260 return result;
1261 }
1262
ScsiPeripheralInitOne(napi_env env,napi_callback_info info)1263 static napi_value ScsiPeripheralInitOne(napi_env env, napi_callback_info info)
1264 {
1265 int32_t ret = OH_ScsiPeripheral_Init();
1266 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1267 OH_ScsiPeripheral_Release();
1268
1269 napi_value result = nullptr;
1270 NAPI_CALL(env, napi_create_int32(env, ret, &result));
1271 return result;
1272 }
1273
ScsiPeripheralReleaseOne(napi_env env,napi_callback_info info)1274 static napi_value ScsiPeripheralReleaseOne(napi_env env, napi_callback_info info)
1275 {
1276 int32_t ret = OH_ScsiPeripheral_Release();
1277 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_Release failed");
1278
1279 napi_value result = nullptr;
1280 NAPI_CALL(env, napi_create_int32(env, ret, &result));
1281 return result;
1282 }
1283
ScsiPeripheralReleaseTwo(napi_env env,napi_callback_info info)1284 static napi_value ScsiPeripheralReleaseTwo(napi_env env, napi_callback_info info)
1285 {
1286 int32_t ret = OH_ScsiPeripheral_Init();
1287 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1288 ret = OH_ScsiPeripheral_Release();
1289 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Release failed");
1290
1291 napi_value result = nullptr;
1292 NAPI_CALL(env, napi_create_int32(env, ret, &result));
1293 return result;
1294 }
1295
ScsiPeripheralOpenOne(napi_env env,napi_callback_info info)1296 static napi_value ScsiPeripheralOpenOne(napi_env env, napi_callback_info info)
1297 {
1298 uint64_t deviceId = GetDeviceId(env, info);
1299 ScsiPeripheral_Device *device = nullptr;
1300 int32_t ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1301 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_Open failed");
1302
1303 napi_value result = nullptr;
1304 napi_status status = napi_create_int32(env, ret, &result);
1305 NAPI_CALL(env, status);
1306 return result;
1307 }
1308
ScsiPeripheralOpenTwo(napi_env env,napi_callback_info info)1309 static napi_value ScsiPeripheralOpenTwo(napi_env env, napi_callback_info info)
1310 {
1311 int32_t ret = OH_ScsiPeripheral_Init();
1312 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1313
1314 uint64_t deviceId = GetDeviceId(env, info);
1315 ret = OH_ScsiPeripheral_Open(deviceId, 0, nullptr);
1316 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Open failed");
1317
1318 OH_ScsiPeripheral_Release();
1319
1320 napi_value result = nullptr;
1321 napi_status status = napi_create_int32(env, ret, &result);
1322 NAPI_CALL(env, status);
1323 return result;
1324 }
1325
ScsiPeripheralOpenThree(napi_env env,napi_callback_info info)1326 static napi_value ScsiPeripheralOpenThree(napi_env env, napi_callback_info info)
1327 {
1328 int32_t ret = OH_ScsiPeripheral_Init();
1329 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1330
1331 ScsiPeripheral_Device *device = nullptr;
1332 ret = OH_ScsiPeripheral_Open(SCSI_DDK_INVALID_DEVICE_ID, 0, &device);
1333 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND, "OH_ScsiPeripheral_Open failed");
1334
1335 OH_ScsiPeripheral_Release();
1336
1337 napi_value result = nullptr;
1338 napi_status status = napi_create_int32(env, ret, &result);
1339 NAPI_CALL(env, status);
1340 return result;
1341 }
1342
ScsiPeripheralOpenFour(napi_env env,napi_callback_info info)1343 static napi_value ScsiPeripheralOpenFour(napi_env env, napi_callback_info info)
1344 {
1345 int32_t ret = OH_ScsiPeripheral_Init();
1346 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1347
1348 uint64_t deviceId = GetDeviceId(env, info);
1349 ScsiPeripheral_Device *device = nullptr;
1350 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1351 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1352
1353 OH_ScsiPeripheral_Close(&device);
1354 OH_ScsiPeripheral_Release();
1355
1356 napi_value result = nullptr;
1357 napi_status status = napi_create_int32(env, ret, &result);
1358 NAPI_CALL(env, status);
1359 return result;
1360 }
1361
ScsiPeripheralOpenFive(napi_env env,napi_callback_info info)1362 static napi_value ScsiPeripheralOpenFive(napi_env env, napi_callback_info info)
1363 {
1364 int32_t ret = OH_ScsiPeripheral_Init();
1365 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1366
1367 uint64_t deviceId = 0; // Invalid deviceId
1368 ScsiPeripheral_Device *device = nullptr;
1369 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1370 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND, "OH_ScsiPeripheral_Open failed");
1371 if (ret == SCSIPERIPHERAL_DDK_SUCCESS) {
1372 OH_ScsiPeripheral_Close(&device);
1373 }
1374 OH_ScsiPeripheral_Release();
1375
1376 napi_value result = nullptr;
1377 napi_status status = napi_create_int32(env, ret, &result);
1378 NAPI_CALL(env, status);
1379 return result;
1380 }
1381
ScsiPeripheralOpenSix(napi_env env,napi_callback_info info)1382 static napi_value ScsiPeripheralOpenSix(napi_env env, napi_callback_info info)
1383 {
1384 int32_t ret = OH_ScsiPeripheral_Init();
1385 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1386
1387 uint64_t deviceId = UINT64_MAX; // Invalid deviceId
1388 ScsiPeripheral_Device *device = nullptr;
1389 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1390 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND, "OH_ScsiPeripheral_Open success");
1391
1392 if (ret == SCSIPERIPHERAL_DDK_SUCCESS) {
1393 OH_ScsiPeripheral_Close(&device);
1394 }
1395
1396 OH_ScsiPeripheral_Release();
1397
1398 napi_value result = nullptr;
1399 napi_status status = napi_create_int32(env, ret, &result);
1400 NAPI_CALL(env, status);
1401 return result;
1402 }
1403
ScsiPeripheralOpenSeven(napi_env env,napi_callback_info info)1404 static napi_value ScsiPeripheralOpenSeven(napi_env env, napi_callback_info info)
1405 {
1406 int32_t ret = OH_ScsiPeripheral_Init();
1407 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1408
1409 uint64_t deviceId = GetDeviceId(env, info);
1410 ScsiPeripheral_Device *device = nullptr;
1411 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1412 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1413
1414 if (ret == SCSIPERIPHERAL_DDK_SUCCESS) {
1415 OH_ScsiPeripheral_Close(&device);
1416 }
1417 OH_ScsiPeripheral_Release();
1418
1419 napi_value result = nullptr;
1420 napi_status status = napi_create_int32(env, ret, &result);
1421 NAPI_CALL(env, status);
1422 return result;
1423 }
1424
ScsiPeripheralOpenEight(napi_env env,napi_callback_info info)1425 static napi_value ScsiPeripheralOpenEight(napi_env env, napi_callback_info info)
1426 {
1427 int32_t ret = OH_ScsiPeripheral_Init();
1428 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1429
1430 uint64_t deviceId = GetDeviceId(env, info);
1431 ScsiPeripheral_Device *device = nullptr;
1432
1433 ret = OH_ScsiPeripheral_Open(deviceId, UINT8_MAX, &device);
1434 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND, "OH_ScsiPeripheral_Open success");
1435
1436 if (ret == SCSIPERIPHERAL_DDK_SUCCESS) {
1437 OH_ScsiPeripheral_Close(&device);
1438 }
1439 OH_ScsiPeripheral_Release();
1440
1441 napi_value result = nullptr;
1442 napi_status status = napi_create_int32(env, ret, &result);
1443 NAPI_CALL(env, status);
1444 return result;
1445 }
1446
ScsiPeripheralOpenNine(napi_env env,napi_callback_info info)1447 static napi_value ScsiPeripheralOpenNine(napi_env env, napi_callback_info info)
1448 {
1449 int32_t ret = OH_ScsiPeripheral_Init();
1450 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1451
1452 uint64_t deviceId = GetDeviceId(env, info);
1453 ScsiPeripheral_Device *device = nullptr;
1454 ret = OH_ScsiPeripheral_Open(deviceId, 1, &device);
1455 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND, "OH_ScsiPeripheral_Open failed");
1456
1457 OH_ScsiPeripheral_Release();
1458
1459 napi_value result = nullptr;
1460 napi_status status = napi_create_int32(env, ret, &result);
1461 NAPI_CALL(env, status);
1462 return result;
1463 }
1464
ScsiPeripheralCloseOne(napi_env env,napi_callback_info info)1465 static napi_value ScsiPeripheralCloseOne(napi_env env, napi_callback_info info)
1466 {
1467 ScsiPeripheral_Device *device = nullptr;
1468 int32_t ret = OH_ScsiPeripheral_Close(&device);
1469 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_Close failed");
1470
1471 napi_value result = nullptr;
1472 napi_status status = napi_create_int32(env, ret, &result);
1473 NAPI_CALL(env, status);
1474 return result;
1475 }
1476
ScsiPeripheralCloseTwo(napi_env env,napi_callback_info info)1477 static napi_value ScsiPeripheralCloseTwo(napi_env env, napi_callback_info info)
1478 {
1479 int32_t ret = OH_ScsiPeripheral_Init();
1480 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1481
1482 ScsiPeripheral_Device **dev = nullptr;
1483 ret = OH_ScsiPeripheral_Close(dev);
1484 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Close failed");
1485
1486 ScsiPeripheral_Device *dev2 = nullptr;
1487 ret = OH_ScsiPeripheral_Close(&dev2);
1488 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Close failed");
1489
1490 OH_ScsiPeripheral_Release();
1491
1492 napi_value result = nullptr;
1493 napi_status status = napi_create_int32(env, ret, &result);
1494 NAPI_CALL(env, status);
1495 return result;
1496 }
1497
ScsiPeripheralCloseThree(napi_env env,napi_callback_info info)1498 static napi_value ScsiPeripheralCloseThree(napi_env env, napi_callback_info info)
1499 {
1500 int32_t ret = OH_ScsiPeripheral_Init();
1501 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1502
1503 uint64_t deviceId = GetDeviceId(env, info);
1504 ScsiPeripheral_Device *device = nullptr;
1505 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1506 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1507
1508 ret = OH_ScsiPeripheral_Close(&device);
1509 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Close failed");
1510
1511 OH_ScsiPeripheral_Release();
1512
1513 napi_value result = nullptr;
1514 napi_status status = napi_create_int32(env, ret, &result);
1515 NAPI_CALL(env, status);
1516 return result;
1517 }
1518
ScsiPeripheralReadCapacityOne(napi_env env,napi_callback_info info)1519 static napi_value ScsiPeripheralReadCapacityOne(napi_env env, napi_callback_info info)
1520 {
1521 int32_t ret = OH_ScsiPeripheral_ReadCapacity10(nullptr, nullptr, nullptr, nullptr);
1522 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_ReadCapacity10 failed");
1523
1524 napi_value result = nullptr;
1525 napi_status status = napi_create_int32(env, ret, &result);
1526 NAPI_CALL(env, status);
1527 return result;
1528 }
1529
ScsiPeripheralReadCapacityTwo(napi_env env,napi_callback_info info)1530 static napi_value ScsiPeripheralReadCapacityTwo(napi_env env, napi_callback_info info)
1531 {
1532 int32_t ret = OH_ScsiPeripheral_Init();
1533 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1534
1535 ScsiPeripheral_Device *dev = nullptr;
1536 ScsiPeripheral_ReadCapacityRequest req = {0};
1537 ScsiPeripheral_CapacityInfo capacityInfo = {0};
1538 ScsiPeripheral_Response resp = {{0}};
1539 ret = OH_ScsiPeripheral_ReadCapacity10(dev, &req, &capacityInfo, &resp);
1540 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_ReadCapacity10 failed");
1541
1542 uint64_t deviceId = GetDeviceId(env, info);
1543 ScsiPeripheral_Device *dev2 = nullptr;
1544 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev2);
1545 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1546
1547 ScsiPeripheral_ReadCapacityRequest *req2 = nullptr;
1548 ScsiPeripheral_CapacityInfo capacityInfo2 = {0};
1549 ScsiPeripheral_Response resp2 = {{0}};
1550 ret = OH_ScsiPeripheral_ReadCapacity10(dev2, req2, &capacityInfo2, &resp2);
1551 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_ReadCapacity10 failed");
1552
1553 ScsiPeripheral_Device *dev3 = dev2;
1554 ScsiPeripheral_ReadCapacityRequest req3 = {0};
1555 ScsiPeripheral_CapacityInfo *capacityInfo3 = nullptr;
1556 ScsiPeripheral_Response resp3 = {{0}};
1557 ret = OH_ScsiPeripheral_ReadCapacity10(dev3, &req3, capacityInfo3, &resp3);
1558 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_ReadCapacity10 failed");
1559
1560 ScsiPeripheral_Device *dev4 = dev2;
1561 ScsiPeripheral_ReadCapacityRequest req4 = {0};
1562 ScsiPeripheral_CapacityInfo capacityInfo4 = {0};
1563 ScsiPeripheral_Response *resp4 = nullptr;
1564 ret = OH_ScsiPeripheral_ReadCapacity10(dev4, &req4, &capacityInfo4, resp4);
1565 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_ReadCapacity10 failed");
1566
1567 OH_ScsiPeripheral_Close(&dev2);
1568 OH_ScsiPeripheral_Release();
1569
1570 napi_value result = nullptr;
1571 napi_status status = napi_create_int32(env, ret, &result);
1572 NAPI_CALL(env, status);
1573 return result;
1574 }
1575
ScsiPeripheralReadCapacityThree(napi_env env,napi_callback_info info)1576 static napi_value ScsiPeripheralReadCapacityThree(napi_env env, napi_callback_info info)
1577 {
1578 int32_t ret = OH_ScsiPeripheral_Init();
1579 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1580 uint64_t deviceId = GetDeviceId(env, info);
1581 ScsiPeripheral_Device *device = nullptr;
1582 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1583 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1584
1585 const uint32_t timeOut = 2000;
1586 ScsiPeripheral_ReadCapacityRequest req = {0};
1587 req.lbAddress = 0;
1588 req.control = 0;
1589 req.byte8 = 0;
1590 req.timeout = timeOut;
1591 ScsiPeripheral_CapacityInfo capacityInfo = {0};
1592 ScsiPeripheral_Response resp = {{0}};
1593 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1594 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1595
1596 OH_ScsiPeripheral_Close(&device);
1597 OH_ScsiPeripheral_Release();
1598
1599 napi_value result = nullptr;
1600 napi_status status = napi_create_int32(env, ret, &result);
1601 NAPI_CALL(env, status);
1602 return result;
1603 }
1604
ScsiPeripheralReadCapacityFour(napi_env env,napi_callback_info info)1605 static napi_value ScsiPeripheralReadCapacityFour(napi_env env, napi_callback_info info)
1606 {
1607 int32_t ret = OH_ScsiPeripheral_Init();
1608 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1609 uint64_t deviceId = GetDeviceId(env, info);
1610 ScsiPeripheral_Device *device = nullptr;
1611 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1612 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1613
1614 ScsiPeripheral_ReadCapacityRequest req = {0};
1615 req.lbAddress = 0;
1616 ScsiPeripheral_CapacityInfo capacityInfo = {0};
1617 ScsiPeripheral_Response resp = {{0}};
1618 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1619 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1620
1621 req.lbAddress = UINT32_MAX;
1622 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1623 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1624
1625 req.lbAddress = CONTROL_INQUIRY_DATA;
1626 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1627 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1628
1629 OH_ScsiPeripheral_Close(&device);
1630 OH_ScsiPeripheral_Release();
1631
1632 napi_value result = nullptr;
1633 napi_status status = napi_create_int32(env, ret, &result);
1634 NAPI_CALL(env, status);
1635 return result;
1636 }
1637
ScsiPeripheralReadCapacityFive(napi_env env,napi_callback_info info)1638 static napi_value ScsiPeripheralReadCapacityFive(napi_env env, napi_callback_info info)
1639 {
1640 int32_t ret = OH_ScsiPeripheral_Init();
1641 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1642 uint64_t deviceId = GetDeviceId(env, info);
1643 ScsiPeripheral_Device *device = nullptr;
1644 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1645 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1646
1647 ScsiPeripheral_ReadCapacityRequest req = {0};
1648 req.control = 0;
1649 ScsiPeripheral_CapacityInfo capacityInfo = {0};
1650 ScsiPeripheral_Response resp = {{0}};
1651 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1652 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1653
1654 req.control = UINT8_MAX;
1655 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1656 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1657
1658 req.control = CONTROL_INQUIRY_DATA;
1659 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1660 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1661
1662 OH_ScsiPeripheral_Close(&device);
1663 OH_ScsiPeripheral_Release();
1664
1665 napi_value result = nullptr;
1666 napi_status status = napi_create_int32(env, ret, &result);
1667 NAPI_CALL(env, status);
1668 return result;
1669 }
1670
ScsiPeripheralReadCapacitySix(napi_env env,napi_callback_info info)1671 static napi_value ScsiPeripheralReadCapacitySix(napi_env env, napi_callback_info info)
1672 {
1673 int32_t ret = OH_ScsiPeripheral_Init();
1674 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1675 uint64_t deviceId = GetDeviceId(env, info);
1676 ScsiPeripheral_Device *device = nullptr;
1677 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1678 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1679
1680 ScsiPeripheral_ReadCapacityRequest req = {0};
1681 req.byte8 = 0;
1682 ScsiPeripheral_CapacityInfo capacityInfo = {0};
1683 ScsiPeripheral_Response resp = {{0}};
1684 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1685 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1686
1687 req.byte8 = UINT8_MAX;
1688 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1689 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1690
1691 req.byte8 = CONTROL_INQUIRY_DATA;
1692 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1693 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1694
1695 OH_ScsiPeripheral_Close(&device);
1696 OH_ScsiPeripheral_Release();
1697
1698 napi_value result = nullptr;
1699 napi_status status = napi_create_int32(env, ret, &result);
1700 NAPI_CALL(env, status);
1701 return result;
1702 }
1703
ScsiPeripheralReadCapacitySeven(napi_env env,napi_callback_info info)1704 static napi_value ScsiPeripheralReadCapacitySeven(napi_env env, napi_callback_info info)
1705 {
1706 int32_t ret = OH_ScsiPeripheral_Init();
1707 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1708 uint64_t deviceId = GetDeviceId(env, info);
1709 ScsiPeripheral_Device *device = nullptr;
1710 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1711 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1712
1713 ScsiPeripheral_ReadCapacityRequest req = {0};
1714 req.timeout = UINT32_MAX;
1715 ScsiPeripheral_CapacityInfo capacityInfo = {0};
1716 ScsiPeripheral_Response resp = {{0}};
1717 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1718 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1719
1720 req.timeout = CONTROL_READY_DATA;
1721 ret = OH_ScsiPeripheral_ReadCapacity10(device, &req, &capacityInfo, &resp);
1722 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_ReadCapacity10 failed");
1723
1724 OH_ScsiPeripheral_Close(&device);
1725 OH_ScsiPeripheral_Release();
1726
1727 napi_value result = nullptr;
1728 napi_status status = napi_create_int32(env, ret, &result);
1729 NAPI_CALL(env, status);
1730 return result;
1731 }
1732
ScsiPeripheralTestUnitReadyOne(napi_env env,napi_callback_info info)1733 static napi_value ScsiPeripheralTestUnitReadyOne(napi_env env, napi_callback_info info)
1734 {
1735 ScsiPeripheral_Device *device = nullptr;
1736 ScsiPeripheral_TestUnitReadyRequest req = {0};
1737 ScsiPeripheral_Response resp = {{0}};
1738 int32_t ret = OH_ScsiPeripheral_TestUnitReady(device, &req, &resp);
1739 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_TestUnitReady failed");
1740
1741 napi_value result = nullptr;
1742 napi_status status = napi_create_int32(env, ret, &result);
1743 NAPI_CALL(env, status);
1744 return result;
1745 }
1746
ScsiPeripheralTestUnitReadyTwo(napi_env env,napi_callback_info info)1747 static napi_value ScsiPeripheralTestUnitReadyTwo(napi_env env, napi_callback_info info)
1748 {
1749 int32_t ret = OH_ScsiPeripheral_Init();
1750 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1751
1752 ScsiPeripheral_Device *device = nullptr;
1753 ScsiPeripheral_TestUnitReadyRequest req = {0};
1754 ScsiPeripheral_Response resp = {{0}};
1755 ret = OH_ScsiPeripheral_TestUnitReady(device, &req, &resp);
1756 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_TestUnitReady failed");
1757
1758 ScsiPeripheral_Device *dev = NewScsiPeripheralDevice();
1759 ret = OH_ScsiPeripheral_TestUnitReady(dev, nullptr, &resp);
1760 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_TestUnitReady failed");
1761
1762 ret = OH_ScsiPeripheral_TestUnitReady(dev, &req, nullptr);
1763 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_TestUnitReady failed");
1764
1765 DeleteScsiPeripheralDevice(&dev);
1766 OH_ScsiPeripheral_Release();
1767
1768 napi_value result = nullptr;
1769 napi_status status = napi_create_int32(env, ret, &result);
1770 NAPI_CALL(env, status);
1771 return result;
1772 }
1773
ScsiPeripheralTestUnitReadyThree(napi_env env,napi_callback_info info)1774 static napi_value ScsiPeripheralTestUnitReadyThree(napi_env env, napi_callback_info info)
1775 {
1776 int32_t ret = OH_ScsiPeripheral_Init();
1777 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1778 uint64_t deviceId = GetDeviceId(env, info);
1779 ScsiPeripheral_Device *device = nullptr;
1780 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1781 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1782
1783 ScsiPeripheral_TestUnitReadyRequest req = {0};
1784 req.timeout = TIMEOUT;
1785 ScsiPeripheral_Response resp = {{0}};
1786 ret = OH_ScsiPeripheral_TestUnitReady(device, &req, &resp);
1787 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_TestUnitReady failed");
1788
1789 OH_ScsiPeripheral_Close(&device);
1790 OH_ScsiPeripheral_Release();
1791
1792 napi_value result = nullptr;
1793 napi_status status = napi_create_int32(env, ret, &result);
1794 NAPI_CALL(env, status);
1795 return result;
1796 }
1797
ScsiPeripheralTestUnitReadyFour(napi_env env,napi_callback_info info)1798 static napi_value ScsiPeripheralTestUnitReadyFour(napi_env env, napi_callback_info info)
1799 {
1800 int32_t ret = OH_ScsiPeripheral_Init();
1801 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1802 uint64_t deviceId = GetDeviceId(env, info);
1803 ScsiPeripheral_Device *device = nullptr;
1804 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1805 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1806
1807 ScsiPeripheral_TestUnitReadyRequest req = {0};
1808 req.control = 0;
1809 ScsiPeripheral_Response resp = {{0}};
1810 ret = OH_ScsiPeripheral_TestUnitReady(device, &req, &resp);
1811 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_TestUnitReady failed");
1812
1813 req.control = UINT8_MAX;
1814 ret = OH_ScsiPeripheral_TestUnitReady(device, &req, &resp);
1815 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_TestUnitReady failed");
1816
1817 req.control = CONTROL_READY_DATA;
1818 ret = OH_ScsiPeripheral_TestUnitReady(device, &req, &resp);
1819 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_TestUnitReady failed");
1820
1821 OH_ScsiPeripheral_Close(&device);
1822 OH_ScsiPeripheral_Release();
1823
1824 napi_value result = nullptr;
1825 napi_status status = napi_create_int32(env, ret, &result);
1826 NAPI_CALL(env, status);
1827 return result;
1828 }
1829
ScsiPeripheralTestUnitReadyFive(napi_env env,napi_callback_info info)1830 static napi_value ScsiPeripheralTestUnitReadyFive(napi_env env, napi_callback_info info)
1831 {
1832 int32_t ret = OH_ScsiPeripheral_Init();
1833 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1834 uint64_t deviceId = GetDeviceId(env, info);
1835 ScsiPeripheral_Device *device = nullptr;
1836 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1837 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1838
1839 ScsiPeripheral_TestUnitReadyRequest req = {0};
1840 req.timeout = UINT32_MAX;
1841 ScsiPeripheral_Response resp = {{0}};
1842 ret = OH_ScsiPeripheral_TestUnitReady(device, &req, &resp);
1843 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_TestUnitReady failed");
1844
1845 OH_ScsiPeripheral_Close(&device);
1846 OH_ScsiPeripheral_Release();
1847
1848 napi_value result = nullptr;
1849 napi_status status = napi_create_int32(env, ret, &result);
1850 NAPI_CALL(env, status);
1851 return result;
1852 }
1853
ScsiPeripheralInquiryOne(napi_env env,napi_callback_info info)1854 static napi_value ScsiPeripheralInquiryOne(napi_env env, napi_callback_info info)
1855 {
1856 ScsiPeripheral_InquiryRequest req = {0};
1857 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
1858 ScsiPeripheral_Response resp = {{0}};
1859 int32_t ret = OH_ScsiPeripheral_Inquiry(nullptr, &req, &inquiryInfo, &resp);
1860 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_Inquiry failed");
1861
1862 napi_value result = nullptr;
1863 napi_status status = napi_create_int32(env, ret, &result);
1864 NAPI_CALL(env, status);
1865 return result;
1866 }
1867
ScsiPeripheralInquiryTwo(napi_env env,napi_callback_info info)1868 static napi_value ScsiPeripheralInquiryTwo(napi_env env, napi_callback_info info)
1869 {
1870 int32_t ret = OH_ScsiPeripheral_Init();
1871 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1872
1873 ScsiPeripheral_Device *dev = nullptr;
1874 ScsiPeripheral_InquiryRequest req = {0};
1875 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
1876 ScsiPeripheral_Response resp = {{0}};
1877 ret = OH_ScsiPeripheral_Inquiry(dev, &req, &inquiryInfo, &resp);
1878 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Inquiry failed");
1879
1880 uint64_t deviceId = GetDeviceId(env, info);
1881 ScsiPeripheral_Device *dev2 = nullptr;
1882 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev2);
1883 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1884
1885 ScsiPeripheral_InquiryRequest *req2 = nullptr;
1886 ScsiPeripheral_InquiryInfo inquiryInfo2 = {0};
1887 ScsiPeripheral_Response resp2 = {{0}};
1888 ret = OH_ScsiPeripheral_Inquiry(dev2, req2, &inquiryInfo2, &resp2);
1889 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Inquiry failed");
1890
1891 ScsiPeripheral_Device *dev3 = dev2;
1892 ScsiPeripheral_InquiryRequest req3 = {0};
1893 ScsiPeripheral_InquiryInfo *inquiryInfo3 = nullptr;
1894 ScsiPeripheral_Response resp3 = {{0}};
1895 ret = OH_ScsiPeripheral_Inquiry(dev3, &req3, inquiryInfo3, &resp3);
1896 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Inquiry failed");
1897
1898 ScsiPeripheral_Device *dev4 = dev2;
1899 ScsiPeripheral_InquiryRequest req4 = {0};
1900 ScsiPeripheral_InquiryInfo inquiryInfo4 = {0};
1901 ScsiPeripheral_Response *resp4 = nullptr;
1902 ret = OH_ScsiPeripheral_Inquiry(dev4, &req4, &inquiryInfo4, resp4);
1903 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Inquiry failed");
1904
1905 OH_ScsiPeripheral_Close(&dev2);
1906 OH_ScsiPeripheral_Release();
1907
1908 napi_value result = nullptr;
1909 napi_status status = napi_create_int32(env, ret, &result);
1910 NAPI_CALL(env, status);
1911 return result;
1912 }
1913
ScsiPeripheralInquiryThree(napi_env env,napi_callback_info info)1914 static napi_value ScsiPeripheralInquiryThree(napi_env env, napi_callback_info info)
1915 {
1916 int32_t ret = OH_ScsiPeripheral_Init();
1917 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1918 uint64_t deviceId = GetDeviceId(env, info);
1919 ScsiPeripheral_Device *device = nullptr;
1920 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1921 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1922
1923 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
1924 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
1925 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
1926 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
1927 ScsiPeripheral_InquiryRequest req = {0};
1928 req.timeout = TIMEOUT;
1929 inquiryInfo.data = devMmap;
1930 ScsiPeripheral_Response resp = {{0}};
1931 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
1932 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
1933
1934 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
1935 OH_ScsiPeripheral_Close(&device);
1936 OH_ScsiPeripheral_Release();
1937
1938 napi_value result = nullptr;
1939 napi_status status = napi_create_int32(env, ret, &result);
1940 NAPI_CALL(env, status);
1941 return result;
1942 }
1943
ScsiPeripheralInquiryFour(napi_env env,napi_callback_info info)1944 static napi_value ScsiPeripheralInquiryFour(napi_env env, napi_callback_info info)
1945 {
1946 int32_t ret = OH_ScsiPeripheral_Init();
1947 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1948 uint64_t deviceId = GetDeviceId(env, info);
1949 ScsiPeripheral_Device *device = nullptr;
1950 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1951 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1952 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
1953 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
1954 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
1955
1956 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
1957 ScsiPeripheral_InquiryRequest req = {0};
1958 req.pageCode = 0;
1959 req.byte1 = 0;
1960 inquiryInfo.data = devMmap;
1961 ScsiPeripheral_Response resp = {{0}};
1962 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
1963 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
1964
1965 req.pageCode = UINT8_MAX;
1966 req.byte1 = 0;
1967 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
1968 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
1969
1970 req.pageCode = 1;
1971 req.byte1 = 1;
1972 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
1973 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
1974
1975 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
1976 OH_ScsiPeripheral_Close(&device);
1977 OH_ScsiPeripheral_Release();
1978
1979 napi_value result = nullptr;
1980 napi_status status = napi_create_int32(env, ret, &result);
1981 NAPI_CALL(env, status);
1982 return result;
1983 }
1984
ScsiPeripheralInquiryFive(napi_env env,napi_callback_info info)1985 static napi_value ScsiPeripheralInquiryFive(napi_env env, napi_callback_info info)
1986 {
1987 int32_t ret = OH_ScsiPeripheral_Init();
1988 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
1989 uint64_t deviceId = GetDeviceId(env, info);
1990 ScsiPeripheral_Device *device = nullptr;
1991 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
1992 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
1993 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
1994 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_MAX_SIZE, &devMmap);
1995 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
1996
1997 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
1998 ScsiPeripheral_InquiryRequest req = {0};
1999 inquiryInfo.data = devMmap;
2000 req.allocationLength = 0;
2001 ScsiPeripheral_Response resp = {{0}};
2002 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2003 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2004
2005 req.allocationLength = UINT16_MAX;
2006 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2007 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2008
2009 req.allocationLength = ALLOCATIONLENGTH_DATA;
2010 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2011 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2012
2013 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2014 OH_ScsiPeripheral_Close(&device);
2015 OH_ScsiPeripheral_Release();
2016
2017 napi_value result = nullptr;
2018 napi_status status = napi_create_int32(env, ret, &result);
2019 NAPI_CALL(env, status);
2020 return result;
2021 }
2022
ScsiPeripheralInquirySix(napi_env env,napi_callback_info info)2023 static napi_value ScsiPeripheralInquirySix(napi_env env, napi_callback_info info)
2024 {
2025 int32_t ret = OH_ScsiPeripheral_Init();
2026 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2027 uint64_t deviceId = GetDeviceId(env, info);
2028 ScsiPeripheral_Device *device = nullptr;
2029 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2030 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2031 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2032 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2033 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2034
2035 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
2036 ScsiPeripheral_InquiryRequest req = {0};
2037 inquiryInfo.data = devMmap;
2038 req.control = 0;
2039 ScsiPeripheral_Response resp = {{0}};
2040 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2041 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2042
2043 req.control = UINT8_MAX;
2044 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2045 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2046
2047 req.control = CONTROL_INQUIRY_DATA;
2048 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2049 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2050
2051 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2052 OH_ScsiPeripheral_Close(&device);
2053 OH_ScsiPeripheral_Release();
2054
2055 napi_value result = nullptr;
2056 napi_status status = napi_create_int32(env, ret, &result);
2057 NAPI_CALL(env, status);
2058 return result;
2059 }
2060
ScsiPeripheralInquirySeven(napi_env env,napi_callback_info info)2061 static napi_value ScsiPeripheralInquirySeven(napi_env env, napi_callback_info info)
2062 {
2063 int32_t ret = OH_ScsiPeripheral_Init();
2064 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2065 uint64_t deviceId = GetDeviceId(env, info);
2066 ScsiPeripheral_Device *device = nullptr;
2067 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2068 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2069 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2070 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2071 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2072
2073 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
2074 ScsiPeripheral_InquiryRequest req = {0};
2075 inquiryInfo.data = devMmap;
2076 req.pageCode = TWO_BYTE;
2077 req.byte1 = 0;
2078 ScsiPeripheral_Response resp = {{0}};
2079 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2080 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2081
2082 req.pageCode = 0;
2083 req.byte1 = UINT8_MAX;
2084 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2085 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2086
2087 req.pageCode = TWO_BYTE;
2088 req.byte1 = 1;
2089 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2090 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2091
2092 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2093 OH_ScsiPeripheral_Close(&device);
2094 OH_ScsiPeripheral_Release();
2095
2096 napi_value result = nullptr;
2097 napi_status status = napi_create_int32(env, ret, &result);
2098 NAPI_CALL(env, status);
2099 return result;
2100 }
2101
ScsiPeripheralInquiryEight(napi_env env,napi_callback_info info)2102 static napi_value ScsiPeripheralInquiryEight(napi_env env, napi_callback_info info)
2103 {
2104 int32_t ret = OH_ScsiPeripheral_Init();
2105 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2106 uint64_t deviceId = GetDeviceId(env, info);
2107 ScsiPeripheral_Device *device = nullptr;
2108 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2109 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2110 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2111 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2112 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2113
2114 ScsiPeripheral_InquiryInfo inquiryInfo = {0};
2115 ScsiPeripheral_InquiryRequest req = {0};
2116 inquiryInfo.data = devMmap;
2117 req.timeout = UINT32_MAX;
2118 ScsiPeripheral_Response resp = {{0}};
2119 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2120 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2121
2122 req.timeout = CONTROL_READY_DATA;
2123 ret = OH_ScsiPeripheral_Inquiry(device, &req, &inquiryInfo, &resp);
2124 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Inquiry failed");
2125
2126 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2127 OH_ScsiPeripheral_Close(&device);
2128 OH_ScsiPeripheral_Release();
2129
2130 napi_value result = nullptr;
2131 napi_status status = napi_create_int32(env, ret, &result);
2132 NAPI_CALL(env, status);
2133 return result;
2134 }
2135
ScsiPeripheralRequestSenseOne(napi_env env,napi_callback_info info)2136 static napi_value ScsiPeripheralRequestSenseOne(napi_env env, napi_callback_info info)
2137 {
2138 ScsiPeripheral_Device *device = nullptr;
2139 ScsiPeripheral_RequestSenseRequest req = {0};
2140 ScsiPeripheral_Response resp = {{0}};
2141 int32_t ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2142 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_RequestSense failed");
2143
2144 napi_value result = nullptr;
2145 napi_status status = napi_create_int32(env, ret, &result);
2146 NAPI_CALL(env, status);
2147 return result;
2148 }
2149
ScsiPeripheralRequestSenseTwo(napi_env env,napi_callback_info info)2150 static napi_value ScsiPeripheralRequestSenseTwo(napi_env env, napi_callback_info info)
2151 {
2152 int32_t ret = OH_ScsiPeripheral_Init();
2153 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2154
2155 ScsiPeripheral_RequestSenseRequest req = {0};
2156 ScsiPeripheral_Response resp = {{0}};
2157 ret = OH_ScsiPeripheral_RequestSense(nullptr, &req, &resp);
2158 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_RequestSense failed");
2159
2160 ScsiPeripheral_Device *dev = NewScsiPeripheralDevice();
2161 ret = OH_ScsiPeripheral_RequestSense(dev, nullptr, &resp);
2162 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_RequestSense failed");
2163
2164 ret = OH_ScsiPeripheral_RequestSense(dev, &req, nullptr);
2165 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_RequestSense failed");
2166
2167 DeleteScsiPeripheralDevice(&dev);
2168 OH_ScsiPeripheral_Release();
2169
2170 napi_value result = nullptr;
2171 napi_status status = napi_create_int32(env, ret, &result);
2172 NAPI_CALL(env, status);
2173 return result;
2174 }
2175
ScsiPeripheralRequestSenseThree(napi_env env,napi_callback_info info)2176 static napi_value ScsiPeripheralRequestSenseThree(napi_env env, napi_callback_info info)
2177 {
2178 int32_t ret = OH_ScsiPeripheral_Init();
2179 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2180 uint64_t deviceId = GetDeviceId(env, info);
2181 ScsiPeripheral_Device *device = nullptr;
2182 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2183 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2184
2185 ScsiPeripheral_RequestSenseRequest req = {0};
2186 req.timeout = TIMEOUT;
2187 ScsiPeripheral_Response resp = {{0}};
2188 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2189 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2190
2191 OH_ScsiPeripheral_Close(&device);
2192 OH_ScsiPeripheral_Release();
2193
2194 napi_value result = nullptr;
2195 napi_status status = napi_create_int32(env, ret, &result);
2196 NAPI_CALL(env, status);
2197 return result;
2198 }
2199
ScsiPeripheralRequestSenseFour(napi_env env,napi_callback_info info)2200 static napi_value ScsiPeripheralRequestSenseFour(napi_env env, napi_callback_info info)
2201 {
2202 int32_t ret = OH_ScsiPeripheral_Init();
2203 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2204 uint64_t deviceId = GetDeviceId(env, info);
2205 ScsiPeripheral_Device *device = nullptr;
2206 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2207 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2208
2209 ScsiPeripheral_RequestSenseRequest req = {0};
2210 req.allocationLength = 0;
2211 ScsiPeripheral_Response resp = {{0}};
2212 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2213 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2214
2215 req.allocationLength = UINT8_MAX;
2216 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2217 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2218
2219 req.allocationLength = ALLOCATIONLENGTH_DATA;
2220 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2221 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2222
2223 OH_ScsiPeripheral_Close(&device);
2224 OH_ScsiPeripheral_Release();
2225
2226 napi_value result = nullptr;
2227 napi_status status = napi_create_int32(env, ret, &result);
2228 NAPI_CALL(env, status);
2229 return result;
2230 }
2231
ScsiPeripheralRequestSenseFive(napi_env env,napi_callback_info info)2232 static napi_value ScsiPeripheralRequestSenseFive(napi_env env, napi_callback_info info)
2233 {
2234 int32_t ret = OH_ScsiPeripheral_Init();
2235 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2236 uint64_t deviceId = GetDeviceId(env, info);
2237 ScsiPeripheral_Device *device = nullptr;
2238 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2239 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2240
2241 ScsiPeripheral_RequestSenseRequest req = {0};
2242 req.control = 0;
2243 ScsiPeripheral_Response resp = {{0}};
2244 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2245 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2246
2247 req.control = UINT8_MAX;
2248 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2249 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2250
2251 req.control = CONTROL_INQUIRY_DATA;
2252 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2253 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2254
2255 OH_ScsiPeripheral_Close(&device);
2256 OH_ScsiPeripheral_Release();
2257
2258 napi_value result = nullptr;
2259 napi_status status = napi_create_int32(env, ret, &result);
2260 NAPI_CALL(env, status);
2261 return result;
2262 }
2263
ScsiPeripheralRequestSenseSix(napi_env env,napi_callback_info info)2264 static napi_value ScsiPeripheralRequestSenseSix(napi_env env, napi_callback_info info)
2265 {
2266 int32_t ret = OH_ScsiPeripheral_Init();
2267 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2268 uint64_t deviceId = GetDeviceId(env, info);
2269 ScsiPeripheral_Device *device = nullptr;
2270 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2271 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2272
2273 ScsiPeripheral_RequestSenseRequest req = {0};
2274 req.byte1 = 0;
2275 ScsiPeripheral_Response resp = {{0}};
2276 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2277 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2278
2279 req.byte1 = UINT8_MAX;
2280 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2281 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2282
2283 req.byte1 = 1;
2284 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2285 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2286
2287 req.timeout = CONTROL_READY_DATA;
2288 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2289 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2290
2291 req.timeout = UINT32_MAX;
2292 ret = OH_ScsiPeripheral_RequestSense(device, &req, &resp);
2293 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_RequestSense failed");
2294
2295 OH_ScsiPeripheral_Close(&device);
2296 OH_ScsiPeripheral_Release();
2297
2298 napi_value result = nullptr;
2299 napi_status status = napi_create_int32(env, ret, &result);
2300 NAPI_CALL(env, status);
2301 return result;
2302 }
2303
ScsiPeripheralReadOne(napi_env env,napi_callback_info info)2304 static napi_value ScsiPeripheralReadOne(napi_env env, napi_callback_info info)
2305 {
2306 ScsiPeripheral_Device *device = nullptr;
2307 ScsiPeripheral_IORequest req = {0};
2308 ScsiPeripheral_Response resp = {{0}};
2309 int32_t ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2310 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_Read10 failed");
2311
2312 napi_value result = nullptr;
2313 napi_status status = napi_create_int32(env, ret, &result);
2314 NAPI_CALL(env, status);
2315 return result;
2316 }
2317
ScsiPeripheralReadTwo(napi_env env,napi_callback_info info)2318 static napi_value ScsiPeripheralReadTwo(napi_env env, napi_callback_info info)
2319 {
2320 int32_t ret = OH_ScsiPeripheral_Init();
2321 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2322
2323 ScsiPeripheral_IORequest req = {0};
2324 ScsiPeripheral_Response resp = {{0}};
2325 ret = OH_ScsiPeripheral_Read10(nullptr, &req, &resp);
2326 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Read10 failed");
2327
2328 ScsiPeripheral_Device *dev = NewScsiPeripheralDevice();
2329 ret = OH_ScsiPeripheral_Read10(dev, nullptr, &resp);
2330 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Read10 failed");
2331
2332 ret = OH_ScsiPeripheral_Read10(dev, &req, &resp);
2333 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Read10 failed");
2334
2335 uint8_t buff;
2336 ScsiPeripheral_DeviceMemMap devMmap({&buff, sizeof(buff), 0, sizeof(buff), 0});
2337 req.data = &devMmap;
2338 ret = OH_ScsiPeripheral_Read10(dev, &req, nullptr);
2339 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Read10 failed");
2340
2341 DeleteScsiPeripheralDevice(&dev);
2342 OH_ScsiPeripheral_Release();
2343
2344 napi_value result = nullptr;
2345 napi_status status = napi_create_int32(env, ret, &result);
2346 NAPI_CALL(env, status);
2347 return result;
2348 }
2349
ScsiPeripheralReadThree(napi_env env,napi_callback_info info)2350 static napi_value ScsiPeripheralReadThree(napi_env env, napi_callback_info info)
2351 {
2352 int32_t ret = OH_ScsiPeripheral_Init();
2353 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2354 uint64_t deviceId = GetDeviceId(env, info);
2355 ScsiPeripheral_Device *device = nullptr;
2356 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2357 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2358
2359 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2360 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2361 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2362 NAPI_ASSERT(env, devMmap != nullptr, "devMmap is nullptr");
2363 ScsiPeripheral_IORequest req = {0};
2364
2365 const uint32_t tmpTimeout = TIMEOUT2;
2366 req.lbAddress = 1;
2367 req.transferLength = 1;
2368 req.control = 0;
2369 req.byte1 = 0;
2370 req.byte6 = 0;
2371 req.timeout = tmpTimeout;
2372 req.data = devMmap;
2373 ScsiPeripheral_Response resp = {{0}};
2374 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2375 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2376
2377 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2378 OH_ScsiPeripheral_Close(&device);
2379 OH_ScsiPeripheral_Release();
2380
2381 napi_value result = nullptr;
2382 napi_status status = napi_create_int32(env, ret, &result);
2383 NAPI_CALL(env, status);
2384 return result;
2385 }
2386
ScsiPeripheralReadFour(napi_env env,napi_callback_info info)2387 static napi_value ScsiPeripheralReadFour(napi_env env, napi_callback_info info)
2388 {
2389 int32_t ret = OH_ScsiPeripheral_Init();
2390 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2391 uint64_t deviceId = GetDeviceId(env, info);
2392 ScsiPeripheral_Device *device = nullptr;
2393 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2394 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2395
2396 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2397 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2398 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2399 NAPI_ASSERT(env, devMmap != nullptr, "devMmap is nullptr");
2400
2401 ScsiPeripheral_IORequest req = {0};
2402 req.lbAddress = 0;
2403 req.data = devMmap;
2404 ScsiPeripheral_Response resp = {{0}};
2405 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2406 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2407
2408 req.lbAddress = UINT32_MAX;
2409 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2410 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2411
2412 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2413 OH_ScsiPeripheral_Close(&device);
2414 OH_ScsiPeripheral_Release();
2415
2416 napi_value result = nullptr;
2417 napi_status status = napi_create_int32(env, ret, &result);
2418 NAPI_CALL(env, status);
2419 return result;
2420 }
2421
ScsiPeripheralReadFive(napi_env env,napi_callback_info info)2422 static napi_value ScsiPeripheralReadFive(napi_env env, napi_callback_info info)
2423 {
2424 int32_t ret = OH_ScsiPeripheral_Init();
2425 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2426 uint64_t deviceId = GetDeviceId(env, info);
2427 ScsiPeripheral_Device *device = nullptr;
2428 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2429 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2430
2431 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2432 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_MAX_SIZE, &devMmap);
2433 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2434 NAPI_ASSERT(env, devMmap != nullptr, "devMmap is nullptr");
2435
2436 ScsiPeripheral_IORequest req = {0};
2437 req.transferLength = 0;
2438 req.data = devMmap;
2439 ScsiPeripheral_Response resp = {{0}};
2440 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2441 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2442
2443 req.transferLength = UINT16_MAX;
2444 req.lbAddress = 0;
2445 req.byte1 = 0;
2446 req.byte6 = 0;
2447 req.control = 0;
2448 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2449 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_IO_ERROR || ret == SCSIPERIPHERAL_DDK_SUCCESS,
2450 "OH_ScsiPeripheral_Read10 failed");
2451
2452 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2453 OH_ScsiPeripheral_Close(&device);
2454 OH_ScsiPeripheral_Release();
2455
2456 napi_value result = nullptr;
2457 napi_status status = napi_create_int32(env, ret, &result);
2458 NAPI_CALL(env, status);
2459 return result;
2460 }
2461
ScsiPeripheralReadSix(napi_env env,napi_callback_info info)2462 static napi_value ScsiPeripheralReadSix(napi_env env, napi_callback_info info)
2463 {
2464 int32_t ret = OH_ScsiPeripheral_Init();
2465 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2466 uint64_t deviceId = GetDeviceId(env, info);
2467 ScsiPeripheral_Device *device = nullptr;
2468 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2469 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2470
2471 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2472 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2473 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2474 NAPI_ASSERT(env, devMmap != nullptr, "devMmap is nullptr");
2475
2476 ScsiPeripheral_IORequest req = {0};
2477 req.control = 0;
2478 req.data = devMmap;
2479 ScsiPeripheral_Response resp = {{0}};
2480 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2481 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2482
2483 req.control = UINT8_MAX;
2484 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2485 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2486
2487 req.control = CONTROL_INQUIRY_DATA;
2488 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2489 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2490
2491 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2492 OH_ScsiPeripheral_Close(&device);
2493 OH_ScsiPeripheral_Release();
2494
2495 napi_value result = nullptr;
2496 napi_status status = napi_create_int32(env, ret, &result);
2497 NAPI_CALL(env, status);
2498 return result;
2499 }
2500
ScsiPeripheralReadSeven(napi_env env,napi_callback_info info)2501 static napi_value ScsiPeripheralReadSeven(napi_env env, napi_callback_info info)
2502 {
2503 int32_t ret = OH_ScsiPeripheral_Init();
2504 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2505 uint64_t deviceId = GetDeviceId(env, info);
2506 ScsiPeripheral_Device *device = nullptr;
2507 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2508 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2509
2510 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2511 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2512 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2513 NAPI_ASSERT(env, devMmap != nullptr, "devMmap is nullptr");
2514
2515 ScsiPeripheral_IORequest req = {0};
2516 req.byte1 = 0;
2517 req.data = devMmap;
2518 ScsiPeripheral_Response resp = {{0}};
2519 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2520 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2521
2522 req.byte1 = UINT8_MAX;
2523 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2524 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2525
2526 req.byte1 = READ10_DATA;
2527 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2528 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2529
2530 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2531 OH_ScsiPeripheral_Close(&device);
2532 OH_ScsiPeripheral_Release();
2533
2534 napi_value result = nullptr;
2535 napi_status status = napi_create_int32(env, ret, &result);
2536 NAPI_CALL(env, status);
2537 return result;
2538 }
2539
ScsiPeripheralReadEight(napi_env env,napi_callback_info info)2540 static napi_value ScsiPeripheralReadEight(napi_env env, napi_callback_info info)
2541 {
2542 int32_t ret = OH_ScsiPeripheral_Init();
2543 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2544 uint64_t deviceId = GetDeviceId(env, info);
2545 ScsiPeripheral_Device *device = nullptr;
2546 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2547 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2548
2549 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2550 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2551 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2552 NAPI_ASSERT(env, devMmap != nullptr, "devMmap is nullptr");
2553
2554 ScsiPeripheral_IORequest req = {0};
2555 req.byte6 = 0;
2556 req.data = devMmap;
2557 ScsiPeripheral_Response resp = {{0}};
2558 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2559 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2560
2561 req.byte6 = UINT8_MAX;
2562 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2563 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2564
2565 req.byte6 = READ10_DATA;
2566 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2567 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2568
2569 req.timeout = UINT32_MAX;
2570 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2571 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2572
2573 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2574 OH_ScsiPeripheral_Close(&device);
2575 OH_ScsiPeripheral_Release();
2576
2577 napi_value result = nullptr;
2578 napi_status status = napi_create_int32(env, ret, &result);
2579 NAPI_CALL(env, status);
2580 return result;
2581 }
2582
ScsiPeripheralReadNine(napi_env env,napi_callback_info info)2583 static napi_value ScsiPeripheralReadNine(napi_env env, napi_callback_info info)
2584 {
2585 int32_t ret = OH_ScsiPeripheral_Init();
2586 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2587 uint64_t deviceId = GetDeviceId(env, info);
2588 ScsiPeripheral_Device *device = nullptr;
2589 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2590 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2591
2592 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2593 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2594 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2595 NAPI_ASSERT(env, devMmap != nullptr, "devMmap is nullptr");
2596 ScsiPeripheral_IORequest req = {0};
2597
2598 const uint32_t tmpTimeout = 10000;
2599 req.lbAddress = 1;
2600 req.transferLength = 1;
2601 req.control = 0;
2602 req.byte1 = 0;
2603 req.byte6 = 0;
2604 req.timeout = tmpTimeout;
2605 req.data = devMmap;
2606 ScsiPeripheral_Response resp = {{0}};
2607 ret = OH_ScsiPeripheral_Read10(device, &req, &resp);
2608 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Read10 failed");
2609
2610 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2611 OH_ScsiPeripheral_Close(&device);
2612 OH_ScsiPeripheral_Release();
2613
2614 napi_value result = nullptr;
2615 napi_status status = napi_create_int32(env, ret, &result);
2616 NAPI_CALL(env, status);
2617 return result;
2618 }
2619
ScsiPeripheralWriteOne(napi_env env,napi_callback_info info)2620 static napi_value ScsiPeripheralWriteOne(napi_env env, napi_callback_info info)
2621 {
2622 ScsiPeripheral_Device *device = nullptr;
2623 ScsiPeripheral_IORequest req = {0};
2624 ScsiPeripheral_Response resp = {{0}};
2625 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2626 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_Write10 failed");
2627
2628 napi_value result = nullptr;
2629 napi_status status = napi_create_int32(env, ret, &result);
2630 NAPI_CALL(env, status);
2631 return result;
2632 }
2633
ScsiPeripheralWriteTwo(napi_env env,napi_callback_info info)2634 static napi_value ScsiPeripheralWriteTwo(napi_env env, napi_callback_info info)
2635 {
2636 int32_t ret = OH_ScsiPeripheral_Init();
2637 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2638
2639 ScsiPeripheral_IORequest req = {0};
2640 ScsiPeripheral_Response resp = {{0}};
2641 ret = OH_ScsiPeripheral_Write10(nullptr, &req, &resp);
2642 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Write10 failed");
2643
2644 ScsiPeripheral_Device *dev = NewScsiPeripheralDevice();
2645 ret = OH_ScsiPeripheral_Write10(dev, nullptr, &resp);
2646 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Write10 failed");
2647
2648 ret = OH_ScsiPeripheral_Write10(dev, &req, &resp);
2649 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Write10 failed");
2650
2651 uint8_t buff;
2652 ScsiPeripheral_DeviceMemMap devMmap({&buff, sizeof(buff), 0, sizeof(buff), 0});
2653 req.data = &devMmap;
2654 ret = OH_ScsiPeripheral_Write10(dev, &req, nullptr);
2655 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Write10 failed");
2656
2657 DeleteScsiPeripheralDevice(&dev);
2658 OH_ScsiPeripheral_Release();
2659
2660 napi_value result = nullptr;
2661 napi_status status = napi_create_int32(env, ret, &result);
2662 NAPI_CALL(env, status);
2663 return result;
2664 }
2665
ScsiPeripheralWriteThree(napi_env env,napi_callback_info info)2666 static napi_value ScsiPeripheralWriteThree(napi_env env, napi_callback_info info)
2667 {
2668 int32_t ret = OH_ScsiPeripheral_Init();
2669 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2670 uint64_t deviceId = GetDeviceId(env, info);
2671 ScsiPeripheral_Device *device = nullptr;
2672 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2673 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2674
2675 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2676 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
2677 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2678 ScsiPeripheral_IORequest req = {0};
2679 const uint32_t tmpTimeout = TIMEOUT2;
2680 req.lbAddress = 1;
2681 req.transferLength = 1;
2682 req.control = 0;
2683 req.byte1 = 0;
2684 req.byte6 = 0;
2685 req.timeout = tmpTimeout;
2686 req.data = devMmap;
2687 ScsiPeripheral_Response resp = {{0}};
2688 ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2689 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Write10 failed");
2690
2691 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
2692 OH_ScsiPeripheral_Close(&device);
2693 OH_ScsiPeripheral_Release();
2694
2695 napi_value result = nullptr;
2696 napi_status status = napi_create_int32(env, ret, &result);
2697 NAPI_CALL(env, status);
2698 return result;
2699 }
2700
WriteBytes1(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2701 static napi_value WriteBytes1(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2702 {
2703 ScsiPeripheral_IORequest req;
2704 const uint32_t tmpTimeout = 20000;
2705 req.lbAddress = 0;
2706 req.transferLength = 1;
2707 req.control = 0;
2708 req.byte1 = 0;
2709 req.byte6 = 0;
2710 req.timeout = tmpTimeout;
2711 req.data = devMmap;
2712 ScsiPeripheral_Response resp = {{0}};
2713 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2714 char statusMsg[STATUS_MSG_LEN] = "WriteBytes1 failed ret: ";
2715 AppendIntToString(statusMsg, ret);
2716 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2717 napi_throw_error(env, nullptr, statusMsg);
2718 return nullptr;
2719 }
2720 return nullptr;
2721 }
2722
WriteBytes2(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2723 static napi_value WriteBytes2(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2724 {
2725 ScsiPeripheral_IORequest req;
2726 const uint32_t tmpTimeout = 20000;
2727 req.lbAddress = 1;
2728 req.transferLength = 1;
2729 req.control = 0;
2730 req.byte1 = UINT8_MAX;
2731 req.byte6 = 0;
2732 req.timeout = tmpTimeout;
2733 req.data = devMmap;
2734 ScsiPeripheral_Response resp = {{0}};
2735 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2736 char statusMsg[STATUS_MSG_LEN] = "WriteBytes2 failed ret: ";
2737 AppendIntToString(statusMsg, ret);
2738
2739 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2740 napi_throw_error(env, nullptr, statusMsg);
2741 return nullptr;
2742 }
2743 return nullptr;
2744 }
2745
WriteBytes3(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2746 static napi_value WriteBytes3(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2747 {
2748 ScsiPeripheral_IORequest req;
2749 const uint32_t tmpTimeout = 20000;
2750 req.lbAddress = 0;
2751 req.transferLength = 1;
2752 req.control = 0;
2753 req.byte1 = 0x13;
2754 req.byte6 = 0;
2755 req.timeout = tmpTimeout;
2756 req.data = devMmap;
2757 ScsiPeripheral_Response resp = {{0}};
2758 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2759 char statusMsg[STATUS_MSG_LEN] = "WriteBytes3 failed ret: ";
2760 AppendIntToString(statusMsg, ret);
2761
2762 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2763 napi_throw_error(env, nullptr, statusMsg);
2764 return nullptr;
2765 }
2766 return nullptr;
2767 }
2768
WriteBytes6Check1(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2769 static napi_value WriteBytes6Check1(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2770 {
2771 ScsiPeripheral_IORequest req;
2772 const uint32_t tmpTimeout = 20000;
2773 req.lbAddress = 0;
2774 req.transferLength = 1;
2775 req.control = 0;
2776 req.byte1 = 0;
2777 req.byte6 = 0;
2778 req.timeout = tmpTimeout;
2779 req.data = devMmap;
2780 ScsiPeripheral_Response resp = {{0}};
2781 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2782 char statusMsg[STATUS_MSG_LEN] = "WriteBytes6Check1 failed ret: ";
2783 AppendIntToString(statusMsg, ret);
2784
2785 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2786 napi_throw_error(env, nullptr, statusMsg);
2787 return nullptr;
2788 }
2789 return nullptr;
2790 }
2791
WriteBytes6Check2(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2792 static napi_value WriteBytes6Check2(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2793 {
2794 ScsiPeripheral_IORequest req;
2795 const uint32_t tmpTimeout = 20000;
2796 req.lbAddress = 0;
2797 req.transferLength = 1;
2798 req.control = 0;
2799 req.byte1 = 0;
2800 req.byte6 = UINT8_MAX;
2801 req.timeout = tmpTimeout;
2802 req.data = devMmap;
2803 ScsiPeripheral_Response resp = {{0}};
2804 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2805 char statusMsg[STATUS_MSG_LEN] = "WriteBytes6Check2 failed ret: ";
2806 AppendIntToString(statusMsg, ret);
2807
2808 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2809 napi_throw_error(env, nullptr, statusMsg);
2810 return nullptr;
2811 }
2812 return nullptr;
2813 }
2814
WriteBytes6Check3(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2815 static napi_value WriteBytes6Check3(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2816 {
2817 ScsiPeripheral_IORequest req;
2818 const uint32_t tmpTimeout = 10000;
2819 req.lbAddress = 0;
2820 req.transferLength = 1;
2821 req.control = 0;
2822 req.byte1 = 0;
2823 req.byte6 = 0x13;
2824 req.timeout = tmpTimeout;
2825 req.data = devMmap;
2826 ScsiPeripheral_Response resp = {{0}};
2827 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2828 char statusMsg[STATUS_MSG_LEN] = "WriteBytes6Check3 failed ret: ";
2829 AppendIntToString(statusMsg, ret);
2830
2831 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2832 napi_throw_error(env, nullptr, statusMsg);
2833 return nullptr;
2834 }
2835 return nullptr;
2836 }
2837
WriteBytes6Check4(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2838 static napi_value WriteBytes6Check4(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2839 {
2840 ScsiPeripheral_IORequest req;
2841 const uint32_t tmpTimeout = 10000;
2842 req.lbAddress = UINT32_MAX;
2843 req.transferLength = 0x10;
2844 req.control = 0;
2845 req.byte1 = 0;
2846 req.byte6 = 0x13;
2847 req.timeout = tmpTimeout;
2848 req.data = devMmap;
2849 ScsiPeripheral_Response resp = {{0}};
2850 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2851 char statusMsg[STATUS_MSG_LEN] = "WriteBytes6Check4 failed ret: ";
2852 AppendIntToString(statusMsg, ret);
2853 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2854 napi_throw_error(env, nullptr, statusMsg);
2855 return nullptr;
2856 }
2857
2858 if ((resp.status != SCSIPERIPHERAL_STATUS_GOOD) && (resp.status != SCSIPERIPHERAL_STATUS_CHECK_CONDITION_NEEDED)) {
2859 char statusMsg2[STATUS_MSG_LEN] = "WriteBytes6Check4 Status check condition needed, actual status: ";
2860 AppendIntToString(statusMsg2, resp.status);
2861 napi_throw_error(env, nullptr, statusMsg2);
2862 return nullptr;
2863 }
2864 return nullptr;
2865 }
2866
WriteBytesTrans1(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2867 static napi_value WriteBytesTrans1(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2868 {
2869 ScsiPeripheral_IORequest req;
2870 const uint32_t tmpTimeout = 10000;
2871 req.lbAddress = 0;
2872 req.transferLength = 0;
2873 req.control = 0;
2874 req.byte1 = 0;
2875 req.byte6 = 0x13;
2876 req.timeout = tmpTimeout;
2877 req.data = devMmap;
2878 ScsiPeripheral_Response resp = {{0}};
2879 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2880 char statusMsg[STATUS_MSG_LEN] = "WriteBytesTrans1 failed ret: ";
2881 AppendIntToString(statusMsg, ret);
2882 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2883 napi_throw_error(env, nullptr, statusMsg);
2884 return nullptr;
2885 }
2886 return nullptr;
2887 }
2888
WriteBytesTrans2(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2889 static int32_t WriteBytesTrans2(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2890 {
2891 ScsiPeripheral_IORequest req;
2892 const uint32_t tmpTimeout = 10000;
2893 req.lbAddress = 0;
2894 req.transferLength = UINT16_MAX;
2895 req.control = 0;
2896 req.byte1 = 0;
2897 req.byte6 = 0x13;
2898 req.timeout = tmpTimeout;
2899 req.data = devMmap;
2900 ScsiPeripheral_Response resp = {{0}};
2901 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2902 char statusMsg[STATUS_MSG_LEN] = "WriteBytesTrans2 failed ret: ";
2903 AppendIntToString(statusMsg, ret);
2904 if ((ret != SCSIPERIPHERAL_DDK_IO_ERROR) && (ret != SCSIPERIPHERAL_DDK_SUCCESS)) {
2905 napi_throw_error(env, nullptr, statusMsg);
2906 return ret;
2907 }
2908 return ret;
2909 }
2910
WriteBytesTrans3(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2911 static napi_value WriteBytesTrans3(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2912 {
2913 ScsiPeripheral_IORequest req;
2914 const uint32_t tmpTimeout = 10000;
2915 req.lbAddress = 0;
2916 req.transferLength = 0x10;
2917 req.control = 0;
2918 req.byte1 = 0;
2919 req.byte6 = 0x13;
2920 req.timeout = tmpTimeout;
2921 req.data = devMmap;
2922 ScsiPeripheral_Response resp = {{0}};
2923 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2924 char statusMsg[STATUS_MSG_LEN] = "WriteBytesTrans3 failed ret: ";
2925 AppendIntToString(statusMsg, ret);
2926 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2927 napi_throw_error(env, nullptr, statusMsg);
2928 return nullptr;
2929 }
2930 return nullptr;
2931 }
2932
WriteBytesTrans4(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2933 static napi_value WriteBytesTrans4(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2934 {
2935 ScsiPeripheral_IORequest req;
2936 const uint32_t tmpTimeout = 10000;
2937 req.lbAddress = 0;
2938 req.transferLength = 0x10;
2939 req.control = UINT8_MAX;
2940 req.byte1 = 0;
2941 req.byte6 = 0x13;
2942 req.timeout = tmpTimeout;
2943 req.data = devMmap;
2944 ScsiPeripheral_Response resp = {{0}};
2945 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2946 char statusMsg[STATUS_MSG_LEN] = "WriteBytesTrans4 failed ret: ";
2947 AppendIntToString(statusMsg, ret);
2948 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2949 napi_throw_error(env, nullptr, statusMsg);
2950 return nullptr;
2951 }
2952 return nullptr;
2953 }
2954
WriteBytesTrans5(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMmap)2955 static napi_value WriteBytesTrans5(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMmap)
2956 {
2957 ScsiPeripheral_IORequest req;
2958 const uint32_t tmpTimeout = 10000;
2959 const uint32_t control = 100;
2960 req.lbAddress = 0;
2961 req.transferLength = 0x10;
2962 req.control = control;
2963 req.byte1 = 0;
2964 req.byte6 = 0x13;
2965 req.timeout = tmpTimeout;
2966 req.data = devMmap;
2967 ScsiPeripheral_Response resp = {{0}};
2968 int32_t ret = OH_ScsiPeripheral_Write10(device, &req, &resp);
2969 char statusMsg[STATUS_MSG_LEN] = "WriteBytesTrans5 failed ret: ";
2970 AppendIntToString(statusMsg, ret);
2971 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
2972 napi_throw_error(env, nullptr, statusMsg);
2973 return nullptr;
2974 }
2975 return nullptr;
2976 }
2977
ScsiPeripheralWriteFour(napi_env env,napi_callback_info info)2978 static napi_value ScsiPeripheralWriteFour(napi_env env, napi_callback_info info)
2979 {
2980 int32_t ret = OH_ScsiPeripheral_Init();
2981 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
2982 uint64_t deviceId = GetDeviceId(env, info);
2983 ScsiPeripheral_Device *device = nullptr;
2984 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
2985 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
2986
2987 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
2988 ret = OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE_50K, &devMmap);
2989 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
2990 WriteBytes1(env, device, devMmap);
2991 WriteBytes2(env, device, devMmap);
2992 WriteBytes3(env, device, devMmap);
2993 WriteBytes6Check1(env, device, devMmap);
2994 WriteBytes6Check2(env, device, devMmap);
2995 WriteBytes6Check3(env, device, devMmap);
2996 WriteBytes6Check4(env, device, devMmap);
2997 WriteBytesTrans1(env, device, devMmap);
2998 WriteBytesTrans3(env, device, devMmap);
2999 WriteBytesTrans4(env, device, devMmap);
3000 WriteBytesTrans5(env, device, devMmap);
3001 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
3002
3003 OH_ScsiPeripheral_Close(&device);
3004 OH_ScsiPeripheral_Release();
3005
3006 napi_value result = nullptr;
3007 napi_status status = napi_create_int32(env, ret, &result);
3008 NAPI_CALL(env, status);
3009 return result;
3010 }
3011
CheckCDB1(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMemMap)3012 static int32_t CheckCDB1(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMemMap)
3013 {
3014 ScsiPeripheral_Request request;
3015 request.cdbLength = 0;
3016 const uint8_t tmpCommand = 28;
3017 const int32_t tmpDataDirection = 1;
3018 request.commandDescriptorBlock[0] = tmpCommand;
3019 request.commandDescriptorBlock[ONE_BYTE] = 0;
3020 request.commandDescriptorBlock[TWO_BYTE] = 0;
3021 request.commandDescriptorBlock[THREE_BYTE] = 0;
3022 request.commandDescriptorBlock[FOUR_BYTE] = 0;
3023 request.commandDescriptorBlock[FIVE_BYTE] = 0;
3024 request.commandDescriptorBlock[SIX_BYTE] = 0;
3025 request.commandDescriptorBlock[SEVEN_BYTE] = 0;
3026 request.commandDescriptorBlock[EIGHT_BYTE] = 1;
3027 request.commandDescriptorBlock[NINE_BYTE] = 0;
3028 request.dataTransferDirection = tmpDataDirection;
3029 request.timeout = TIMEOUT;
3030 request.data = devMemMap;
3031 ScsiPeripheral_Response response = {{0}};
3032 int32_t ret = OH_ScsiPeripheral_SendRequestByCdb(device, &request, &response);
3033 char statusMsg[STATUS_MSG_LEN] = "CheckCDB1 failed ret: ";
3034 AppendIntToString(statusMsg, ret);
3035
3036 if (ret != SCSIPERIPHERAL_DDK_INVALID_PARAMETER) {
3037 napi_throw_error(env, nullptr, statusMsg);
3038 return ret;
3039 }
3040 return ret;
3041 }
3042
ScsiPeripheralWriteFour1(napi_env env,napi_callback_info info)3043 static napi_value ScsiPeripheralWriteFour1(napi_env env, napi_callback_info info)
3044 {
3045 int32_t ret = OH_ScsiPeripheral_Init();
3046 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3047 uint64_t deviceId = GetDeviceId(env, info);
3048 ScsiPeripheral_Device *device = nullptr;
3049 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
3050 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
3051
3052 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
3053 OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE, &devMmap);
3054 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3055 ret = CheckCDB1(env, device, devMmap);
3056
3057 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
3058 OH_ScsiPeripheral_Close(&device);
3059 OH_ScsiPeripheral_Release();
3060
3061 napi_value result = nullptr;
3062 napi_status status = napi_create_int32(env, ret, &result);
3063 NAPI_CALL(env, status);
3064 return result;
3065 }
3066
ScsiPeripheralWriteFive(napi_env env,napi_callback_info info)3067 static napi_value ScsiPeripheralWriteFive(napi_env env, napi_callback_info info)
3068 {
3069 int32_t ret = OH_ScsiPeripheral_Init();
3070 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3071 uint64_t deviceId = GetDeviceId(env, info);
3072 ScsiPeripheral_Device *device = nullptr;
3073 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
3074 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
3075
3076 ScsiPeripheral_DeviceMemMap *devMmap = nullptr;
3077 OH_ScsiPeripheral_CreateDeviceMemMap(device, DEVICE_MEM_MAP_SIZE_128M, &devMmap);
3078 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3079 ret = WriteBytesTrans2(env, device, devMmap);
3080
3081 OH_ScsiPeripheral_DestroyDeviceMemMap(devMmap);
3082 OH_ScsiPeripheral_Close(&device);
3083 OH_ScsiPeripheral_Release();
3084
3085 napi_value result = nullptr;
3086 napi_status status = napi_create_int32(env, ret, &result);
3087 NAPI_CALL(env, status);
3088 return result;
3089 }
3090
ScsiPeripheralVerifyOne(napi_env env,napi_callback_info info)3091 static napi_value ScsiPeripheralVerifyOne(napi_env env, napi_callback_info info)
3092 {
3093 ScsiPeripheral_Device *device = nullptr;
3094 ScsiPeripheral_VerifyRequest req;
3095 ScsiPeripheral_Response resp = {{0}};
3096 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3097 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_Verify10 failed");
3098
3099 napi_value result = nullptr;
3100 napi_status status = napi_create_int32(env, ret, &result);
3101 NAPI_CALL(env, status);
3102 return result;
3103 }
3104
ScsiPeripheralVerifyTwo(napi_env env,napi_callback_info info)3105 static napi_value ScsiPeripheralVerifyTwo(napi_env env, napi_callback_info info)
3106 {
3107 int32_t ret = OH_ScsiPeripheral_Init();
3108 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3109
3110 ScsiPeripheral_VerifyRequest req = {0};
3111 ScsiPeripheral_Response resp = {{0}};
3112 ret = OH_ScsiPeripheral_Verify10(nullptr, &req, &resp);
3113 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Verify10 failed");
3114
3115 ScsiPeripheral_Device *dev = NewScsiPeripheralDevice();
3116 ret = OH_ScsiPeripheral_Verify10(dev, nullptr, &resp);
3117 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Verify10 failed");
3118
3119 ret = OH_ScsiPeripheral_Verify10(dev, &req, nullptr);
3120 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_Verify10 failed");
3121
3122 DeleteScsiPeripheralDevice(&dev);
3123 OH_ScsiPeripheral_Release();
3124
3125 napi_value result = nullptr;
3126 napi_status status = napi_create_int32(env, ret, &result);
3127 NAPI_CALL(env, status);
3128 return result;
3129 }
3130
Verify0(napi_env env,ScsiPeripheral_Device * device)3131 static napi_value Verify0(napi_env env, ScsiPeripheral_Device *device)
3132 {
3133 ScsiPeripheral_VerifyRequest req;
3134 req.timeout = TIMEOUT;
3135 ScsiPeripheral_Response resp = {{0}};
3136 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3137
3138 char statusMsg[STATUS_MSG_LEN] = "Verify0 failed ret: ";
3139 AppendIntToString(statusMsg, ret);
3140 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3141 napi_throw_error(env, nullptr, statusMsg);
3142 return nullptr;
3143 }
3144 return nullptr;
3145 }
3146
Verify1(napi_env env,ScsiPeripheral_Device * device)3147 static napi_value Verify1(napi_env env, ScsiPeripheral_Device *device)
3148 {
3149 ScsiPeripheral_VerifyRequest req;
3150 req.lbAddress = 0;
3151 req.timeout = TIMEOUT;
3152 ScsiPeripheral_Response resp = {{0}};
3153 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3154
3155 char statusMsg[STATUS_MSG_LEN] = "Verify1 failed ret: ";
3156 AppendIntToString(statusMsg, ret);
3157 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3158 napi_throw_error(env, nullptr, statusMsg);
3159 return nullptr;
3160 }
3161 return nullptr;
3162 }
3163
Verify2(napi_env env,ScsiPeripheral_Device * device)3164 static napi_value Verify2(napi_env env, ScsiPeripheral_Device *device)
3165 {
3166 ScsiPeripheral_VerifyRequest req;
3167 req.lbAddress = UINT32_MAX;
3168 req.timeout = TIMEOUT;
3169 ScsiPeripheral_Response resp = {{0}};
3170 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3171 char statusMsg[STATUS_MSG_LEN] = "Verify2 failed ret: ";
3172 AppendIntToString(statusMsg, ret);
3173 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3174 napi_throw_error(env, nullptr, statusMsg);
3175 return nullptr;
3176 }
3177 if ((resp.status != SCSIPERIPHERAL_STATUS_GOOD) && (resp.status != SCSIPERIPHERAL_STATUS_CHECK_CONDITION_NEEDED)) {
3178 char statusMsg2[STATUS_MSG_LEN] = "Verify2 Status check condition needed, actual status: ";
3179 AppendIntToString(statusMsg2, resp.status);
3180 napi_throw_error(env, nullptr, statusMsg2);
3181 return nullptr;
3182 }
3183 return nullptr;
3184 }
3185
Verify3(napi_env env,ScsiPeripheral_Device * device)3186 static napi_value Verify3(napi_env env, ScsiPeripheral_Device *device)
3187 {
3188 ScsiPeripheral_VerifyRequest req;
3189 req.verificationLength = 0;
3190 req.timeout = TIMEOUT;
3191 ScsiPeripheral_Response resp = {{0}};
3192 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3193 char statusMsg[STATUS_MSG_LEN] = "Verify3 failed ret: ";
3194 AppendIntToString(statusMsg, ret);
3195 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3196 napi_throw_error(env, nullptr, statusMsg);
3197 return nullptr;
3198 }
3199 return nullptr;
3200 }
3201
Verify4(napi_env env,ScsiPeripheral_Device * device)3202 static napi_value Verify4(napi_env env, ScsiPeripheral_Device *device)
3203 {
3204 ScsiPeripheral_VerifyRequest req;
3205 req.verificationLength = 0;
3206 req.timeout = TIMEOUT;
3207 ScsiPeripheral_Response resp = {{0}};
3208 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3209 char statusMsg[STATUS_MSG_LEN] = "Verify4 failed ret: ";
3210 AppendIntToString(statusMsg, ret);
3211 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3212 napi_throw_error(env, nullptr, statusMsg);
3213 return nullptr;
3214 }
3215 return nullptr;
3216 }
3217
Verify5(napi_env env,ScsiPeripheral_Device * device)3218 static napi_value Verify5(napi_env env, ScsiPeripheral_Device *device)
3219 {
3220 ScsiPeripheral_VerifyRequest req;
3221 req.verificationLength = 0x16;
3222 req.timeout = TIMEOUT;
3223 ScsiPeripheral_Response resp = {{0}};
3224 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3225 char statusMsg[STATUS_MSG_LEN] = "Verify5 failed ret: ";
3226 AppendIntToString(statusMsg, ret);
3227 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3228 napi_throw_error(env, nullptr, statusMsg);
3229 return nullptr;
3230 }
3231 return nullptr;
3232 }
3233
Verify6(napi_env env,ScsiPeripheral_Device * device)3234 static napi_value Verify6(napi_env env, ScsiPeripheral_Device *device)
3235 {
3236 ScsiPeripheral_VerifyRequest req;
3237 req.control = 0;
3238 req.timeout = TIMEOUT;
3239 ScsiPeripheral_Response resp = {{0}};
3240 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3241 char statusMsg[STATUS_MSG_LEN] = "Verify6 failed ret: ";
3242 AppendIntToString(statusMsg, ret);
3243 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3244 napi_throw_error(env, nullptr, statusMsg);
3245 return nullptr;
3246 }
3247 return nullptr;
3248 }
3249
Verify7(napi_env env,ScsiPeripheral_Device * device)3250 static napi_value Verify7(napi_env env, ScsiPeripheral_Device *device)
3251 {
3252 ScsiPeripheral_VerifyRequest req;
3253 req.control = UINT8_MAX;
3254 req.timeout = TIMEOUT;
3255 ScsiPeripheral_Response resp = {{0}};
3256 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3257 char statusMsg[STATUS_MSG_LEN] = "Verify7 failed ret: ";
3258 AppendIntToString(statusMsg, ret);
3259 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3260 napi_throw_error(env, nullptr, statusMsg);
3261 return nullptr;
3262 }
3263 return nullptr;
3264 }
3265
Verify8(napi_env env,ScsiPeripheral_Device * device)3266 static napi_value Verify8(napi_env env, ScsiPeripheral_Device *device)
3267 {
3268 ScsiPeripheral_VerifyRequest req;
3269 req.control = 0x64;
3270 req.timeout = TIMEOUT;
3271 ScsiPeripheral_Response resp = {{0}};
3272 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3273 char statusMsg[STATUS_MSG_LEN] = "Verify8 failed ret: ";
3274 AppendIntToString(statusMsg, ret);
3275 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3276 napi_throw_error(env, nullptr, statusMsg);
3277 return nullptr;
3278 }
3279 return nullptr;
3280 }
3281
Verify9(napi_env env,ScsiPeripheral_Device * device)3282 static napi_value Verify9(napi_env env, ScsiPeripheral_Device *device)
3283 {
3284 ScsiPeripheral_VerifyRequest req;
3285 req.byte1 = 0;
3286 req.timeout = TIMEOUT;
3287 ScsiPeripheral_Response resp = {{0}};
3288 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3289 char statusMsg[STATUS_MSG_LEN] = "Verify9 failed ret: ";
3290 AppendIntToString(statusMsg, ret);
3291 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3292 napi_throw_error(env, nullptr, statusMsg);
3293 return nullptr;
3294 }
3295 return nullptr;
3296 }
3297
Verify10(napi_env env,ScsiPeripheral_Device * device)3298 static napi_value Verify10(napi_env env, ScsiPeripheral_Device *device)
3299 {
3300 ScsiPeripheral_VerifyRequest req;
3301 req.byte1 = UINT8_MAX;
3302 req.timeout = TIMEOUT;
3303 ScsiPeripheral_Response resp = {{0}};
3304 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3305 char statusMsg[STATUS_MSG_LEN] = "Verify10 failed ret: ";
3306 AppendIntToString(statusMsg, ret);
3307 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3308 napi_throw_error(env, nullptr, statusMsg);
3309 return nullptr;
3310 }
3311 return nullptr;
3312 }
3313
Verify11(napi_env env,ScsiPeripheral_Device * device)3314 static napi_value Verify11(napi_env env, ScsiPeripheral_Device *device)
3315 {
3316 ScsiPeripheral_VerifyRequest req;
3317 req.byte1 = 0x88;
3318 req.timeout = TIMEOUT;
3319 ScsiPeripheral_Response resp = {{0}};
3320 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3321 char statusMsg[STATUS_MSG_LEN] = "Verify11 failed ret: ";
3322 AppendIntToString(statusMsg, ret);
3323 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3324 napi_throw_error(env, nullptr, statusMsg);
3325 return nullptr;
3326 }
3327 return nullptr;
3328 }
3329
Verify12(napi_env env,ScsiPeripheral_Device * device)3330 static napi_value Verify12(napi_env env, ScsiPeripheral_Device *device)
3331 {
3332 ScsiPeripheral_VerifyRequest req;
3333 req.byte6 = 0;
3334 req.timeout = TIMEOUT;
3335 ScsiPeripheral_Response resp = {{0}};
3336 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3337 char statusMsg[STATUS_MSG_LEN] = "Verify12 failed ret: ";
3338 AppendIntToString(statusMsg, ret);
3339 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3340 napi_throw_error(env, nullptr, statusMsg);
3341 return nullptr;
3342 }
3343 return nullptr;
3344 }
3345
Verify13(napi_env env,ScsiPeripheral_Device * device)3346 static napi_value Verify13(napi_env env, ScsiPeripheral_Device *device)
3347 {
3348 ScsiPeripheral_VerifyRequest req;
3349 req.byte6 = UINT8_MAX;
3350 req.timeout = TIMEOUT;
3351 ScsiPeripheral_Response resp = {{0}};
3352 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3353 char statusMsg[STATUS_MSG_LEN] = "Verify13 failed ret: ";
3354 AppendIntToString(statusMsg, ret);
3355 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3356 napi_throw_error(env, nullptr, statusMsg);
3357 return nullptr;
3358 }
3359 return nullptr;
3360 }
3361
Verify14(napi_env env,ScsiPeripheral_Device * device)3362 static napi_value Verify14(napi_env env, ScsiPeripheral_Device *device)
3363 {
3364 ScsiPeripheral_VerifyRequest req;
3365 req.byte6 = 0x88;
3366 req.timeout = TIMEOUT;
3367 ScsiPeripheral_Response resp = {{0}};
3368 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3369 char statusMsg[STATUS_MSG_LEN] = "Verify14 failed ret: ";
3370 AppendIntToString(statusMsg, ret);
3371 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3372 napi_throw_error(env, nullptr, statusMsg);
3373 return nullptr;
3374 }
3375 return nullptr;
3376 }
3377
Verify15(napi_env env,ScsiPeripheral_Device * device)3378 static napi_value Verify15(napi_env env, ScsiPeripheral_Device *device)
3379 {
3380 ScsiPeripheral_VerifyRequest req;
3381 req.timeout = UINT32_MAX;
3382 ScsiPeripheral_Response resp = {{0}};
3383 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3384 char statusMsg[STATUS_MSG_LEN] = "Verify15 failed ret: ";
3385 AppendIntToString(statusMsg, ret);
3386 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3387 napi_throw_error(env, nullptr, statusMsg);
3388 return nullptr;
3389 }
3390 return nullptr;
3391 }
3392
Verify16(napi_env env,ScsiPeripheral_Device * device)3393 static napi_value Verify16(napi_env env, ScsiPeripheral_Device *device)
3394 {
3395 ScsiPeripheral_VerifyRequest req;
3396 req.timeout = 0x10;
3397 ScsiPeripheral_Response resp = {{0}};
3398 int32_t ret = OH_ScsiPeripheral_Verify10(device, &req, &resp);
3399 char statusMsg[STATUS_MSG_LEN] = "Verify16 failed ret: ";
3400 AppendIntToString(statusMsg, ret);
3401 if (ret != SCSIPERIPHERAL_DDK_SUCCESS) {
3402 napi_throw_error(env, nullptr, statusMsg);
3403 return nullptr;
3404 }
3405 return nullptr;
3406 }
3407
ScsiPeripheralVerifyThree(napi_env env,napi_callback_info info)3408 static napi_value ScsiPeripheralVerifyThree(napi_env env, napi_callback_info info)
3409 {
3410 int32_t ret = OH_ScsiPeripheral_Init();
3411 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3412 uint64_t deviceId = GetDeviceId(env, info);
3413 ScsiPeripheral_Device *device = nullptr;
3414 ret = OH_ScsiPeripheral_Open(deviceId, 0, &device);
3415 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
3416
3417 Verify0(env, device);
3418 Verify1(env, device);
3419 Verify2(env, device);
3420 Verify3(env, device);
3421 Verify4(env, device);
3422 Verify5(env, device);
3423 Verify6(env, device);
3424 Verify7(env, device);
3425 Verify8(env, device);
3426 Verify9(env, device);
3427 Verify10(env, device);
3428 Verify11(env, device);
3429 Verify12(env, device);
3430 Verify13(env, device);
3431 Verify14(env, device);
3432 Verify15(env, device);
3433 Verify16(env, device);
3434 OH_ScsiPeripheral_Close(&device);
3435 OH_ScsiPeripheral_Release();
3436
3437 napi_value result = nullptr;
3438 napi_status status = napi_create_int32(env, ret, &result);
3439 NAPI_CALL(env, status);
3440 return result;
3441 }
3442
ScsiPeripheralSendRequestByCDBOne(napi_env env,napi_callback_info info)3443 static napi_value ScsiPeripheralSendRequestByCDBOne(napi_env env, napi_callback_info info)
3444 {
3445 size_t argc = PARAM_1;
3446 napi_value args[PARAM_1] = {nullptr};
3447 NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
3448
3449 ScsiPeripheral_Device *dev = NewScsiPeripheralDevice();
3450 ScsiPeripheral_Request request = {{0}};
3451 ScsiPeripheral_Response response = {{0}};
3452 int32_t ret = OH_ScsiPeripheral_SendRequestByCdb(dev, &request, &response);
3453 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INIT_ERROR, "OH_ScsiPeripheral_SendRequestByCdb failed");
3454 DeleteScsiPeripheralDevice(&dev);
3455 napi_value result = nullptr;
3456 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3457 return result;
3458 }
3459
ScsiPeripheralSendRequestByCDBTwo(napi_env env,napi_callback_info info)3460 static napi_value ScsiPeripheralSendRequestByCDBTwo(napi_env env, napi_callback_info info)
3461 {
3462 int32_t ret = OH_ScsiPeripheral_Init();
3463 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3464
3465 ScsiPeripheral_Request request = {{0}};
3466 ScsiPeripheral_Response response = {{0}};
3467 ret = OH_ScsiPeripheral_SendRequestByCdb(nullptr, &request, &response);
3468 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER, "OH_ScsiPeripheral_SendRequestByCdb failed");
3469
3470 OH_ScsiPeripheral_Release();
3471
3472 napi_value result = nullptr;
3473 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3474 return result;
3475 }
3476
ScsiPeripheralSendRequestByCDBThree(napi_env env,napi_callback_info info)3477 static napi_value ScsiPeripheralSendRequestByCDBThree(napi_env env, napi_callback_info info)
3478 {
3479 int32_t ret = OH_ScsiPeripheral_Init();
3480 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3481
3482 uint64_t deviceId = GetDeviceId(env, info);
3483 ScsiPeripheral_Device *dev = nullptr;
3484 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev);
3485 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
3486
3487 ScsiPeripheral_DeviceMemMap *devMemMap = nullptr;
3488 ret = OH_ScsiPeripheral_CreateDeviceMemMap(dev, DEVICE_MEM_MAP_SIZE, &devMemMap);
3489 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3490
3491 ScsiPeripheral_Request request = {{0}};
3492 request.cdbLength = CDB_LENGTH_TEN;
3493 const uint8_t tmpCommand = 28;
3494 const int32_t tmpDataDirection = -3;
3495 constexpr uint32_t tmpTimeout = 10;
3496 request.commandDescriptorBlock[0] = tmpCommand;
3497 request.commandDescriptorBlock[ONE_BYTE] = 0;
3498 request.commandDescriptorBlock[TWO_BYTE] = 0;
3499 request.commandDescriptorBlock[THREE_BYTE] = 0;
3500 request.commandDescriptorBlock[FOUR_BYTE] = 0;
3501 request.commandDescriptorBlock[FIVE_BYTE] = 0;
3502 request.commandDescriptorBlock[SIX_BYTE] = 0;
3503 request.commandDescriptorBlock[SEVEN_BYTE] = 0;
3504 request.commandDescriptorBlock[EIGHT_BYTE] = 1;
3505 request.commandDescriptorBlock[NINE_BYTE] = 0;
3506 request.dataTransferDirection = tmpDataDirection;
3507 request.timeout = tmpTimeout;
3508 request.data = devMemMap;
3509 ScsiPeripheral_Response response = {{0}};
3510 ret = OH_ScsiPeripheral_SendRequestByCdb(dev, &request, &response);
3511 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_SendRequestByCdb failed");
3512
3513 OH_ScsiPeripheral_DestroyDeviceMemMap(devMemMap);
3514 OH_ScsiPeripheral_Close(&dev);
3515 OH_ScsiPeripheral_Release();
3516
3517 napi_value result = nullptr;
3518 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3519 return result;
3520 }
3521
CheckCDB2(napi_env env,ScsiPeripheral_Device * device,ScsiPeripheral_DeviceMemMap * devMemMap)3522 static int32_t CheckCDB2(napi_env env, ScsiPeripheral_Device *device, ScsiPeripheral_DeviceMemMap *devMemMap)
3523 {
3524 ScsiPeripheral_Request request = {{0}};
3525 request.cdbLength = UINT8_MAX;
3526 const uint8_t tmpCommand = 28;
3527 const int32_t tmpDataDirection = 2;
3528 request.commandDescriptorBlock[0] = tmpCommand;
3529 request.commandDescriptorBlock[ONE_BYTE] = 0;
3530 request.commandDescriptorBlock[TWO_BYTE] = 0;
3531 request.commandDescriptorBlock[THREE_BYTE] = 0;
3532 request.commandDescriptorBlock[FOUR_BYTE] = 0;
3533 request.commandDescriptorBlock[FIVE_BYTE] = 0;
3534 request.commandDescriptorBlock[SIX_BYTE] = 0;
3535 request.commandDescriptorBlock[SEVEN_BYTE] = 0;
3536 request.commandDescriptorBlock[EIGHT_BYTE] = 1;
3537 request.commandDescriptorBlock[NINE_BYTE] = 0;
3538 request.dataTransferDirection = tmpDataDirection;
3539 request.timeout = TIMEOUT;
3540 request.data = devMemMap;
3541 ScsiPeripheral_Response response = {{0}};
3542 int32_t ret = OH_ScsiPeripheral_SendRequestByCdb(device, &request, &response);
3543 char statusMsg[STATUS_MSG_LEN] = "CheckCDB2 failed ret: ";
3544 AppendIntToString(statusMsg, ret);
3545 if (ret != SCSIPERIPHERAL_DDK_IO_ERROR) {
3546 napi_throw_error(env, nullptr, statusMsg);
3547 return ret;
3548 }
3549 return ret;
3550 }
3551
ScsiPeripheralSendRequestByCDBFour(napi_env env,napi_callback_info info)3552 static napi_value ScsiPeripheralSendRequestByCDBFour(napi_env env, napi_callback_info info)
3553 {
3554 int32_t ret = OH_ScsiPeripheral_Init();
3555 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3556
3557 uint64_t deviceId = GetDeviceId(env, info);
3558 ScsiPeripheral_Device *dev = nullptr;
3559 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev);
3560 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
3561
3562 ScsiPeripheral_DeviceMemMap *devMemMap = nullptr;
3563 ret = OH_ScsiPeripheral_CreateDeviceMemMap(dev, DEVICE_MEM_MAP_SIZE, &devMemMap);
3564 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3565
3566 ret = CheckCDB1(env, dev, devMemMap);
3567 ret = CheckCDB2(env, dev, devMemMap);
3568
3569 OH_ScsiPeripheral_DestroyDeviceMemMap(devMemMap);
3570 OH_ScsiPeripheral_Close(&dev);
3571 OH_ScsiPeripheral_Release();
3572
3573 napi_value result = nullptr;
3574 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3575 return result;
3576 }
3577
ScsiPeripheralCreateDeviceMemMapOne(napi_env env,napi_callback_info info)3578 static napi_value ScsiPeripheralCreateDeviceMemMapOne(napi_env env, napi_callback_info info)
3579 {
3580 int32_t ret = OH_ScsiPeripheral_Init();
3581 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3582
3583 ScsiPeripheral_DeviceMemMap *devMemMap = nullptr;
3584 ret = OH_ScsiPeripheral_CreateDeviceMemMap(nullptr, DEVICE_MEM_MAP_SIZE, &devMemMap);
3585 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3586 "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3587
3588 ScsiPeripheral_Device *dev = NewScsiPeripheralDevice();
3589 ret = OH_ScsiPeripheral_CreateDeviceMemMap(dev, DEVICE_MEM_MAP_SIZE, nullptr);
3590 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3591 "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3592
3593 ret = OH_ScsiPeripheral_CreateDeviceMemMap(dev, DEVICE_MEM_MAP_SIZE, &devMemMap);
3594 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3595 "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3596 OH_ScsiPeripheral_DestroyDeviceMemMap(devMemMap);
3597 DeleteScsiPeripheralDevice(&dev);
3598 OH_ScsiPeripheral_Release();
3599
3600 napi_value result = nullptr;
3601 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3602 return result;
3603 }
3604
ScsiPeripheralCreateDeviceMemMapTwo(napi_env env,napi_callback_info info)3605 static napi_value ScsiPeripheralCreateDeviceMemMapTwo(napi_env env, napi_callback_info info)
3606 {
3607 int32_t ret = OH_ScsiPeripheral_Init();
3608 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3609
3610 uint64_t deviceId = GetDeviceId(env, info);
3611 ScsiPeripheral_Device *dev;
3612 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev);
3613 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
3614
3615 ScsiPeripheral_DeviceMemMap *devMemMap = nullptr;
3616 ret = OH_ScsiPeripheral_CreateDeviceMemMap(dev, MAX_MEM_LEN, &devMemMap);
3617 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3618 "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3619
3620 ret = OH_ScsiPeripheral_DestroyDeviceMemMap(devMemMap);
3621 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3622 "OH_ScsiPeripheral_DestroyDeviceMemMap failed");
3623 OH_ScsiPeripheral_Close(&dev);
3624 ret = OH_ScsiPeripheral_Release();
3625 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Release failed");
3626
3627 napi_value result = nullptr;
3628 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3629 return result;
3630 }
3631
CheckMemory1(napi_env env,ScsiPeripheral_Device * dev)3632 static int32_t CheckMemory1(napi_env env, ScsiPeripheral_Device *dev)
3633 {
3634 ScsiPeripheral_DeviceMemMap *devMemMap = nullptr;
3635 size_t memSize = 0;
3636 int32_t ret = OH_ScsiPeripheral_CreateDeviceMemMap(dev, memSize, &devMemMap);
3637
3638 char statusMsg[STATUS_MSG_LEN] = "CheckMemory1 failed ret: ";
3639 AppendIntToString(statusMsg, ret);
3640 OH_ScsiPeripheral_DestroyDeviceMemMap(devMemMap);
3641 if (ret != SCSIPERIPHERAL_DDK_MEMORY_ERROR) {
3642 napi_throw_error(env, nullptr, statusMsg);
3643 return ret;
3644 }
3645
3646 return ret;
3647 }
3648
ScsiPeripheralCreateDeviceMemMapThree(napi_env env,napi_callback_info info)3649 static napi_value ScsiPeripheralCreateDeviceMemMapThree(napi_env env, napi_callback_info info)
3650 {
3651 int32_t ret = OH_ScsiPeripheral_Init();
3652 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3653
3654 uint64_t deviceId = GetDeviceId(env, info);
3655 ScsiPeripheral_Device *dev;
3656 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev);
3657 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Open failed");
3658
3659 ret = CheckMemory1(env, dev);
3660
3661 OH_ScsiPeripheral_Close(&dev);
3662 OH_ScsiPeripheral_Release();
3663
3664 napi_value result = nullptr;
3665 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3666 return result;
3667 }
3668
ScsiPeripheralDestroyDeviceMemMapOne(napi_env env,napi_callback_info info)3669 static napi_value ScsiPeripheralDestroyDeviceMemMapOne(napi_env env, napi_callback_info info)
3670 {
3671 int32_t ret = OH_ScsiPeripheral_DestroyDeviceMemMap(nullptr);
3672 napi_value result = nullptr;
3673 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3674 return result;
3675 }
3676
ScsiPeripheralDestroyDeviceMemMapTwo(napi_env env,napi_callback_info info)3677 static napi_value ScsiPeripheralDestroyDeviceMemMapTwo(napi_env env, napi_callback_info info)
3678 {
3679 int32_t ret = OH_ScsiPeripheral_Init();
3680 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS, "OH_ScsiPeripheral_Init failed");
3681
3682 uint64_t deviceId = GetDeviceId(env, info);
3683 ScsiPeripheral_Device *dev = nullptr;
3684 ret = OH_ScsiPeripheral_Open(deviceId, 0, &dev);
3685
3686 ScsiPeripheral_DeviceMemMap *devMemMap = nullptr;
3687 OH_ScsiPeripheral_CreateDeviceMemMap(dev, DEVICE_MEM_MAP_SIZE, &devMemMap);
3688 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3689 "OH_ScsiPeripheral_CreateDeviceMemMap failed");
3690
3691 ret = OH_ScsiPeripheral_DestroyDeviceMemMap(devMemMap);
3692 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3693 "OH_ScsiPeripheral_DestroyDeviceMemMap failed");
3694
3695 OH_ScsiPeripheral_Close(&dev);
3696 OH_ScsiPeripheral_Release();
3697
3698 napi_value result = nullptr;
3699 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3700 return result;
3701 }
3702
ScsiPeripheralParseBasicSenseInfoOne(napi_env env,napi_callback_info info)3703 static napi_value ScsiPeripheralParseBasicSenseInfoOne(napi_env env, napi_callback_info info)
3704 {
3705 uint8_t senseData[SCSIPERIPHERAL_MAX_SENSE_DATA_LEN] = {0x00};
3706 ScsiPeripheral_BasicSenseInfo senseInfo = {0};
3707 int32_t ret = OH_ScsiPeripheral_ParseBasicSenseInfo(nullptr, sizeof(senseData), &senseInfo);
3708 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3709 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3710
3711 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, 0, &senseInfo);
3712 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3713 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3714
3715 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), nullptr);
3716 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3717 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3718
3719 uint8_t tmpLen = 0;
3720 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, tmpLen, &senseInfo);
3721 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3722 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3723
3724 tmpLen = UINT8_MAX;
3725 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, tmpLen, &senseInfo);
3726 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_INVALID_PARAMETER,
3727 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3728
3729 napi_value result = nullptr;
3730 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3731 return result;
3732 }
3733
ScsiPeripheralParseBasicSenseInfoTwo(napi_env env,napi_callback_info info)3734 static napi_value ScsiPeripheralParseBasicSenseInfoTwo(napi_env env, napi_callback_info info)
3735 {
3736 uint8_t senseData[SCSIPERIPHERAL_MAX_SENSE_DATA_LEN] = {0x00};
3737 senseData[0] = 0x70 | 0x80;
3738 ScsiPeripheral_BasicSenseInfo senseInfo = {0};
3739 int32_t ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), &senseInfo);
3740 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3741 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3742
3743 senseData[0] = 0x71 | 0x80;
3744 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), &senseInfo);
3745 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3746 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3747
3748 senseData[0] = 0x72;
3749 senseData[SEVEN_BYTE] = THIRTYTWO_BIT;
3750 senseData[EIGHT_BYTE] = 0x00;
3751 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), &senseInfo);
3752 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3753 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3754
3755 senseData[0] = 0x73;
3756 senseData[SEVEN_BYTE] = THIRTYTWO_BIT;
3757 senseData[EIGHT_BYTE] = 0x00;
3758 senseData[NINE_BYTE] = 0x0A;
3759 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), &senseInfo);
3760 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3761 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3762
3763 senseData[0] = 0x73;
3764 senseData[SEVEN_BYTE] = THIRTYTWO_BIT;
3765 senseData[EIGHT_BYTE] = 0x01;
3766 senseData[NINE_BYTE] = 0x0A;
3767 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), &senseInfo);
3768 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3769 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3770
3771 senseData[0] = 0x73;
3772 senseData[SEVEN_BYTE] = THIRTYTWO_BIT;
3773 senseData[EIGHT_BYTE] = 0x02;
3774 senseData[NINE_BYTE] = 0x06;
3775 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), &senseInfo);
3776 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3777 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3778
3779 senseData[0] = 0x73;
3780 senseData[SEVEN_BYTE] = THIRTYTWO_BIT;
3781 senseData[EIGHT_BYTE] = 0x02;
3782 senseData[NINE_BYTE] = THIRTYTWO_BIT;
3783 ret = OH_ScsiPeripheral_ParseBasicSenseInfo(senseData, sizeof(senseData), &senseInfo);
3784 NAPI_ASSERT(env, ret == SCSIPERIPHERAL_DDK_SUCCESS,
3785 "OH_ScsiPeripheral_ParseBasicSenseInfo failed");
3786
3787 napi_value result = nullptr;
3788 NAPI_CALL(env, napi_create_int32(env, ret, &result));
3789 return result;
3790 }
3791
GetDevicedId(napi_env env,napi_callback_info info)3792 static uint64_t GetDevicedId(napi_env env, napi_callback_info info)
3793 {
3794 size_t argc = PARM_1;
3795 napi_value args[PARM_1];
3796 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
3797
3798 int64_t tmpDeviceId;
3799 napi_get_value_int64(env, args[0], &tmpDeviceId);
3800 uint64_t deviceId = static_cast<uint64_t>(tmpDeviceId);
3801 return deviceId;
3802 }
3803
OpenUsbSerial(uint64_t deviceId,UsbSerial_Device ** deviceHandle)3804 static int32_t OpenUsbSerial(uint64_t deviceId, UsbSerial_Device **deviceHandle)
3805 {
3806 int32_t returnValue = OH_UsbSerial_Open(deviceId, 0, deviceHandle);
3807 if (returnValue != USB_SERIAL_DDK_SUCCESS) {
3808 OH_UsbSerial_Close(deviceHandle);
3809 OH_UsbSerial_Release();
3810 }
3811 return returnValue;
3812 }
3813
IsUsbSerialDevice(napi_env env,napi_callback_info info)3814 static napi_value IsUsbSerialDevice(napi_env env, napi_callback_info info)
3815 {
3816 uint64_t deviceId = GetDevicedId(env, info);
3817 int32_t returnValue = OH_UsbSerial_Init();
3818 UsbSerial_Device *deviceHandle = nullptr;
3819
3820 returnValue = OH_UsbSerial_Open(deviceId, 0, &deviceHandle);
3821 bool boolRet = returnValue != USB_SERIAL_DDK_DEVICE_NOT_FOUND;
3822 OH_UsbSerial_Close(&deviceHandle);
3823 OH_UsbSerial_Release();
3824 napi_value result = nullptr;
3825 napi_status status = napi_get_boolean(env, boolRet, &result);
3826 NAPI_CALL(env, status);
3827 return result;
3828 }
3829
UsbSerialOpenOne(napi_env env,napi_callback_info info)3830 static napi_value UsbSerialOpenOne(napi_env env, napi_callback_info info)
3831 {
3832 uint64_t deviceId = GetDevicedId(env, info);
3833 UsbSerial_Device *deviceHandle = nullptr;
3834 int32_t returnValue = OH_UsbSerial_Open(deviceId, 0, &deviceHandle);
3835 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_Open failed");
3836
3837 napi_value result = nullptr;
3838 napi_status status = napi_create_int32(env, returnValue, &result);
3839 NAPI_CALL(env, status);
3840 return result;
3841 }
3842
UsbSerialOpenTwo(napi_env env,napi_callback_info info)3843 static napi_value UsbSerialOpenTwo(napi_env env, napi_callback_info info)
3844 {
3845 uint64_t deviceId = GetDevicedId(env, info);
3846 int32_t returnValue = OH_UsbSerial_Init();
3847 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
3848
3849 returnValue = OH_UsbSerial_Open(deviceId, 0, nullptr);
3850 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Open failed");
3851
3852 OH_UsbSerial_Release();
3853 napi_value result = nullptr;
3854 napi_status status = napi_create_int32(env, returnValue, &result);
3855 NAPI_CALL(env, status);
3856 return result;
3857 }
3858
UsbSerialOpenThree(napi_env env,napi_callback_info info)3859 static napi_value UsbSerialOpenThree(napi_env env, napi_callback_info info)
3860 {
3861 napi_status status;
3862 int32_t returnValue = OH_UsbSerial_Init();
3863 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
3864
3865 uint64_t deviceId = 10001001;
3866 UsbSerial_Device *deviceHandle = nullptr;
3867 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
3868 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_DEVICE_NOT_FOUND, "OH_UsbSerial_Open failed");
3869 napi_value result = nullptr;
3870 status = napi_create_int32(env, returnValue, &result);
3871 NAPI_CALL(env, status);
3872 return result;
3873 }
3874
UsbSerialOpenFour(napi_env env,napi_callback_info info)3875 static napi_value UsbSerialOpenFour(napi_env env, napi_callback_info info)
3876 {
3877 uint64_t deviceId = GetDevicedId(env, info);
3878 int32_t returnValue = OH_UsbSerial_Init();
3879 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
3880
3881 UsbSerial_Device *deviceHandle = nullptr;
3882 returnValue = OH_UsbSerial_Open(deviceId, 0, &deviceHandle);
3883 OH_UsbSerial_Close(&deviceHandle);
3884 OH_UsbSerial_Release();
3885 napi_value result = nullptr;
3886 napi_status status = napi_create_int32(env, returnValue, &result);
3887 NAPI_CALL(env, status);
3888 return result;
3889 }
3890
UsbSerialOpenFive(napi_env env,napi_callback_info info)3891 static napi_value UsbSerialOpenFive(napi_env env, napi_callback_info info)
3892 {
3893 uint64_t deviceId = GetDevicedId(env, info);
3894 int32_t returnValue = OH_UsbSerial_Init();
3895 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
3896
3897 UsbSerial_Device *deviceHandle = nullptr;
3898 interfaceIndex = INTERFACE_INDEX2;
3899 returnValue = OH_UsbSerial_Open(deviceId, interfaceIndex, &deviceHandle);
3900 OH_UsbSerial_Release();
3901 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_DEVICE_NOT_FOUND, "OH_UsbSerial_Open failed");
3902
3903 napi_value result = nullptr;
3904 napi_status status = napi_create_int32(env, returnValue, &result);
3905 NAPI_CALL(env, status);
3906 return result;
3907 }
3908
UsbSerialWriteOne(napi_env env,napi_callback_info info)3909 static napi_value UsbSerialWriteOne(napi_env env, napi_callback_info info)
3910 {
3911 napi_status status;
3912 UsbSerial_Device *deviceHandle = nullptr;
3913 std::vector<uint8_t> buff = {1, 2, 3, 4, 5, 6};
3914 uint32_t bytesWritten = 0;
3915
3916 int32_t returnValue = OH_UsbSerial_Write(deviceHandle, buff.data(), buff.size(), &bytesWritten);
3917 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_Write failed");
3918
3919 napi_value result = nullptr;
3920 status = napi_create_int32(env, returnValue, &result);
3921 NAPI_CALL(env, status);
3922 return result;
3923 }
3924
UsbSerialWriteTwo(napi_env env,napi_callback_info info)3925 static napi_value UsbSerialWriteTwo(napi_env env, napi_callback_info info)
3926 {
3927 napi_status status;
3928 int32_t returnValue = OH_UsbSerial_Init();
3929 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
3930
3931 UsbSerial_Device *deviceHandle = nullptr;
3932 std::vector<uint8_t> buff = {1, 2, 3, 4, 5, 6};
3933 uint32_t bytesWritten = 0;
3934 returnValue = OH_UsbSerial_Write(deviceHandle, buff.data(), buff.size(), &bytesWritten);
3935 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed");
3936
3937 uint64_t deviceId = GetDevicedId(env, info);
3938 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
3939 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
3940
3941 returnValue = OH_UsbSerial_Write(deviceHandle, nullptr, buff.size(), &bytesWritten);
3942 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed buffer null");
3943
3944 returnValue = OH_UsbSerial_Write(deviceHandle, buff.data(), 0, &bytesWritten);
3945 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed size 0");
3946
3947 returnValue = OH_UsbSerial_Write(deviceHandle, buff.data(), buff.size(), nullptr);
3948 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed bytesWritten null");
3949
3950 OH_UsbSerial_Close(&deviceHandle);
3951 OH_UsbSerial_Release();
3952 napi_value result = nullptr;
3953 status = napi_create_int32(env, returnValue, &result);
3954 NAPI_CALL(env, status);
3955 return result;
3956 }
3957
UsbSerialWriteThree(napi_env env,napi_callback_info info)3958 static napi_value UsbSerialWriteThree(napi_env env, napi_callback_info info)
3959 {
3960 uint64_t deviceId = GetDevicedId(env, info);
3961 int32_t returnValue = OH_UsbSerial_Init();
3962 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
3963
3964 UsbSerial_Device *deviceHandle = nullptr;
3965 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
3966 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
3967
3968 std::vector<uint8_t> buff = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0xA};
3969 uint32_t bytesWritten = 0;
3970 returnValue = OH_UsbSerial_Write(deviceHandle, buff.data(), buff.size(), &bytesWritten);
3971 OH_UsbSerial_Close(&deviceHandle);
3972 OH_UsbSerial_Release();
3973 napi_value result = nullptr;
3974 napi_status status = napi_create_int32(env, returnValue, &result);
3975 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
3976 NAPI_CALL(env, status);
3977 return result;
3978 }
3979
UsbSerialWriteFour(napi_env env,napi_callback_info info)3980 static napi_value UsbSerialWriteFour(napi_env env, napi_callback_info info)
3981 {
3982 int32_t returnValue = OH_UsbSerial_Init();
3983 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
3984
3985 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
3986 std::vector<uint8_t> buff = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0xA};
3987 uint32_t bytesWritten = 0;
3988 returnValue = OH_UsbSerial_Write(deviceHandle, buff.data(), buff.size(), &bytesWritten);
3989 DeleteUsbSerialDeviceHandle(&deviceHandle);
3990 OH_UsbSerial_Release();
3991 napi_value result = nullptr;
3992 napi_status status = napi_create_int32(env, returnValue, &result);
3993 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
3994 NAPI_CALL(env, status);
3995 return result;
3996 }
3997
UsbSerialCloseThree(napi_env env,napi_callback_info info)3998 static napi_value UsbSerialCloseThree(napi_env env, napi_callback_info info)
3999 {
4000 uint64_t deviceId = GetDevicedId(env, info);
4001 int32_t returnValue = OH_UsbSerial_Init();
4002 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4003
4004 UsbSerial_Device *deviceHandle = nullptr;
4005 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4006 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4007
4008 returnValue = OH_UsbSerial_Close(&deviceHandle);
4009 OH_UsbSerial_Release();
4010 napi_value result = nullptr;
4011 napi_status status = napi_create_int32(env, returnValue, &result);
4012 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4013 NAPI_CALL(env, status);
4014 return result;
4015 }
4016
UsbSerialCloseFour(napi_env env,napi_callback_info info)4017 static napi_value UsbSerialCloseFour(napi_env env, napi_callback_info info)
4018 {
4019 int32_t returnValue = OH_UsbSerial_Init();
4020 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4021
4022 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4023 returnValue = OH_UsbSerial_Close(&deviceHandle);
4024 OH_UsbSerial_Release();
4025 napi_value result = nullptr;
4026 napi_status status = napi_create_int32(env, returnValue, &result);
4027 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4028 NAPI_CALL(env, status);
4029 return result;
4030 }
4031
UsbSerialReadOne(napi_env env,napi_callback_info info)4032 static napi_value UsbSerialReadOne(napi_env env, napi_callback_info info)
4033 {
4034 napi_status status;
4035 UsbSerial_Device *deviceHandle = nullptr;
4036 std::vector<uint8_t> buff(USB_SERIAL_TEST_BUF_SIZE);
4037 uint32_t bytesRead = 0;
4038
4039 int32_t returnValue = OH_UsbSerial_Read(deviceHandle, buff.data(), buff.size(), &bytesRead);
4040 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_Read failed");
4041
4042 napi_value result = nullptr;
4043 status = napi_create_int32(env, returnValue, &result);
4044 NAPI_CALL(env, status);
4045 return result;
4046 }
4047
UsbSerialReadTwo(napi_env env,napi_callback_info info)4048 static napi_value UsbSerialReadTwo(napi_env env, napi_callback_info info)
4049 {
4050 napi_status status;
4051 int32_t returnValue = OH_UsbSerial_Init();
4052 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4053
4054 UsbSerial_Device *deviceHandle = nullptr;
4055 std::vector<uint8_t> buff(USB_SERIAL_TEST_BUF_SIZE);
4056 uint32_t bytesRead = 0;
4057 returnValue = OH_UsbSerial_Read(deviceHandle, buff.data(), buff.size(), &bytesRead);
4058 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed");
4059
4060 uint64_t deviceId = GetDevicedId(env, info);
4061 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4062 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4063
4064 returnValue = OH_UsbSerial_Read(deviceHandle, nullptr, buff.size(), &bytesRead);
4065 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed");
4066
4067 returnValue = OH_UsbSerial_Read(deviceHandle, buff.data(), 0, &bytesRead);
4068 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed");
4069
4070 returnValue = OH_UsbSerial_Read(deviceHandle, buff.data(), buff.size(), nullptr);
4071 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Write failed");
4072
4073 OH_UsbSerial_Close(&deviceHandle);
4074 OH_UsbSerial_Release();
4075 napi_value result = nullptr;
4076 status = napi_create_int32(env, returnValue, &result);
4077 NAPI_CALL(env, status);
4078 return result;
4079 }
4080
UsbSerialReadThree(napi_env env,napi_callback_info info)4081 static napi_value UsbSerialReadThree(napi_env env, napi_callback_info info)
4082 {
4083 uint64_t deviceId = GetDevicedId(env, info);
4084
4085 int32_t returnValue = OH_UsbSerial_Init();
4086 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4087
4088 UsbSerial_Device *deviceHandle = nullptr;
4089 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4090 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4091
4092 UsbSerial_Params params = {9600, 8, 1, 0};
4093 returnValue = OH_UsbSerial_SetParams(deviceHandle, ¶ms);
4094
4095 std::vector<uint8_t> writeBuff = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0xA};
4096 uint32_t bytesWritten = 0;
4097 returnValue = OH_UsbSerial_Write(deviceHandle, writeBuff.data(), writeBuff.size(), &bytesWritten);
4098
4099 std::vector<uint8_t> readBuff(USB_SERIAL_TEST_BUF_SIZE);
4100 uint32_t bytesRead = 0;
4101 returnValue = OH_UsbSerial_Read(deviceHandle, readBuff.data(), readBuff.size(), &bytesRead);
4102
4103 OH_UsbSerial_Close(&deviceHandle);
4104 OH_UsbSerial_Release();
4105 napi_value result = nullptr;
4106 napi_status status = napi_create_int32(env, returnValue, &result);
4107 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4108 NAPI_CALL(env, status);
4109 return result;
4110 }
4111
UsbSerialReadFour(napi_env env,napi_callback_info info)4112 static napi_value UsbSerialReadFour(napi_env env, napi_callback_info info)
4113 {
4114 int32_t returnValue = OH_UsbSerial_Init();
4115 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4116
4117 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4118 std::vector<uint8_t> readBuff(USB_SERIAL_TEST_BUF_SIZE);
4119 uint32_t bytesRead = 0;
4120 returnValue = OH_UsbSerial_Read(deviceHandle, readBuff.data(), readBuff.size(), &bytesRead);
4121 DeleteUsbSerialDeviceHandle(&deviceHandle);
4122 OH_UsbSerial_Release();
4123 napi_value result = nullptr;
4124 napi_status status = napi_create_int32(env, returnValue, &result);
4125 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4126 NAPI_CALL(env, status);
4127 return result;
4128 }
4129
UsbSerialSetBaudRateOne(napi_env env,napi_callback_info info)4130 static napi_value UsbSerialSetBaudRateOne(napi_env env, napi_callback_info info)
4131 {
4132 UsbSerial_Device *deviceHandle = nullptr;
4133 uint32_t baudRate = 9600;
4134 int32_t returnValue = OH_UsbSerial_SetBaudRate(deviceHandle, baudRate);
4135 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_SetBaudRate failed");
4136
4137 napi_value result = nullptr;
4138 napi_status status = napi_create_int32(env, returnValue, &result);
4139 NAPI_CALL(env, status);
4140 return result;
4141 }
4142
UsbSerialSetBaudRateTwo(napi_env env,napi_callback_info info)4143 static napi_value UsbSerialSetBaudRateTwo(napi_env env, napi_callback_info info)
4144 {
4145 int32_t returnValue = OH_UsbSerial_Init();
4146 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4147
4148 UsbSerial_Device *deviceHandle = nullptr;
4149 uint32_t baudRate = 9600;
4150 returnValue = OH_UsbSerial_SetBaudRate(deviceHandle, baudRate);
4151 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_SetBaudRate failed");
4152
4153 OH_UsbSerial_Release();
4154 napi_value result = nullptr;
4155 napi_status status = napi_create_int32(env, returnValue, &result);
4156 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4157 NAPI_CALL(env, status);
4158 return result;
4159 }
4160
UsbSerialSetBaudRateThree(napi_env env,napi_callback_info info)4161 static napi_value UsbSerialSetBaudRateThree(napi_env env, napi_callback_info info)
4162 {
4163 int32_t returnValue = OH_UsbSerial_Init();
4164 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4165
4166 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4167 uint32_t baudRate = 9600;
4168 returnValue = OH_UsbSerial_SetBaudRate(deviceHandle, baudRate);
4169 DeleteUsbSerialDeviceHandle(&deviceHandle);
4170 OH_UsbSerial_Release();
4171 napi_value result = nullptr;
4172 napi_status status = napi_create_int32(env, returnValue, &result);
4173 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4174 NAPI_CALL(env, status);
4175 return result;
4176 }
4177
UsbSerialSetBaudRateFour(napi_env env,napi_callback_info info)4178 static napi_value UsbSerialSetBaudRateFour(napi_env env, napi_callback_info info)
4179 {
4180 uint64_t deviceId = GetDevicedId(env, info);
4181 int32_t returnValue = OH_UsbSerial_Init();
4182 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4183
4184 UsbSerial_Device *deviceHandle = nullptr;
4185 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4186 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4187
4188 uint32_t baudRate = 9600;
4189 returnValue = OH_UsbSerial_SetBaudRate(deviceHandle, baudRate);
4190 OH_UsbSerial_Close(&deviceHandle);
4191 OH_UsbSerial_Release();
4192 napi_value result = nullptr;
4193 napi_status status = napi_create_int32(env, returnValue, &result);
4194 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4195 NAPI_CALL(env, status);
4196 return result;
4197 }
4198
UsbSerialSetParamsOne(napi_env env,napi_callback_info info)4199 static napi_value UsbSerialSetParamsOne(napi_env env, napi_callback_info info)
4200 {
4201 UsbSerial_Device *deviceHandle = nullptr;
4202 UsbSerial_Params params = {9600, 0, 10, 0};
4203 int32_t returnValue = OH_UsbSerial_SetParams(deviceHandle, ¶ms);
4204 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_SetParams failed");
4205
4206 napi_value result = nullptr;
4207 napi_status status = napi_create_int32(env, returnValue, &result);
4208 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4209 NAPI_CALL(env, status);
4210 return result;
4211 }
4212
UsbSerialSetParamsTwo(napi_env env,napi_callback_info info)4213 static napi_value UsbSerialSetParamsTwo(napi_env env, napi_callback_info info)
4214 {
4215 int32_t returnValue = OH_UsbSerial_Init();
4216 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4217
4218 UsbSerial_Device *deviceHandle = nullptr;
4219 UsbSerial_Params params = {9600, 0, 10, 0};
4220 returnValue = OH_UsbSerial_SetParams(deviceHandle, ¶ms);
4221 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Init failed");
4222
4223 uint64_t deviceId = GetDevicedId(env, info);
4224 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4225 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4226
4227 returnValue = OH_UsbSerial_SetParams(deviceHandle, nullptr);
4228 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Init failed");
4229 OH_UsbSerial_Close(&deviceHandle);
4230 OH_UsbSerial_Release();
4231 napi_value result = nullptr;
4232 napi_status status = napi_create_int32(env, returnValue, &result);
4233 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4234 NAPI_CALL(env, status);
4235 return result;
4236 }
4237
UsbSerialSetParamsThree(napi_env env,napi_callback_info info)4238 static napi_value UsbSerialSetParamsThree(napi_env env, napi_callback_info info)
4239 {
4240 int32_t returnValue = OH_UsbSerial_Init();
4241 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4242
4243 UsbSerial_Params params = {9600, 8, 1, 0};
4244 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4245 returnValue = OH_UsbSerial_SetParams(deviceHandle, ¶ms);
4246 DeleteUsbSerialDeviceHandle(&deviceHandle);
4247 OH_UsbSerial_Release();
4248 napi_value result = nullptr;
4249 napi_status status = napi_create_int32(env, returnValue, &result);
4250 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4251 NAPI_CALL(env, status);
4252 return result;
4253 }
4254
UsbSerialSetParamsFour(napi_env env,napi_callback_info info)4255 static napi_value UsbSerialSetParamsFour(napi_env env, napi_callback_info info)
4256 {
4257 uint64_t deviceId = GetDevicedId(env, info);
4258 int32_t returnValue = OH_UsbSerial_Init();
4259 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4260
4261 UsbSerial_Device *deviceHandle = nullptr;
4262 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4263 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4264
4265 UsbSerial_Params params = {9600, 8, 1, 0};
4266 returnValue = OH_UsbSerial_SetParams(deviceHandle, ¶ms);
4267 OH_UsbSerial_Close(&deviceHandle);
4268 OH_UsbSerial_Release();
4269 napi_value result = nullptr;
4270 napi_status status = napi_create_int32(env, returnValue, &result);
4271 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4272 NAPI_CALL(env, status);
4273 return result;
4274 }
4275
UsbSerialSetTimeoutOne(napi_env env,napi_callback_info info)4276 static napi_value UsbSerialSetTimeoutOne(napi_env env, napi_callback_info info)
4277 {
4278 UsbSerial_Device *deviceHandle = nullptr;
4279 int32_t returnValue = OH_UsbSerial_SetTimeout(deviceHandle, timeout);
4280 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_SetTimeout failed");
4281
4282 napi_value result = nullptr;
4283 napi_status status = napi_create_int32(env, returnValue, &result);
4284 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4285 NAPI_CALL(env, status);
4286 return result;
4287 }
4288
UsbSerialSetTimeoutTwo(napi_env env,napi_callback_info info)4289 static napi_value UsbSerialSetTimeoutTwo(napi_env env, napi_callback_info info)
4290 {
4291 int32_t returnValue = OH_UsbSerial_Init();
4292 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4293
4294 UsbSerial_Device *deviceHandle = nullptr;
4295 returnValue = OH_UsbSerial_SetTimeout(deviceHandle, timeout);
4296 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_SetTimeout failed");
4297
4298 OH_UsbSerial_Release();
4299 napi_value result = nullptr;
4300 napi_status status = napi_create_int32(env, returnValue, &result);
4301 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4302 NAPI_CALL(env, status);
4303 return result;
4304 }
4305
UsbSerialSetTimeoutThree(napi_env env,napi_callback_info info)4306 static napi_value UsbSerialSetTimeoutThree(napi_env env, napi_callback_info info)
4307 {
4308 int32_t returnValue = OH_UsbSerial_Init();
4309 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4310
4311 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4312 returnValue = OH_UsbSerial_SetTimeout(deviceHandle, timeout);
4313 DeleteUsbSerialDeviceHandle(&deviceHandle);
4314 OH_UsbSerial_Release();
4315 napi_value result = nullptr;
4316 napi_status status = napi_create_int32(env, returnValue, &result);
4317 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4318 NAPI_CALL(env, status);
4319 return result;
4320 }
4321
UsbSerialSetTimeoutFour(napi_env env,napi_callback_info info)4322 static napi_value UsbSerialSetTimeoutFour(napi_env env, napi_callback_info info)
4323 {
4324 uint64_t deviceId = GetDevicedId(env, info);
4325 int32_t returnValue = OH_UsbSerial_Init();
4326 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4327
4328 UsbSerial_Device *deviceHandle = nullptr;
4329 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4330 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4331
4332 returnValue = OH_UsbSerial_SetTimeout(deviceHandle, timeout);
4333 OH_UsbSerial_Close(&deviceHandle);
4334 OH_UsbSerial_Release();
4335 napi_value result = nullptr;
4336 napi_status status = napi_create_int32(env, returnValue, &result);
4337 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4338 NAPI_CALL(env, status);
4339 return result;
4340 }
4341
UsbSerialSetTimeoutFive(napi_env env,napi_callback_info info)4342 static napi_value UsbSerialSetTimeoutFive(napi_env env, napi_callback_info info)
4343 {
4344 uint64_t deviceId = GetDevicedId(env, info);
4345 int32_t returnValue = OH_UsbSerial_Init();
4346 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4347
4348 UsbSerial_Device *deviceHandle = nullptr;
4349 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4350 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4351
4352 timeout = TIMEOUT3;
4353 returnValue = OH_UsbSerial_SetTimeout(deviceHandle, timeout);
4354 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_SetTimeout failed");
4355 OH_UsbSerial_Close(&deviceHandle);
4356 OH_UsbSerial_Release();
4357 napi_value result = nullptr;
4358 napi_status status = napi_create_int32(env, returnValue, &result);
4359 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4360 NAPI_CALL(env, status);
4361 return result;
4362 }
4363
UsbSerialSetFlowControlOne(napi_env env,napi_callback_info info)4364 static napi_value UsbSerialSetFlowControlOne(napi_env env, napi_callback_info info)
4365 {
4366 UsbSerial_Device *deviceHandle = nullptr;
4367 int32_t returnValue = 0;
4368 returnValue = OH_UsbSerial_SetFlowControl(deviceHandle, UsbSerial_FlowControl::USB_SERIAL_SOFTWARE_FLOW_CONTROL);
4369 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_SetFlowControl failed");
4370
4371 napi_value result = nullptr;
4372 napi_status status = napi_create_int32(env, returnValue, &result);
4373 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4374 NAPI_CALL(env, status);
4375 return result;
4376 }
4377
UsbSerialSetFlowControlTwo(napi_env env,napi_callback_info info)4378 static napi_value UsbSerialSetFlowControlTwo(napi_env env, napi_callback_info info)
4379 {
4380 int32_t returnValue = OH_UsbSerial_Init();
4381 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4382
4383 UsbSerial_Device *deviceHandle = nullptr;
4384 returnValue = OH_UsbSerial_SetFlowControl(deviceHandle, UsbSerial_FlowControl::USB_SERIAL_SOFTWARE_FLOW_CONTROL);
4385 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_SetFlowControl failed");
4386
4387 OH_UsbSerial_Release();
4388 napi_value result = nullptr;
4389 napi_status status = napi_create_int32(env, returnValue, &result);
4390 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4391 NAPI_CALL(env, status);
4392 return result;
4393 }
4394
UsbSerialSetFlowControlThree(napi_env env,napi_callback_info info)4395 static napi_value UsbSerialSetFlowControlThree(napi_env env, napi_callback_info info)
4396 {
4397 int32_t returnValue = OH_UsbSerial_Init();
4398 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4399
4400 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4401 returnValue = OH_UsbSerial_SetFlowControl(deviceHandle, UsbSerial_FlowControl::USB_SERIAL_SOFTWARE_FLOW_CONTROL);
4402 DeleteUsbSerialDeviceHandle(&deviceHandle);
4403 OH_UsbSerial_Release();
4404 napi_value result = nullptr;
4405 napi_status status = napi_create_int32(env, returnValue, &result);
4406 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4407 NAPI_CALL(env, status);
4408 return result;
4409 }
4410
UsbSerialSetFlowControlFour(napi_env env,napi_callback_info info)4411 static napi_value UsbSerialSetFlowControlFour(napi_env env, napi_callback_info info)
4412 {
4413 uint64_t deviceId = GetDevicedId(env, info);
4414 int32_t returnValue = OH_UsbSerial_Init();
4415 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4416
4417 UsbSerial_Device *deviceHandle = nullptr;
4418 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4419 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4420
4421 returnValue = OH_UsbSerial_SetFlowControl(deviceHandle, UsbSerial_FlowControl::USB_SERIAL_SOFTWARE_FLOW_CONTROL);
4422 OH_UsbSerial_Close(&deviceHandle);
4423 OH_UsbSerial_Release();
4424 napi_value result = nullptr;
4425 napi_status status = napi_create_int32(env, returnValue, &result);
4426 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4427 NAPI_CALL(env, status);
4428 return result;
4429 }
4430
UsbSerialFlushOne(napi_env env,napi_callback_info info)4431 static napi_value UsbSerialFlushOne(napi_env env, napi_callback_info info)
4432 {
4433 UsbSerial_Device *deviceHandle = nullptr;
4434 int32_t returnValue = OH_UsbSerial_Flush(deviceHandle);
4435 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_Flush failed");
4436
4437 napi_value result = nullptr;
4438 napi_status status = napi_create_int32(env, returnValue, &result);
4439 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4440 NAPI_CALL(env, status);
4441 return result;
4442 }
4443
UsbSerialFlushTwo(napi_env env,napi_callback_info info)4444 static napi_value UsbSerialFlushTwo(napi_env env, napi_callback_info info)
4445 {
4446 int32_t returnValue = OH_UsbSerial_Init();
4447 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4448
4449 UsbSerial_Device *deviceHandle = nullptr;
4450 returnValue = OH_UsbSerial_Flush(deviceHandle);
4451 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_Flush failed");
4452
4453 OH_UsbSerial_Release();
4454 napi_value result = nullptr;
4455 napi_status status = napi_create_int32(env, returnValue, &result);
4456 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4457 NAPI_CALL(env, status);
4458 return result;
4459 }
4460
UsbSerialFlushThree(napi_env env,napi_callback_info info)4461 static napi_value UsbSerialFlushThree(napi_env env, napi_callback_info info)
4462 {
4463 int32_t returnValue = OH_UsbSerial_Init();
4464 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4465
4466 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4467 returnValue = OH_UsbSerial_Flush(deviceHandle);
4468 DeleteUsbSerialDeviceHandle(&deviceHandle);
4469 OH_UsbSerial_Release();
4470 napi_value result = nullptr;
4471 napi_status status = napi_create_int32(env, returnValue, &result);
4472 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4473 NAPI_CALL(env, status);
4474 return result;
4475 }
4476
UsbSerialFlushFour(napi_env env,napi_callback_info info)4477 static napi_value UsbSerialFlushFour(napi_env env, napi_callback_info info)
4478 {
4479 uint64_t deviceId = GetDevicedId(env, info);
4480 int32_t returnValue = OH_UsbSerial_Init();
4481 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4482
4483 UsbSerial_Device *deviceHandle = nullptr;
4484 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4485 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4486
4487 returnValue = OH_UsbSerial_Flush(deviceHandle);
4488 OH_UsbSerial_Close(&deviceHandle);
4489 OH_UsbSerial_Release();
4490 napi_value result = nullptr;
4491 napi_status status = napi_create_int32(env, returnValue, &result);
4492 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4493 NAPI_CALL(env, status);
4494 return result;
4495 }
4496
UsbSerialFlushInputOne(napi_env env,napi_callback_info info)4497 static napi_value UsbSerialFlushInputOne(napi_env env, napi_callback_info info)
4498 {
4499 UsbSerial_Device *deviceHandle = nullptr;
4500 int32_t returnValue = OH_UsbSerial_FlushInput(deviceHandle);
4501 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_FlushInput failed");
4502
4503 napi_value result = nullptr;
4504 napi_status status = napi_create_int32(env, returnValue, &result);
4505 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4506 NAPI_CALL(env, status);
4507 return result;
4508 }
4509
UsbSerialFlushInputTwo(napi_env env,napi_callback_info info)4510 static napi_value UsbSerialFlushInputTwo(napi_env env, napi_callback_info info)
4511 {
4512 int32_t returnValue = OH_UsbSerial_Init();
4513 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4514
4515 UsbSerial_Device *deviceHandle = nullptr;
4516 returnValue = OH_UsbSerial_FlushInput(deviceHandle);
4517 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_FlushInput failed");
4518
4519 OH_UsbSerial_Release();
4520 napi_value result = nullptr;
4521 napi_status status = napi_create_int32(env, returnValue, &result);
4522 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4523 NAPI_CALL(env, status);
4524 return result;
4525 }
4526
UsbSerialFlushInputThree(napi_env env,napi_callback_info info)4527 static napi_value UsbSerialFlushInputThree(napi_env env, napi_callback_info info)
4528 {
4529 int32_t returnValue = OH_UsbSerial_Init();
4530 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4531
4532 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4533 returnValue = OH_UsbSerial_FlushInput(deviceHandle);
4534 DeleteUsbSerialDeviceHandle(&deviceHandle);
4535 OH_UsbSerial_Release();
4536 napi_value result = nullptr;
4537 napi_status status = napi_create_int32(env, returnValue, &result);
4538 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4539 NAPI_CALL(env, status);
4540 return result;
4541 }
4542
UsbSerialFlushInputFour(napi_env env,napi_callback_info info)4543 static napi_value UsbSerialFlushInputFour(napi_env env, napi_callback_info info)
4544 {
4545 uint64_t deviceId = GetDevicedId(env, info);
4546 int32_t returnValue = OH_UsbSerial_Init();
4547 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4548
4549 UsbSerial_Device *deviceHandle = nullptr;
4550 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4551 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4552
4553 returnValue = OH_UsbSerial_FlushInput(deviceHandle);
4554 OH_UsbSerial_Close(&deviceHandle);
4555 OH_UsbSerial_Release();
4556 napi_value result = nullptr;
4557 napi_status status = napi_create_int32(env, returnValue, &result);
4558 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4559 NAPI_CALL(env, status);
4560 return result;
4561 }
4562
UsbSerialFlushOutputOne(napi_env env,napi_callback_info info)4563 static napi_value UsbSerialFlushOutputOne(napi_env env, napi_callback_info info)
4564 {
4565 UsbSerial_Device *deviceHandle = nullptr;
4566 int32_t returnValue = OH_UsbSerial_FlushOutput(deviceHandle);
4567 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INIT_ERROR, "OH_UsbSerial_FlushOutput failed");
4568
4569 napi_value result = nullptr;
4570 napi_status status = napi_create_int32(env, returnValue, &result);
4571 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4572 NAPI_CALL(env, status);
4573 return result;
4574 }
4575
UsbSerialFlushOutputTwo(napi_env env,napi_callback_info info)4576 static napi_value UsbSerialFlushOutputTwo(napi_env env, napi_callback_info info)
4577 {
4578 int32_t returnValue = OH_UsbSerial_Init();
4579 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4580
4581 UsbSerial_Device *deviceHandle = nullptr;
4582 returnValue = OH_UsbSerial_FlushOutput(deviceHandle);
4583 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_INVALID_PARAMETER, "OH_UsbSerial_FlushOutput failed");
4584
4585 OH_UsbSerial_Release();
4586 napi_value result = nullptr;
4587 napi_status status = napi_create_int32(env, returnValue, &result);
4588 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4589 NAPI_CALL(env, status);
4590 return result;
4591 }
4592
UsbSerialFlushOutputThree(napi_env env,napi_callback_info info)4593 static napi_value UsbSerialFlushOutputThree(napi_env env, napi_callback_info info)
4594 {
4595 int32_t returnValue = OH_UsbSerial_Init();
4596 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4597
4598 UsbSerial_Device *deviceHandle = NewSerialDeviceHandle();
4599 returnValue = OH_UsbSerial_FlushOutput(deviceHandle);
4600 DeleteUsbSerialDeviceHandle(&deviceHandle);
4601 OH_UsbSerial_Release();
4602 napi_value result = nullptr;
4603 napi_status status = napi_create_int32(env, returnValue, &result);
4604 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4605 NAPI_CALL(env, status);
4606 return result;
4607 }
4608
UsbSerialFlushOutputFour(napi_env env,napi_callback_info info)4609 static napi_value UsbSerialFlushOutputFour(napi_env env, napi_callback_info info)
4610 {
4611 uint64_t deviceId = GetDevicedId(env, info);
4612 int32_t returnValue = OH_UsbSerial_Init();
4613 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Init failed");
4614
4615 UsbSerial_Device *deviceHandle = nullptr;
4616 returnValue = OpenUsbSerial(deviceId, &deviceHandle);
4617 NAPI_ASSERT(env, returnValue == USB_SERIAL_DDK_SUCCESS, "OH_UsbSerial_Open failed");
4618
4619 returnValue = OH_UsbSerial_FlushOutput(deviceHandle);
4620 OH_UsbSerial_Close(&deviceHandle);
4621 OH_UsbSerial_Release();
4622 napi_value result = nullptr;
4623 napi_status status = napi_create_int32(env, returnValue, &result);
4624 NAPI_ASSERT(env, status == napi_ok, "napi_create_int32 failed");
4625 NAPI_CALL(env, status);
4626 return result;
4627 }
4628
4629 EXTERN_C_START
Init(napi_env env,napi_value exports)4630 static napi_value Init(napi_env env, napi_value exports)
4631 {
4632 napi_property_descriptor desc[] = {
4633 {"usbInit", nullptr, UsbInit, nullptr, nullptr, nullptr, napi_default, nullptr},
4634 {"usbRelease", nullptr, UsbRelease, nullptr, nullptr, nullptr, napi_default, nullptr},
4635 {"usbReleaseResource", nullptr, UsbReleaseResource, nullptr, nullptr, nullptr, napi_default, nullptr},
4636 {"usbGetDeviceDescriptorOne", nullptr, UsbGetDeviceDescriptorOne, nullptr, nullptr, nullptr, napi_default,
4637 nullptr},
4638 {"usbGetDeviceDescriptorTwo", nullptr, UsbGetDeviceDescriptorTwo, nullptr, nullptr, nullptr, napi_default,
4639 nullptr},
4640 {"usbGetConfigDescriptorOne", nullptr, UsbGetConfigDescriptorOne, nullptr, nullptr, nullptr, napi_default,
4641 nullptr},
4642 {"usbGetConfigDescriptorTwo", nullptr, UsbGetConfigDescriptorTwo, nullptr, nullptr, nullptr, napi_default,
4643 nullptr},
4644 {"usbGetConfigDescriptorThree", nullptr, UsbGetConfigDescriptorThree, nullptr, nullptr, nullptr, napi_default,
4645 nullptr},
4646 {"usbFreeConfigDescriptor", nullptr, UsbFreeConfigDescriptor, nullptr, nullptr, nullptr, napi_default,
4647 nullptr},
4648 {"usbClaimInterfaceOne", nullptr, UsbClaimInterfaceOne, nullptr, nullptr, nullptr, napi_default, nullptr},
4649 {"usbClaimInterfaceTwo", nullptr, UsbClaimInterfaceTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
4650 {"usbClaimInterfaceThree", nullptr, UsbClaimInterfaceThree, nullptr, nullptr, nullptr, napi_default, nullptr},
4651 {"usbReleaseInterface", nullptr, UsbReleaseInterface, nullptr, nullptr, nullptr, napi_default, nullptr},
4652 {"usbSelectInterfaceSettingOne", nullptr, UsbSelectInterfaceSettingOne, nullptr, nullptr, nullptr,
4653 napi_default, nullptr},
4654 {"usbSelectInterfaceSettingTwo", nullptr, UsbSelectInterfaceSettingTwo, nullptr, nullptr, nullptr,
4655 napi_default, nullptr},
4656 {"usbGetCurrentInterfaceSettingOne", nullptr, UsbGetCurrentInterfaceSettingOne, nullptr, nullptr, nullptr,
4657 napi_default, nullptr},
4658 {"usbGetCurrentInterfaceSettingTwo", nullptr, UsbGetCurrentInterfaceSettingTwo, nullptr, nullptr, nullptr,
4659 napi_default, nullptr},
4660 {"usbGetCurrentInterfaceSettingThree", nullptr, UsbGetCurrentInterfaceSettingThree, nullptr, nullptr, nullptr,
4661 napi_default, nullptr},
4662 {"usbSendControlReadRequestOne", nullptr, UsbSendControlReadRequestOne, nullptr, nullptr, nullptr,
4663 napi_default, nullptr},
4664 {"usbSendControlReadRequestTwo", nullptr, UsbSendControlReadRequestTwo, nullptr, nullptr, nullptr,
4665 napi_default, nullptr},
4666 {"usbSendControlReadRequestThree", nullptr, UsbSendControlReadRequestThree, nullptr, nullptr, nullptr,
4667 napi_default, nullptr},
4668 {"usbSendControlReadRequestFour", nullptr, UsbSendControlReadRequestFour, nullptr, nullptr, nullptr,
4669 napi_default, nullptr},
4670 {"usbSendControlReadRequestFive", nullptr, UsbSendControlReadRequestFive, nullptr, nullptr, nullptr,
4671 napi_default, nullptr},
4672 {"usbSendControlWriteRequestOne", nullptr, UsbSendControlWriteRequestOne, nullptr, nullptr, nullptr,
4673 napi_default, nullptr},
4674 {"usbSendControlWriteRequestTwo", nullptr, UsbSendControlWriteRequestTwo, nullptr, nullptr, nullptr,
4675 napi_default, nullptr},
4676 {"usbSendControlWriteRequestThree", nullptr, UsbSendControlWriteRequestThree, nullptr, nullptr, nullptr,
4677 napi_default, nullptr},
4678 {"usbSendControlWriteRequestFour", nullptr, UsbSendControlWriteRequestFour, nullptr, nullptr, nullptr,
4679 napi_default, nullptr},
4680 {"usbSendControlWriteRequestFive", nullptr, UsbSendControlWriteRequestFive, nullptr, nullptr, nullptr,
4681 napi_default, nullptr},
4682 {"usbSendPipeRequestOne", nullptr, UsbSendPipeRequestOne, nullptr, nullptr, nullptr,
4683 napi_default, nullptr},
4684 {"usbSendPipeRequestTwo", nullptr, UsbSendPipeRequestTwo, nullptr, nullptr, nullptr,
4685 napi_default, nullptr},
4686 {"usbSendPipeRequestThree", nullptr, UsbSendPipeRequestThree, nullptr, nullptr, nullptr, napi_default,
4687 nullptr},
4688 {"usbSendPipeRequestFour", nullptr, UsbSendPipeRequestFour, nullptr, nullptr, nullptr,
4689 napi_default, nullptr},
4690 {"usbCreateDeviceMemMapOne", nullptr, UsbCreateDeviceMemMapOne, nullptr, nullptr, nullptr, napi_default,
4691 nullptr},
4692 {"usbCreateDeviceMemMapTwo", nullptr, UsbCreateDeviceMemMapTwo, nullptr, nullptr, nullptr, napi_default,
4693 nullptr},
4694 {"usbDestroyDeviceMemMap", nullptr, UsbDestroyDeviceMemMap, nullptr, nullptr, nullptr,
4695 napi_default, nullptr},
4696 {"usbSendPipeRequestWithAshmemOne", nullptr, UsbSendPipeRequestWithAshmemOne, nullptr, nullptr, nullptr,
4697 napi_default, nullptr},
4698 {"usbSendPipeRequestWithAshmemTwo", nullptr, UsbSendPipeRequestWithAshmemTwo, nullptr, nullptr, nullptr,
4699 napi_default, nullptr},
4700 {"usbSendPipeRequestWithAshmemThree", nullptr, UsbSendPipeRequestWithAshmemThree, nullptr, nullptr, nullptr,
4701 napi_default, nullptr},
4702 {"usbSendPipeRequestWithAshmemFour", nullptr, UsbSendPipeRequestWithAshmemFour, nullptr, nullptr, nullptr,
4703 napi_default, nullptr},
4704 {"usbGetDevicesOne", nullptr, UsbGetDevicesOne, nullptr, nullptr, nullptr, napi_default, nullptr},
4705 {"usbGetDevicesTwo", nullptr, UsbGetDevicesTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
4706 {"usbGetDevicesThree", nullptr, UsbGetDevicesThree, nullptr, nullptr, nullptr, napi_default, nullptr},
4707 {"isScsiDevice", nullptr, IsScsiDevice, nullptr, nullptr, nullptr, napi_default, nullptr},
4708 {"scsiPeripheralInitOne", nullptr, ScsiPeripheralInitOne, nullptr, nullptr, nullptr,
4709 napi_default, nullptr},
4710 {"scsiPeripheralReleaseOne", nullptr, ScsiPeripheralReleaseOne, nullptr, nullptr, nullptr,
4711 napi_default, nullptr},
4712 {"scsiPeripheralReleaseTwo", nullptr, ScsiPeripheralReleaseTwo, nullptr, nullptr, nullptr,
4713 napi_default, nullptr},
4714 {"scsiPeripheralOpenOne", nullptr, ScsiPeripheralOpenOne, nullptr, nullptr, nullptr,
4715 napi_default, nullptr},
4716 {"scsiPeripheralOpenTwo", nullptr, ScsiPeripheralOpenTwo, nullptr, nullptr, nullptr,
4717 napi_default, nullptr},
4718 {"scsiPeripheralOpenThree", nullptr, ScsiPeripheralOpenThree, nullptr, nullptr, nullptr,
4719 napi_default, nullptr},
4720 {"scsiPeripheralOpenFour", nullptr, ScsiPeripheralOpenFour, nullptr, nullptr, nullptr,
4721 napi_default, nullptr},
4722 {"scsiPeripheralOpenFive", nullptr, ScsiPeripheralOpenFive, nullptr, nullptr, nullptr,
4723 napi_default, nullptr},
4724 {"scsiPeripheralOpenSix", nullptr, ScsiPeripheralOpenSix, nullptr, nullptr, nullptr,
4725 napi_default, nullptr},
4726 {"scsiPeripheralOpenSeven", nullptr, ScsiPeripheralOpenSeven, nullptr, nullptr, nullptr,
4727 napi_default, nullptr},
4728 {"scsiPeripheralOpenEight", nullptr, ScsiPeripheralOpenEight, nullptr, nullptr, nullptr,
4729 napi_default, nullptr},
4730 {"scsiPeripheralOpenNine", nullptr, ScsiPeripheralOpenNine, nullptr, nullptr, nullptr,
4731 napi_default, nullptr},
4732 {"scsiPeripheralCloseOne", nullptr, ScsiPeripheralCloseOne, nullptr, nullptr, nullptr,
4733 napi_default, nullptr},
4734 {"scsiPeripheralCloseTwo", nullptr, ScsiPeripheralCloseTwo, nullptr, nullptr, nullptr,
4735 napi_default, nullptr},
4736 {"scsiPeripheralCloseThree", nullptr, ScsiPeripheralCloseThree, nullptr, nullptr, nullptr,
4737 napi_default, nullptr},
4738 {"scsiPeripheralReadCapacityOne", nullptr, ScsiPeripheralReadCapacityOne, nullptr, nullptr,
4739 nullptr, napi_default, nullptr},
4740 {"scsiPeripheralReadCapacityTwo", nullptr, ScsiPeripheralReadCapacityTwo, nullptr, nullptr,
4741 nullptr, napi_default, nullptr},
4742 {"scsiPeripheralReadCapacityThree", nullptr, ScsiPeripheralReadCapacityThree, nullptr,
4743 nullptr, nullptr, napi_default, nullptr},
4744 {"scsiPeripheralReadCapacityFour", nullptr, ScsiPeripheralReadCapacityFour, nullptr,
4745 nullptr, nullptr, napi_default, nullptr},
4746 {"scsiPeripheralReadCapacityFive", nullptr, ScsiPeripheralReadCapacityFive, nullptr,
4747 nullptr, nullptr, napi_default, nullptr},
4748 {"scsiPeripheralReadCapacitySix", nullptr, ScsiPeripheralReadCapacitySix, nullptr,
4749 nullptr, nullptr, napi_default, nullptr},
4750 {"scsiPeripheralReadCapacitySeven", nullptr, ScsiPeripheralReadCapacitySeven, nullptr,
4751 nullptr, nullptr, napi_default, nullptr},
4752 {"scsiPeripheralTestUnitReadyOne", nullptr, ScsiPeripheralTestUnitReadyOne, nullptr,
4753 nullptr, nullptr, napi_default, nullptr},
4754 {"scsiPeripheralTestUnitReadyTwo", nullptr, ScsiPeripheralTestUnitReadyTwo, nullptr,
4755 nullptr, nullptr, napi_default, nullptr},
4756 {"scsiPeripheralTestUnitReadyThree", nullptr, ScsiPeripheralTestUnitReadyThree, nullptr,
4757 nullptr, nullptr, napi_default, nullptr},
4758 {"scsiPeripheralTestUnitReadyFour", nullptr, ScsiPeripheralTestUnitReadyFour, nullptr,
4759 nullptr, nullptr, napi_default, nullptr},
4760 {"scsiPeripheralTestUnitReadyFive", nullptr, ScsiPeripheralTestUnitReadyFive, nullptr,
4761 nullptr, nullptr, napi_default, nullptr},
4762 {"scsiPeripheralInquiryOne", nullptr, ScsiPeripheralInquiryOne, nullptr, nullptr, nullptr,
4763 napi_default, nullptr},
4764 {"scsiPeripheralInquiryTwo", nullptr, ScsiPeripheralInquiryTwo, nullptr, nullptr, nullptr,
4765 napi_default, nullptr},
4766 {"scsiPeripheralInquiryThree", nullptr, ScsiPeripheralInquiryThree, nullptr, nullptr, nullptr,
4767 napi_default, nullptr},
4768 {"scsiPeripheralInquiryFour", nullptr, ScsiPeripheralInquiryFour, nullptr, nullptr, nullptr,
4769 napi_default, nullptr},
4770 {"scsiPeripheralInquiryFive", nullptr, ScsiPeripheralInquiryFive, nullptr, nullptr, nullptr,
4771 napi_default, nullptr},
4772 {"scsiPeripheralInquirySix", nullptr, ScsiPeripheralInquirySix, nullptr, nullptr, nullptr,
4773 napi_default, nullptr},
4774 {"scsiPeripheralInquirySeven", nullptr, ScsiPeripheralInquirySeven, nullptr, nullptr, nullptr,
4775 napi_default, nullptr},
4776 {"scsiPeripheralInquiryEight", nullptr, ScsiPeripheralInquiryEight, nullptr, nullptr, nullptr,
4777 napi_default, nullptr},
4778 {"scsiPeripheralRequestSenseOne", nullptr, ScsiPeripheralRequestSenseOne, nullptr, nullptr,
4779 nullptr, napi_default, nullptr},
4780 {"scsiPeripheralRequestSenseTwo", nullptr, ScsiPeripheralRequestSenseTwo, nullptr, nullptr,
4781 nullptr, napi_default, nullptr},
4782 {"scsiPeripheralRequestSenseThree", nullptr, ScsiPeripheralRequestSenseThree, nullptr, nullptr,
4783 nullptr, napi_default, nullptr},
4784 {"scsiPeripheralRequestSenseFour", nullptr, ScsiPeripheralRequestSenseFour, nullptr, nullptr,
4785 nullptr, napi_default, nullptr},
4786 {"scsiPeripheralRequestSenseFive", nullptr, ScsiPeripheralRequestSenseFive, nullptr, nullptr,
4787 nullptr, napi_default, nullptr},
4788 {"scsiPeripheralRequestSenseSix", nullptr, ScsiPeripheralRequestSenseSix, nullptr, nullptr,
4789 nullptr, napi_default, nullptr},
4790 {"scsiPeripheralReadOne", nullptr, ScsiPeripheralReadOne, nullptr, nullptr, nullptr,
4791 napi_default, nullptr},
4792 {"scsiPeripheralReadTwo", nullptr, ScsiPeripheralReadTwo, nullptr, nullptr, nullptr,
4793 napi_default, nullptr},
4794 {"scsiPeripheralReadThree", nullptr, ScsiPeripheralReadThree, nullptr, nullptr, nullptr,
4795 napi_default, nullptr},
4796 {"scsiPeripheralReadFour", nullptr, ScsiPeripheralReadFour, nullptr, nullptr, nullptr,
4797 napi_default, nullptr},
4798 {"scsiPeripheralReadFive", nullptr, ScsiPeripheralReadFive, nullptr, nullptr, nullptr,
4799 napi_default, nullptr},
4800 {"scsiPeripheralReadSix", nullptr, ScsiPeripheralReadSix, nullptr, nullptr, nullptr,
4801 napi_default, nullptr},
4802 {"scsiPeripheralReadSeven", nullptr, ScsiPeripheralReadSeven, nullptr, nullptr, nullptr,
4803 napi_default, nullptr},
4804 {"scsiPeripheralReadEight", nullptr, ScsiPeripheralReadEight, nullptr, nullptr, nullptr,
4805 napi_default, nullptr},
4806 {"scsiPeripheralReadNine", nullptr, ScsiPeripheralReadNine, nullptr, nullptr, nullptr,
4807 napi_default, nullptr},
4808 {"scsiPeripheralWriteOne", nullptr, ScsiPeripheralWriteOne, nullptr, nullptr, nullptr,
4809 napi_default, nullptr},
4810 {"scsiPeripheralWriteTwo", nullptr, ScsiPeripheralWriteTwo, nullptr, nullptr, nullptr,
4811 napi_default, nullptr},
4812 {"scsiPeripheralWriteThree", nullptr, ScsiPeripheralWriteThree, nullptr, nullptr, nullptr,
4813 napi_default, nullptr},
4814 {"scsiPeripheralWriteFour", nullptr, ScsiPeripheralWriteFour, nullptr, nullptr, nullptr,
4815 napi_default, nullptr},
4816 {"scsiPeripheralWriteFour1", nullptr, ScsiPeripheralWriteFour1, nullptr, nullptr, nullptr,
4817 napi_default, nullptr},
4818 {"scsiPeripheralWriteFive", nullptr, ScsiPeripheralWriteFive, nullptr, nullptr, nullptr,
4819 napi_default, nullptr},
4820 {"scsiPeripheralVerifyOne", nullptr, ScsiPeripheralVerifyOne, nullptr, nullptr, nullptr,
4821 napi_default, nullptr},
4822 {"scsiPeripheralVerifyTwo", nullptr, ScsiPeripheralVerifyTwo, nullptr, nullptr, nullptr,
4823 napi_default, nullptr},
4824 {"scsiPeripheralVerifyThree", nullptr, ScsiPeripheralVerifyThree, nullptr, nullptr, nullptr,
4825 napi_default, nullptr},
4826 {"scsiPeripheralSendRequestByCDBOne", nullptr, ScsiPeripheralSendRequestByCDBOne, nullptr,
4827 nullptr, nullptr, napi_default, nullptr},
4828 {"scsiPeripheralSendRequestByCDBTwo", nullptr, ScsiPeripheralSendRequestByCDBTwo, nullptr,
4829 nullptr, nullptr, napi_default, nullptr},
4830 {"scsiPeripheralSendRequestByCDBThree", nullptr, ScsiPeripheralSendRequestByCDBThree, nullptr,
4831 nullptr, nullptr, napi_default, nullptr},
4832 {"scsiPeripheralSendRequestByCDBFour", nullptr, ScsiPeripheralSendRequestByCDBFour, nullptr,
4833 nullptr, nullptr, napi_default, nullptr},
4834 {"scsiPeripheralCreateDeviceMemMapOne", nullptr, ScsiPeripheralCreateDeviceMemMapOne, nullptr,
4835 nullptr, nullptr, napi_default, nullptr},
4836 {"scsiPeripheralCreateDeviceMemMapTwo", nullptr, ScsiPeripheralCreateDeviceMemMapTwo, nullptr,
4837 nullptr, nullptr, napi_default, nullptr},
4838 {"scsiPeripheralCreateDeviceMemMapThree", nullptr, ScsiPeripheralCreateDeviceMemMapThree, nullptr,
4839 nullptr, nullptr, napi_default, nullptr},
4840 {"scsiPeripheralDestroyDeviceMemMapOne", nullptr, ScsiPeripheralDestroyDeviceMemMapOne, nullptr,
4841 nullptr, nullptr, napi_default, nullptr},
4842 {"scsiPeripheralDestroyDeviceMemMapTwo", nullptr, ScsiPeripheralDestroyDeviceMemMapTwo, nullptr,
4843 nullptr, nullptr, napi_default, nullptr},
4844 {"scsiPeripheralParseBasicSenseInfoOne", nullptr, ScsiPeripheralParseBasicSenseInfoOne, nullptr,
4845 nullptr, nullptr, napi_default, nullptr},
4846 {"scsiPeripheralParseBasicSenseInfoTwo", nullptr, ScsiPeripheralParseBasicSenseInfoTwo, nullptr,
4847 nullptr, nullptr, napi_default, nullptr},
4848 {"isUsbSerialDevice", nullptr, IsUsbSerialDevice, nullptr, nullptr, nullptr,
4849 napi_default, nullptr},
4850 {"usbSerialOpenOne", nullptr, UsbSerialOpenOne, nullptr, nullptr, nullptr,
4851 napi_default, nullptr},
4852 {"usbSerialOpenTwo", nullptr, UsbSerialOpenTwo, nullptr, nullptr, nullptr,
4853 napi_default, nullptr},
4854 {"usbSerialOpenThree", nullptr, UsbSerialOpenThree, nullptr, nullptr, nullptr,
4855 napi_default, nullptr},
4856 {"usbSerialOpenFour", nullptr, UsbSerialOpenFour, nullptr, nullptr, nullptr,
4857 napi_default, nullptr},
4858 {"usbSerialOpenFive", nullptr, UsbSerialOpenFive, nullptr, nullptr, nullptr,
4859 napi_default, nullptr},
4860 {"usbSerialCloseThree", nullptr, UsbSerialCloseThree, nullptr, nullptr, nullptr,
4861 napi_default, nullptr},
4862 {"usbSerialCloseFour", nullptr, UsbSerialCloseFour, nullptr, nullptr, nullptr,
4863 napi_default, nullptr},
4864 {"usbSerialWriteOne", nullptr, UsbSerialWriteOne, nullptr, nullptr, nullptr,
4865 napi_default, nullptr},
4866 {"usbSerialWriteTwo", nullptr, UsbSerialWriteTwo, nullptr, nullptr, nullptr,
4867 napi_default, nullptr},
4868 {"usbSerialWriteThree", nullptr, UsbSerialWriteThree, nullptr, nullptr, nullptr,
4869 napi_default, nullptr},
4870 {"usbSerialWriteFour", nullptr, UsbSerialWriteFour, nullptr, nullptr, nullptr,
4871 napi_default, nullptr},
4872 {"usbSerialReadOne", nullptr, UsbSerialReadOne, nullptr, nullptr, nullptr,
4873 napi_default, nullptr},
4874 {"usbSerialReadTwo", nullptr, UsbSerialReadTwo, nullptr, nullptr, nullptr,
4875 napi_default, nullptr},
4876 {"usbSerialReadThree", nullptr, UsbSerialReadThree, nullptr, nullptr, nullptr,
4877 napi_default, nullptr},
4878 {"usbSerialReadFour", nullptr, UsbSerialReadFour, nullptr, nullptr, nullptr,
4879 napi_default, nullptr},
4880 {"usbSerialSetBaudRateOne", nullptr, UsbSerialSetBaudRateOne, nullptr, nullptr, nullptr,
4881 napi_default, nullptr},
4882 {"usbSerialSetBaudRateTwo", nullptr, UsbSerialSetBaudRateTwo, nullptr, nullptr, nullptr,
4883 napi_default, nullptr},
4884 {"usbSerialSetBaudRateThree", nullptr, UsbSerialSetBaudRateThree, nullptr, nullptr, nullptr,
4885 napi_default, nullptr},
4886 {"usbSerialSetBaudRateFour", nullptr, UsbSerialSetBaudRateFour, nullptr, nullptr, nullptr,
4887 napi_default, nullptr},
4888 {"usbSerialSetParamsOne", nullptr, UsbSerialSetParamsOne, nullptr, nullptr, nullptr,
4889 napi_default, nullptr},
4890 {"usbSerialSetParamsTwo", nullptr, UsbSerialSetParamsTwo, nullptr, nullptr, nullptr,
4891 napi_default, nullptr},
4892 {"usbSerialSetParamsThree", nullptr, UsbSerialSetParamsThree, nullptr, nullptr, nullptr,
4893 napi_default, nullptr},
4894 {"usbSerialSetParamsFour", nullptr, UsbSerialSetParamsFour, nullptr, nullptr, nullptr,
4895 napi_default, nullptr},
4896 {"usbSerialSetTimeoutOne", nullptr, UsbSerialSetTimeoutOne, nullptr, nullptr, nullptr,
4897 napi_default, nullptr},
4898 {"usbSerialSetTimeoutTwo", nullptr, UsbSerialSetTimeoutTwo, nullptr, nullptr, nullptr,
4899 napi_default, nullptr},
4900 {"usbSerialSetTimeoutThree", nullptr, UsbSerialSetTimeoutThree, nullptr, nullptr, nullptr,
4901 napi_default, nullptr},
4902 {"usbSerialSetTimeoutFour", nullptr, UsbSerialSetTimeoutFour, nullptr, nullptr, nullptr,
4903 napi_default, nullptr},
4904 {"usbSerialSetTimeoutFive", nullptr, UsbSerialSetTimeoutFive, nullptr, nullptr, nullptr,
4905 napi_default, nullptr},
4906 {"usbSerialSetFlowControlOne", nullptr, UsbSerialSetFlowControlOne, nullptr, nullptr, nullptr,
4907 napi_default, nullptr},
4908 {"usbSerialSetFlowControlTwo", nullptr, UsbSerialSetFlowControlTwo, nullptr, nullptr, nullptr,
4909 napi_default, nullptr},
4910 {"usbSerialSetFlowControlThree", nullptr, UsbSerialSetFlowControlThree, nullptr, nullptr, nullptr,
4911 napi_default, nullptr},
4912 {"usbSerialSetFlowControlFour", nullptr, UsbSerialSetFlowControlFour, nullptr, nullptr, nullptr,
4913 napi_default, nullptr},
4914 {"usbSerialFlushOne", nullptr, UsbSerialFlushOne, nullptr, nullptr, nullptr,
4915 napi_default, nullptr},
4916 {"usbSerialFlushTwo", nullptr, UsbSerialFlushTwo, nullptr, nullptr, nullptr,
4917 napi_default, nullptr},
4918 {"usbSerialFlushThree", nullptr, UsbSerialFlushThree, nullptr, nullptr, nullptr,
4919 napi_default, nullptr},
4920 {"usbSerialFlushFour", nullptr, UsbSerialFlushFour, nullptr, nullptr, nullptr,
4921 napi_default, nullptr},
4922 {"usbSerialFlushInputOne", nullptr, UsbSerialFlushInputOne, nullptr, nullptr, nullptr,
4923 napi_default, nullptr},
4924 {"usbSerialFlushInputTwo", nullptr, UsbSerialFlushInputTwo, nullptr, nullptr, nullptr,
4925 napi_default, nullptr},
4926 {"usbSerialFlushInputThree", nullptr, UsbSerialFlushInputThree, nullptr, nullptr, nullptr,
4927 napi_default, nullptr},
4928 {"usbSerialFlushInputFour", nullptr, UsbSerialFlushInputFour, nullptr, nullptr, nullptr,
4929 napi_default, nullptr},
4930 {"usbSerialFlushOutputOne", nullptr, UsbSerialFlushOutputOne, nullptr, nullptr, nullptr,
4931 napi_default, nullptr},
4932 {"usbSerialFlushOutputTwo", nullptr, UsbSerialFlushOutputTwo, nullptr, nullptr, nullptr,
4933 napi_default, nullptr},
4934 {"usbSerialFlushOutputThree", nullptr, UsbSerialFlushOutputThree, nullptr, nullptr, nullptr,
4935 napi_default, nullptr},
4936 {"usbSerialFlushOutputFour", nullptr, UsbSerialFlushOutputFour, nullptr, nullptr, nullptr,
4937 napi_default, nullptr},
4938 };
4939
4940 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
4941 return exports;
4942 }
4943 EXTERN_C_END
4944
4945 static napi_module demoModule = {
4946 .nm_version = 1,
4947 .nm_flags = 0,
4948 .nm_filename = nullptr,
4949 .nm_register_func = Init,
4950 .nm_modname = "libusbddk",
4951 .nm_priv = ((void *)0),
4952 .reserved = {0},
4953 };
4954
RegisterModule(void)4955 extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&demoModule); }
4956