1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* (C) Copyright 2012
* Joe Hershberger, National Instruments, joe.hershberger@ni.com
*/
#ifndef __ENV_FLAGS_H__
#define __ENV_FLAGS_H__
enum env_flags_vartype {
env_flags_vartype_string,
env_flags_vartype_decimal,
env_flags_vartype_hex,
env_flags_vartype_bool,
#ifdef CONFIG_NET
env_flags_vartype_ipaddr,
env_flags_vartype_macaddr,
#endif
env_flags_vartype_end
};
enum env_flags_varaccess {
env_flags_varaccess_any,
env_flags_varaccess_readonly,
env_flags_varaccess_writeonce,
env_flags_varaccess_changedefault,
#ifdef CONFIG_ENV_WRITEABLE_LIST
env_flags_varaccess_writeable,
#endif
env_flags_varaccess_end
};
#define ENV_FLAGS_VAR ".flags"
#define ENV_FLAGS_ATTR_MAX_LEN 2
#define ENV_FLAGS_VARTYPE_LOC 0
#define ENV_FLAGS_VARACCESS_LOC 1
#ifndef CFG_ENV_FLAGS_LIST_STATIC
#define CFG_ENV_FLAGS_LIST_STATIC ""
#endif
#ifdef CONFIG_NET
#ifdef CONFIG_REGEX
#define ETHADDR_WILDCARD "\\d*"
#else
#define ETHADDR_WILDCARD
#endif
#ifdef CONFIG_ENV_OVERWRITE
#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
#else
#ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
#else
#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
#endif
#endif
#define NET_FLAGS \
"ipaddr:i," \
"gatewayip:i," \
"netmask:i," \
"serverip:i," \
"nvlan:d," \
"vlan:d," \
"dnsip:i,"
#else
#define ETHADDR_FLAGS
#define NET_FLAGS
#endif
#ifdef CONFIG_IPV6
#define NET6_FLAGS \
"ip6addr:s," \
"serverip6:s," \
"gatewayip6:s,"
#else
#define NET6_FLAGS
#endif
#ifndef CONFIG_ENV_OVERWRITE
#define SERIAL_FLAGS "serial#:so,"
#else
#define SERIAL_FLAGS ""
#endif
#define ENV_FLAGS_LIST_STATIC \
ETHADDR_FLAGS \
NET_FLAGS \
NET6_FLAGS \
SERIAL_FLAGS \
CFG_ENV_FLAGS_LIST_STATIC
#ifdef CONFIG_CMD_ENV_FLAGS
/*
* Print the whole list of available type flags.
*/
void env_flags_print_vartypes(void);
/*
* Print the whole list of available access flags.
*/
void env_flags_print_varaccess(void);
/*
* Return the name of the type.
*/
const char *env_flags_get_vartype_name(enum env_flags_vartype type);
/*
* Return the name of the access.
*/
const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
#endif
/*
* Parse the flags string from a .flags attribute list into the vartype enum.
*/
enum env_flags_vartype env_flags_parse_vartype(const char *flags);
/*
* Parse the flags string from a .flags attribute list into the varaccess enum.
*/
enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
/*
* Parse the binary flags from a hash table entry into the varaccess enum.
*/
enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
#ifdef CONFIG_NET
/*
* Check if a string has the format of an Ethernet MAC address
*/
int eth_validate_ethaddr_str(const char *addr);
#endif
#ifdef USE_HOSTCC
/*
* Look up the type of a variable directly from the .flags var.
*/
enum env_flags_vartype env_flags_get_type(const char *name);
/*
* Look up the access of a variable directly from the .flags var.
*/
enum env_flags_varaccess env_flags_get_access(const char *name);
/*
* Validate the newval for its type to conform with the requirements defined by
* its flags (directly looked at the .flags var).
*/
int env_flags_validate_type(const char *name, const char *newval);
/*
* Validate the newval for its access to conform with the requirements defined
* by its flags (directly looked at the .flags var).
*/
int env_flags_validate_access(const char *name, int check_mask);
/*
* Validate that the proposed access to variable "name" is valid according to
* the defined flags for that variable, if any.
*/
int env_flags_validate_varaccess(const char *name, int check_mask);
/*
* Validate the parameters passed to "env set" for type compliance
*/
int env_flags_validate_env_set_params(char *name, char *const val[], int count);
#else /* !USE_HOSTCC */
#include <env.h>
#include <search.h>
/*
* When adding a variable to the environment, initialize the flags for that
* variable.
*/
void env_flags_init(struct env_entry *var_entry);
/*
* Validate the newval for to conform with the requirements defined by its flags
*/
int env_flags_validate(const struct env_entry *item, const char *newval,
enum env_op op, int flag);
#endif /* USE_HOSTCC */
/*
* These are the binary flags used in the environment entry->flags variable to
* decribe properties of veriables in the table
*/
#define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
/* The actual variable type values use the enum value (within the mask) */
#define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
#define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
#define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
#define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
#define ENV_FLAGS_VARACCESS_WRITEABLE 0x00000080
#define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000f8
#endif /* __ENV_FLAGS_H__ */
|