1 /******************************************************************************
3 * Copyright (C) 2009-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 #define LOG_TAG "bt_bte_conf"
26 #include "osi/include/compat.h"
27 #include "osi/include/config.h"
28 #include "osi/include/log.h"
30 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
31 extern int btm_ble_tx_power[BTM_BLE_ADV_TX_POWER_MAX + 1];
32 void bte_load_ble_conf(const char* path)
36 LOG_INFO(LOG_TAG, "%s attempt to load ble stack conf from %s", __func__, path);
38 config_t *config = config_new(path);
40 LOG_INFO(LOG_TAG, "%s file >%s< not found", __func__, path);
44 const char* ble_adv_tx_power = config_get_string(config, CONFIG_DEFAULT_SECTION, "BLE_ADV_TX_POWER", "");
45 if(*ble_adv_tx_power) {
46 sscanf(ble_adv_tx_power, "%d,%d,%d,%d,%d", btm_ble_tx_power, btm_ble_tx_power + 1, btm_ble_tx_power + 2,
47 btm_ble_tx_power + 3, btm_ble_tx_power + 4);
48 LOG_INFO(LOG_TAG, "loaded btm_ble_tx_power: %d, %d, %d, %d, %d", (char)btm_ble_tx_power[0], (char)btm_ble_tx_power[1],
49 btm_ble_tx_power[2], btm_ble_tx_power[3], btm_ble_tx_power[4]);
55 // Parses the specified Device ID configuration file and registers the
56 // Device ID records with SDP.
57 void bte_load_did_conf(const char *p_path) {
58 assert(p_path != NULL);
60 config_t *config = config_new(p_path);
62 LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path);
66 for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) {
67 char section_name[16] = { 0 };
68 snprintf(section_name, sizeof(section_name), "DID%d", i);
70 if (!config_has_section(config, section_name)) {
71 LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name);
75 tBTA_DI_RECORD record;
76 record.vendor = config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM);
77 record.vendor_id_source = config_get_int(config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG);
78 record.product = config_get_int(config, section_name, "productId", 0);
79 record.version = config_get_int(config, section_name, "version", 0);
80 record.primary_record = config_get_bool(config, section_name, "primaryRecord", false);
81 strlcpy(record.client_executable_url, config_get_string(config, section_name, "clientExecutableURL", ""), sizeof(record.client_executable_url));
82 strlcpy(record.service_description, config_get_string(config, section_name, "serviceDescription", ""), sizeof(record.service_description));
83 strlcpy(record.documentation_url, config_get_string(config, section_name, "documentationURL", ""), sizeof(record.documentation_url));
85 if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG &&
86 record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) {
87 LOG_ERROR(LOG_TAG, "%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i);
91 LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary"));
92 LOG_DEBUG(LOG_TAG, " vendorId = %04x", record.vendor);
93 LOG_DEBUG(LOG_TAG, " vendorIdSource = %04x", record.vendor_id_source);
94 LOG_DEBUG(LOG_TAG, " product = %04x", record.product);
95 LOG_DEBUG(LOG_TAG, " version = %04x", record.version);
96 LOG_DEBUG(LOG_TAG, " clientExecutableURL = %s", record.client_executable_url);
97 LOG_DEBUG(LOG_TAG, " serviceDescription = %s", record.service_description);
98 LOG_DEBUG(LOG_TAG, " documentationURL = %s", record.documentation_url);
100 uint32_t record_handle;
101 tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle);
102 if (status != BTA_SUCCESS) {
103 LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.", __func__, i, status);