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