interop.c 1.9 KB

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