env_flags.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2012
  4. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  5. */
  6. #ifndef __ENV_FLAGS_H__
  7. #define __ENV_FLAGS_H__
  8. enum env_flags_vartype {
  9. env_flags_vartype_string,
  10. env_flags_vartype_decimal,
  11. env_flags_vartype_hex,
  12. env_flags_vartype_bool,
  13. #ifdef CONFIG_CMD_NET
  14. env_flags_vartype_ipaddr,
  15. env_flags_vartype_macaddr,
  16. #endif
  17. env_flags_vartype_end
  18. };
  19. enum env_flags_varaccess {
  20. env_flags_varaccess_any,
  21. env_flags_varaccess_readonly,
  22. env_flags_varaccess_writeonce,
  23. env_flags_varaccess_changedefault,
  24. env_flags_varaccess_end
  25. };
  26. #define ENV_FLAGS_VAR ".flags"
  27. #define ENV_FLAGS_ATTR_MAX_LEN 2
  28. #define ENV_FLAGS_VARTYPE_LOC 0
  29. #define ENV_FLAGS_VARACCESS_LOC 1
  30. #ifndef CONFIG_ENV_FLAGS_LIST_STATIC
  31. #define CONFIG_ENV_FLAGS_LIST_STATIC ""
  32. #endif
  33. #ifdef CONFIG_NET
  34. #ifdef CONFIG_REGEX
  35. #define ETHADDR_WILDCARD "\\d*"
  36. #else
  37. #define ETHADDR_WILDCARD
  38. #endif
  39. #ifdef CONFIG_ENV_OVERWRITE
  40. #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
  41. #else
  42. #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
  43. #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
  44. #else
  45. #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
  46. #endif
  47. #endif
  48. #define NET_FLAGS \
  49. "ipaddr:i," \
  50. "gatewayip:i," \
  51. "netmask:i," \
  52. "serverip:i," \
  53. "nvlan:d," \
  54. "vlan:d," \
  55. "dnsip:i,"
  56. #else
  57. #define ETHADDR_FLAGS
  58. #define NET_FLAGS
  59. #endif
  60. #ifndef CONFIG_ENV_OVERWRITE
  61. #define SERIAL_FLAGS "serial#:so,"
  62. #else
  63. #define SERIAL_FLAGS ""
  64. #endif
  65. #define ENV_FLAGS_LIST_STATIC \
  66. ETHADDR_FLAGS \
  67. NET_FLAGS \
  68. SERIAL_FLAGS \
  69. CONFIG_ENV_FLAGS_LIST_STATIC
  70. #ifdef CONFIG_CMD_ENV_FLAGS
  71. /*
  72. * Print the whole list of available type flags.
  73. */
  74. void env_flags_print_vartypes(void);
  75. /*
  76. * Print the whole list of available access flags.
  77. */
  78. void env_flags_print_varaccess(void);
  79. /*
  80. * Return the name of the type.
  81. */
  82. const char *env_flags_get_vartype_name(enum env_flags_vartype type);
  83. /*
  84. * Return the name of the access.
  85. */
  86. const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
  87. #endif
  88. /*
  89. * Parse the flags string from a .flags attribute list into the vartype enum.
  90. */
  91. enum env_flags_vartype env_flags_parse_vartype(const char *flags);
  92. /*
  93. * Parse the flags string from a .flags attribute list into the varaccess enum.
  94. */
  95. enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
  96. /*
  97. * Parse the binary flags from a hash table entry into the varaccess enum.
  98. */
  99. enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
  100. #ifdef CONFIG_CMD_NET
  101. /*
  102. * Check if a string has the format of an Ethernet MAC address
  103. */
  104. int eth_validate_ethaddr_str(const char *addr);
  105. #endif
  106. #ifdef USE_HOSTCC
  107. /*
  108. * Look up the type of a variable directly from the .flags var.
  109. */
  110. enum env_flags_vartype env_flags_get_type(const char *name);
  111. /*
  112. * Look up the access of a variable directly from the .flags var.
  113. */
  114. enum env_flags_varaccess env_flags_get_access(const char *name);
  115. /*
  116. * Validate the newval for its type to conform with the requirements defined by
  117. * its flags (directly looked at the .flags var).
  118. */
  119. int env_flags_validate_type(const char *name, const char *newval);
  120. /*
  121. * Validate the newval for its access to conform with the requirements defined
  122. * by its flags (directly looked at the .flags var).
  123. */
  124. int env_flags_validate_access(const char *name, int check_mask);
  125. /*
  126. * Validate that the proposed access to variable "name" is valid according to
  127. * the defined flags for that variable, if any.
  128. */
  129. int env_flags_validate_varaccess(const char *name, int check_mask);
  130. /*
  131. * Validate the parameters passed to "env set" for type compliance
  132. */
  133. int env_flags_validate_env_set_params(char *name, char *const val[], int count);
  134. #else /* !USE_HOSTCC */
  135. #include <env.h>
  136. #include <search.h>
  137. /*
  138. * When adding a variable to the environment, initialize the flags for that
  139. * variable.
  140. */
  141. void env_flags_init(struct env_entry *var_entry);
  142. /*
  143. * Validate the newval for to conform with the requirements defined by its flags
  144. */
  145. int env_flags_validate(const struct env_entry *item, const char *newval,
  146. enum env_op op, int flag);
  147. #endif /* USE_HOSTCC */
  148. /*
  149. * These are the binary flags used in the environment entry->flags variable to
  150. * decribe properties of veriables in the table
  151. */
  152. #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
  153. /* The actual variable type values use the enum value (within the mask) */
  154. #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
  155. #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
  156. #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
  157. #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
  158. #define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
  159. #endif /* __ENV_FLAGS_H__ */