blob: 655094a1e516229fc16492a7111a804e6b7ab190 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
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
Chris Mantonf8027002015-03-12 09:22:48 -070019#define LOG_TAG "bt_bte_conf"
The Android Open Source Project5738f832012-12-12 16:00:35 -080020
Sharvil Nanavatifa52a072014-05-04 22:48:09 -070021#include <assert.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080022#include <stdio.h>
23#include <string.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080024
The Android Open Source Project5738f832012-12-12 16:00:35 -080025#include "bta_api.h"
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -070026#include "btif_common.h"
Scott James Remnant47d68ee2015-04-02 15:22:29 -070027#include "osi/include/compat.h"
Sharvil Nanavati0f9b91e2015-03-12 15:42:50 -070028#include "osi/include/config.h"
Sharvil Nanavati44802762014-12-23 23:08:58 -080029#include "osi/include/log.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080030
Sharvil Nanavati0e377132014-06-14 15:01:20 -070031// Parses the specified Device ID configuration file and registers the
32// Device ID records with SDP.
33void bte_load_did_conf(const char *p_path) {
34 assert(p_path != NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -080035
Sharvil Nanavati0e377132014-06-14 15:01:20 -070036 config_t *config = config_new(p_path);
37 if (!config) {
Marie Janssendb554582015-06-26 14:53:46 -070038 LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path);
Sharvil Nanavati0e377132014-06-14 15:01:20 -070039 return;
40 }
The Android Open Source Project5738f832012-12-12 16:00:35 -080041
Sharvil Nanavati0e377132014-06-14 15:01:20 -070042 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);
The Android Open Source Project5738f832012-12-12 16:00:35 -080045
Sharvil Nanavati0e377132014-06-14 15:01:20 -070046 if (!config_has_section(config, section_name)) {
Marie Janssendb554582015-06-26 14:53:46 -070047 LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name);
Sharvil Nanavati0e377132014-06-14 15:01:20 -070048 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -080049 }
50
Sharvil Nanavati0e377132014-06-14 15:01:20 -070051 tBTA_DI_RECORD record;
52 record.vendor = config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM);
53 record.vendor_id_source = config_get_int(config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG);
54 record.product = config_get_int(config, section_name, "productId", 0);
55 record.version = config_get_int(config, section_name, "version", 0);
56 record.primary_record = config_get_bool(config, section_name, "primaryRecord", false);
57 strlcpy(record.client_executable_url, config_get_string(config, section_name, "clientExecutableURL", ""), sizeof(record.client_executable_url));
58 strlcpy(record.service_description, config_get_string(config, section_name, "serviceDescription", ""), sizeof(record.service_description));
59 strlcpy(record.documentation_url, config_get_string(config, section_name, "documentationURL", ""), sizeof(record.documentation_url));
The Android Open Source Project5738f832012-12-12 16:00:35 -080060
Sharvil Nanavati0e377132014-06-14 15:01:20 -070061 if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG &&
62 record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) {
Marie Janssendb554582015-06-26 14:53:46 -070063 LOG_ERROR(LOG_TAG, "%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i);
Sharvil Nanavati0e377132014-06-14 15:01:20 -070064 continue;
The Android Open Source Project5738f832012-12-12 16:00:35 -080065 }
66
Marie Janssendb554582015-06-26 14:53:46 -070067 LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary"));
68 LOG_DEBUG(LOG_TAG, " vendorId = %04x", record.vendor);
69 LOG_DEBUG(LOG_TAG, " vendorIdSource = %04x", record.vendor_id_source);
70 LOG_DEBUG(LOG_TAG, " product = %04x", record.product);
71 LOG_DEBUG(LOG_TAG, " version = %04x", record.version);
72 LOG_DEBUG(LOG_TAG, " clientExecutableURL = %s", record.client_executable_url);
73 LOG_DEBUG(LOG_TAG, " serviceDescription = %s", record.service_description);
74 LOG_DEBUG(LOG_TAG, " documentationURL = %s", record.documentation_url);
The Android Open Source Project5738f832012-12-12 16:00:35 -080075
Sharvil Nanavati0e377132014-06-14 15:01:20 -070076 uint32_t record_handle;
77 tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle);
78 if (status != BTA_SUCCESS) {
Marie Janssendb554582015-06-26 14:53:46 -070079 LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.", __func__, i, status);
The Android Open Source Project5738f832012-12-12 16:00:35 -080080 }
81 }
Sharvil Nanavati0e377132014-06-14 15:01:20 -070082
83 config_free(config);
The Android Open Source Project5738f832012-12-12 16:00:35 -080084}
Prerepa Viswanadham4c94c5f2014-07-18 15:20:54 -070085