1/* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License as 4 * published by the Free Software Foundation; either version 2 of 5 * the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 15 * MA 02111-1307 USA 16 */ 17/* 18 Copyright 2001, ASUSTeK Inc. 19 All Rights Reserved. 20 21 This is UNPUBLISHED PROPRIETARY SOURCE CODE of ASUSTeK Inc.; 22 the contents of this file may not be disclosed to third parties, copied or 23 duplicated in any form, in whole or in part, without the prior written 24 permission of ASUSTeK Inc.. 25*/ 26/* 27 * This module creates an array of name, value pairs 28 * and supports updating the nvram space. 29 * 30 * This module requires the following support routines 31 * 32 * malloc, free, strcmp, strncmp, strcpy, strtol, strchr, printf and sprintf 33 */ 34#include <string.h> 35#include <stdio.h> 36#include <stdlib.h> 37#include <syslog.h> 38#include <bcmnvram.h> 39#include <sys/mman.h> 40 41#define MAX_LINE_SIZE 512 42#define MAX_FILE_NAME 64 43 44/* 45 * NOTE : The mutex must be initialized in the OS previous to the point at 46 * which multiple entry points to the nvram code are enabled 47 * 48 */ 49#define MAX_NVRAM_SIZE 4096 50#define EPI_VERSION_STR "2.4.5" 51 52/* 53 * Set the value of an NVRAM variable 54 * @param name name of variable to set 55 * @param value value of variable 56 * @return 0 on success and errno on failure 57 */ 58int 59nvram_set_x(const char *sid, const char *name, const char *value) 60{ 61 return (nvram_set(name, value)); 62} 63 64 65/* 66 * Get the value of an NVRAM variable 67 * @param name name of variable to get 68 * @return value of variable or NULL if undefined 69 */ 70char* 71nvram_get_x(const char *sid, const char *name) 72{ 73 return (nvram_safe_get(name)); 74} 75 76 77/* 78 * Get the value of an NVRAM variable 79 * @param name name of variable to get 80 * @return value of variable or NULL if undefined 81 */ 82char* 83nvram_get_f(const char *file, const char *field) 84{ 85 return (nvram_safe_get(field)); 86} 87 88/* 89 * Set the value of an NVRAM variable from file 90 * @param name name of variable to get 91 * @return value of variable or NULL if undefined 92 */ 93int 94nvram_set_f(const char *file, const char *field, const char *value) 95{ 96 return (nvram_set(field, value)); 97} 98 99/* 100 * Get the value of an NVRAM variable list 101 * @param name name of variable to get 102 * index index of the list, start from 1 103 * @return value of variable or NULL if undefined 104 */ 105 106char *nvram_get_list_x(const char *sid, const char *name, int index) 107{ 108 char new_name[MAX_LINE_SIZE]; 109 110 sprintf(new_name, "%s%d", name, index); 111 112 return (nvram_get_f(sid, new_name)); 113} 114 115/* 116 * Add the value into the end an NVRAM variable list 117 * @param name name of variable to get 118 * @return 0 on success and errno on failure 119 */ 120int nvram_add_lists_x(const char *sid, const char *name, const char *value, int count) 121{ 122 char name1[32], name2[32]; 123 124 strcpy(name1, name); 125 126 if (name[0]!='\0') 127 { 128 sprintf(name2, "%s%d", name1, count); 129 nvram_set(name2, value); 130 } 131 return (0); 132} 133 134 135/* 136 * Delete the value from an NVRAM variable list 137 * @param name name of variable list 138 * index index of variable list 139 * @return 0 on success and errno on failure 140 */ 141int nvram_del_lists_x(const char *sid, const char *name, int *delMap) 142{ 143// FILE *fp; 144 char names[32], oname[32], nname[32], *oval, *nval; 145 int oi, ni, di; 146 147 strcpy(names, name); 148 149 if (names[0]!='\0') 150 { 151 oi=0; 152 ni=0; 153 di=0; 154 while (1) 155 { 156 sprintf(oname, "%s%d", names, oi); 157 sprintf(nname, "%s%d", names, ni); 158 159 oval = nvram_get(oname); 160 nval = nvram_get(nname); 161 162 if (oval==NULL) break; 163 164 printf("d: %d %d %d %d\n", oi, ni, di, delMap[di]); 165 if (delMap[di]!=-1&&delMap[di]==oi) 166 { 167 oi++; 168 di++; 169 } 170 else 171 { 172 nvram_set(nname, oval); 173 ni++; 174 oi++; 175 } 176 } 177 } 178 return (0); 179} 180 181