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 "classic_adapter_properties.h"
17 
18 #include <string>
19 
20 #include "classic_data_structure.h"
21 #include "classic_data_type_defs.h"
22 #include "classic_defs.h"
23 #include "classic_utils.h"
24 #include "gap_if.h"
25 #include "log_util.h"
26 #include "raw_address.h"
27 #include "securec.h"
28 
29 namespace OHOS {
30 namespace bluetooth {
GetInstance()31 ClassicAdapterProperties &ClassicAdapterProperties::GetInstance()
32 {
33     static ClassicAdapterProperties instance;
34     return instance;
35 }
36 
ClassicAdapterProperties()37 ClassicAdapterProperties::ClassicAdapterProperties() : config_(ClassicConfig::GetInstance())
38 {}
39 
~ClassicAdapterProperties()40 ClassicAdapterProperties::~ClassicAdapterProperties()
41 {}
42 
LoadConfigInfo()43 bool ClassicAdapterProperties::LoadConfigInfo()
44 {
45     if (!config_.LoadConfigFile()) {
46         LOG_ERROR("Load config file failed!");
47         return false;
48     } else {
49         LoadHostInfo();
50     }
51 
52     return true;
53 }
54 
LoadHostInfo()55 void ClassicAdapterProperties::LoadHostInfo()
56 {
57     deviceName_ = config_.GetLocalName();
58     if (deviceName_.empty()) {
59         deviceName_ = DEFAULT_DEVICE_NAME;
60     }
61 
62     cod_ = (config_.GetLocalDeviceClass() & CLASS_OF_DEVICE_RANGE);
63     if (INVALID_VALUE > cod_) {
64         cod_ = DEFAULT_CLASS_OF_DEVICE;
65     }
66 
67     ioCapability_ = config_.GetIoCapability();
68     if ((GAP_IO_DISPLAYONLY > ioCapability_) || (GAP_IO_NOINPUTNOOUTPUT < ioCapability_)) {
69         ioCapability_ = GAP_IO_DISPLAYYESNO;
70     }
71 
72     passkey_ = config_.GetLocalPasskey();
73     if (passkey_.empty()) {
74         passkey_ = DEFAULT_PASSKEY;
75     }
76 
77     securityMode_ = config_.GetSecurityMode();
78     if ((securityMode_ != SEC_MODE_2) && (securityMode_ != SEC_MODE_4)) {
79         securityMode_ = SEC_MODE_2;
80     }
81 
82     LOG_DEBUG("Get Host info:");
83     LOG_DEBUG("Device name is: %{public}s", deviceName_.c_str());
84     LOG_DEBUG("Class of device is: %{public}d", cod_);
85     LOG_DEBUG("IoCapability is: %{public}d", ioCapability_);
86     LOG_DEBUG("Passkey is: %{public}s", passkey_.c_str());
87     LOG_DEBUG("securityMode is: %{public}d", securityMode_);
88 }
89 
GetLocalName() const90 std::string ClassicAdapterProperties::GetLocalName() const
91 {
92     return deviceName_;
93 }
94 
SetLocalName(const std::string &name)95 bool ClassicAdapterProperties::SetLocalName(const std::string &name)
96 {
97     std::lock_guard<std::recursive_mutex> lock(propertiesMutex_);
98 
99     int length = name.length();
100     if (length > MAX_LOC_BT_NAME_LEN) {
101         std::string ellipsis = "...";
102         int limitLength = MAX_LOC_BT_NAME_LEN - ellipsis.length();
103         deviceName_ = name.substr(0, limitLength);
104         deviceName_ += ellipsis;
105     } else {
106         deviceName_ = name;
107     }
108 
109     // Update controller
110     bool ret = (GAPIF_SetLocalName(deviceName_.c_str(), length) == BT_SUCCESS);
111     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "GAPIF_SetLocalName", ret);
112 
113     // Set EIR
114     ret &= SetEirData();
115     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetEirData", ret);
116 
117     // Update config
118     ret &= UpdateConfig(BT_PROPERTY_BDNAME);
119     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "UpdateConfig", ret);
120 
121     return ret;
122 }
123 
GetLocalAddress() const124 std::string ClassicAdapterProperties::GetLocalAddress() const
125 {
126     return macAddr_;
127 }
128 
GetLocalDeviceClass() const129 int ClassicAdapterProperties::GetLocalDeviceClass() const
130 {
131     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s cod: %{public}d", __func__, cod_);
132     return cod_;
133 }
134 
SetLocalDeviceClass(int deviceClass)135 bool ClassicAdapterProperties::SetLocalDeviceClass(int deviceClass)
136 {
137     bool ret = false;
138     cod_ = deviceClass;
139 
140     int result = GAPIF_SetClassOfDevice(cod_);
141     if (result != BT_SUCCESS) {
142         LOG_ERROR("ClassicAdapterProperties::%{public}s GAPIF_SetClassOfDevice failed!", __func__);
143         return ret;
144     }
145 
146     ret = UpdateConfig(BT_PROPERTY_CLASS_OF_DEVICE);
147     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "UpdateConfig", ret);
148 
149     return true;
150 }
151 
GetBondableMode() const152 int ClassicAdapterProperties::GetBondableMode() const
153 {
154     return bondableMode_;
155 }
156 
SetBondableMode(int mode)157 bool ClassicAdapterProperties::SetBondableMode(int mode)
158 {
159     if (mode < BONDABLE_MODE_OFF || mode > BONDABLE_MODE_ON) {
160         LOG_ERROR("ClassicAdapterProperties::%{public}s. Invalid Parameter", __func__);
161         return false;
162     }
163 
164     switch (mode) {
165         case BONDABLE_MODE_OFF:
166             bondableMode_ = GAP_BONDABLE_MODE_NON;
167             break;
168         case BONDABLE_MODE_ON:
169             bondableMode_ = GAP_BONDABLE_MODE;
170             break;
171         default:
172             bondableMode_ = GAP_BONDABLE_MODE_NON;
173             break;
174     }
175     int ret = GAPIF_SetBondableMode(bondableMode_);
176     if (ret != BT_SUCCESS) {
177         return false;
178     }
179 
180     return true;
181 }
182 
GetPasskey() const183 std::string ClassicAdapterProperties::GetPasskey() const
184 {
185     return passkey_;
186 }
187 
GetIoCapability() const188 int ClassicAdapterProperties::GetIoCapability() const
189 {
190     return ioCapability_;
191 }
192 
SetIoCapability(int ioCapability)193 bool ClassicAdapterProperties::SetIoCapability(int ioCapability)
194 {
195     ioCapability_ = ioCapability;
196     return true;
197 }
198 
ConfigProperties()199 bool ClassicAdapterProperties::ConfigProperties()
200 {
201     /// Read MAC Addr from Controller.
202     bool ret = ReadAddrFromController();
203     if (!ret) {
204         return ret;
205     }
206 
207     /// Update MAC Addr to config file.
208     ret &= UpdateConfig(BT_PROPERTY_BDADDR);
209     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "UpdateConfig", ret);
210 
211     ret &= SetLocalName(deviceName_);
212     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetLocalName", ret);
213 
214     // Set Class of Device.
215     ret &= SetLocalDeviceClass(cod_);
216     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetLocalDeviceClass", ret);
217 
218     return ret;
219 }
220 
InitMode()221 bool ClassicAdapterProperties::InitMode()
222 {
223     /// Set BondMode.
224     bool ret = true;
225     if (bondableMode_ != BONDABLE_MODE_OFF) {
226         ret = SetBondableMode(BONDABLE_MODE_OFF);
227         ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetBondableMode", ret);
228     }
229 
230     return ret;
231 }
232 
SetSecurityMode()233 bool ClassicAdapterProperties::SetSecurityMode()
234 {
235     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
236 
237     bool ret = (GAPIF_SetSecurityMode((GAP_SecurityMode)securityMode_) == BT_SUCCESS);
238     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "GAPIF_SetSecurityMode", ret);
239 
240     return ret;
241 }
242 
GetDiscoverableTimeout() const243 int ClassicAdapterProperties::GetDiscoverableTimeout() const
244 {
245     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
246 
247     return discoverableTimeout_;
248 }
249 
SetDiscoverableTimeout(int time)250 bool ClassicAdapterProperties::SetDiscoverableTimeout(int time)
251 {
252     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s time = %{public}d", __func__, time);
253 
254     bool ret = true;
255     if (discoverableTimeout_ != time) {
256         discoverableTimeout_ = time;
257     } else {
258         LOG_WARN("ClassicAdapterProperties::SetDiscoverableTimeout same value");
259     }
260 
261     return ret;
262 }
263 
ReadAddrFromController()264 bool ClassicAdapterProperties::ReadAddrFromController()
265 {
266     BtAddr btAddr;
267     errno_t result = memset_s(&btAddr, sizeof(BtAddr), 0, sizeof(BtAddr));
268     if (result != EOK) {
269         LOG_ERROR("%{public}s::memset_s failed!", __func__);
270         return false;
271     }
272 
273     bool ret = (GAPIF_GetLocalAddr(&btAddr) == BT_SUCCESS);
274     if (!ret) {
275         return ret;
276     }
277     macAddr_ = RawAddress::ConvertToString(btAddr.addr).GetAddress();
278     HILOGI("GAPIF_GetLocalAddr: %{public}s", GetEncryptAddr(macAddr_).c_str());
279 
280     return ret;
281 }
282 
UpdateConfig(int type)283 bool ClassicAdapterProperties::UpdateConfig(int type)
284 {
285     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s Type: %{public}d", __func__, type);
286 
287     bool ret = false;
288     switch (type) {
289         case BT_PROPERTY_BDNAME: {
290             ret = config_.SetLocalName(deviceName_);
291             if (ret == false) {
292                 LOG_ERROR("UpdateConfig::SetLocalName failed");
293             } else {
294                 SendDeviceNameChanged(deviceName_);
295             }
296             break;
297         }
298         case BT_PROPERTY_BDADDR: {
299             ret = config_.SetLocalAddress(macAddr_);
300             if (ret == false) {
301                 LOG_ERROR("UpdateConfig::SetLocalAddress failed");
302             } else {
303                 SendDeviceAddrChanged(macAddr_);
304             }
305             break;
306         }
307         case BT_PROPERTY_CLASS_OF_DEVICE:
308             ret = config_.SetLocalDeviceClass(cod_);
309             ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetLocalDeviceClass", ret);
310             break;
311         case BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT:
312             ret = config_.SetDiscoverableTimeout(discoverableTimeout_);
313             ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetDiscoverableTimeout", ret);
314             break;
315         default:
316             break;
317     }
318 
319     ret = config_.Save();
320     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "Save", ret);
321 
322     return ret;
323 }
324 
SendDeviceNameChanged(const std::string &deviceName)325 void ClassicAdapterProperties::SendDeviceNameChanged(const std::string &deviceName)
326 {
327     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
328 
329     adapterObservers_.ForEach(
330         [deviceName](IAdapterClassicObserver &observer) { observer.OnDeviceNameChanged(deviceName); });
331 }
332 
SendDeviceAddrChanged(const std::string &address)333 void ClassicAdapterProperties::SendDeviceAddrChanged(const std::string &address)
334 {
335     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
336 
337     adapterObservers_.ForEach([address](IAdapterClassicObserver &observer) { observer.OnDeviceAddrChanged(address); });
338 }
339 
SetEirData()340 bool ClassicAdapterProperties::SetEirData()
341 {
342     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
343 
344     std::lock_guard<std::recursive_mutex> lock(propertiesMutex_);
345     bool ret = true;
346     /// New bluetooth object to make up the eir data.
347     std::unique_ptr<ClassicBluetoothData> eirData = std::make_unique<ClassicBluetoothData>();
348 
349     /// Set data length for eir.
350     eirData->SetDataMaxLength(MAX_EXTEND_INQUIRY_RESPONSE_LEN);
351 
352     /// Set eir name length and eir type.
353     uint8_t nameLen = deviceName_.length() + EXTEND_INQUIRY_RESPONSE_TYPE_SIZE;
354     int nameType = BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME;
355 
356     uint8_t uuidLen = (UUID16_BYTES_TYPE * uuids_.size()) + EXTEND_INQUIRY_RESPONSE_TYPE_SIZE;
357     if (EXTEND_INQUIRY_RESPONSE_TYPE_SIZE < uuidLen) {
358         int dataLen = nameLen + EXTEND_INQUIRY_RESPONSE_LENGTH_SIZE + uuidLen + EXTEND_INQUIRY_RESPONSE_LENGTH_SIZE;
359         if (dataLen >= MAX_EXTEND_INQUIRY_RESPONSE_LEN) {
360             nameType = BLUETOOTH_DATA_TYPE_SHORTENED_LOCAL_NAME;
361             nameLen = MAX_EXTEND_INQUIRY_RESPONSE_LEN - (uuidLen + EXTEND_INQUIRY_RESPONSE_LENGTH_SIZE) -
362                       EXTEND_INQUIRY_RESPONSE_TYPE_SIZE;
363         }
364     } else {
365         if (nameLen >= MAX_EXTEND_INQUIRY_RESPONSE_LEN) {
366             nameType = BLUETOOTH_DATA_TYPE_SHORTENED_LOCAL_NAME;
367             nameLen = MAX_EXTEND_INQUIRY_RESPONSE_LEN - EXTEND_INQUIRY_RESPONSE_TYPE_SIZE;
368         }
369     }
370     std::string subString = deviceName_.substr(0, (nameLen - 1));
371     std::vector<uint8_t> eirName;
372     eirName.assign(subString.begin(), subString.end());
373 
374     /// Construct the eir data
375     ClassicDataStructure nameData(nameLen, nameType, eirName);
376     eirData->AddDataStructure(nameData);
377 
378     if (!uuids_.empty()) {
379         int uuidType = BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS;
380         std::vector<uint8_t> value(uuidLen - EXTEND_INQUIRY_RESPONSE_TYPE_SIZE);
381         int idx = 0;
382         for (auto it = uuids_.begin(); it != uuids_.end(); it++) {
383             uint16_t uuid = (*it).ConvertTo16Bits();
384             value[idx] = (uint8_t)(uuid & 0x00FF);
385             value[idx + 1] = (uint8_t)((uuid & 0xFF00) >> MOVE_ONE_BYTE);
386             idx += sizeof(uint16_t);
387         }
388         ClassicDataStructure uuidData(uuidLen, uuidType, value);
389         eirData->AddDataStructure(uuidData);
390         value.clear();
391     }
392 
393     /// Set eir data to GAP
394     int result = GAPIF_SetExtendedInquiryResponse(eirData->GetClassicBluetoothData().data());
395     if (result != BT_SUCCESS) {
396         LOG_ERROR("ClassicAdapterProperties::GAPIF_SetExtendedInquiryResponse failed, ret = %{public}d", result);
397         ret = false;
398     }
399     return ret;
400 }
401 
RegisterClassicAdapterObserver(IAdapterClassicObserver &observer)402 void ClassicAdapterProperties::RegisterClassicAdapterObserver(IAdapterClassicObserver &observer)
403 {
404     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
405     adapterObservers_.Register(observer);
406 }
407 
DeregisterClassicAdapterObserver(IAdapterClassicObserver &observer)408 void ClassicAdapterProperties::DeregisterClassicAdapterObserver(IAdapterClassicObserver &observer)
409 {
410     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
411     adapterObservers_.Deregister(observer);
412 }
413 
GetPairedAddrList() const414 std::vector<std::string> ClassicAdapterProperties::GetPairedAddrList() const
415 {
416     return config_.GetPairedAddrList();
417 }
418 
SaveConfigFile() const419 void ClassicAdapterProperties::SaveConfigFile() const
420 {
421     LOG_DEBUG("[ClassicAdapterProperties]::%{public}s", __func__);
422     bool ret = config_.Save();
423     LOG_DEBUG("ClassicAdapterProperties::%{public}s result = %{public}d", __func__, ret);
424 }
425 
GetPairedDevice(std::string addr)426 std::shared_ptr<ClassicRemoteDevice> ClassicAdapterProperties::GetPairedDevice(std::string addr)
427 {
428     HILOGI("addr: %{public}s", GetEncryptAddr(addr).c_str());
429 
430     std::shared_ptr<ClassicRemoteDevice> remote = std::make_shared<ClassicRemoteDevice>(addr);
431 
432     std::string name = config_.GetRemoteName(addr);
433     remote->SetRemoteName(name);
434 
435     std::string alias = config_.GetRemoteAlias(addr);
436     remote->SetAliasName(alias);
437 
438     int linkKeyType = config_.GetRemoteLinkkeyType(addr);
439     remote->SetLinkKeyType(linkKeyType);
440 
441     if (linkKeyType != PAIR_INVALID_LINK_KEY_TYPE) {
442         std::string key = config_.GetRemoteLinkkey(addr);
443         LOG_DEBUG("Get linkKey value is %{public}s", key.c_str());
444         std::vector<uint8_t> linkKey;
445         ClassicUtils::ConvertHexStringToInt(key, linkKey);
446         remote->SetLinkKey(linkKey);
447     }
448 
449     int io = config_.GetRemoteDeviceIoCapability(addr);
450     remote->SetIoCapability(io);
451 
452     int cod = config_.GetRemoteDeviceClass(addr);
453     remote->SetDeviceClass(cod);
454 
455     int deviceType = config_.GetRemoteDeviceType(addr);
456     remote->SetDeviceType(deviceType);
457 
458     bool pairFlag = config_.GetRemoteDevicePairFlag(addr);
459     if (pairFlag == true) {
460         remote->SetPairedStatus(PAIR_PAIRED);
461     }
462 
463     bool bondFromLocal = config_.GetRemoteDeviceBondFromLocal(addr);
464     remote->SetBondedFromLocal(bondFromLocal);
465 
466     std::string uuidVal = config_.GetRemoteUuids(addr);
467     std::vector<Uuid> uuids = ClassicUtils::ConvertStringToUuid(uuidVal);
468     if (!uuids.empty()) {
469         remote->SetDeviceUuids(uuids);
470     }
471 
472     return remote;
473 }
474 
SavePairedDeviceInfo(std::shared_ptr<ClassicRemoteDevice> remote)475 void ClassicAdapterProperties::SavePairedDeviceInfo(std::shared_ptr<ClassicRemoteDevice> remote)
476 {
477     HILOGI("addr: %{public}s", GetEncryptAddr(remote->GetAddress()).c_str());
478     std::string addr = remote->GetAddress();
479 
480     std::string name = remote->GetRemoteName();
481     if (!name.empty()) {
482         config_.SetRemoteName(addr, name);
483     }
484 
485     std::string alias = remote->GetAliasName();
486     if (!alias.empty()) {
487         config_.SetRemoteAlias(addr, alias);
488     }
489 
490     int linkKeyType = remote->GetLinkKeyType();
491     config_.SetRemoteLinkkeyType(addr, linkKeyType);
492 
493     if (linkKeyType != PAIR_INVALID_LINK_KEY_TYPE) {
494         std::vector<uint8_t> linkKey = remote->GetLinkKey();
495         std::string key = ClassicUtils::ConvertIntToHexString(linkKey);
496         LOG_DEBUG("Save LinkKey value is %{public}s", key.c_str());
497         config_.SetRemoteLinkkey(addr, key);
498     }
499 
500     int io = remote->GetIoCapability();
501     config_.SetRemoteDeviceIoCapability(addr, io);
502 
503     int cod = remote->GetDeviceClass();
504     config_.SetRemoteDeviceClass(addr, cod);
505 
506     int deviceType = remote->GetDeviceType();
507     config_.SetRemoteDeviceType(addr, deviceType);
508 
509     bool pairFlag = remote->IsPaired();
510     config_.SetRemoteDevicePairFlag(addr, pairFlag);
511 
512     bool bondFromLocal = remote->IsBondedFromLocal();
513     config_.SetRemoteDeviceBondFromLocal(addr, bondFromLocal);
514 
515     std::lock_guard<std::recursive_mutex> lock(propertiesMutex_);
516     std::vector<Uuid> uuids = remote->GetDeviceUuids();
517     if (uuids.empty()) {
518         return;
519     }
520     std::string uuidVal = ClassicUtils::ConvertUuidToString(uuids);
521     if (!uuidVal.empty()) {
522         config_.SetRemoteUuids(addr, uuidVal);
523     }
524 }
525 
RemovePairedDeviceInfo(std::string addr) const526 void ClassicAdapterProperties::RemovePairedDeviceInfo(std::string addr) const
527 {
528     HILOGI("addr: %{public}s", GetEncryptAddr(addr).c_str());
529 
530     bool ret = config_.RemovePairedDevice(addr);
531     if (ret == false) {
532         HILOGI("failed, addr is %{public}s", GetEncryptAddr(addr).c_str());
533     }
534 }
535 
SaveSupportUuids(const std::vector<Uuid> &uuids)536 bool ClassicAdapterProperties::SaveSupportUuids(const std::vector<Uuid> &uuids)
537 {
538     std::lock_guard<std::recursive_mutex> lock(propertiesMutex_);
539 
540     if (uuids.empty()) {
541         LOG_DEBUG("ClassicAdapterProperties::%{public}s input parameter(uuids) is null.", __func__);
542         return false;
543     }
544 
545     if (!uuids_.empty()) {
546         uuids_.clear();
547     }
548     uuids_ = uuids;
549 
550     bool ret = SetEirData();
551     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetEirData", ret);
552 
553     return ret;
554 }
555 
SetHidPnpInfo(const std::string &addr, int vendorId, int productId, int version)556 bool ClassicAdapterProperties::SetHidPnpInfo(const std::string &addr, int vendorId, int productId, int version)
557 {
558     bool retVendorId = config_.SetRemoteHidVendorId(addr, vendorId);
559     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetRemoteHidVendorId", retVendorId);
560 
561     bool retProductId = config_.SetRemoteHidProductId(addr, productId);
562     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetRemoteHidProductId", retProductId);
563 
564     bool retVersion = config_.SetRemoteHidVersion(addr, version);
565     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetRemoteHidVersion", retVersion);
566 
567     if (retVendorId && retProductId && retVersion) {
568         return true;
569     }
570     return false;
571 }
572 
SetHidDescInfo(const std::string &addr, int ctryCode, const std::string &descInfo)573 bool ClassicAdapterProperties::SetHidDescInfo(const std::string &addr, int ctryCode, const std::string &descInfo)
574 {
575     bool retCtryCode = config_.SetRemoteHidCtryCode(addr, ctryCode);
576     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetRemoteHidCtryCode", retCtryCode);
577 
578     bool retDescInfo = config_.SetRemoteHidDescInfo(addr, descInfo);
579     ClassicUtils::CheckReturnValue("ClassicAdapaterProperties", "SetRemoteHidProductId", retDescInfo);
580 
581     if (retCtryCode && retDescInfo) {
582         return true;
583     }
584     return false;
585 }
586 
GetHidPnpInfo(const std::string &addr, int &vendorId, int &productId, int &version)587 void ClassicAdapterProperties::GetHidPnpInfo(const std::string &addr, int &vendorId, int &productId, int &version)
588 {
589     vendorId = config_.GetRemoteHidVendorId(addr);
590     productId = config_.GetRemoteHidProductId(addr);
591     version = config_.GetRemoteHidVersion(addr);
592 }
593 
GetHidDescInfo(const std::string &addr, int &ctryCode, std::string &descInfo)594 void ClassicAdapterProperties::GetHidDescInfo(const std::string &addr, int &ctryCode, std::string &descInfo)
595 {
596     ctryCode = config_.GetRemoteHidCtryCode(addr);
597     descInfo = config_.GetRemoteHidDescInfo(addr);
598 }
599 }  // namespace bluetooth
600 }  // namespace OHOS