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
19 /******************************************************************************
20 *
21 * Filename: conf.c
22 *
23 * Description: Contains functions to conduct run-time module configuration
24 * based on entries present in the .conf file
25 *
26 ******************************************************************************/
27
28 #define LOG_TAG "bt_vnd_conf"
29
30 #include <utils/Log.h>
31 #include <string.h>
32 #include "bt_vendor_brcm.h"
33 #include <stdio.h>
34
35 /******************************************************************************
36 ** Externs
37 ******************************************************************************/
38 int userial_set_port(char *p_conf_name, char *p_conf_value, int param);
39 int hw_set_patch_file_path(char *p_conf_name, char *p_conf_value, int param);
40 int hw_set_patch_file_name(char *p_conf_name, char *p_conf_value, int param);
41 #if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
42 int hw_set_patch_settlement_delay(char *p_conf_name, char *p_conf_value, int param);
43 #endif
44
45
46 /******************************************************************************
47 ** Local type definitions
48 ******************************************************************************/
49
50 #define CONF_COMMENT '#'
51 #define CONF_DELIMITERS " =\n\r\t"
52 #define CONF_VALUES_DELIMITERS "=\n\r\t"
53 #define CONF_MAX_LINE_LEN 255
54
55 typedef int (conf_action_t)(char *p_conf_name, char *p_conf_value, int param);
56
57 typedef struct {
58 const char *conf_entry;
59 conf_action_t *p_action;
60 int param;
61 } conf_entry_t;
62
63 /******************************************************************************
64 ** Static variables
65 ******************************************************************************/
66
67 /*
68 * Current supported entries and corresponding action functions
69 */
70 static const conf_entry_t conf_table[] = {
71 {"UartPort", userial_set_port, 0},
72 {"FwPatchFilePath", hw_set_patch_file_path, 0},
73 {"FwPatchFileName", hw_set_patch_file_name, 0},
74 #if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE)
75 {"FwPatchSettlementDelay", hw_set_patch_settlement_delay, 0},
76 #endif
77 {(const char *) NULL, NULL, 0}
78 };
79
80 /*****************************************************************************
81 ** CONF INTERFACE FUNCTIONS
82 *****************************************************************************/
83
84 /*******************************************************************************
85 **
86 ** Function vnd_load_conf
87 **
88 ** Description Read conf entry from p_path file one by one and call
89 ** the corresponding config function
90 **
91 ** Returns None
92 **
93 *******************************************************************************/
vnd_load_conf(const char * p_path)94 void vnd_load_conf(const char *p_path)
95 {
96 FILE *p_file;
97 char *p_name;
98 char *p_value;
99 conf_entry_t *p_entry;
100 char line[CONF_MAX_LINE_LEN+1]; /* add 1 for \0 char */
101
102 ALOGI("Attempt to load conf from %s", p_path);
103
104 if ((p_file = fopen(p_path, "r")) != NULL)
105 {
106 /* read line by line */
107 while (fgets(line, CONF_MAX_LINE_LEN+1, p_file) != NULL)
108 {
109 if (line[0] == CONF_COMMENT)
110 continue;
111
112 p_name = strtok(line, CONF_DELIMITERS);
113
114 if (NULL == p_name)
115 {
116 continue;
117 }
118
119 p_value = strtok(NULL, CONF_DELIMITERS);
120
121 if (NULL == p_value)
122 {
123 ALOGW("vnd_load_conf: missing value for name: %s", p_name);
124 continue;
125 }
126
127 p_entry = (conf_entry_t *)conf_table;
128
129 while (p_entry->conf_entry != NULL)
130 {
131 if (strcmp(p_entry->conf_entry, (const char *)p_name) == 0)
132 {
133 p_entry->p_action(p_name, p_value, p_entry->param);
134 break;
135 }
136
137 p_entry++;
138 }
139 }
140
141 fclose(p_file);
142 }
143 else
144 {
145 ALOGI( "vnd_load_conf file >%s< not found", p_path);
146 }
147 }
148
149