blob: 23744e395c8afb0b1c7dcd618fb2a925157be720 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Joe Hershberger71497d02012-12-11 22:16:31 -06002/*
3 * (C) Copyright 2012
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
Joe Hershberger71497d02012-12-11 22:16:31 -06005 */
6
7#ifndef __ENV_FLAGS_H__
8#define __ENV_FLAGS_H__
9
10enum env_flags_vartype {
11 env_flags_vartype_string,
12 env_flags_vartype_decimal,
13 env_flags_vartype_hex,
14 env_flags_vartype_bool,
15#ifdef CONFIG_CMD_NET
16 env_flags_vartype_ipaddr,
17 env_flags_vartype_macaddr,
18#endif
19 env_flags_vartype_end
20};
21
Joe Hershberger6fe26c92012-12-11 22:16:34 -060022enum env_flags_varaccess {
23 env_flags_varaccess_any,
24 env_flags_varaccess_readonly,
25 env_flags_varaccess_writeonce,
26 env_flags_varaccess_changedefault,
27 env_flags_varaccess_end
28};
29
Joe Hershberger71497d02012-12-11 22:16:31 -060030#define ENV_FLAGS_VAR ".flags"
31#define ENV_FLAGS_ATTR_MAX_LEN 2
32#define ENV_FLAGS_VARTYPE_LOC 0
Joe Hershberger6fe26c92012-12-11 22:16:34 -060033#define ENV_FLAGS_VARACCESS_LOC 1
Joe Hershberger71497d02012-12-11 22:16:31 -060034
35#ifndef CONFIG_ENV_FLAGS_LIST_STATIC
36#define CONFIG_ENV_FLAGS_LIST_STATIC ""
37#endif
38
Joe Hershberger2289ec12012-12-11 22:16:37 -060039#ifdef CONFIG_CMD_NET
Joe Hershbergere84ca292015-05-20 14:27:22 -050040#ifdef CONFIG_REGEX
Simon Goldschmidt7da02292018-11-22 17:06:39 +010041#define ETHADDR_WILDCARD "\\d*"
Joe Hershbergere84ca292015-05-20 14:27:22 -050042#else
43#define ETHADDR_WILDCARD
44#endif
Joe Hershberger2289ec12012-12-11 22:16:37 -060045#ifdef CONFIG_ENV_OVERWRITE
Joe Hershbergere84ca292015-05-20 14:27:22 -050046#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060047#else
48#ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
Joe Hershbergere84ca292015-05-20 14:27:22 -050049#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060050#else
Joe Hershbergere84ca292015-05-20 14:27:22 -050051#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060052#endif
53#endif
Joe Hershbergerd26195e72015-05-20 14:27:24 -050054#define NET_FLAGS \
55 "ipaddr:i," \
56 "gatewayip:i," \
57 "netmask:i," \
58 "serverip:i," \
Stefan Agner18c067f2016-04-13 16:38:01 -070059 "nvlan:d," \
60 "vlan:d," \
Joe Hershbergerd26195e72015-05-20 14:27:24 -050061 "dnsip:i,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060062#else
Joe Hershbergerd26195e72015-05-20 14:27:24 -050063#define ETHADDR_FLAGS
64#define NET_FLAGS
Joe Hershberger2289ec12012-12-11 22:16:37 -060065#endif
66
67#ifndef CONFIG_ENV_OVERWRITE
68#define SERIAL_FLAGS "serial#:so,"
69#else
70#define SERIAL_FLAGS ""
71#endif
72
Joe Hershberger71497d02012-12-11 22:16:31 -060073#define ENV_FLAGS_LIST_STATIC \
Joe Hershberger2289ec12012-12-11 22:16:37 -060074 ETHADDR_FLAGS \
Joe Hershbergerd26195e72015-05-20 14:27:24 -050075 NET_FLAGS \
Joe Hershberger2289ec12012-12-11 22:16:37 -060076 SERIAL_FLAGS \
Joe Hershberger71497d02012-12-11 22:16:31 -060077 CONFIG_ENV_FLAGS_LIST_STATIC
78
Joe Hershbergera2d62b72012-12-11 22:16:33 -060079#ifdef CONFIG_CMD_ENV_FLAGS
80/*
81 * Print the whole list of available type flags.
82 */
83void env_flags_print_vartypes(void);
84/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -060085 * Print the whole list of available access flags.
86 */
87void env_flags_print_varaccess(void);
88/*
Joe Hershbergera2d62b72012-12-11 22:16:33 -060089 * Return the name of the type.
90 */
91const char *env_flags_get_vartype_name(enum env_flags_vartype type);
Joe Hershberger6fe26c92012-12-11 22:16:34 -060092/*
93 * Return the name of the access.
94 */
95const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
Joe Hershbergera2d62b72012-12-11 22:16:33 -060096#endif
97
Joe Hershberger71497d02012-12-11 22:16:31 -060098/*
99 * Parse the flags string from a .flags attribute list into the vartype enum.
100 */
101enum env_flags_vartype env_flags_parse_vartype(const char *flags);
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600102/*
103 * Parse the flags string from a .flags attribute list into the varaccess enum.
104 */
105enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
106/*
107 * Parse the binary flags from a hash table entry into the varaccess enum.
108 */
109enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
Joe Hershberger71497d02012-12-11 22:16:31 -0600110
Codrin Ciubotariu265c0d32015-09-09 18:00:51 +0300111#ifdef CONFIG_CMD_NET
112/*
113 * Check if a string has the format of an Ethernet MAC address
114 */
115int eth_validate_ethaddr_str(const char *addr);
116#endif
117
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600118#ifdef USE_HOSTCC
119/*
120 * Look up the type of a variable directly from the .flags var.
121 */
122enum env_flags_vartype env_flags_get_type(const char *name);
123/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600124 * Look up the access of a variable directly from the .flags var.
125 */
126enum env_flags_varaccess env_flags_get_access(const char *name);
127/*
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600128 * Validate the newval for its type to conform with the requirements defined by
129 * its flags (directly looked at the .flags var).
130 */
131int env_flags_validate_type(const char *name, const char *newval);
132/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600133 * Validate the newval for its access to conform with the requirements defined
134 * by its flags (directly looked at the .flags var).
135 */
136int env_flags_validate_access(const char *name, int check_mask);
137/*
138 * Validate that the proposed access to variable "name" is valid according to
139 * the defined flags for that variable, if any.
140 */
141int env_flags_validate_varaccess(const char *name, int check_mask);
142/*
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600143 * Validate the parameters passed to "env set" for type compliance
144 */
Andreas Fenkart4e336ee2015-12-09 13:13:21 +0100145int env_flags_validate_env_set_params(char *name, char *const val[], int count);
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600146
147#else /* !USE_HOSTCC */
148
Joe Hershberger71497d02012-12-11 22:16:31 -0600149#include <search.h>
150
151/*
152 * When adding a variable to the environment, initialize the flags for that
153 * variable.
154 */
155void env_flags_init(ENTRY *var_entry);
156
157/*
158 * Validate the newval for to conform with the requirements defined by its flags
159 */
160int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
161 int flag);
162
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600163#endif /* USE_HOSTCC */
164
Joe Hershberger71497d02012-12-11 22:16:31 -0600165/*
166 * These are the binary flags used in the environment entry->flags variable to
167 * decribe properties of veriables in the table
168 */
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600169#define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
Joe Hershberger71497d02012-12-11 22:16:31 -0600170/* The actual variable type values use the enum value (within the mask) */
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600171#define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
172#define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
173#define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
174#define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
175#define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600176
Joe Hershberger71497d02012-12-11 22:16:31 -0600177#endif /* __ENV_FLAGS_H__ */