1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)/****************************************************************************** 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * Copyright (C) 2009-2012 Broadcom Corporation 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License"); 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * you may not use this file except in compliance with the License. 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * You may obtain a copy of the License at: 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * http://www.apache.org/licenses/LICENSE-2.0 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * Unless required by applicable law or agreed to in writing, software 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS, 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * See the License for the specific language governing permissions and 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * limitations under the License. 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) * 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ******************************************************************************/ 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define LOG_TAG "bte_conf" 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <assert.h> 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <stdio.h> 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <string.h> 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <utils/Log.h> 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "bta_api.h" 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "config.h" 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// TODO: eliminate these global variables. 30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)extern char hci_logfile[256]; 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)extern BOOLEAN hci_logging_enabled; 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)extern BOOLEAN hci_save_log; 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)extern BOOLEAN trace_conf_enabled; 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void bte_trace_conf_config(const config_t *config); 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Reads the stack configuration file and populates global variables with 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// the contents of the file. 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void bte_load_conf(const char *path) { 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) assert(path != NULL); 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ALOGI("%s attempt to load stack conf from %s", __func__, path); 42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) config_t *config = config_new(path); 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!config) { 45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ALOGI("%s file >%s< not found", __func__, path); 46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) strlcpy(hci_logfile, config_get_string(config, CONFIG_DEFAULT_SECTION, "BtSnoopFileName", ""), sizeof(hci_logfile)); 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) hci_logging_enabled = config_get_bool(config, CONFIG_DEFAULT_SECTION, "BtSnoopLogOutput", false); 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) hci_save_log = config_get_bool(config, CONFIG_DEFAULT_SECTION, "BtSnoopSaveLog", false); 52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) trace_conf_enabled = config_get_bool(config, CONFIG_DEFAULT_SECTION, "TraceConf", false); 53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bte_trace_conf_config(config); 55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) config_free(config); 56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)extern int btm_ble_tx_power[BTM_BLE_ADV_TX_POWER_MAX + 1]; 60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void bte_load_ble_conf(const char* path) 61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles){ 62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) assert(path != NULL); 63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ALOGI("%s attempt to load ble stack conf from %s", __func__, path); 65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) config_t *config = config_new(path); 67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!config) { 68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ALOGI("%s file >%s< not found", __func__, path); 69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const char* ble_adv_tx_power = config_get_string(config, CONFIG_DEFAULT_SECTION, "BLE_ADV_TX_POWER", ""); 73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if(*ble_adv_tx_power) { 74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) sscanf(ble_adv_tx_power, "%d,%d,%d,%d,%d", btm_ble_tx_power, btm_ble_tx_power + 1, btm_ble_tx_power + 2, 75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) btm_ble_tx_power + 3, btm_ble_tx_power + 4); 76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ALOGI("loaded btm_ble_tx_power: %d, %d, %d, %d, %d", (char)btm_ble_tx_power[0], (char)btm_ble_tx_power[1], 77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) btm_ble_tx_power[2], btm_ble_tx_power[3], btm_ble_tx_power[4]); 78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) config_free(config); 80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Parses the specified Device ID configuration file and registers the 84// Device ID records with SDP. 85void bte_load_did_conf(const char *p_path) { 86 assert(p_path != NULL); 87 88 config_t *config = config_new(p_path); 89 if (!config) { 90 ALOGE("%s unable to load DID config '%s'.", __func__, p_path); 91 return; 92 } 93 94 for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) { 95 char section_name[16] = { 0 }; 96 snprintf(section_name, sizeof(section_name), "DID%d", i); 97 98 if (!config_has_section(config, section_name)) { 99 ALOGD("%s no section named %s.", __func__, section_name); 100 break; 101 } 102 103 tBTA_DI_RECORD record; 104 record.vendor = config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM); 105 record.vendor_id_source = config_get_int(config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG); 106 record.product = config_get_int(config, section_name, "productId", 0); 107 record.version = config_get_int(config, section_name, "version", 0); 108 record.primary_record = config_get_bool(config, section_name, "primaryRecord", false); 109 strlcpy(record.client_executable_url, config_get_string(config, section_name, "clientExecutableURL", ""), sizeof(record.client_executable_url)); 110 strlcpy(record.service_description, config_get_string(config, section_name, "serviceDescription", ""), sizeof(record.service_description)); 111 strlcpy(record.documentation_url, config_get_string(config, section_name, "documentationURL", ""), sizeof(record.documentation_url)); 112 113 if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG && 114 record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) { 115 ALOGE("%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); 116 continue; 117 } 118 119 ALOGD("Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); 120 ALOGD(" vendorId = %04x", record.vendor); 121 ALOGD(" vendorIdSource = %04x", record.vendor_id_source); 122 ALOGD(" product = %04x", record.product); 123 ALOGD(" version = %04x", record.version); 124 ALOGD(" clientExecutableURL = %s", record.client_executable_url); 125 ALOGD(" serviceDescription = %s", record.service_description); 126 ALOGD(" documentationURL = %s", record.documentation_url); 127 128 uint32_t record_handle; 129 tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle); 130 if (status != BTA_SUCCESS) { 131 ALOGE("%s unable to set device ID record %d: error %d.", __func__, i, status); 132 } 133 } 134 135 config_free(config); 136} 137 138