1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef LOG_TAG
16 #define LOG_TAG "bt_napi_ble_utils"
17 #endif
18
19 #include "napi_bluetooth_utils.h"
20 #include "napi_bluetooth_ble_utils.h"
21 #include <algorithm>
22 #include <functional>
23 #include <optional>
24 #include "bluetooth_errorcode.h"
25 #include "bluetooth_log.h"
26 #include "napi/native_api.h"
27 #include "napi/native_node_api.h"
28 #include "napi_bluetooth_error.h"
29 #include "securec.h"
30
31 namespace OHOS {
32 namespace Bluetooth {
33 using namespace std;
ConvertGattServiceToJS(napi_env env,napi_value result,GattService & service)34 void ConvertGattServiceToJS(napi_env env, napi_value result, GattService& service)
35 {
36 napi_value serviceUuid;
37 napi_create_string_utf8(env, service.GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH, &serviceUuid);
38 napi_set_named_property(env, result, "serviceUuid", serviceUuid);
39
40 napi_value isPrimary;
41 napi_get_boolean(env, service.IsPrimary(), &isPrimary);
42 napi_set_named_property(env, result, "isPrimary", isPrimary);
43 HILOGI("uuid: %{public}s, isPrimary: %{public}d", service.GetUuid().ToString().c_str(), service.IsPrimary());
44
45 napi_value characteristics;
46 napi_create_array(env, &characteristics);
47 ConvertBLECharacteristicVectorToJS(env, characteristics, service.GetCharacteristics());
48 napi_set_named_property(env, result, "characteristics", characteristics);
49
50 napi_value includeServices;
51 napi_create_array(env, &includeServices);
52 vector<GattService> services;
53 vector<std::reference_wrapper<GattService>> srvs = service.GetIncludedServices();
54 for (auto &srv : srvs) {
55 services.push_back(srv.get());
56 }
57 ConvertGattServiceVectorToJS(env, includeServices, services);
58 napi_set_named_property(env, result, "includeServices", includeServices);
59 }
60
ConvertGattServiceVectorToJS(napi_env env,napi_value result,vector<GattService> & services)61 void ConvertGattServiceVectorToJS(napi_env env, napi_value result, vector<GattService>& services)
62 {
63 HILOGI("enter");
64 size_t idx = 0;
65
66 if (services.empty()) {
67 return;
68 }
69 HILOGI("size: %{public}zu", services.size());
70 for (auto& service : services) {
71 napi_value obj = nullptr;
72 napi_create_object(env, &obj);
73 ConvertGattServiceToJS(env, obj, service);
74 napi_set_element(env, result, idx, obj);
75 idx++;
76 }
77 }
78
ConvertBLECharacteristicVectorToJS(napi_env env,napi_value result,vector<GattCharacteristic> & characteristics)79 void ConvertBLECharacteristicVectorToJS(napi_env env, napi_value result,
80 vector<GattCharacteristic>& characteristics)
81 {
82 HILOGI("size: %{public}zu", characteristics.size());
83 size_t idx = 0;
84 if (characteristics.empty()) {
85 return;
86 }
87
88 for (auto &characteristic : characteristics) {
89 napi_value obj = nullptr;
90 napi_create_object(env, &obj);
91 ConvertBLECharacteristicToJS(env, obj, characteristic);
92 napi_set_element(env, result, idx, obj);
93 idx++;
94 }
95 }
96
HasProperty(int properties,int propertyMask)97 bool HasProperty(int properties, int propertyMask)
98 {
99 if (properties < 0 || propertyMask < 0) {
100 HILOGE("properties or propertyMask is less than 0");
101 return false;
102 }
103 return (static_cast<unsigned int>(properties) & static_cast<unsigned int>(propertyMask)) != 0;
104 }
ConvertGattPropertiesToJs(napi_env env,int properties)105 napi_value ConvertGattPropertiesToJs(napi_env env, int properties)
106 {
107 napi_value object;
108 napi_create_object(env, &object);
109
110 napi_value value;
111 napi_get_boolean(env, HasProperty(properties, GattCharacteristic::WRITE), &value);
112 napi_set_named_property(env, object, "write", value);
113
114 napi_get_boolean(env, HasProperty(properties, GattCharacteristic::WRITE_WITHOUT_RESPONSE), &value);
115 napi_set_named_property(env, object, "writeNoResponse", value);
116
117 napi_get_boolean(env, HasProperty(properties, GattCharacteristic::READ), &value);
118 napi_set_named_property(env, object, "read", value);
119
120 napi_get_boolean(env, HasProperty(properties, GattCharacteristic::NOTIFY), &value);
121 napi_set_named_property(env, object, "notify", value);
122
123 napi_get_boolean(env, HasProperty(properties, GattCharacteristic::INDICATE), &value);
124 napi_set_named_property(env, object, "indicate", value);
125 return object;
126 }
127
ConvertBLECharacteristicToJS(napi_env env,napi_value result,GattCharacteristic & characteristic)128 void ConvertBLECharacteristicToJS(napi_env env, napi_value result, GattCharacteristic& characteristic)
129 {
130 napi_value characteristicUuid;
131 HILOGI("uuid: %{public}s", characteristic.GetUuid().ToString().c_str());
132 napi_create_string_utf8(env, characteristic.GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH, &characteristicUuid);
133 napi_set_named_property(env, result, "characteristicUuid", characteristicUuid);
134
135 if (characteristic.GetService() != nullptr) {
136 napi_value serviceUuid;
137 napi_create_string_utf8(env, characteristic.GetService()->GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH,
138 &serviceUuid);
139 napi_set_named_property(env, result, "serviceUuid", serviceUuid);
140 }
141
142 size_t valueSize = 0;
143 uint8_t* valueData = characteristic.GetValue(&valueSize).get();
144 {
145 napi_value value = nullptr;
146 uint8_t* bufferData = nullptr;
147 napi_create_arraybuffer(env, valueSize, (void**)&bufferData, &value);
148 if (valueSize > 0 && memcpy_s(bufferData, valueSize, valueData, valueSize) != EOK) {
149 HILOGE("memcpy_s failed");
150 return;
151 }
152 napi_set_named_property(env, result, "characteristicValue", value);
153 }
154
155 napi_value propertiesValue = ConvertGattPropertiesToJs(env, characteristic.GetProperties());
156 napi_set_named_property(env, result, "properties", propertiesValue);
157
158 napi_value descriptors;
159 napi_create_array(env, &descriptors);
160 ConvertBLEDescriptorVectorToJS(env, descriptors, characteristic.GetDescriptors());
161 napi_set_named_property(env, result, "descriptors", descriptors);
162
163 napi_value characteristicValueHandle;
164 napi_create_uint32(env, static_cast<uint32_t>(characteristic.GetHandle()), &characteristicValueHandle);
165 napi_set_named_property(env, result, "characteristicValueHandle", characteristicValueHandle);
166 }
167
ConvertBLEDescriptorVectorToJS(napi_env env,napi_value result,vector<GattDescriptor> & descriptors)168 void ConvertBLEDescriptorVectorToJS(napi_env env, napi_value result, vector<GattDescriptor>& descriptors)
169 {
170 HILOGI("size: %{public}zu", descriptors.size());
171 size_t idx = 0;
172
173 if (descriptors.empty()) {
174 return;
175 }
176
177 for (auto& descriptor : descriptors) {
178 napi_value obj = nullptr;
179 napi_create_object(env, &obj);
180 ConvertBLEDescriptorToJS(env, obj, descriptor);
181 napi_set_element(env, result, idx, obj);
182 idx++;
183 }
184 }
185
ConvertBLEDescriptorToJS(napi_env env,napi_value result,GattDescriptor & descriptor)186 void ConvertBLEDescriptorToJS(napi_env env, napi_value result, GattDescriptor& descriptor)
187 {
188 HILOGI("uuid: %{public}s", descriptor.GetUuid().ToString().c_str());
189
190 napi_value descriptorUuid;
191 napi_create_string_utf8(env, descriptor.GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH, &descriptorUuid);
192 napi_set_named_property(env, result, "descriptorUuid", descriptorUuid);
193
194 if (descriptor.GetCharacteristic() != nullptr) {
195 napi_value characteristicUuid;
196 napi_create_string_utf8(env, descriptor.GetCharacteristic()->GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH,
197 &characteristicUuid);
198 napi_set_named_property(env, result, "characteristicUuid", characteristicUuid);
199
200 if (descriptor.GetCharacteristic()->GetService() != nullptr) {
201 napi_value serviceUuid;
202 napi_create_string_utf8(env, descriptor.GetCharacteristic()->GetService()->GetUuid().ToString().c_str(),
203 NAPI_AUTO_LENGTH, &serviceUuid);
204 napi_set_named_property(env, result, "serviceUuid", serviceUuid);
205 }
206 }
207
208 napi_value value;
209 size_t valueSize;
210 uint8_t* valueData = descriptor.GetValue(&valueSize).get();
211 uint8_t* bufferData = nullptr;
212 napi_create_arraybuffer(env, valueSize, (void**)&bufferData, &value);
213 if (memcpy_s(bufferData, valueSize, valueData, valueSize) != EOK) {
214 HILOGE("memcpy_s error");
215 }
216 napi_set_named_property(env, result, "descriptorValue", value);
217
218 napi_value descriptorHandle;
219 napi_create_uint32(env, static_cast<uint32_t>(descriptor.GetHandle()), &descriptorHandle);
220 napi_set_named_property(env, result, "descriptorHandle", descriptorHandle);
221 }
222
ConvertCharacteristicReadReqToJS(napi_env env,napi_value result,const std::string & device,const GattCharacteristic & characteristic,int requestId)223 void ConvertCharacteristicReadReqToJS(napi_env env, napi_value result, const std::string &device,
224 const GattCharacteristic &characteristic, int requestId)
225 {
226 napi_value deviceId;
227 napi_create_string_utf8(env, device.c_str(), NAPI_AUTO_LENGTH, &deviceId);
228 napi_set_named_property(env, result, "deviceId", deviceId);
229
230 napi_value transId;
231 napi_create_int32(env, requestId, &transId);
232 napi_set_named_property(env, result, "transId", transId);
233
234 napi_value offset;
235 napi_create_int32(env, 0, &offset);
236 napi_set_named_property(env, result, "offset", offset);
237 HILOGI("offset is %{public}d", 0);
238
239 napi_value characteristicUuid;
240 napi_create_string_utf8(env, characteristic.GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH, &characteristicUuid);
241 napi_set_named_property(env, result, "characteristicUuid", characteristicUuid);
242 HILOGI("characteristicUuid is %{public}s", characteristic.GetUuid().ToString().c_str());
243
244 if (characteristic.GetService() != nullptr) {
245 napi_value serviceUuid;
246 napi_create_string_utf8(env, characteristic.GetService()->GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH,
247 &serviceUuid);
248 napi_set_named_property(env, result, "serviceUuid", serviceUuid);
249 }
250 }
251
ConvertDescriptorReadReqToJS(napi_env env,napi_value result,const std::string & device,const GattDescriptor & descriptor,int requestId)252 void ConvertDescriptorReadReqToJS(napi_env env, napi_value result, const std::string &device,
253 const GattDescriptor& descriptor, int requestId)
254 {
255 napi_value deviceId;
256 napi_create_string_utf8(env, device.c_str(), NAPI_AUTO_LENGTH, &deviceId);
257 napi_set_named_property(env, result, "deviceId", deviceId);
258
259 napi_value transId;
260 napi_create_int32(env, requestId, &transId);
261 napi_set_named_property(env, result, "transId", transId);
262
263 napi_value offset;
264 napi_create_int32(env, 0, &offset);
265 napi_set_named_property(env, result, "offset", offset);
266 HILOGI("offset is %{public}d", 0);
267
268 napi_value descriptorUuid;
269 napi_create_string_utf8(env, descriptor.GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH, &descriptorUuid);
270 napi_set_named_property(env, result, "descriptorUuid", descriptorUuid);
271 HILOGI("descriptorUuid is %{public}s", descriptor.GetUuid().ToString().c_str());
272
273 if (descriptor.GetCharacteristic() != nullptr) {
274 napi_value characteristicUuid;
275 napi_create_string_utf8(env, descriptor.GetCharacteristic()->GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH,
276 &characteristicUuid);
277 napi_set_named_property(env, result, "characteristicUuid", characteristicUuid);
278
279 if (descriptor.GetCharacteristic()->GetService() != nullptr) {
280 napi_value serviceUuid;
281 napi_create_string_utf8(env, descriptor.GetCharacteristic()->GetService()->GetUuid().ToString().c_str(),
282 NAPI_AUTO_LENGTH, &serviceUuid);
283 napi_set_named_property(env, result, "serviceUuid", serviceUuid);
284 }
285 }
286 }
287
ConvertCharacteristicWriteReqToJS(napi_env env,napi_value result,const std::string & device,const GattCharacteristic & characteristic,int requestId)288 void ConvertCharacteristicWriteReqToJS(napi_env env, napi_value result, const std::string &device,
289 const GattCharacteristic& characteristic, int requestId)
290 {
291 napi_value deviceId;
292 napi_create_string_utf8(env, device.c_str(), NAPI_AUTO_LENGTH, &deviceId);
293 napi_set_named_property(env, result, "deviceId", deviceId);
294
295 napi_value transId;
296 napi_create_int32(env, requestId, &transId);
297 napi_set_named_property(env, result, "transId", transId);
298
299 napi_value offset;
300 napi_create_int32(env, 0, &offset);
301 napi_set_named_property(env, result, "offset", offset);
302 HILOGI("offset is %{public}d", 0);
303
304 napi_value isPrepared;
305 napi_get_boolean(env, false, &isPrepared);
306 napi_set_named_property(env, result, "isPrepared", isPrepared);
307
308 napi_value needRsp;
309 napi_get_boolean(env, characteristic.GetWriteType() == GattCharacteristic::WriteType::DEFAULT, &needRsp);
310 napi_set_named_property(env, result, "needRsp", needRsp);
311
312 napi_value value;
313 size_t valueSize;
314 uint8_t* valueData = characteristic.GetValue(&valueSize).get();
315 uint8_t* bufferData = nullptr;
316 napi_create_arraybuffer(env, valueSize, (void**)&bufferData, &value);
317 if (memcpy_s(bufferData, valueSize, valueData, valueSize) != EOK) {
318 HILOGE("memcpy_s error");
319 }
320 napi_set_named_property(env, result, "value", value);
321
322 napi_value characteristicUuid;
323 napi_create_string_utf8(env, characteristic.GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH, &characteristicUuid);
324 napi_set_named_property(env, result, "characteristicUuid", characteristicUuid);
325 HILOGI("characteristicUuid is %{public}s", characteristic.GetUuid().ToString().c_str());
326
327 if (characteristic.GetService() != nullptr) {
328 napi_value serviceUuid;
329 napi_create_string_utf8(env, characteristic.GetService()->GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH,
330 &serviceUuid);
331 napi_set_named_property(env, result, "serviceUuid", serviceUuid);
332 }
333 }
334
ConvertDescriptorWriteReqToJS(napi_env env,napi_value result,const std::string & device,const GattDescriptor & descriptor,int requestId)335 void ConvertDescriptorWriteReqToJS(napi_env env, napi_value result, const std::string &device,
336 const GattDescriptor &descriptor, int requestId)
337 {
338 napi_value deviceId;
339 napi_create_string_utf8(env, device.c_str(), NAPI_AUTO_LENGTH, &deviceId);
340 napi_set_named_property(env, result, "deviceId", deviceId);
341
342 napi_value transId;
343 napi_create_int32(env, requestId, &transId);
344 napi_set_named_property(env, result, "transId", transId);
345
346 napi_value offset;
347 napi_create_int32(env, 0, &offset);
348 napi_set_named_property(env, result, "offset", offset);
349 HILOGI("offset is %{public}d", 0);
350
351 napi_value isPrepared;
352 napi_get_boolean(env, false, &isPrepared);
353 napi_set_named_property(env, result, "isPrepared", isPrepared);
354
355 napi_value needRsp;
356 napi_get_boolean(env, true, &needRsp);
357 napi_set_named_property(env, result, "needRsp", needRsp);
358
359 napi_value value;
360 size_t valueSize;
361 uint8_t* valueData = descriptor.GetValue(&valueSize).get();
362 uint8_t* bufferData = nullptr;
363 napi_create_arraybuffer(env, valueSize, (void**)&bufferData, &value);
364 if (memcpy_s(bufferData, valueSize, valueData, valueSize) != EOK) {
365 HILOGE("memcpy_s error");
366 }
367 napi_set_named_property(env, result, "value", value);
368
369 napi_value descriptorUuid;
370 napi_create_string_utf8(env, descriptor.GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH, &descriptorUuid);
371 napi_set_named_property(env, result, "descriptorUuid", descriptorUuid);
372 HILOGI("descriptorUuid is %{public}s", descriptor.GetUuid().ToString().c_str());
373
374 if (descriptor.GetCharacteristic() != nullptr) {
375 napi_value characteristicUuid;
376 napi_create_string_utf8(env, descriptor.GetCharacteristic()->GetUuid().ToString().c_str(), NAPI_AUTO_LENGTH,
377 &characteristicUuid);
378 napi_set_named_property(env, result, "characteristicUuid", characteristicUuid);
379
380 if (descriptor.GetCharacteristic()->GetService() != nullptr) {
381 napi_value serviceUuid;
382 napi_create_string_utf8(env, descriptor.GetCharacteristic()->GetService()->GetUuid().ToString().c_str(),
383 NAPI_AUTO_LENGTH, &serviceUuid);
384 napi_set_named_property(env, result, "serviceUuid", serviceUuid);
385 }
386 }
387 }
388
ScanReportTypeInit(napi_env env)389 napi_value ScanReportTypeInit(napi_env env)
390 {
391 HILOGD("enter");
392 napi_value scanReportTypeObj = nullptr;
393 napi_create_object(env, &scanReportTypeObj);
394 SetNamedPropertyByInteger(
395 env, scanReportTypeObj, static_cast<int32_t>(ScanReportType::ON_FOUND), "ON_FOUND");
396 SetNamedPropertyByInteger(
397 env, scanReportTypeObj, static_cast<int32_t>(ScanReportType::ON_LOST), "ON_LOST");
398 return scanReportTypeObj;
399 }
400
ScanDutyInit(napi_env env)401 napi_value ScanDutyInit(napi_env env)
402 {
403 HILOGD("enter");
404 napi_value scanDutyObj = nullptr;
405 napi_create_object(env, &scanDutyObj);
406 SetNamedPropertyByInteger(
407 env, scanDutyObj, static_cast<int>(ScanDuty::SCAN_MODE_LOW_POWER), "SCAN_MODE_LOW_POWER");
408 SetNamedPropertyByInteger(
409 env, scanDutyObj, static_cast<int>(ScanDuty::SCAN_MODE_BALANCED), "SCAN_MODE_BALANCED");
410 SetNamedPropertyByInteger(
411 env, scanDutyObj, static_cast<int>(ScanDuty::SCAN_MODE_LOW_LATENCY), "SCAN_MODE_LOW_LATENCY");
412 return scanDutyObj;
413 }
414
MatchModeInit(napi_env env)415 napi_value MatchModeInit(napi_env env)
416 {
417 HILOGD("enter");
418 napi_value matchModeObj = nullptr;
419 napi_create_object(env, &matchModeObj);
420 SetNamedPropertyByInteger(
421 env, matchModeObj, static_cast<int>(MatchMode::MATCH_MODE_AGGRESSIVE), "MATCH_MODE_AGGRESSIVE");
422 SetNamedPropertyByInteger(
423 env, matchModeObj, static_cast<int>(MatchMode::MATCH_MODE_STICKY), "MATCH_MODE_STICKY");
424 return matchModeObj;
425 }
426
PhyTypeInit(napi_env env)427 napi_value PhyTypeInit(napi_env env)
428 {
429 HILOGD("enter");
430 napi_value phyTypeObj = nullptr;
431 napi_create_object(env, &phyTypeObj);
432 SetNamedPropertyByInteger(
433 env, phyTypeObj, static_cast<int32_t>(PhyType::PHY_LE_1M), "PHY_LE_1M");
434 SetNamedPropertyByInteger(
435 env, phyTypeObj, static_cast<int32_t>(PhyType::PHY_LE_ALL_SUPPORTED), "PHY_LE_ALL_SUPPORTED");
436 return phyTypeObj;
437 }
438
ScanReportModeInit(napi_env env)439 napi_value ScanReportModeInit(napi_env env)
440 {
441 HILOGD("enter");
442 napi_value reportModeObj = nullptr;
443 napi_create_object(env, &reportModeObj);
444 SetNamedPropertyByInteger(
445 env, reportModeObj, static_cast<int32_t>(ScanReportMode::NORMAL), "NORMAL");
446 SetNamedPropertyByInteger(
447 env, reportModeObj, static_cast<int32_t>(ScanReportMode::FENCE_SENSITIVITY_LOW), "FENCE_SENSITIVITY_LOW");
448 SetNamedPropertyByInteger(
449 env, reportModeObj, static_cast<int32_t>(ScanReportMode::FENCE_SENSITIVITY_HIGH), "FENCE_SENSITIVITY_HIGH");
450 return reportModeObj;
451 }
452
SetGattClientDeviceId(const std::string & deviceId)453 void SetGattClientDeviceId(const std::string &deviceId)
454 {
455 deviceAddr = deviceId;
456 }
457
GetGattClientDeviceId()458 std::string GetGattClientDeviceId()
459 {
460 return deviceAddr;
461 }
462
ToNapiValue(napi_env env) const463 napi_value NapiNativeBleCharacteristic::ToNapiValue(napi_env env) const
464 {
465 napi_value object;
466 napi_create_object(env, &object);
467 ConvertBLECharacteristicToJS(env, object, const_cast<GattCharacteristic &>(character_));
468 return object;
469 }
470
ToNapiValue(napi_env env) const471 napi_value NapiNativeBleDescriptor::ToNapiValue(napi_env env) const
472 {
473 napi_value object;
474 napi_create_object(env, &object);
475 ConvertBLEDescriptorToJS(env, object, const_cast<GattDescriptor &>(descriptor_));
476 return object;
477 }
478
ToNapiValue(napi_env env) const479 napi_value NapiNativeGattServiceArray::ToNapiValue(napi_env env) const
480 {
481 napi_value object;
482 napi_create_array(env, &object);
483 ConvertGattServiceVectorToJS(env, object, const_cast<vector<GattService> &>(gattServices_));
484 return object;
485 }
486
ToNapiValue(napi_env env) const487 napi_value NapiNativeAdvertisingStateInfo::ToNapiValue(napi_env env) const
488 {
489 napi_value object;
490 napi_create_object(env, &object);
491
492 napi_value value;
493 napi_create_int32(env, advHandle_, &value);
494 napi_set_named_property(env, object, "advertisingId", value);
495
496 napi_create_int32(env, advState_, &value);
497 napi_set_named_property(env, object, "state", value);
498 return object;
499 }
500
ToNapiValue(napi_env env) const501 napi_value NapiNativeGattsCharacterReadRequest::ToNapiValue(napi_env env) const
502 {
503 napi_value result = nullptr;
504 napi_create_object(env, &result);
505
506 ConvertCharacteristicReadReqToJS(env, result, deviceAddr_, character_, transId_);
507 return result;
508 }
509
ToNapiValue(napi_env env) const510 napi_value NapiNativeGattsCharacterWriteRequest::ToNapiValue(napi_env env) const
511 {
512 napi_value result = nullptr;
513 napi_create_object(env, &result);
514
515 ConvertCharacteristicWriteReqToJS(env, result, deviceAddr_, character_, transId_);
516 return result;
517 }
518
ToNapiValue(napi_env env) const519 napi_value NapiNativeGattsDescriptorWriteRequest::ToNapiValue(napi_env env) const
520 {
521 napi_value result = nullptr;
522 napi_create_object(env, &result);
523
524 ConvertDescriptorWriteReqToJS(env, result, deviceAddr_, descriptor_, transId_);
525 return result;
526 }
527
ToNapiValue(napi_env env) const528 napi_value NapiNativeGattsDescriptorReadRequest::ToNapiValue(napi_env env) const
529 {
530 napi_value result = nullptr;
531 napi_create_object(env, &result);
532
533 ConvertDescriptorReadReqToJS(env, result, deviceAddr_, descriptor_, transId_);
534 return result;
535 }
536 } // namespace Bluetooth
537 } // namespace OHOS
538