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 "compat.h"
17 
18 #include <algorithm>
19 
20 namespace OHOS {
21 namespace bluetooth {
22 const std::map<CompatType, std::vector<std::string>> Compat::COMPAT_DATA = {
23     {CompatType::COMPAT_DISABLE_BLE_SECURE_CONNECTIONS, {
24         "08:62:66",
25         "38:2C:4A:C9",
26         "38:2C:4A:E6",
27         "54:A0:50:D9",
28         "AC:9E:17",
29         "F0:79:59",
30         "80:E4:DA:70",
31         "1C:96:5A"}},
32     {CompatType::COMPAT_REJECT_NAME_REQUEST, {
33         "D4:7A:E2"}},
34     {CompatType::COMPAT_REJECT_AUTO_PAIRING, {
35         "34:C7:31",
36         "00:07:04",
37         "E0:75:0A",
38         "Audi",
39         "BMW",
40         "Parrot",
41         "Car",
42         "NISSAN",
43         "CAR"}},
44     {CompatType::COMPAT_KEYBOARD_REQUIRES_FIXED_PIN, {
45         "00:0F:F6"}},
46     {CompatType::COMPAT_GATTC_NO_SERVICE_CHANGED_IND, {
47         "Pixel C Keyboard"}},
48     {CompatType::COMPAT_REJECT_AVDTP_RECONFIGURE, {
49         "00:1D:86",
50         "KMM-BT51*HD"}},
51     {CompatType::COMPAT_REJECT_ABSOLUTE_VOLUME, {
52         "44:5E:F3",
53         "D4:9C:28",
54         "00:24:1C",
55         "A4:15:66",
56         "00:26:7E",
57         "90:03:B7",
58         "0C:A6:94",
59         "00:18:6B",
60         "B8:AD:3E",
61         "A0:E9:DB",
62         "00:14:02",
63         "00:11:B1",
64         "00:14:F1",
65         "94:16:25",
66         "9C:64:8B"}}
67 };
68 
CompatCheck(CompatType type,const std::string & value)69 bool Compat::CompatCheck(CompatType type, const std::string &value)
70 {
71     auto data = COMPAT_DATA.find(type);
72     if (data != COMPAT_DATA.end()) {
73         for (auto it = data->second.begin(); it != data->second.end(); it++) {
74             if (value.compare(0, it->size(), *it) == 0) {
75                 return true;
76             }
77         }
78     }
79     return false;
80 }
81 }  // namespace bluetooth
82 }  // namespace OHOS