1 /*
2 * Copyright (c) 2024 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 "hilog/log.h"
17 #include "napi/native_api.h"
18 #include "native_common.h"
19 #include "usb_ddk_api.h"
20 #include "usb_ddk_types.h"
21 #include <cstdlib>
22 #include <js_native_api_types.h>
23 #include <tuple>
24 #include <unistd.h>
25
26
27 #define ENDPOINT 0
28 #define SLEEP 2
29 #define PARAM_8 8
30 #define USB_DDK_TEST_BUF_SIZE 100
31 #define USB_DDK_ENDPOINT_DIR_MASK 0x80
32 #define USB_DDK_DIR_IN 0x80
33 #define USB_DDK_ENDPOINT_XFERTYPE_MASK 0x03
34 #define USB_DDK_ENDPOINT_XFER_INT 0x03
35 static uint8_t configIndex = 0;
36 static uint8_t interfaceIndex = 0;
37 static uint64_t interfaceHandle = 0;
38 static uint8_t settingIndex = 0;
39 static uint32_t timeout = 1000;
40
41 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_APP, 0xFEFE, "JSAPP"};
42 #define MY_HILOG(op, fmt, args...) \
43 do { \
44 op(LABEL, "{%{public}s:%{public}d} " fmt, __FUNCTION__, __LINE__, ##args); \
45 } while (0)
46 #define DEBUG_LOG(fmt, ...) MY_HILOG(OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__)
47
48 uint64_t g_devHandle = 0;
49
IsInterruptInEndpoint(const UsbEndpointDescriptor & epDesc)50 static bool IsInterruptInEndpoint(const UsbEndpointDescriptor &epDesc)
51 {
52 return (((epDesc.bEndpointAddress & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN) &&
53 ((epDesc.bmAttributes & USB_DDK_ENDPOINT_XFERTYPE_MASK) == USB_DDK_ENDPOINT_XFER_INT));
54 }
55
FindForEachInterface(const UsbDdkInterface & interface)56 static std::tuple<bool, uint8_t, uint8_t, uint16_t> FindForEachInterface(const UsbDdkInterface &interface)
57 {
58 struct UsbDdkInterfaceDescriptor *intDesc = interface.altsetting;
59 uint32_t numSetting = interface.numAltsetting;
60 for (uint32_t setIdx = 0; setIdx < numSetting; ++setIdx) {
61 uint32_t numEp = intDesc[setIdx].interfaceDescriptor.bNumEndpoints;
62 struct UsbDdkEndpointDescriptor *epDesc = intDesc[setIdx].endPoint;
63 for (uint32_t epIdx = 0; epIdx < numEp; ++epIdx) {
64 if (IsInterruptInEndpoint(epDesc[epIdx].endpointDescriptor)) {
65 return {true, intDesc[setIdx].interfaceDescriptor.bInterfaceNumber,
66 epDesc[epIdx].endpointDescriptor.bEndpointAddress,
67 epDesc[epIdx].endpointDescriptor.wMaxPacketSize};
68 }
69 }
70 }
71
72 return {false, {}, {}, {}};
73 }
74
GetEndpointInfo(const struct UsbDdkConfigDescriptor * config)75 static std::tuple<bool, uint8_t, uint8_t, uint16_t> GetEndpointInfo(const struct UsbDdkConfigDescriptor *config)
76 {
77 for (uint32_t intIdx = 0; intIdx < config->configDescriptor.bNumInterfaces; ++intIdx) {
78 auto result = FindForEachInterface(config->interface[intIdx]);
79 if (std::get<0>(result)) {
80 return result;
81 }
82 }
83 return {false, {}, {}, {}};
84 }
85
GetDeviceId(void)86 uint64_t GetDeviceId(void)
87 {
88 return g_devHandle;
89 }
90
ReleaseDeviceId(void)91 void ReleaseDeviceId(void)
92 {
93 DEBUG_LOG("ReleaseDeviceId,START");
94 DEBUG_LOG("ReleaseDeviceId,END");
95 }
96
UsbInit(napi_env env,napi_callback_info)97 static napi_value UsbInit(napi_env env, napi_callback_info)
98 {
99 int32_t returnValue = OH_Usb_Init();
100 OH_Usb_Release();
101 napi_value result = nullptr;
102 napi_create_int32(env, returnValue, &result);
103 return result;
104 }
105
UsbRelease(napi_env env,napi_callback_info)106 static napi_value UsbRelease(napi_env env, napi_callback_info)
107 {
108 int32_t usbInitReturnValue = OH_Usb_Init();
109 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
110 OH_Usb_Release();
111 napi_value result = nullptr;
112 napi_create_int32(env, true, &result);
113 return result;
114 }
115
UsbGetDeviceDescriptorOne(napi_env env,napi_callback_info)116 static napi_value UsbGetDeviceDescriptorOne(napi_env env, napi_callback_info)
117 {
118 int32_t usbInitReturnValue = OH_Usb_Init();
119 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
120 struct UsbDeviceDescriptor devDesc;
121 GetDeviceId();
122 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
123 int32_t returnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
124 ReleaseDeviceId();
125 napi_value result = nullptr;
126 napi_create_int32(env, returnValue, &result);
127 return result;
128 }
129
UsbGetDeviceDescriptorTwo(napi_env env,napi_callback_info)130 static napi_value UsbGetDeviceDescriptorTwo(napi_env env, napi_callback_info)
131 {
132 int32_t usbInitReturnValue = OH_Usb_Init();
133 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
134 GetDeviceId();
135 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
136 int32_t returnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, nullptr);
137 ReleaseDeviceId();
138 napi_value result = nullptr;
139 napi_create_int32(env, returnValue, &result);
140 return result;
141 }
142
UsbGetConfigDescriptorOne(napi_env env,napi_callback_info)143 static napi_value UsbGetConfigDescriptorOne(napi_env env, napi_callback_info)
144 {
145 int32_t usbInitReturnValue = OH_Usb_Init();
146 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
147 struct UsbDdkConfigDescriptor *config = nullptr;
148 GetDeviceId();
149 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
150 int32_t returnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
151 OH_Usb_FreeConfigDescriptor(config);
152 ReleaseDeviceId();
153 napi_value result = nullptr;
154 napi_create_int32(env, returnValue, &result);
155 return result;
156 }
157
UsbGetConfigDescriptorTwo(napi_env env,napi_callback_info)158 static napi_value UsbGetConfigDescriptorTwo(napi_env env, napi_callback_info)
159 {
160 struct UsbDdkConfigDescriptor *config = nullptr;
161 uint64_t errorId = 1;
162 int32_t returnValue = OH_Usb_GetConfigDescriptor(errorId, configIndex, &config);
163 OH_Usb_FreeConfigDescriptor(config);
164 napi_value result = nullptr;
165 napi_create_int32(env, returnValue, &result);
166 return result;
167 }
168
UsbGetConfigDescriptorThree(napi_env env,napi_callback_info)169 static napi_value UsbGetConfigDescriptorThree(napi_env env, napi_callback_info)
170 {
171 int32_t usbInitReturnValue = OH_Usb_Init();
172 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
173 GetDeviceId();
174 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
175 int32_t returnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, nullptr);
176 ReleaseDeviceId();
177 napi_value result = nullptr;
178 napi_create_int32(env, returnValue, &result);
179 return result;
180 }
181
UsbFreeConfigDescriptor(napi_env env,napi_callback_info)182 static napi_value UsbFreeConfigDescriptor(napi_env env, napi_callback_info)
183 {
184 int32_t usbInitReturnValue = OH_Usb_Init();
185 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
186 struct UsbDdkConfigDescriptor *config = nullptr;
187 GetDeviceId();
188 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
189 int32_t returnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
190 NAPI_ASSERT(env, returnValue == 0, "OH_Usb_GetConfigDescriptor failed");
191 OH_Usb_FreeConfigDescriptor(config);
192 ReleaseDeviceId();
193 napi_value result = nullptr;
194 napi_create_int32(env, true, &result);
195 return result;
196 }
197
UsbClaimInterfaceOne(napi_env env,napi_callback_info)198 static napi_value UsbClaimInterfaceOne(napi_env env, napi_callback_info)
199 {
200 int32_t usbInitReturnValue = OH_Usb_Init();
201 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
202 GetDeviceId();
203 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
204 int32_t returnValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
205 ReleaseDeviceId();
206 napi_value result = nullptr;
207 napi_create_int32(env, returnValue, &result);
208 return result;
209 }
210
UsbClaimInterfaceTwo(napi_env env,napi_callback_info)211 static napi_value UsbClaimInterfaceTwo(napi_env env, napi_callback_info)
212 {
213 GetDeviceId();
214 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
215 uint64_t errorId = 1;
216 int32_t returnValue = OH_Usb_ClaimInterface(errorId, interfaceIndex, &interfaceHandle);
217 ReleaseDeviceId();
218 napi_value result = nullptr;
219 napi_create_int32(env, returnValue, &result);
220 return result;
221 }
222
UsbClaimInterfaceThree(napi_env env,napi_callback_info)223 static napi_value UsbClaimInterfaceThree(napi_env env, napi_callback_info)
224 {
225 int32_t usbInitReturnValue = OH_Usb_Init();
226 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
227 GetDeviceId();
228 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
229 int32_t returnValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, nullptr);
230 ReleaseDeviceId();
231 napi_value result = nullptr;
232 napi_create_int32(env, returnValue, &result);
233 return result;
234 }
235
UsbReleaseInterface(napi_env env,napi_callback_info)236 static napi_value UsbReleaseInterface(napi_env env, napi_callback_info)
237 {
238 int32_t usbInitReturnValue = OH_Usb_Init();
239 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
240 GetDeviceId();
241 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
242 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
243 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
244 int32_t returnValue = OH_Usb_ReleaseInterface(interfaceHandle);
245 ReleaseDeviceId();
246 napi_value result = nullptr;
247 napi_create_int32(env, returnValue, &result);
248 return result;
249 }
250
UsbSelectInterfaceSettingOne(napi_env env,napi_callback_info)251 static napi_value UsbSelectInterfaceSettingOne(napi_env env, napi_callback_info)
252 {
253 int32_t usbInitReturnValue = OH_Usb_Init();
254 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
255 GetDeviceId();
256 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
257 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
258 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
259 int32_t returnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
260 ReleaseDeviceId();
261 napi_value result = nullptr;
262 napi_create_int32(env, returnValue, &result);
263 return result;
264 }
265
UsbSelectInterfaceSettingTwo(napi_env env,napi_callback_info)266 static napi_value UsbSelectInterfaceSettingTwo(napi_env env, napi_callback_info)
267 {
268 int32_t usbInitReturnValue = OH_Usb_Init();
269 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
270 GetDeviceId();
271 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
272 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
273 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
274 OH_Usb_Release();
275 int32_t returnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
276 ReleaseDeviceId();
277 napi_value result = nullptr;
278 napi_create_int32(env, returnValue, &result);
279 return result;
280 }
281
UsbGetCurrentInterfaceSettingOne(napi_env env,napi_callback_info)282 static napi_value UsbGetCurrentInterfaceSettingOne(napi_env env, napi_callback_info)
283 {
284 int32_t usbInitReturnValue = OH_Usb_Init();
285 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
286 GetDeviceId();
287 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
288 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
289 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "OH_Usb_ClaimInterface failed");
290 int32_t usbSelectInterfaceSettingReturnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
291 NAPI_ASSERT(env, usbSelectInterfaceSettingReturnValue == 0, "OH_Usb_SelectInterfaceSetting failed");
292 int32_t returnValue = OH_Usb_GetCurrentInterfaceSetting(interfaceHandle, &settingIndex);
293 ReleaseDeviceId();
294 napi_value result = nullptr;
295 napi_create_int32(env, returnValue, &result);
296 return result;
297 }
298
UsbGetCurrentInterfaceSettingTwo(napi_env env,napi_callback_info)299 static napi_value UsbGetCurrentInterfaceSettingTwo(napi_env env, napi_callback_info)
300 {
301 int32_t usbInitReturnValue = OH_Usb_Init();
302 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
303 GetDeviceId();
304 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
305 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
306 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "OH_Usb_ClaimInterface failed");
307 int32_t usbSelectInterfaceSettingReturnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
308 NAPI_ASSERT(env, usbSelectInterfaceSettingReturnValue == 0, "OH_Usb_SelectInterfaceSetting failed");
309 OH_Usb_Release();
310 int32_t returnValue = OH_Usb_GetCurrentInterfaceSetting(interfaceHandle, &settingIndex);
311 ReleaseDeviceId();
312 napi_value result = nullptr;
313 napi_create_int32(env, returnValue, &result);
314 return result;
315 }
316
UsbGetCurrentInterfaceSettingThree(napi_env env,napi_callback_info)317 static napi_value UsbGetCurrentInterfaceSettingThree(napi_env env, napi_callback_info)
318 {
319 int32_t usbInitReturnValue = OH_Usb_Init();
320 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
321 GetDeviceId();
322 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
323 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
324 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
325 int32_t usbSelectInterfaceSettingReturnValue = OH_Usb_SelectInterfaceSetting(interfaceHandle, settingIndex);
326 NAPI_ASSERT(env, usbSelectInterfaceSettingReturnValue == 0, "Usb_ClaimInterface failed");
327 int32_t returnValue = OH_Usb_GetCurrentInterfaceSetting(interfaceHandle, nullptr);
328 ReleaseDeviceId();
329 napi_value result = nullptr;
330 napi_create_int32(env, returnValue, &result);
331 return result;
332 }
333
UsbSendControlReadRequestOne(napi_env env,napi_callback_info)334 static napi_value UsbSendControlReadRequestOne(napi_env env, napi_callback_info)
335 {
336 int32_t usbInitReturnValue = OH_Usb_Init();
337 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
338 GetDeviceId();
339 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
340 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
341 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
342 struct UsbControlRequestSetup setup;
343 uint8_t data[USB_DDK_TEST_BUF_SIZE] = {0};
344 uint32_t dataLen = USB_DDK_TEST_BUF_SIZE;
345 setup.bmRequestType = 0x80;
346 setup.bRequest = 0x06;
347 setup.wValue = (0x03 << PARAM_8) | 0x01;
348 setup.wIndex = 0x409;
349 setup.wLength = dataLen;
350 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, UINT32_MAX, data, &dataLen);
351 ReleaseDeviceId();
352 napi_value result = nullptr;
353 napi_create_int32(env, returnValue, &result);
354 return result;
355 }
356
UsbSendControlReadRequestTwo(napi_env env,napi_callback_info)357 static napi_value UsbSendControlReadRequestTwo(napi_env env, napi_callback_info)
358 {
359 int32_t usbInitReturnValue = OH_Usb_Init();
360 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
361 GetDeviceId();
362 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
363 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
364 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
365 OH_Usb_Release();
366 struct UsbControlRequestSetup setup;
367 uint8_t data[USB_DDK_TEST_BUF_SIZE] = {0};
368 uint32_t dataLen = USB_DDK_TEST_BUF_SIZE;
369 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, timeout, data, &dataLen);
370 ReleaseDeviceId();
371 napi_value result = nullptr;
372 napi_create_int32(env, returnValue, &result);
373 return result;
374 }
375
UsbSendControlReadRequestThree(napi_env env,napi_callback_info)376 static napi_value UsbSendControlReadRequestThree(napi_env env, napi_callback_info)
377 {
378 int32_t usbInitReturnValue = OH_Usb_Init();
379 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
380 GetDeviceId();
381 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
382 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
383 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
384 uint8_t data[USB_DDK_TEST_BUF_SIZE] = {0};
385 uint32_t dataLen = USB_DDK_TEST_BUF_SIZE;
386 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, nullptr, timeout, data, &dataLen);
387 ReleaseDeviceId();
388 napi_value result = nullptr;
389 napi_create_int32(env, returnValue, &result);
390 return result;
391 }
392
UsbSendControlReadRequestFour(napi_env env,napi_callback_info)393 static napi_value UsbSendControlReadRequestFour(napi_env env, napi_callback_info)
394 {
395 int32_t usbInitReturnValue = OH_Usb_Init();
396 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
397 GetDeviceId();
398 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
399 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
400 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
401 struct UsbControlRequestSetup setup;
402 uint32_t dataLen = 10;
403 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, timeout, nullptr, &dataLen);
404 ReleaseDeviceId();
405 napi_value result = nullptr;
406 napi_create_int32(env, returnValue, &result);
407 return result;
408 }
409
UsbSendControlReadRequestFive(napi_env env,napi_callback_info)410 static napi_value UsbSendControlReadRequestFive(napi_env env, napi_callback_info)
411 {
412 int32_t usbInitReturnValue = OH_Usb_Init();
413 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
414 GetDeviceId();
415 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
416 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
417 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
418 struct UsbControlRequestSetup setup;
419 uint8_t data = 10;
420 int32_t returnValue = OH_Usb_SendControlReadRequest(interfaceHandle, &setup, timeout, &data, nullptr);
421 ReleaseDeviceId();
422 napi_value result = nullptr;
423 napi_create_int32(env, returnValue, &result);
424 return result;
425 }
426
UsbSendControlWriteRequestOne(napi_env env,napi_callback_info)427 static napi_value UsbSendControlWriteRequestOne(napi_env env, napi_callback_info)
428 {
429 int32_t usbInitReturnValue = OH_Usb_Init();
430 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
431 GetDeviceId();
432 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
433 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
434 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
435 struct UsbControlRequestSetup setup;
436 uint8_t data = 10;
437 uint32_t dataLen = 10;
438 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, &setup, timeout, &data, dataLen);
439 ReleaseDeviceId();
440 napi_value result = nullptr;
441 napi_create_int32(env, returnValue, &result);
442 return result;
443 }
444
UsbSendControlWriteRequestTwo(napi_env env,napi_callback_info)445 static napi_value UsbSendControlWriteRequestTwo(napi_env env, napi_callback_info)
446 {
447 int32_t usbInitReturnValue = OH_Usb_Init();
448 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
449 GetDeviceId();
450 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
451 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
452 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
453 OH_Usb_Release();
454 struct UsbControlRequestSetup setup;
455 uint8_t data = 10;
456 uint32_t dataLen = 10;
457 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, &setup, timeout, &data, dataLen);
458 ReleaseDeviceId();
459 napi_value result = nullptr;
460 napi_create_int32(env, returnValue, &result);
461 return result;
462 }
463
UsbSendControlWriteRequestThree(napi_env env,napi_callback_info)464 static napi_value UsbSendControlWriteRequestThree(napi_env env, napi_callback_info)
465 {
466 int32_t usbInitReturnValue = OH_Usb_Init();
467 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
468 GetDeviceId();
469 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
470 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
471 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
472 uint8_t data = 10;
473 uint32_t dataLen = 10;
474 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, nullptr, timeout, &data, dataLen);
475 ReleaseDeviceId();
476 napi_value result = nullptr;
477 napi_create_int32(env, returnValue, &result);
478 return result;
479 }
480
UsbSendControlWriteRequestFour(napi_env env,napi_callback_info)481 static napi_value UsbSendControlWriteRequestFour(napi_env env, napi_callback_info)
482 {
483 int32_t usbInitReturnValue = OH_Usb_Init();
484 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
485 GetDeviceId();
486 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
487 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
488 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
489 struct UsbControlRequestSetup setup;
490 uint32_t dataLen = 10;
491 int32_t returnValue = OH_Usb_SendControlWriteRequest(interfaceHandle, &setup, timeout, nullptr, dataLen);
492 ReleaseDeviceId();
493 napi_value result = nullptr;
494 napi_create_int32(env, returnValue, &result);
495 return result;
496 }
497
UsbSendPipeRequestOne(napi_env env,napi_callback_info)498 static napi_value UsbSendPipeRequestOne(napi_env env, napi_callback_info)
499 {
500 int32_t usbInitReturnValue = OH_Usb_Init();
501 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
502 GetDeviceId();
503 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
504 struct UsbDeviceDescriptor devDesc;
505 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
506 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == 0, "OH_Usb_GetDeviceDescriptor failed");
507 struct UsbDdkConfigDescriptor *config = nullptr;
508 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
509 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == 0, "OH_Usb_GetConfigDescriptor failed");
510 auto [result1, interface1, endpoint1, maxPktSize1] = GetEndpointInfo(config);
511 OH_Usb_FreeConfigDescriptor(config);
512 int32_t usbClaimInterfaceValue = OH_Usb_ClaimInterface(g_devHandle, interfaceIndex, &interfaceHandle);
513 NAPI_ASSERT(env, usbClaimInterfaceValue == 0, "Usb_ClaimInterface failed");
514 struct UsbDeviceMemMap *devMemMap = nullptr;
515 size_t bufferLen = 10;
516 int32_t UsbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(g_devHandle, bufferLen, &devMemMap);
517 NAPI_ASSERT(env, UsbCreateDeviceMemMapReturnValue == 0, "OH_Usb_CreateDeviceMemMap failed");
518 NAPI_ASSERT(env, devMemMap != nullptr, "OH_Usb_CreateDeviceMemMap failed");
519 struct UsbRequestPipe pipe;
520 pipe.interfaceHandle = interfaceHandle;
521 pipe.endpoint = endpoint1;
522 pipe.timeout = UINT32_MAX;
523 int32_t returnValue = OH_Usb_SendPipeRequest(&pipe, devMemMap);
524 OH_Usb_DestroyDeviceMemMap(devMemMap);
525 ReleaseDeviceId();
526 napi_value result = nullptr;
527 napi_create_int32(env, returnValue, &result);
528 return result;
529 }
530
UsbSendPipeRequestTwo(napi_env env,napi_callback_info)531 static napi_value UsbSendPipeRequestTwo(napi_env env, napi_callback_info)
532 {
533 int32_t usbInitReturnValue = OH_Usb_Init();
534 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
535 GetDeviceId();
536 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
537 struct UsbDeviceDescriptor devDesc;
538 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
539 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == 0, "OH_Usb_GetDeviceDescriptor failed");
540 struct UsbDdkConfigDescriptor *config = nullptr;
541 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
542 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == 0, "OH_Usb_GetConfigDescriptor failed");
543 OH_Usb_FreeConfigDescriptor(config);
544 struct UsbDeviceMemMap *devMemMap = nullptr;
545 size_t bufferLen = 10;
546 int32_t UsbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(g_devHandle, bufferLen, &devMemMap);
547 NAPI_ASSERT(env, UsbCreateDeviceMemMapReturnValue == 0, "OH_Usb_CreateDeviceMemMap failed");
548 OH_Usb_Release();
549 struct UsbRequestPipe pipe;
550 pipe.interfaceHandle = interfaceHandle;
551 pipe.endpoint = ENDPOINT;
552 pipe.timeout = UINT32_MAX;
553 int32_t returnValue = OH_Usb_SendPipeRequest(&pipe, devMemMap);
554 OH_Usb_DestroyDeviceMemMap(devMemMap);
555 ReleaseDeviceId();
556 napi_value result = nullptr;
557 napi_create_int32(env, returnValue, &result);
558 return result;
559 }
560
UsbSendPipeRequestThree(napi_env env,napi_callback_info)561 static napi_value UsbSendPipeRequestThree(napi_env env, napi_callback_info)
562 {
563 int32_t usbInitReturnValue = OH_Usb_Init();
564 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
565 GetDeviceId();
566 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
567 struct UsbDeviceDescriptor devDesc;
568 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
569 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == 0, "OH_Usb_GetDeviceDescriptor failed");
570 struct UsbDdkConfigDescriptor *config = nullptr;
571 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
572 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == 0, "OH_Usb_GetConfigDescriptor failed");
573 OH_Usb_FreeConfigDescriptor(config);
574 struct UsbDeviceMemMap *devMemMap = nullptr;
575 size_t bufferLen = 10;
576 int32_t UsbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(g_devHandle, bufferLen, &devMemMap);
577 NAPI_ASSERT(env, UsbCreateDeviceMemMapReturnValue == 0, "OH_Usb_CreateDeviceMemMap failed");
578 struct UsbRequestPipe pipe;
579 pipe.interfaceHandle = interfaceHandle;
580 pipe.endpoint = ENDPOINT;
581 pipe.timeout = UINT32_MAX;
582 int32_t returnValue = OH_Usb_SendPipeRequest(nullptr, devMemMap);
583 OH_Usb_DestroyDeviceMemMap(devMemMap);
584 ReleaseDeviceId();
585 napi_value result = nullptr;
586 napi_create_int32(env, returnValue, &result);
587 return result;
588 }
589
UsbSendPipeRequestFour(napi_env env,napi_callback_info)590 static napi_value UsbSendPipeRequestFour(napi_env env, napi_callback_info)
591 {
592 int32_t usbInitReturnValue = OH_Usb_Init();
593 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
594 GetDeviceId();
595 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
596 struct UsbDeviceDescriptor devDesc;
597 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
598 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == 0, "OH_Usb_GetDeviceDescriptor failed");
599 struct UsbDdkConfigDescriptor *config = nullptr;
600 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
601 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == 0, "OH_Usb_GetConfigDescriptor failed");
602 OH_Usb_FreeConfigDescriptor(config);
603 struct UsbDeviceMemMap *devMemMap = nullptr;
604 size_t bufferLen = 10;
605 int32_t UsbCreateDeviceMemMapReturnValue = OH_Usb_CreateDeviceMemMap(g_devHandle, bufferLen, &devMemMap);
606 NAPI_ASSERT(env, UsbCreateDeviceMemMapReturnValue == 0, "OH_Usb_CreateDeviceMemMap failed");
607 struct UsbRequestPipe pipe;
608 pipe.interfaceHandle = interfaceHandle;
609 pipe.endpoint = ENDPOINT;
610 pipe.timeout = UINT32_MAX;
611 int32_t returnValue = OH_Usb_SendPipeRequest(&pipe, nullptr);
612 OH_Usb_DestroyDeviceMemMap(devMemMap);
613 ReleaseDeviceId();
614 napi_value result = nullptr;
615 napi_create_int32(env, returnValue, &result);
616 return result;
617 }
618
UsbCreateDeviceMemMapOne(napi_env env,napi_callback_info)619 static napi_value UsbCreateDeviceMemMapOne(napi_env env, napi_callback_info)
620 {
621 int32_t usbInitReturnValue = OH_Usb_Init();
622 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
623 GetDeviceId();
624 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
625 struct UsbDeviceDescriptor devDesc;
626 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
627 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == 0, "OH_Usb_GetDeviceDescriptor failed");
628 struct UsbDdkConfigDescriptor *config = nullptr;
629 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
630 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == 0, "OH_Usb_GetConfigDescriptor failed");
631 OH_Usb_FreeConfigDescriptor(config);
632 struct UsbDeviceMemMap *devMemMap = nullptr;
633 size_t bufferLen = 10;
634 int32_t returnValue = OH_Usb_CreateDeviceMemMap(g_devHandle, bufferLen, &devMemMap);
635 OH_Usb_DestroyDeviceMemMap(devMemMap);
636 ReleaseDeviceId();
637 napi_value result = nullptr;
638 napi_create_int32(env, returnValue, &result);
639 return result;
640 }
641
UsbCreateDeviceMemMapTow(napi_env env,napi_callback_info)642 static napi_value UsbCreateDeviceMemMapTow(napi_env env, napi_callback_info)
643 {
644 int32_t usbInitReturnValue = OH_Usb_Init();
645 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
646 GetDeviceId();
647 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
648 struct UsbDeviceDescriptor devDesc;
649 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
650 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == 0, "OH_Usb_GetDeviceDescriptor failed");
651 struct UsbDdkConfigDescriptor *config = nullptr;
652 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
653 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == 0, "OH_Usb_GetConfigDescriptor failed");
654 OH_Usb_FreeConfigDescriptor(config);
655 size_t bufferLen = 10;
656 int32_t returnValue = OH_Usb_CreateDeviceMemMap(g_devHandle, bufferLen, nullptr);
657 ReleaseDeviceId();
658 napi_value result = nullptr;
659 napi_create_int32(env, returnValue, &result);
660 return result;
661 }
662
UsbDestroyDeviceMemMap(napi_env env,napi_callback_info)663 static napi_value UsbDestroyDeviceMemMap(napi_env env, napi_callback_info)
664 {
665 int32_t usbInitReturnValue = OH_Usb_Init();
666 NAPI_ASSERT(env, usbInitReturnValue == 0, "OH_Usb_Init failed");
667 GetDeviceId();
668 DEBUG_LOG("OH_Usb_UnRegisterNotificationBack %{public}llu", g_devHandle);
669 struct UsbDeviceDescriptor devDesc;
670 int32_t usbGetDeviceDescriptorReturnValue = OH_Usb_GetDeviceDescriptor(g_devHandle, &devDesc);
671 NAPI_ASSERT(env, usbGetDeviceDescriptorReturnValue == 0, "OH_Usb_GetDeviceDescriptor failed");
672 struct UsbDdkConfigDescriptor *config = nullptr;
673 int32_t usbGetConfigDescriptorReturnValue = OH_Usb_GetConfigDescriptor(g_devHandle, configIndex, &config);
674 NAPI_ASSERT(env, usbGetConfigDescriptorReturnValue == 0, "OH_Usb_GetConfigDescriptor failed");
675 OH_Usb_FreeConfigDescriptor(config);
676 struct UsbDeviceMemMap *devMemMap = nullptr;
677 size_t bufferLen = 10;
678 OH_Usb_CreateDeviceMemMap(g_devHandle, bufferLen, &devMemMap);
679 OH_Usb_DestroyDeviceMemMap(devMemMap);
680 ReleaseDeviceId();
681 napi_value result = nullptr;
682 napi_create_int32(env, true, &result);
683 return result;
684 }
685
686 EXTERN_C_START
Init(napi_env env,napi_value exports)687 static napi_value Init(napi_env env, napi_value exports)
688 {
689 napi_property_descriptor desc[] = {
690 {"usbInit", nullptr, UsbInit, nullptr, nullptr, nullptr, napi_default, nullptr},
691 {"usbRelease", nullptr, UsbRelease, nullptr, nullptr, nullptr, napi_default, nullptr},
692 {"usbGetDeviceDescriptorOne", nullptr, UsbGetDeviceDescriptorOne, nullptr, nullptr, nullptr, napi_default,
693 nullptr},
694 {"usbGetDeviceDescriptorTwo", nullptr, UsbGetDeviceDescriptorTwo, nullptr, nullptr, nullptr, napi_default,
695 nullptr},
696 {"usbGetConfigDescriptorOne", nullptr, UsbGetConfigDescriptorOne, nullptr, nullptr, nullptr, napi_default,
697 nullptr},
698 {"usbGetConfigDescriptorTwo", nullptr, UsbGetConfigDescriptorTwo, nullptr, nullptr, nullptr, napi_default,
699 nullptr},
700 {"usbGetConfigDescriptorThree", nullptr, UsbGetConfigDescriptorThree, nullptr, nullptr, nullptr, napi_default,
701 nullptr},
702 {"usbFreeConfigDescriptor", nullptr, UsbFreeConfigDescriptor, nullptr, nullptr, nullptr, napi_default, nullptr},
703 {"usbClaimInterfaceOne", nullptr, UsbClaimInterfaceOne, nullptr, nullptr, nullptr, napi_default, nullptr},
704 {"usbClaimInterfaceTwo", nullptr, UsbClaimInterfaceTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
705 {"usbClaimInterfaceThree", nullptr, UsbClaimInterfaceThree, nullptr, nullptr, nullptr, napi_default, nullptr},
706 {"usbReleaseInterface", nullptr, UsbReleaseInterface, nullptr, nullptr, nullptr, napi_default, nullptr},
707 {"usbSelectInterfaceSettingOne", nullptr, UsbSelectInterfaceSettingOne, nullptr, nullptr, nullptr, napi_default,
708 nullptr},
709 {"usbSelectInterfaceSettingTwo", nullptr, UsbSelectInterfaceSettingTwo, nullptr, nullptr, nullptr, napi_default,
710 nullptr},
711 {"usbGetCurrentInterfaceSettingOne", nullptr, UsbGetCurrentInterfaceSettingOne, nullptr, nullptr, nullptr,
712 napi_default, nullptr},
713 {"usbGetCurrentInterfaceSettingTwo", nullptr, UsbGetCurrentInterfaceSettingTwo, nullptr, nullptr, nullptr,
714 napi_default, nullptr},
715 {"usbGetCurrentInterfaceSettingThree", nullptr, UsbGetCurrentInterfaceSettingThree, nullptr, nullptr, nullptr,
716 napi_default, nullptr},
717 {"usbSendControlReadRequestOne", nullptr, UsbSendControlReadRequestOne, nullptr, nullptr, nullptr, napi_default,
718 nullptr},
719 {"usbSendControlReadRequestTwo", nullptr, UsbSendControlReadRequestTwo, nullptr, nullptr, nullptr, napi_default,
720 nullptr},
721 {"usbSendControlReadRequestThree", nullptr, UsbSendControlReadRequestThree, nullptr, nullptr, nullptr,
722 napi_default, nullptr},
723 {"usbSendControlReadRequestFour", nullptr, UsbSendControlReadRequestFour, nullptr, nullptr, nullptr,
724 napi_default, nullptr},
725 {"usbSendControlReadRequestFive", nullptr, UsbSendControlReadRequestFive, nullptr, nullptr, nullptr,
726 napi_default, nullptr},
727 {"usbSendControlWriteRequestOne", nullptr, UsbSendControlWriteRequestOne, nullptr, nullptr, nullptr,
728 napi_default, nullptr},
729 {"usbSendControlWriteRequestTwo", nullptr, UsbSendControlWriteRequestTwo, nullptr, nullptr, nullptr,
730 napi_default, nullptr},
731 {"usbSendControlWriteRequestThree", nullptr, UsbSendControlWriteRequestThree, nullptr, nullptr, nullptr,
732 napi_default, nullptr},
733 {"usbSendControlWriteRequestFour", nullptr, UsbSendControlWriteRequestFour, nullptr, nullptr, nullptr,
734 napi_default, nullptr},
735 {"usbSendPipeRequestOne", nullptr, UsbSendPipeRequestOne, nullptr, nullptr, nullptr, napi_default, nullptr},
736 {"usbSendPipeRequestTwo", nullptr, UsbSendPipeRequestTwo, nullptr, nullptr, nullptr, napi_default, nullptr},
737 {"usbSendPipeRequestThree", nullptr, UsbSendPipeRequestThree, nullptr, nullptr, nullptr, napi_default, nullptr},
738 {"usbSendPipeRequestFour", nullptr, UsbSendPipeRequestFour, nullptr, nullptr, nullptr, napi_default, nullptr},
739 {"usbCreateDeviceMemMapOne", nullptr, UsbCreateDeviceMemMapOne, nullptr, nullptr, nullptr, napi_default,
740 nullptr},
741 {"usbCreateDeviceMemMapTow", nullptr, UsbCreateDeviceMemMapTow, nullptr, nullptr, nullptr, napi_default,
742 nullptr},
743 {"usbDestroyDeviceMemMap", nullptr, UsbDestroyDeviceMemMap, nullptr, nullptr, nullptr, napi_default, nullptr}};
744
745 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
746 return exports;
747 }
748 EXTERN_C_END
749
750 static napi_module demoModule = {
751 .nm_version = 1,
752 .nm_flags = 0,
753 .nm_filename = nullptr,
754 .nm_register_func = Init,
755 .nm_modname = "libusbddk",
756 .nm_priv = ((void *)0),
757 .reserved = {0},
758 };
759
RegisterModule(void)760 extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&demoModule); }
761