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