blob: 2d2de88fc04fdd187caf5dd32799a56b6ac3ede0 [file] [log] [blame]
Joe Hershberger71497d02012-12-11 22:16:31 -06001/*
2 * (C) Copyright 2012
3 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Joe Hershberger71497d02012-12-11 22:16:31 -06006 */
7
8#ifndef __ENV_FLAGS_H__
9#define __ENV_FLAGS_H__
10
11enum env_flags_vartype {
12 env_flags_vartype_string,
13 env_flags_vartype_decimal,
14 env_flags_vartype_hex,
15 env_flags_vartype_bool,
16#ifdef CONFIG_CMD_NET
17 env_flags_vartype_ipaddr,
18 env_flags_vartype_macaddr,
19#endif
20 env_flags_vartype_end
21};
22
Joe Hershberger6fe26c92012-12-11 22:16:34 -060023enum 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
29};
30
Joe Hershberger71497d02012-12-11 22:16:31 -060031#define ENV_FLAGS_VAR ".flags"
32#define ENV_FLAGS_ATTR_MAX_LEN 2
33#define ENV_FLAGS_VARTYPE_LOC 0
Joe Hershberger6fe26c92012-12-11 22:16:34 -060034#define ENV_FLAGS_VARACCESS_LOC 1
Joe Hershberger71497d02012-12-11 22:16:31 -060035
36#ifndef CONFIG_ENV_FLAGS_LIST_STATIC
37#define CONFIG_ENV_FLAGS_LIST_STATIC ""
38#endif
39
Joe Hershberger2289ec12012-12-11 22:16:37 -060040#ifdef CONFIG_CMD_NET
Joe Hershbergere84ca292015-05-20 14:27:22 -050041#ifdef CONFIG_REGEX
42#define ETHADDR_WILDCARD "\\d?"
43#else
44#define ETHADDR_WILDCARD
45#endif
Joe Hershberger2289ec12012-12-11 22:16:37 -060046#ifdef CONFIG_ENV_OVERWRITE
Joe Hershbergere84ca292015-05-20 14:27:22 -050047#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060048#else
49#ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
Joe Hershbergere84ca292015-05-20 14:27:22 -050050#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060051#else
Joe Hershbergere84ca292015-05-20 14:27:22 -050052#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060053#endif
54#endif
Joe Hershbergerd26195e72015-05-20 14:27:24 -050055#define NET_FLAGS \
56 "ipaddr:i," \
57 "gatewayip:i," \
58 "netmask:i," \
59 "serverip:i," \
60 "nvlan:i," \
61 "vlan:i," \
62 "dnsip:i,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060063#else
Joe Hershbergerd26195e72015-05-20 14:27:24 -050064#define ETHADDR_FLAGS
65#define NET_FLAGS
Joe Hershberger2289ec12012-12-11 22:16:37 -060066#endif
67
68#ifndef CONFIG_ENV_OVERWRITE
69#define SERIAL_FLAGS "serial#:so,"
70#else
71#define SERIAL_FLAGS ""
72#endif
73
Joe Hershberger71497d02012-12-11 22:16:31 -060074#define ENV_FLAGS_LIST_STATIC \
Joe Hershberger2289ec12012-12-11 22:16:37 -060075 ETHADDR_FLAGS \
Joe Hershbergerd26195e72015-05-20 14:27:24 -050076 NET_FLAGS \
Joe Hershberger2289ec12012-12-11 22:16:37 -060077 SERIAL_FLAGS \
Joe Hershberger71497d02012-12-11 22:16:31 -060078 CONFIG_ENV_FLAGS_LIST_STATIC
79
Joe Hershbergera2d62b72012-12-11 22:16:33 -060080#ifdef CONFIG_CMD_ENV_FLAGS
81/*
82 * Print the whole list of available type flags.
83 */
84void env_flags_print_vartypes(void);
85/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -060086 * Print the whole list of available access flags.
87 */
88void env_flags_print_varaccess(void);
89/*
Joe Hershbergera2d62b72012-12-11 22:16:33 -060090 * Return the name of the type.
91 */
92const char *env_flags_get_vartype_name(enum env_flags_vartype type);
Joe Hershberger6fe26c92012-12-11 22:16:34 -060093/*
94 * Return the name of the access.
95 */
96const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
Joe Hershbergera2d62b72012-12-11 22:16:33 -060097#endif
98
Joe Hershberger71497d02012-12-11 22:16:31 -060099/*
100 * Parse the flags string from a .flags attribute list into the vartype enum.
101 */
102enum env_flags_vartype env_flags_parse_vartype(const char *flags);
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600103/*
104 * Parse the flags string from a .flags attribute list into the varaccess enum.
105 */
106enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
107/*
108 * Parse the binary flags from a hash table entry into the varaccess enum.
109 */
110enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
Joe Hershberger71497d02012-12-11 22:16:31 -0600111
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600112#ifdef USE_HOSTCC
113/*
114 * Look up the type of a variable directly from the .flags var.
115 */
116enum env_flags_vartype env_flags_get_type(const char *name);
117/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600118 * Look up the access of a variable directly from the .flags var.
119 */
120enum env_flags_varaccess env_flags_get_access(const char *name);
121/*
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600122 * Validate the newval for its type to conform with the requirements defined by
123 * its flags (directly looked at the .flags var).
124 */
125int env_flags_validate_type(const char *name, const char *newval);
126/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600127 * Validate the newval for its access to conform with the requirements defined
128 * by its flags (directly looked at the .flags var).
129 */
130int env_flags_validate_access(const char *name, int check_mask);
131/*
132 * Validate that the proposed access to variable "name" is valid according to
133 * the defined flags for that variable, if any.
134 */
135int env_flags_validate_varaccess(const char *name, int check_mask);
136/*
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600137 * Validate the parameters passed to "env set" for type compliance
138 */
139int env_flags_validate_env_set_params(int argc, char * const argv[]);
140
141#else /* !USE_HOSTCC */
142
Joe Hershberger71497d02012-12-11 22:16:31 -0600143#include <search.h>
144
145/*
146 * When adding a variable to the environment, initialize the flags for that
147 * variable.
148 */
149void env_flags_init(ENTRY *var_entry);
150
151/*
152 * Validate the newval for to conform with the requirements defined by its flags
153 */
154int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
155 int flag);
156
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600157#endif /* USE_HOSTCC */
158
Joe Hershberger71497d02012-12-11 22:16:31 -0600159/*
160 * These are the binary flags used in the environment entry->flags variable to
161 * decribe properties of veriables in the table
162 */
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600163#define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
Joe Hershberger71497d02012-12-11 22:16:31 -0600164/* The actual variable type values use the enum value (within the mask) */
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600165#define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
166#define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
167#define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
168#define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
169#define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600170
Joe Hershberger71497d02012-12-11 22:16:31 -0600171#endif /* __ENV_FLAGS_H__ */