1 /* SPDX-License-Identifier: GPL-2.0+ */
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
7 #ifndef __ENV_FLAGS_H__
8 #define __ENV_FLAGS_H__
10 enum env_flags_vartype {
11 env_flags_vartype_string,
12 env_flags_vartype_decimal,
13 env_flags_vartype_hex,
14 env_flags_vartype_bool,
16 env_flags_vartype_ipaddr,
17 env_flags_vartype_macaddr,
22 enum env_flags_varaccess {
23 env_flags_varaccess_any,
24 env_flags_varaccess_readonly,
25 env_flags_varaccess_writeonce,
26 env_flags_varaccess_changedefault,
27 #ifdef CONFIG_ENV_WRITEABLE_LIST
28 env_flags_varaccess_writeable,
30 env_flags_varaccess_end
33 #define ENV_FLAGS_VAR ".flags"
34 #define ENV_FLAGS_ATTR_MAX_LEN 2
35 #define ENV_FLAGS_VARTYPE_LOC 0
36 #define ENV_FLAGS_VARACCESS_LOC 1
38 #ifndef CFG_ENV_FLAGS_LIST_STATIC
39 #define CFG_ENV_FLAGS_LIST_STATIC ""
44 #define ETHADDR_WILDCARD "\\d*"
46 #define ETHADDR_WILDCARD
48 #ifdef CONFIG_ENV_OVERWRITE
49 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
51 #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
52 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
54 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
79 #ifndef CONFIG_ENV_OVERWRITE
80 #define SERIAL_FLAGS "serial#:so,"
82 #define SERIAL_FLAGS ""
85 #define ENV_FLAGS_LIST_STATIC \
90 CFG_ENV_FLAGS_LIST_STATIC
92 #ifdef CONFIG_CMD_ENV_FLAGS
94 * Print the whole list of available type flags.
96 void env_flags_print_vartypes(void);
98 * Print the whole list of available access flags.
100 void env_flags_print_varaccess(void);
102 * Return the name of the type.
104 const char *env_flags_get_vartype_name(enum env_flags_vartype type);
106 * Return the name of the access.
108 const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
112 * Parse the flags string from a .flags attribute list into the vartype enum.
114 enum env_flags_vartype env_flags_parse_vartype(const char *flags);
116 * Parse the flags string from a .flags attribute list into the varaccess enum.
118 enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
120 * Parse the binary flags from a hash table entry into the varaccess enum.
122 enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
124 #ifdef CONFIG_CMD_NET
126 * Check if a string has the format of an Ethernet MAC address
128 int eth_validate_ethaddr_str(const char *addr);
133 * Look up the type of a variable directly from the .flags var.
135 enum env_flags_vartype env_flags_get_type(const char *name);
137 * Look up the access of a variable directly from the .flags var.
139 enum env_flags_varaccess env_flags_get_access(const char *name);
141 * Validate the newval for its type to conform with the requirements defined by
142 * its flags (directly looked at the .flags var).
144 int env_flags_validate_type(const char *name, const char *newval);
146 * Validate the newval for its access to conform with the requirements defined
147 * by its flags (directly looked at the .flags var).
149 int env_flags_validate_access(const char *name, int check_mask);
151 * Validate that the proposed access to variable "name" is valid according to
152 * the defined flags for that variable, if any.
154 int env_flags_validate_varaccess(const char *name, int check_mask);
156 * Validate the parameters passed to "env set" for type compliance
158 int env_flags_validate_env_set_params(char *name, char *const val[], int count);
160 #else /* !USE_HOSTCC */
166 * When adding a variable to the environment, initialize the flags for that
169 void env_flags_init(struct env_entry *var_entry);
172 * Validate the newval for to conform with the requirements defined by its flags
174 int env_flags_validate(const struct env_entry *item, const char *newval,
175 enum env_op op, int flag);
177 #endif /* USE_HOSTCC */
180 * These are the binary flags used in the environment entry->flags variable to
181 * decribe properties of veriables in the table
183 #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
184 /* The actual variable type values use the enum value (within the mask) */
185 #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
186 #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
187 #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
188 #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
189 #define ENV_FLAGS_VARACCESS_WRITEABLE 0x00000080
190 #define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000f8
192 #endif /* __ENV_FLAGS_H__ */