Home | History | Annotate | Download | only in src
      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 <assert.h>
     22 #include <string.h> // For memcmp
     23 
     24 #include "device/include/interop.h"
     25 #include "device/include/interop_database.h"
     26 #include "osi/include/log.h"
     27 
     28 #define CASE_RETURN_STR(const) case const: return #const;
     29 
     30 static const char* interop_feature_string(const interop_feature_t feature) {
     31   switch (feature) {
     32     CASE_RETURN_STR(INTEROP_DISABLE_LE_SECURE_CONNECTIONS)
     33     CASE_RETURN_STR(INTEROP_AUTO_RETRY_PAIRING)
     34   }
     35 
     36   return "UNKNOWN";
     37 }
     38 
     39 // Interface functions
     40 
     41 bool interop_match(const interop_feature_t feature, const bt_bdaddr_t *addr) {
     42   assert(addr);
     43 
     44   const size_t db_size = sizeof(interop_database) / sizeof(interop_entry_t);
     45 
     46   for (size_t i = 0; i != db_size; ++i) {
     47     if (feature == interop_database[i].feature &&
     48         memcmp(addr, &interop_database[i].addr, interop_database[i].len) == 0) {
     49       char bdstr[20] = {0};
     50       LOG_WARN("%s() Device %s is a match for interop workaround %s", __func__,
     51           bdaddr_to_string(addr, bdstr, sizeof(bdstr)), interop_feature_string(feature));
     52       return true;
     53     }
     54   }
     55 
     56   return false;
     57 }
     58