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 "btm_interop.h"
17
18 #include <string.h>
19
20 typedef struct {
21 uint8_t addr[BT_ADDRESS_SIZE];
22 uint8_t length;
23 uint8_t feature;
24 } BtmInteropDbEntry;
25
26 static const BtmInteropDbEntry G_INTEROP_DB[] = {
27 // BMW car kits (Harman/Becker)
28 {{0x9c, 0xdf, 0x03, 0, 0, 0}, 3, INTEROP_AUTO_RETRY_PAIRING}, // 9C:DF:03:XX:XX:XX
29 // Bose QuiteComfort 35, SoundSport and similar
30 {{0x04, 0x52, 0xc7, 0, 0, 0}, 3, INTEROP_2MBPS_LINK_ONLY}, // 04:52:C7:XX:XX:XX
31 // JayBird Family
32 {{0x00, 0x18, 0x91, 0, 0, 0}, 3, INTEROP_2MBPS_LINK_ONLY}, // 00:18:91:XX:XX:XX
33 // Sony MBH-10
34 {{0x20, 0x15, 0x06, 0, 0, 0}, 3, INTEROP_2MBPS_LINK_ONLY}, // 20:15:06:XX:XX:XX
35 // Uconnect
36 {{0x00, 0x54, 0xaf, 0, 0, 0}, 3, INTEROP_2MBPS_LINK_ONLY}, // 00:54:AF:XX:XX:XX
37 {{0x30, 0x14, 0x4a, 0, 0, 0}, 3, INTEROP_2MBPS_LINK_ONLY}, // 30:14:4A:XX:XX:XX
38 };
39
IsMatchedAddr(const uint8_t addr1[BT_ADDRESS_SIZE],const BtAddr * addr2,uint8_t length)40 static bool IsMatchedAddr(const uint8_t addr1[BT_ADDRESS_SIZE], const BtAddr *addr2, uint8_t length)
41 {
42 bool isMatched = true;
43 for (uint8_t i = 0; i < length; i++) {
44 if (addr1[i] != addr2->addr[BT_ADDRESS_SIZE - 1 - i]) {
45 isMatched = false;
46 break;
47 }
48 }
49 return isMatched;
50 }
51
BtmInteropIsMatchedAddr(uint8_t feature,const BtAddr * addr)52 bool BtmInteropIsMatchedAddr(uint8_t feature, const BtAddr *addr)
53 {
54 if (addr == NULL) {
55 return false;
56 }
57
58 const size_t dbSize = sizeof(G_INTEROP_DB) / sizeof(BtmInteropDbEntry);
59 for (size_t i = 0; i < dbSize; i++) {
60 if (feature != G_INTEROP_DB[i].feature) {
61 continue;
62 }
63
64 if (IsMatchedAddr(G_INTEROP_DB[i].addr, addr, G_INTEROP_DB[i].length)) {
65 return true;
66 }
67 }
68 return false;
69 }