1/******************************************************************************
2 *
3 *  Copyright (C) 2014 Google, Inc.
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_stack_config"
20
21#include <assert.h>
22
23#include "osi/include/future.h"
24#include "stack_config.h"
25#include "osi/include/log.h"
26
27const char *BTSNOOP_LOG_PATH_KEY = "BtSnoopFileName";
28const char *BTSNOOP_TURNED_ON_KEY = "BtSnoopLogOutput";
29const char *BTSNOOP_SHOULD_SAVE_LAST_KEY = "BtSnoopSaveLog";
30const char *TRACE_CONFIG_ENABLED_KEY = "TraceConf";
31
32static config_t *config;
33
34// Module lifecycle functions
35
36static future_t *init() {
37  const char *path = "/etc/bluetooth/bt_stack.conf";
38  assert(path != NULL);
39
40  LOG_INFO("%s attempt to load stack conf from %s", __func__, path);
41
42  config = config_new(path);
43  if (!config) {
44    LOG_INFO("%s file >%s< not found", __func__, path);
45    return future_new_immediate(FUTURE_FAIL);
46  }
47
48  return future_new_immediate(FUTURE_SUCCESS);
49}
50
51static future_t *clean_up() {
52  config_free(config);
53  return future_new_immediate(FUTURE_SUCCESS);
54}
55
56const module_t stack_config_module = {
57  .name = STACK_CONFIG_MODULE,
58  .init = init,
59  .start_up = NULL,
60  .shut_down = NULL,
61  .clean_up = clean_up,
62  .dependencies = {
63    NULL
64  }
65};
66
67// Interface functions
68
69static const char *get_btsnoop_log_path(void) {
70  return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log");
71}
72
73static bool get_btsnoop_turned_on(void) {
74  return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_TURNED_ON_KEY, false);
75}
76
77static bool get_btsnoop_should_save_last(void) {
78  return config_get_bool(config, CONFIG_DEFAULT_SECTION, BTSNOOP_SHOULD_SAVE_LAST_KEY, false);
79}
80
81static bool get_trace_config_enabled(void) {
82  return config_get_bool(config, CONFIG_DEFAULT_SECTION, TRACE_CONFIG_ENABLED_KEY, false);
83}
84
85static config_t *get_all(void) {
86  return config;
87}
88
89const stack_config_t interface = {
90  get_btsnoop_log_path,
91  get_btsnoop_turned_on,
92  get_btsnoop_should_save_last,
93  get_trace_config_enabled,
94  get_all
95};
96
97const stack_config_t *stack_config_get_interface() {
98  return &interface;
99}
100