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