ipmi_cfgp.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (c) 2016 Pentair Technical Products. All right reserved
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * Redistribution of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * Redistribution in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * Neither the name of Pentair Technical Products or the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  23. * PENTAIR TECHNICAL SOLUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  29. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef IPMI_CFGP_H
  33. #define IPMI_CFGP_H
  34. #include <stdio.h>
  35. /* Forward declarations. */
  36. struct ipmi_cfgp;
  37. struct ipmi_cfgp_ctx;
  38. /*
  39. * Action types.
  40. */
  41. enum {
  42. /* parse dumped parameter data */
  43. CFGP_PARSE,
  44. /* get parameter from BMC */
  45. CFGP_GET,
  46. /* set parameter to BMC */
  47. CFGP_SET,
  48. /* output parameter data in form that can be parsed back */
  49. CFGP_SAVE,
  50. /* print parameter in user-friendly format */
  51. CFGP_PRINT
  52. };
  53. /*
  54. * Action-specific information.
  55. */
  56. struct ipmi_cfgp_action {
  57. /* Action type. */
  58. int type;
  59. /* Set selector. */
  60. int set;
  61. /* Block selector. */
  62. int block;
  63. /* No error output needed. */
  64. int quiet;
  65. /* Number of command line arguments (only for parse action). */
  66. int argc;
  67. /* Command line arguments (only for parse action). */
  68. const char **argv;
  69. /* Output file (only for dump/print actions). */
  70. FILE *file;
  71. };
  72. /*
  73. * Access types.
  74. */
  75. enum {
  76. CFGP_RDWR,
  77. CFGP_RDONLY,
  78. CFGP_WRONLY,
  79. CFGP_RESERVED
  80. };
  81. /*
  82. * Configuration parameter descriptor.
  83. */
  84. struct ipmi_cfgp {
  85. /* Parameter name. */
  86. const char *name;
  87. /* Parameter format description. */
  88. const char *format;
  89. /* Various parameter traits. */
  90. unsigned int size; /* block size */
  91. unsigned int access:2; /* read-write/read-only/write-only */
  92. unsigned int is_set:1; /* takes non-zero set selectors */
  93. unsigned int first_set:1; /* 1 = 1-based set selector */
  94. unsigned int has_blocks:1; /* takes non-zero block selectors */
  95. unsigned int first_block:1; /* 1 = 1-based block selector */
  96. /* Parameter-specific data. */
  97. int specific;
  98. };
  99. /* Parameter callback. */
  100. typedef int (*ipmi_cfgp_handler_t)(void *priv,
  101. const struct ipmi_cfgp *p, const struct ipmi_cfgp_action *action,
  102. unsigned char *data);
  103. /*
  104. * Parameter selector.
  105. */
  106. struct ipmi_cfgp_sel {
  107. int param;
  108. int set;
  109. int block;
  110. };
  111. /*
  112. * Configuration parameter data.
  113. */
  114. struct ipmi_cfgp_data {
  115. struct ipmi_cfgp_data *next;
  116. struct ipmi_cfgp_sel sel;
  117. unsigned char data[];
  118. };
  119. /*
  120. * Configuration parameter operation context.
  121. */
  122. struct ipmi_cfgp_ctx {
  123. /* Set of parameters. */
  124. const struct ipmi_cfgp *set;
  125. /* Descriptor count. */
  126. int count;
  127. /* Parameter action handler. */
  128. ipmi_cfgp_handler_t handler;
  129. /* ipmitool cmd name */
  130. const char *cmdname;
  131. /* List of parameter values. */
  132. struct ipmi_cfgp_data *v;
  133. /* Private data. */
  134. void *priv;
  135. };
  136. /* Initialize configuration context. */
  137. extern int ipmi_cfgp_init(struct ipmi_cfgp_ctx *ctx,
  138. const struct ipmi_cfgp *set, unsigned int count,
  139. const char *cmdname,
  140. ipmi_cfgp_handler_t handler, void *priv);
  141. /* Uninitialize context, free allocated memory. */
  142. extern int ipmi_cfgp_uninit(struct ipmi_cfgp_ctx *ctx);
  143. /* Print parameter usage. */
  144. void ipmi_cfgp_usage(const struct ipmi_cfgp *set, int count, int write);
  145. /* Parse parameter selector from command line. */
  146. extern int ipmi_cfgp_parse_sel(struct ipmi_cfgp_ctx *ctx,
  147. int argc, const char **argv, struct ipmi_cfgp_sel *sel);
  148. /* Parse parameter data from command line. */
  149. extern int ipmi_cfgp_parse_data(struct ipmi_cfgp_ctx *ctx,
  150. const struct ipmi_cfgp_sel *sel, int argc, const char **argv);
  151. /* Get parameter data from BMC. */
  152. extern int ipmi_cfgp_get(struct ipmi_cfgp_ctx *ctx,
  153. const struct ipmi_cfgp_sel *sel);
  154. /* Set parameter data to BMC. */
  155. extern int ipmi_cfgp_set(struct ipmi_cfgp_ctx *ctx,
  156. const struct ipmi_cfgp_sel *sel);
  157. /* Write parameter data to file. */
  158. extern int ipmi_cfgp_save(struct ipmi_cfgp_ctx *ctx,
  159. const struct ipmi_cfgp_sel *sel, FILE *file);
  160. /* Print parameter data in user-friendly format. */
  161. extern int ipmi_cfgp_print(struct ipmi_cfgp_ctx *ctx,
  162. const struct ipmi_cfgp_sel *sel, FILE *file);
  163. #endif /* IPMI_CFGP_H */