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 <string.h> 31#include <stdio.h> 32#include <utils/Log.h> 33#include "bt_vendor_brcm.h" 34 35/****************************************************************************** 36** Externs 37******************************************************************************/ 38int userial_set_port(char *p_conf_name, char *p_conf_value, int param); 39int hw_set_patch_file_path(char *p_conf_name, char *p_conf_value, int param); 40int hw_set_patch_file_name(char *p_conf_name, char *p_conf_value, int param); 41#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE) 42int hw_set_patch_settlement_delay(char *p_conf_name, char *p_conf_value, int param); 43#endif 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 54typedef int(conf_action_t)(char *p_conf_name, char *p_conf_value, int param); 55 56typedef 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 */ 69static 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*******************************************************************************/ 93void 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 HILOGI("Attempt to load conf from %s", p_path); 102 if ((p_file = fopen(p_path, "r")) == NULL) { 103 HILOGI("vnd_load_conf file >%s< not found", p_path); 104 return; 105 } 106 107 /* read line by line */ 108 while (fgets(line, CONF_MAX_LINE_LEN + 1, p_file) != NULL) { 109 if (line[0] == CONF_COMMENT) { 110 continue; 111 } 112 113 p_name = strtok(line, CONF_DELIMITERS); 114 if (p_name == NULL) { 115 continue; 116 } 117 118 p_value = strtok(NULL, CONF_DELIMITERS); 119 if (p_value == NULL) { 120 HILOGW("vnd_load_conf: missing value for name: %s", p_name); 121 continue; 122 } 123 124 p_entry = (conf_entry_t *)conf_table; 125 while (p_entry->conf_entry != NULL) { 126 if (strcmp(p_entry->conf_entry, (const char *)p_name) == 0) { 127 p_entry->p_action(p_name, p_value, p_entry->param); 128 break; 129 } 130 131 p_entry++; 132 } 133 } 134 135 (void)fclose(p_file); 136} 137