interop.c 2.0 KB

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