bte_conf.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /******************************************************************************
  2. *
  3. * Copyright 2009-2012 Broadcom Corporation
  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. #define LOG_TAG "bt_bte_conf"
  19. #include <base/logging.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include "bta_api.h"
  23. #include "btif_common.h"
  24. #include "osi/include/compat.h"
  25. #include "osi/include/config.h"
  26. #include "osi/include/log.h"
  27. // Parses the specified Device ID configuration file and registers the
  28. // Device ID records with SDP.
  29. void bte_load_did_conf(const char* p_path) {
  30. CHECK(p_path != NULL);
  31. std::unique_ptr<config_t> config = config_new(p_path);
  32. if (!config) {
  33. LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path);
  34. return;
  35. }
  36. for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) {
  37. char section_name[16] = {0};
  38. snprintf(section_name, sizeof(section_name), "DID%d", i);
  39. if (!config_has_section(*config, section_name)) {
  40. LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name);
  41. break;
  42. }
  43. tBTA_DI_RECORD record;
  44. record.vendor =
  45. config_get_int(*config, section_name, "vendorId", LMP_COMPID_GOOGLE);
  46. record.vendor_id_source = config_get_int(
  47. *config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG);
  48. record.product = config_get_int(*config, section_name, "productId", 0);
  49. record.version = config_get_int(*config, section_name, "version", 0);
  50. record.primary_record =
  51. config_get_bool(*config, section_name, "primaryRecord", false);
  52. std::string empty = "";
  53. strlcpy(
  54. record.client_executable_url,
  55. config_get_string(*config, section_name, "clientExecutableURL", &empty)
  56. ->c_str(),
  57. sizeof(record.client_executable_url));
  58. strlcpy(
  59. record.service_description,
  60. config_get_string(*config, section_name, "serviceDescription", &empty)
  61. ->c_str(),
  62. sizeof(record.service_description));
  63. strlcpy(record.documentation_url,
  64. config_get_string(*config, section_name, "documentationURL", &empty)
  65. ->c_str(),
  66. sizeof(record.documentation_url));
  67. if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG &&
  68. record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) {
  69. LOG_ERROR(LOG_TAG,
  70. "%s invalid vendor id source %d; ignoring DID record %d.",
  71. __func__, record.vendor_id_source, i);
  72. continue;
  73. }
  74. LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i,
  75. (record.primary_record ? "primary" : "not primary"));
  76. LOG_DEBUG(LOG_TAG, " vendorId = %04x", record.vendor);
  77. LOG_DEBUG(LOG_TAG, " vendorIdSource = %04x", record.vendor_id_source);
  78. LOG_DEBUG(LOG_TAG, " product = %04x", record.product);
  79. LOG_DEBUG(LOG_TAG, " version = %04x", record.version);
  80. LOG_DEBUG(LOG_TAG, " clientExecutableURL = %s",
  81. record.client_executable_url);
  82. LOG_DEBUG(LOG_TAG, " serviceDescription = %s",
  83. record.service_description);
  84. LOG_DEBUG(LOG_TAG, " documentationURL = %s", record.documentation_url);
  85. uint32_t record_handle;
  86. tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle);
  87. if (status != BTA_SUCCESS) {
  88. LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.",
  89. __func__, i, status);
  90. }
  91. }
  92. }