The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 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 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 19 | #define LOG_TAG "bte_conf" |
| 20 | |
Sharvil Nanavati | fa52a07 | 2014-05-04 22:48:09 -0700 | [diff] [blame] | 21 | #include <assert.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <string.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 24 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 25 | #include "bta_api.h" |
Sharvil Nanavati | fa52a07 | 2014-05-04 22:48:09 -0700 | [diff] [blame] | 26 | #include "config.h" |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 27 | #include "osi/include/log.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 29 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 30 | extern int btm_ble_tx_power[BTM_BLE_ADV_TX_POWER_MAX + 1]; |
| 31 | void bte_load_ble_conf(const char* path) |
| 32 | { |
| 33 | assert(path != NULL); |
| 34 | |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 35 | LOG_INFO("%s attempt to load ble stack conf from %s", __func__, path); |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 36 | |
| 37 | config_t *config = config_new(path); |
| 38 | if (!config) { |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 39 | LOG_INFO("%s file >%s< not found", __func__, path); |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 40 | return; |
| 41 | } |
| 42 | |
| 43 | const char* ble_adv_tx_power = config_get_string(config, CONFIG_DEFAULT_SECTION, "BLE_ADV_TX_POWER", ""); |
| 44 | if(*ble_adv_tx_power) { |
| 45 | sscanf(ble_adv_tx_power, "%d,%d,%d,%d,%d", btm_ble_tx_power, btm_ble_tx_power + 1, btm_ble_tx_power + 2, |
| 46 | btm_ble_tx_power + 3, btm_ble_tx_power + 4); |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 47 | LOG_INFO("loaded btm_ble_tx_power: %d, %d, %d, %d, %d", (char)btm_ble_tx_power[0], (char)btm_ble_tx_power[1], |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 48 | btm_ble_tx_power[2], btm_ble_tx_power[3], btm_ble_tx_power[4]); |
| 49 | } |
| 50 | config_free(config); |
| 51 | } |
| 52 | #endif |
| 53 | |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 54 | // Parses the specified Device ID configuration file and registers the |
| 55 | // Device ID records with SDP. |
| 56 | void bte_load_did_conf(const char *p_path) { |
| 57 | assert(p_path != NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 58 | |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 59 | config_t *config = config_new(p_path); |
| 60 | if (!config) { |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 61 | LOG_ERROR("%s unable to load DID config '%s'.", __func__, p_path); |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 62 | return; |
| 63 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 64 | |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 65 | for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) { |
| 66 | char section_name[16] = { 0 }; |
| 67 | snprintf(section_name, sizeof(section_name), "DID%d", i); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 68 | |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 69 | if (!config_has_section(config, section_name)) { |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 70 | LOG_DEBUG("%s no section named %s.", __func__, section_name); |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 71 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 74 | tBTA_DI_RECORD record; |
| 75 | record.vendor = config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM); |
| 76 | record.vendor_id_source = config_get_int(config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG); |
| 77 | record.product = config_get_int(config, section_name, "productId", 0); |
| 78 | record.version = config_get_int(config, section_name, "version", 0); |
| 79 | record.primary_record = config_get_bool(config, section_name, "primaryRecord", false); |
| 80 | strlcpy(record.client_executable_url, config_get_string(config, section_name, "clientExecutableURL", ""), sizeof(record.client_executable_url)); |
| 81 | strlcpy(record.service_description, config_get_string(config, section_name, "serviceDescription", ""), sizeof(record.service_description)); |
| 82 | strlcpy(record.documentation_url, config_get_string(config, section_name, "documentationURL", ""), sizeof(record.documentation_url)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 83 | |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 84 | if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG && |
| 85 | record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) { |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 86 | LOG_ERROR("%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 87 | continue; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 90 | LOG_DEBUG("Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); |
| 91 | LOG_DEBUG(" vendorId = %04x", record.vendor); |
| 92 | LOG_DEBUG(" vendorIdSource = %04x", record.vendor_id_source); |
| 93 | LOG_DEBUG(" product = %04x", record.product); |
| 94 | LOG_DEBUG(" version = %04x", record.version); |
| 95 | LOG_DEBUG(" clientExecutableURL = %s", record.client_executable_url); |
| 96 | LOG_DEBUG(" serviceDescription = %s", record.service_description); |
| 97 | LOG_DEBUG(" documentationURL = %s", record.documentation_url); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 98 | |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 99 | uint32_t record_handle; |
| 100 | tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle); |
| 101 | if (status != BTA_SUCCESS) { |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 102 | LOG_ERROR("%s unable to set device ID record %d: error %d.", __func__, i, status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 103 | } |
| 104 | } |
Sharvil Nanavati | 0e37713 | 2014-06-14 15:01:20 -0700 | [diff] [blame] | 105 | |
| 106 | config_free(config); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 107 | } |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 108 | |