1 /******************************************************************************
2  *
3  *  Copyright (C) 2015 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 /*
19 #define LOG_TAG "bt_device_interop"
20 */
21 #include <string.h> // For memcmp
22 #include "common/bt_trace.h"
23 #include "device/bdaddr.h"
24 #include "device/interop.h"
25 #include "device/interop_database.h"
26 
27 #define CASE_RETURN_STR(const) case const: return #const;
28 
29 #if (SMP_INCLUDED == TRUE)
30 #if (!CONFIG_BT_STACK_NO_LOG)
interop_feature_string(const interop_feature_t feature)31 static const char *interop_feature_string(const interop_feature_t feature)
32 {
33     switch (feature) {
34         CASE_RETURN_STR(INTEROP_DISABLE_LE_SECURE_CONNECTIONS)
35         CASE_RETURN_STR(INTEROP_AUTO_RETRY_PAIRING)
36     }
37 
38     return "UNKNOWN";
39 }
40 #endif // (!CONFIG_BT_STACK_NO_LOG)
41 // Interface functions
interop_match(const interop_feature_t feature,const bt_bdaddr_t * addr)42 bool interop_match(const interop_feature_t feature, const bt_bdaddr_t *addr)
43 {
44     assert(addr);
45 
46     const size_t db_size = sizeof(interop_database) / sizeof(interop_entry_t);
47 
48     for (size_t i = 0; i != db_size; ++i) {
49         if (feature == interop_database[i].feature &&
50                 memcmp(addr, &interop_database[i].addr, interop_database[i].len) == 0) {
51 #if (!CONFIG_BT_STACK_NO_LOG)
52             char bdstr[20] = {0};
53 #endif
54             LOG_WARN("%s() Device %s is a match for interop workaround %s", __func__,
55                      bdaddr_to_string(addr, bdstr, sizeof(bdstr)), interop_feature_string(feature));
56             return true;
57         }
58     }
59 
60     return false;
61 }
62 #endif  ///SMP_INCLUDED == TRUE
63