1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ble_config.h"
17
18 #include "ble_defs.h"
19 #include "log.h"
20 #include "xml_parse.h"
21
22 namespace bluetooth {
GetInstance()23 BleConfig &BleConfig::GetInstance()
24 {
25 static BleConfig instance;
26 return instance;
27 }
28
BleConfig()29 BleConfig::BleConfig()
30 {
31 config_ = AdapterDeviceConfig::GetInstance();
32 }
33
~BleConfig()34 BleConfig::~BleConfig()
35 {}
36
LoadConfigInfo() const37 bool BleConfig::LoadConfigInfo() const
38 {
39 LOG_DEBUG("[BleConfig] %{public}s", __func__);
40
41 bool ret = config_->Load();
42 if (!ret) {
43 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Load device config file failed!");
44 }
45 return ret;
46 }
47
Save() const48 bool BleConfig::Save() const
49 {
50 LOG_DEBUG("[BleConfig] %{public}s", __func__);
51
52 return config_->Save();
53 }
54
GetLocalName() const55 std::string BleConfig::GetLocalName() const
56 {
57 LOG_DEBUG("[BleConfig] %{public}s", __func__);
58
59 std::string name = "";
60 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_DEVICE_NAME, name);
61 if (!ret) {
62 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get local name failed!");
63 }
64 return name;
65 }
66
SetLocalName(const std::string & name) const67 bool BleConfig::SetLocalName(const std::string &name) const
68 {
69 LOG_DEBUG("[BleConfig] %{public}s", __func__);
70
71 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_DEVICE_NAME, name);
72 if (!ret) {
73 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set local name failed!");
74 }
75 return ret;
76 }
77
GetLocalAddress() const78 std::string BleConfig::GetLocalAddress() const
79 {
80 LOG_DEBUG("[BleConfig] %{public}s", __func__);
81
82 std::string addr = BLE_INVALID_MAC_ADDRESS;
83 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_DEVICE_ADDR, addr);
84 if (!ret) {
85 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get local address failed!");
86 }
87 return addr;
88 }
89
SetLocalAddress(const std::string & addr) const90 bool BleConfig::SetLocalAddress(const std::string &addr) const
91 {
92 LOG_DEBUG("[BleConfig] %{public}s", __func__);
93
94 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_DEVICE_ADDR, addr);
95 if (!ret) {
96 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set local address failed!");
97 }
98 return ret;
99 }
100
GetIoCapability() const101 int BleConfig::GetIoCapability() const
102 {
103 LOG_DEBUG("[BleConfig] %{public}s", __func__);
104
105 int io = 0;
106 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_IO_CAPABILITY, io);
107 if (!ret) {
108 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get local IO capability failed!");
109 }
110 return io;
111 }
112
GetLoaclPasskey() const113 std::string BleConfig::GetLoaclPasskey() const
114 {
115 LOG_DEBUG("[BleConfig] %{public}s", __func__);
116
117 std::string passkey = "";
118 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_LOCAL_PASSKEY, passkey);
119 if (!ret) {
120 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get local passkey failed!");
121 }
122 return passkey;
123 }
124
GetBleRoles() const125 int BleConfig::GetBleRoles() const
126 {
127 LOG_DEBUG("[BleConfig] %{public}s", __func__);
128
129 int roles = (GAP_LE_ROLE_BROADCASTER | GAP_LE_ROLE_OBSERVER | GAP_LE_ROLE_PREIPHERAL | GAP_LE_ROLE_CENTRAL);
130 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_ROLES, roles);
131 if (!ret) {
132 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get ble roles failed!");
133 }
134 return roles;
135 }
136
SetBleRoles(uint8_t roles) const137 bool BleConfig::SetBleRoles(uint8_t roles) const
138 {
139 LOG_DEBUG("[BleConfig] %{public}s", __func__);
140
141 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_ROLES, roles);
142 if (!ret) {
143 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble roles failed!");
144 }
145 return ret;
146 }
147
SetPasskey(const std::string & passkey) const148 bool BleConfig::SetPasskey(const std::string &passkey) const
149 {
150 LOG_DEBUG("[BleConfig] %{public}s", __func__);
151
152 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_LOCAL_PASSKEY, passkey);
153 if (!ret) {
154 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set local pass key failed!");
155 }
156 return ret;
157 }
158
GetBleModel1Level() const159 int BleConfig::GetBleModel1Level() const
160 {
161 LOG_DEBUG("[BleConfig] %{public}s", __func__);
162
163 int level = LE_MODE_1_LEVEL_1;
164 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_MODE_1_LEVEL, level);
165 if (!ret) {
166 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get ble model1 level failed!");
167 }
168 return level;
169 }
170
GetBleModel2Level() const171 int BleConfig::GetBleModel2Level() const
172 {
173 LOG_DEBUG("[BleConfig] %{public}s", __func__);
174
175 int level = LE_MODE_2_LEVEL_1;
176 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_MODE_2_LEVEL, level);
177 if (!ret) {
178 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get ble model2 level failed!");
179 }
180 return level;
181 }
182
GetBleSecurity() const183 bool BleConfig::GetBleSecurity() const
184 {
185 LOG_DEBUG("[BleConfig] %{public}s", __func__);
186
187 bool sc = false;
188 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_SECURITY, sc);
189 if (!ret) {
190 sc = true;
191 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get ble security failed!");
192 }
193 return sc;
194 }
195
GetBleScanMode() const196 int BleConfig::GetBleScanMode() const
197 {
198 LOG_DEBUG("[BleConfig] %{public}s", __func__);
199
200 int scanMode = BLE_SCAN_MODE_ALL;
201 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_SCAN_MODE, scanMode);
202 if (!ret) {
203 scanMode = BLE_SCAN_MODE_ALL;
204 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble non disc mode is valid failed!");
205 }
206 return scanMode;
207 }
208
GetBleLocalAddrType() const209 int BleConfig::GetBleLocalAddrType() const
210 {
211 LOG_DEBUG("[BleConfig] %{public}s", __func__);
212
213 int localAddrType = BLE_ADDR_TYPE_PUBLIC;
214 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_LOCAL_ADDR_TYPE, localAddrType);
215 if (!ret) {
216 localAddrType = BLE_ADDR_TYPE_PUBLIC;
217 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble non disc mode is valid failed!");
218 }
219 return localAddrType;
220 }
221
GetBleAddrType() const222 int BleConfig::GetBleAddrType() const
223 {
224 LOG_DEBUG("[BleConfig] %{public}s", __func__);
225
226 int addrType = BLE_ADDR_TYPE_PUBLIC;
227 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_ADDR_TYPE, addrType);
228 if (!ret) {
229 addrType = BLE_ADDR_TYPE_PUBLIC;
230 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble non disc mode is valid failed!");
231 }
232 return addrType;
233 }
234
SetBleModel1Level(int level) const235 bool BleConfig::SetBleModel1Level(int level) const
236 {
237 LOG_DEBUG("[BleConfig] %{public}s", __func__);
238
239 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_MODE_1_LEVEL, level);
240 if (!ret) {
241 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble model1 level failed!");
242 }
243 return ret;
244 }
245
SetBleModel2Level(int level) const246 bool BleConfig::SetBleModel2Level(int level) const
247 {
248 LOG_DEBUG("[BleConfig] %{public}s", __func__);
249
250 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_MODE_2_LEVEL, level);
251 if (!ret) {
252 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble model1 level failed!");
253 }
254 return ret;
255 }
256
SetBleSecurity(bool security) const257 bool BleConfig::SetBleSecurity(bool security) const
258 {
259 LOG_DEBUG("[BleConfig] %{public}s", __func__);
260
261 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_SECURITY, security);
262 if (!ret) {
263 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble security failed!");
264 }
265 return ret;
266 }
267
SetBleScanMode(int scanmode) const268 bool BleConfig::SetBleScanMode(int scanmode) const
269 {
270 LOG_DEBUG("[BleConfig] %{public}s", __func__);
271
272 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_SCAN_MODE, scanmode);
273 if (!ret) {
274 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble scan mode failed!");
275 }
276 return ret;
277 }
278
SetBleLocalAddrType(int localAddrType) const279 bool BleConfig::SetBleLocalAddrType(int localAddrType) const
280 {
281 LOG_DEBUG("[BleConfig] %{public}s", __func__);
282
283 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_LOCAL_ADDR_TYPE, localAddrType);
284 if (!ret) {
285 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble scan mode failed!");
286 }
287 return ret;
288 }
289
GetAppearance() const290 int BleConfig::GetAppearance() const
291 {
292 LOG_DEBUG("[BleConfig] %{public}s", __func__);
293
294 int appearance = 0;
295 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_APPEARANCE, appearance);
296 if (!ret) {
297 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get ble appearance failed!");
298 }
299 return appearance;
300 }
301
SetLocalIdentityAddr(const std::string & addr) const302 bool BleConfig::SetLocalIdentityAddr(const std::string &addr) const
303 {
304 LOG_DEBUG("[BleConfig] %{public}s", __func__);
305
306 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_LOCAL_IDENTITY_ADDR, addr);
307 if (!ret) {
308 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local identity addr failed!");
309 }
310 return ret;
311 }
312
SetLocalIrk(const std::string & irk) const313 bool BleConfig::SetLocalIrk(const std::string &irk) const
314 {
315 LOG_DEBUG("[BleConfig] %{public}s", __func__);
316
317 bool ret = config_->SetValue(SECTION_HOST, PROPERTY_BLE_LOCAL_IRK, irk);
318 if (!ret) {
319 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local csrk failed!");
320 }
321 return ret;
322 }
323
SetLocalLtk(const std::string & section,const std::string & ltk) const324 bool BleConfig::SetLocalLtk(const std::string §ion, const std::string <k) const
325 {
326 LOG_DEBUG("[BleConfig] %{public}s", __func__);
327
328 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_LTK, ltk);
329 if (!ret) {
330 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local ltk failed!");
331 }
332 return ret;
333 }
334
SetLocalKeySize(const std::string & section,const std::string & keysize) const335 bool BleConfig::SetLocalKeySize(const std::string §ion, const std::string &keysize) const
336 {
337 LOG_DEBUG("[BleConfig] %{public}s", __func__);
338
339 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_KEY_SIZE, keysize);
340 if (!ret) {
341 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local keysize failed!");
342 }
343 return ret;
344 }
345
SetLocalEdivRand(const std::string & section,const std::string & ediv,const std::string & rand) const346 bool BleConfig::SetLocalEdivRand(const std::string §ion, const std::string &ediv, const std::string &rand) const
347 {
348 LOG_DEBUG("[BleConfig] %{public}s", __func__);
349
350 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_EDIV, ediv);
351 if (!ret) {
352 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local ediv failed!");
353 }
354
355 ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_RAND, rand);
356 if (!ret) {
357 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local rand failed!");
358 }
359 return ret;
360 }
361
SetLocalCsrk(const std::string & section,const std::string & csrk) const362 bool BleConfig::SetLocalCsrk(const std::string §ion, const std::string &csrk) const
363 {
364 LOG_DEBUG("[BleConfig] %{public}s", __func__);
365
366 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_CSRK, csrk);
367 if (!ret) {
368 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local csrk failed!");
369 }
370 return ret;
371 }
372
SetLocalSignCounter(const std::string & section,uint32_t signCounter) const373 bool BleConfig::SetLocalSignCounter(const std::string §ion, uint32_t signCounter) const
374 {
375 LOG_DEBUG("[BleConfig] %{public}s", __func__);
376
377 bool ret = config_->SetValue(
378 SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_SIGN_COUNTER, std::to_string(signCounter));
379 if (!ret) {
380 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble local signCounter failed!");
381 }
382 return ret;
383 }
384
SetPeerKeyType(const std::string & section,const std::string & keytype) const385 bool BleConfig::SetPeerKeyType(const std::string §ion, const std::string &keytype) const
386 {
387 LOG_DEBUG("[BleConfig] %{public}s", __func__);
388
389 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_KEY_TYPE, keytype);
390 if (!ret) {
391 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer keytype failed!");
392 }
393 return ret;
394 }
395
SetPeerLtk(const std::string & section,const std::string & ltk) const396 bool BleConfig::SetPeerLtk(const std::string §ion, const std::string <k) const
397 {
398 LOG_DEBUG("[BleConfig] %{public}s", __func__);
399
400 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_LTK, ltk);
401 if (!ret) {
402 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer ltk failed!");
403 }
404 return ret;
405 }
406
SetPeerKeySize(const std::string & section,const std::string & keysize) const407 bool BleConfig::SetPeerKeySize(const std::string §ion, const std::string &keysize) const
408 {
409 LOG_DEBUG("[BleConfig] %{public}s", __func__);
410
411 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_KEY_SIZE, keysize);
412 if (!ret) {
413 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer keysize failed!");
414 }
415 return ret;
416 }
417
SetPeerEdivRand(const std::string & section,const std::string & ediv,const std::string & rand) const418 bool BleConfig::SetPeerEdivRand(const std::string §ion, const std::string &ediv, const std::string &rand) const
419 {
420 LOG_DEBUG("[BleConfig] %{public}s", __func__);
421
422 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_EDIV, ediv);
423 if (!ret) {
424 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer ediv failed!");
425 }
426
427 ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_RAND, rand);
428 if (!ret) {
429 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer rand failed!");
430 }
431 return ret;
432 }
433
SetPeerIdentityAddr(const std::string & section,uint8_t type,const std::string & peerAddress) const434 bool BleConfig::SetPeerIdentityAddr(const std::string §ion, uint8_t type, const std::string &peerAddress) const
435 {
436 LOG_DEBUG("[BleConfig] %{public}s", __func__);
437
438 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_IDENTITY_ADDR_TYPE, type);
439 if (!ret) {
440 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer identity addr type failed!");
441 }
442
443 ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_IDENTITY_ADDR, peerAddress);
444 if (!ret) {
445 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer identity addr failed!");
446 }
447 return ret;
448 }
449
SetPeerIrk(const std::string & section,const std::string & irk) const450 bool BleConfig::SetPeerIrk(const std::string §ion, const std::string &irk) const
451 {
452 LOG_DEBUG("[BleConfig] %{public}s", __func__);
453
454 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_IRK, irk);
455 if (!ret) {
456 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer irk failed!");
457 }
458 return ret;
459 }
460
SetPeerCsrk(const std::string & section,const std::string & csrk) const461 bool BleConfig::SetPeerCsrk(const std::string §ion, const std::string &csrk) const
462 {
463 LOG_DEBUG("[BleConfig] %{public}s", __func__);
464
465 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_CSRK, csrk);
466 if (!ret) {
467 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer csrk failed!");
468 }
469 return ret;
470 }
471
SetPeerSignCounter(const std::string & section,uint32_t signCounter) const472 bool BleConfig::SetPeerSignCounter(const std::string §ion, uint32_t signCounter) const
473 {
474 LOG_DEBUG("[BleConfig] %{public}s", __func__);
475
476 bool ret = config_->SetValue(
477 SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_SIGN_COUNTER, std::to_string(signCounter));
478 if (!ret) {
479 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set ble peer signCounter failed!");
480 }
481 return ret;
482 }
483
GetLocalIrk() const484 std::string BleConfig::GetLocalIrk() const
485 {
486 LOG_DEBUG("[BleConfig] %{public}s", __func__);
487
488 std::string irk;
489 bool ret = config_->GetValue(SECTION_HOST, PROPERTY_BLE_LOCAL_IRK, irk);
490 if (ret) {
491 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble local irk failed!");
492 }
493 return irk;
494 }
495
GetLocalLtk(const std::string & section) const496 std::string BleConfig::GetLocalLtk(const std::string §ion) const
497 {
498 LOG_DEBUG("[BleConfig] %{public}s", __func__);
499
500 std::string ltk;
501 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_LTK, ltk);
502 if (ret) {
503 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble local ltk failed!");
504 }
505 return ltk;
506 }
507
GetLocalEdiv(const std::string & section) const508 std::string BleConfig::GetLocalEdiv(const std::string §ion) const
509 {
510 LOG_DEBUG("[BleConfig] %{public}s", __func__);
511
512 std::string ediv;
513 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_EDIV, ediv);
514 if (!ret) {
515 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble local ediv failed!");
516 }
517 return ediv;
518 }
519
GetLocalRand(const std::string & section) const520 std::string BleConfig::GetLocalRand(const std::string §ion) const
521 {
522 LOG_DEBUG("[BleConfig] %{public}s", __func__);
523
524 std::string rand;
525 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_RAND, rand);
526 if (!ret) {
527 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble local rand failed!");
528 }
529 return rand;
530 }
531
GetLocalCsrk(const std::string & section) const532 std::string BleConfig::GetLocalCsrk(const std::string §ion) const
533 {
534 LOG_DEBUG("[BleConfig] %{public}s", __func__);
535
536 std::string csrk;
537 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_CSRK, csrk);
538 if (!ret) {
539 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble local csrk failed!");
540 }
541 return csrk;
542 }
543
GetLocalSignCounter(const std::string & section) const544 uint32_t BleConfig::GetLocalSignCounter(const std::string §ion) const
545 {
546 LOG_DEBUG("[BleConfig] %{public}s", __func__);
547
548 std::string signCounter = "0";
549 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_LOCAL_SIGN_COUNTER, signCounter);
550 if (!ret) {
551 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble local signCounter failed!");
552 }
553 return std::stoul(signCounter);
554 }
555
GetPeerLtk(const std::string & section) const556 std::string BleConfig::GetPeerLtk(const std::string §ion) const
557 {
558 LOG_DEBUG("[BleConfig] %{public}s", __func__);
559
560 std::string ltk;
561 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_LTK, ltk);
562 if (!ret) {
563 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble pear ltk failed!");
564 }
565 return ltk;
566 }
567
GetPeerEdiv(const std::string & section) const568 std::string BleConfig::GetPeerEdiv(const std::string §ion) const
569 {
570 LOG_DEBUG("[BleConfig] %{public}s", __func__);
571
572 std::string ediv;
573 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_EDIV, ediv);
574 if (!ret) {
575 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble pear ediv failed!");
576 }
577 return ediv;
578 }
579
GetPeerRand(const std::string & section) const580 std::string BleConfig::GetPeerRand(const std::string §ion) const
581 {
582 LOG_DEBUG("[BleConfig] %{public}s", __func__);
583
584 std::string rand;
585 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_RAND, rand);
586 if (!ret) {
587 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble pear rand failed!");
588 }
589 return rand;
590 }
591
GetPeerIdentityAddr(const std::string & section) const592 std::string BleConfig::GetPeerIdentityAddr(const std::string §ion) const
593 {
594 LOG_DEBUG("[BleConfig] %{public}s", __func__);
595
596 std::string peerAddress;
597 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_IDENTITY_ADDR, peerAddress);
598 if (!ret) {
599 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble pear identity addr failed!");
600 }
601 return peerAddress;
602 }
603
GetPeerIrk(const std::string & section) const604 std::string BleConfig::GetPeerIrk(const std::string §ion) const
605 {
606 LOG_DEBUG("[BleConfig] %{public}s", __func__);
607
608 std::string irk;
609 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_IRK, irk);
610 if (!ret) {
611 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble pear irk failed!");
612 }
613 return irk;
614 }
615
GetPeerCsrk(const std::string & section) const616 std::string BleConfig::GetPeerCsrk(const std::string §ion) const
617 {
618 LOG_DEBUG("[BleConfig] %{public}s", __func__);
619
620 std::string csrk;
621 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_CSRK, csrk);
622 if (!ret) {
623 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble pear csrk failed!");
624 }
625 return csrk;
626 }
627
GetPeerSignCounter(const std::string & section) const628 uint32_t BleConfig::GetPeerSignCounter(const std::string §ion) const
629 {
630 LOG_DEBUG("[BleConfig] %{public}s", __func__);
631
632 std::string signCounter = "0";
633 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, section, PROPERTY_BLE_PEER_SIGN_COUNTER, signCounter);
634 if (!ret) {
635 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get ble pear signCounter failed!");
636 }
637 return std::stoul(signCounter);
638 }
639
GetPeerName(const std::string & subSection) const640 std::string BleConfig::GetPeerName(const std::string &subSection) const
641 {
642 LOG_DEBUG("[BleConfig] %{public}s", __func__);
643
644 std::string name = "";
645 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_DEVICE_NAME, name);
646 if (!ret) {
647 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get peer name failed!");
648 }
649 return name;
650 }
651
GetPeerAlias(const std::string & subSection) const652 std::string BleConfig::GetPeerAlias(const std::string &subSection) const
653 {
654 LOG_DEBUG("[BleConfig] %{public}s", __func__);
655
656 std::string name = "";
657 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_ALIAS_NAME, name);
658 if (!ret) {
659 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get peer alias name failed!");
660 }
661 return name;
662 }
663
GetPeerDeviceType(const std::string & subSection) const664 int BleConfig::GetPeerDeviceType(const std::string &subSection) const
665 {
666 LOG_DEBUG("[BleConfig] %{public}s", __func__);
667
668 int type = 0;
669 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_DEVICE_TYPE, type);
670 if (!ret) {
671 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get peer device type failed!");
672 }
673 return type;
674 }
675
GetPeerDeviceIoCapability(const std::string & subSection) const676 int BleConfig::GetPeerDeviceIoCapability(const std::string &subSection) const
677 {
678 LOG_DEBUG("[BleConfig] %{public}s", __func__);
679
680 int io = 0;
681 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_IO_CAPABILITY, io);
682 if (!ret) {
683 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get peer io capability failed!");
684 }
685 return io;
686 }
687
SetPeerName(const std::string & subSection,const std::string & name) const688 bool BleConfig::SetPeerName(const std::string &subSection, const std::string &name) const
689 {
690 LOG_DEBUG("[BleConfig] %{public}s", __func__);
691
692 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_DEVICE_NAME, name);
693 if (!ret) {
694 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set peer device name failed!");
695 }
696 return ret;
697 }
698
SetPeerDeviceType(const std::string & subSection,const int type) const699 bool BleConfig::SetPeerDeviceType(const std::string &subSection, const int type) const
700 {
701 LOG_DEBUG("[BleConfig] %{public}s", __func__);
702
703 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_DEVICE_TYPE, type);
704 if (!ret) {
705 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set peer device type failed!");
706 }
707 return ret;
708 }
709
SetPeerAddressType(const std::string & subSection,const int type) const710 bool BleConfig::SetPeerAddressType(const std::string &subSection, const int type) const
711 {
712 LOG_DEBUG("[BleConfig] %{public}s", __func__);
713
714 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_BLE_PEER_ADDR_TYPE, type);
715 if (!ret) {
716 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set peer address type failed!");
717 }
718 return ret;
719 }
720
GetPeerAddressType(const std::string & subSection) const721 int BleConfig::GetPeerAddressType(const std::string &subSection) const
722 {
723 LOG_DEBUG("[BleConfig] %{public}s", __func__);
724
725 int type = 0;
726 bool ret = config_->GetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_BLE_PEER_ADDR_TYPE, type);
727 if (!ret) {
728 LOG_DEBUG("[BleConfig] %{public}s:%{public}s", __func__, "Get peer address type failed!");
729 }
730 return type;
731 }
732
RemovePairedDevice(const std::string & subSection) const733 bool BleConfig::RemovePairedDevice(const std::string &subSection) const
734 {
735 LOG_DEBUG("[BleConfig] %{public}s", __func__);
736
737 bool ret = config_->RemoveSection(SECTION_BLE_PAIRED_LIST, subSection);
738 if (!ret) {
739 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Remove paired device info failed!");
740 }
741 return ret;
742 }
743
GetPairedAddrList() const744 std::vector<std::string> BleConfig::GetPairedAddrList() const
745 {
746 LOG_DEBUG("[BleConfig] %{public}s", __func__);
747
748 std::vector<std::string> pairedList;
749 bool ret = config_->GetSubSections(SECTION_BLE_PAIRED_LIST, pairedList);
750 if (!ret) {
751 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Get Paired Device List failed!");
752 }
753 return pairedList;
754 }
755
SetPeerDeviceIoCapability(const std::string & subSection,int io) const756 bool BleConfig::SetPeerDeviceIoCapability(const std::string &subSection, int io) const
757 {
758 LOG_DEBUG("[BleConfig] %{public}s", __func__);
759
760 bool ret = config_->SetValue(SECTION_BLE_PAIRED_LIST, subSection, PROPERTY_IO_CAPABILITY, io);
761 if (!ret) {
762 LOG_ERROR("[BleConfig] %{public}s:%{public}s", __func__, "Set peer device name failed!");
763 }
764 return ret;
765 }
766 } // namespace bluetooth
767