2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2012-12-12 04:16:31 +00:00
|
|
|
/*
|
|
|
|
* (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_CMD_NET
|
|
|
|
env_flags_vartype_ipaddr,
|
|
|
|
env_flags_vartype_macaddr,
|
|
|
|
#endif
|
|
|
|
env_flags_vartype_end
|
|
|
|
};
|
|
|
|
|
2012-12-12 04:16:34 +00:00
|
|
|
enum env_flags_varaccess {
|
|
|
|
env_flags_varaccess_any,
|
|
|
|
env_flags_varaccess_readonly,
|
|
|
|
env_flags_varaccess_writeonce,
|
|
|
|
env_flags_varaccess_changedefault,
|
2020-07-07 18:51:39 +00:00
|
|
|
#ifdef CONFIG_ENV_WRITEABLE_LIST
|
|
|
|
env_flags_varaccess_writeable,
|
|
|
|
#endif
|
2012-12-12 04:16:34 +00:00
|
|
|
env_flags_varaccess_end
|
|
|
|
};
|
|
|
|
|
2012-12-12 04:16:31 +00:00
|
|
|
#define ENV_FLAGS_VAR ".flags"
|
|
|
|
#define ENV_FLAGS_ATTR_MAX_LEN 2
|
|
|
|
#define ENV_FLAGS_VARTYPE_LOC 0
|
2012-12-12 04:16:34 +00:00
|
|
|
#define ENV_FLAGS_VARACCESS_LOC 1
|
2012-12-12 04:16:31 +00:00
|
|
|
|
2022-12-04 15:03:40 +00:00
|
|
|
#ifndef CFG_ENV_FLAGS_LIST_STATIC
|
|
|
|
#define CFG_ENV_FLAGS_LIST_STATIC ""
|
2012-12-12 04:16:31 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-02 08:10:34 +00:00
|
|
|
#ifdef CONFIG_NET
|
2015-05-20 19:27:22 +00:00
|
|
|
#ifdef CONFIG_REGEX
|
2018-11-22 16:06:39 +00:00
|
|
|
#define ETHADDR_WILDCARD "\\d*"
|
2015-05-20 19:27:22 +00:00
|
|
|
#else
|
|
|
|
#define ETHADDR_WILDCARD
|
|
|
|
#endif
|
2012-12-12 04:16:37 +00:00
|
|
|
#ifdef CONFIG_ENV_OVERWRITE
|
2015-05-20 19:27:22 +00:00
|
|
|
#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
|
2012-12-12 04:16:37 +00:00
|
|
|
#else
|
|
|
|
#ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
|
2015-05-20 19:27:22 +00:00
|
|
|
#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
|
2012-12-12 04:16:37 +00:00
|
|
|
#else
|
2015-05-20 19:27:22 +00:00
|
|
|
#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
|
2012-12-12 04:16:37 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2015-05-20 19:27:24 +00:00
|
|
|
#define NET_FLAGS \
|
|
|
|
"ipaddr:i," \
|
|
|
|
"gatewayip:i," \
|
|
|
|
"netmask:i," \
|
|
|
|
"serverip:i," \
|
2016-04-13 23:38:01 +00:00
|
|
|
"nvlan:d," \
|
|
|
|
"vlan:d," \
|
2015-05-20 19:27:24 +00:00
|
|
|
"dnsip:i,"
|
2012-12-12 04:16:37 +00:00
|
|
|
#else
|
2015-05-20 19:27:24 +00:00
|
|
|
#define ETHADDR_FLAGS
|
|
|
|
#define NET_FLAGS
|
2012-12-12 04:16:37 +00:00
|
|
|
#endif
|
|
|
|
|
2022-12-02 09:18:00 +00:00
|
|
|
#ifdef CONFIG_IPV6
|
|
|
|
#define NET6_FLAGS \
|
|
|
|
"ip6addr:s," \
|
|
|
|
"serverip6:s," \
|
|
|
|
"gatewayip6:s"
|
|
|
|
#else
|
|
|
|
#define NET6_FLAGS
|
|
|
|
#endif
|
|
|
|
|
2012-12-12 04:16:37 +00:00
|
|
|
#ifndef CONFIG_ENV_OVERWRITE
|
|
|
|
#define SERIAL_FLAGS "serial#:so,"
|
|
|
|
#else
|
|
|
|
#define SERIAL_FLAGS ""
|
|
|
|
#endif
|
|
|
|
|
2012-12-12 04:16:31 +00:00
|
|
|
#define ENV_FLAGS_LIST_STATIC \
|
2012-12-12 04:16:37 +00:00
|
|
|
ETHADDR_FLAGS \
|
2015-05-20 19:27:24 +00:00
|
|
|
NET_FLAGS \
|
2022-12-02 09:18:00 +00:00
|
|
|
NET6_FLAGS \
|
2012-12-12 04:16:37 +00:00
|
|
|
SERIAL_FLAGS \
|
2022-12-04 15:03:40 +00:00
|
|
|
CFG_ENV_FLAGS_LIST_STATIC
|
2012-12-12 04:16:31 +00:00
|
|
|
|
2012-12-12 04:16:33 +00:00
|
|
|
#ifdef CONFIG_CMD_ENV_FLAGS
|
|
|
|
/*
|
|
|
|
* Print the whole list of available type flags.
|
|
|
|
*/
|
|
|
|
void env_flags_print_vartypes(void);
|
2012-12-12 04:16:34 +00:00
|
|
|
/*
|
|
|
|
* Print the whole list of available access flags.
|
|
|
|
*/
|
|
|
|
void env_flags_print_varaccess(void);
|
2012-12-12 04:16:33 +00:00
|
|
|
/*
|
|
|
|
* Return the name of the type.
|
|
|
|
*/
|
|
|
|
const char *env_flags_get_vartype_name(enum env_flags_vartype type);
|
2012-12-12 04:16:34 +00:00
|
|
|
/*
|
|
|
|
* Return the name of the access.
|
|
|
|
*/
|
|
|
|
const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
|
2012-12-12 04:16:33 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-12 04:16:31 +00:00
|
|
|
/*
|
|
|
|
* Parse the flags string from a .flags attribute list into the vartype enum.
|
|
|
|
*/
|
|
|
|
enum env_flags_vartype env_flags_parse_vartype(const char *flags);
|
2012-12-12 04:16:34 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2012-12-12 04:16:31 +00:00
|
|
|
|
2015-09-09 15:00:51 +00:00
|
|
|
#ifdef CONFIG_CMD_NET
|
|
|
|
/*
|
|
|
|
* Check if a string has the format of an Ethernet MAC address
|
|
|
|
*/
|
|
|
|
int eth_validate_ethaddr_str(const char *addr);
|
|
|
|
#endif
|
|
|
|
|
2012-12-12 04:16:32 +00:00
|
|
|
#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);
|
2012-12-12 04:16:34 +00:00
|
|
|
/*
|
|
|
|
* Look up the access of a variable directly from the .flags var.
|
|
|
|
*/
|
|
|
|
enum env_flags_varaccess env_flags_get_access(const char *name);
|
2012-12-12 04:16:32 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2012-12-12 04:16:34 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2012-12-12 04:16:32 +00:00
|
|
|
/*
|
|
|
|
* Validate the parameters passed to "env set" for type compliance
|
|
|
|
*/
|
2015-12-09 12:13:21 +00:00
|
|
|
int env_flags_validate_env_set_params(char *name, char *const val[], int count);
|
2012-12-12 04:16:32 +00:00
|
|
|
|
|
|
|
#else /* !USE_HOSTCC */
|
|
|
|
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2012-12-12 04:16:31 +00:00
|
|
|
#include <search.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When adding a variable to the environment, initialize the flags for that
|
|
|
|
* variable.
|
|
|
|
*/
|
2019-08-02 15:44:18 +00:00
|
|
|
void env_flags_init(struct env_entry *var_entry);
|
2012-12-12 04:16:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate the newval for to conform with the requirements defined by its flags
|
|
|
|
*/
|
2019-08-02 15:44:18 +00:00
|
|
|
int env_flags_validate(const struct env_entry *item, const char *newval,
|
|
|
|
enum env_op op, int flag);
|
2012-12-12 04:16:31 +00:00
|
|
|
|
2012-12-12 04:16:34 +00:00
|
|
|
#endif /* USE_HOSTCC */
|
|
|
|
|
2012-12-12 04:16:31 +00:00
|
|
|
/*
|
|
|
|
* These are the binary flags used in the environment entry->flags variable to
|
|
|
|
* decribe properties of veriables in the table
|
|
|
|
*/
|
2012-12-12 04:16:34 +00:00
|
|
|
#define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
|
2012-12-12 04:16:31 +00:00
|
|
|
/* The actual variable type values use the enum value (within the mask) */
|
2012-12-12 04:16:34 +00:00
|
|
|
#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
|
2020-07-07 18:51:39 +00:00
|
|
|
#define ENV_FLAGS_VARACCESS_WRITEABLE 0x00000080
|
|
|
|
#define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000f8
|
2012-12-12 04:16:32 +00:00
|
|
|
|
2012-12-12 04:16:31 +00:00
|
|
|
#endif /* __ENV_FLAGS_H__ */
|