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