interop.c 2.1 KB

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