env_flags.h 4.5 KB

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