3 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
5 * SPDX-License-Identifier: GPL-2.0+
8 #ifndef __ENV_FLAGS_H__
9 #define __ENV_FLAGS_H__
11 enum env_flags_vartype {
12 env_flags_vartype_string,
13 env_flags_vartype_decimal,
14 env_flags_vartype_hex,
15 env_flags_vartype_bool,
17 env_flags_vartype_ipaddr,
18 env_flags_vartype_macaddr,
23 enum env_flags_varaccess {
24 env_flags_varaccess_any,
25 env_flags_varaccess_readonly,
26 env_flags_varaccess_writeonce,
27 env_flags_varaccess_changedefault,
28 env_flags_varaccess_end
31 #define ENV_FLAGS_VAR ".flags"
32 #define ENV_FLAGS_ATTR_MAX_LEN 2
33 #define ENV_FLAGS_VARTYPE_LOC 0
34 #define ENV_FLAGS_VARACCESS_LOC 1
36 #ifndef CONFIG_ENV_FLAGS_LIST_STATIC
37 #define CONFIG_ENV_FLAGS_LIST_STATIC ""
42 #define ETHADDR_WILDCARD "\\d?"
44 #define ETHADDR_WILDCARD
46 #ifdef CONFIG_ENV_OVERWRITE
47 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
49 #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
50 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
52 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
56 #define ETHADDR_FLAGS ""
59 #ifndef CONFIG_ENV_OVERWRITE
60 #define SERIAL_FLAGS "serial#:so,"
62 #define SERIAL_FLAGS ""
65 #define ENV_FLAGS_LIST_STATIC \
68 CONFIG_ENV_FLAGS_LIST_STATIC
70 #ifdef CONFIG_CMD_ENV_FLAGS
72 * Print the whole list of available type flags.
74 void env_flags_print_vartypes(void);
76 * Print the whole list of available access flags.
78 void env_flags_print_varaccess(void);
80 * Return the name of the type.
82 const char *env_flags_get_vartype_name(enum env_flags_vartype type);
84 * Return the name of the access.
86 const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
90 * Parse the flags string from a .flags attribute list into the vartype enum.
92 enum env_flags_vartype env_flags_parse_vartype(const char *flags);
94 * Parse the flags string from a .flags attribute list into the varaccess enum.
96 enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
98 * Parse the binary flags from a hash table entry into the varaccess enum.
100 enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
104 * Look up the type of a variable directly from the .flags var.
106 enum env_flags_vartype env_flags_get_type(const char *name);
108 * Look up the access of a variable directly from the .flags var.
110 enum env_flags_varaccess env_flags_get_access(const char *name);
112 * Validate the newval for its type to conform with the requirements defined by
113 * its flags (directly looked at the .flags var).
115 int env_flags_validate_type(const char *name, const char *newval);
117 * Validate the newval for its access to conform with the requirements defined
118 * by its flags (directly looked at the .flags var).
120 int env_flags_validate_access(const char *name, int check_mask);
122 * Validate that the proposed access to variable "name" is valid according to
123 * the defined flags for that variable, if any.
125 int env_flags_validate_varaccess(const char *name, int check_mask);
127 * Validate the parameters passed to "env set" for type compliance
129 int env_flags_validate_env_set_params(int argc, char * const argv[]);
131 #else /* !USE_HOSTCC */
136 * When adding a variable to the environment, initialize the flags for that
139 void env_flags_init(ENTRY *var_entry);
142 * Validate the newval for to conform with the requirements defined by its flags
144 int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
147 #endif /* USE_HOSTCC */
150 * These are the binary flags used in the environment entry->flags variable to
151 * decribe properties of veriables in the table
153 #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
154 /* The actual variable type values use the enum value (within the mask) */
155 #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
156 #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
157 #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
158 #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
159 #define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
161 #endif /* __ENV_FLAGS_H__ */