helper.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights 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 Sun Microsystems, Inc. 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 "AS IS," without a warranty of any kind.
  20. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  21. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  22. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  23. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  24. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  25. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  26. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  27. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  28. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  29. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  30. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #ifndef IPMI_HELPER_H
  33. #define IPMI_HELPER_H
  34. #include <sys/types.h>
  35. #include <inttypes.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #ifndef TRUE
  39. #define TRUE 1
  40. #endif
  41. #ifndef FALSE
  42. #define FALSE 0
  43. #endif
  44. #ifndef tboolean
  45. #define tboolean int
  46. #endif
  47. /* IPMI spec. - UID 0 reserved, 63 maximum UID which can be used */
  48. #ifndef IPMI_UID_MIN
  49. # define IPMI_UID_MIN 1
  50. #endif
  51. #ifndef IPMI_UID_MAX
  52. # define IPMI_UID_MAX 63
  53. #endif
  54. struct ipmi_intf;
  55. struct valstr {
  56. uint16_t val;
  57. const char * str;
  58. };
  59. struct oemvalstr {
  60. uint32_t oem;
  61. uint16_t val;
  62. const char * str;
  63. };
  64. const char * val2str(uint16_t val, const struct valstr * vs);
  65. const char * oemval2str(uint32_t oem,uint16_t val, const struct oemvalstr * vs);
  66. int str2double(const char * str, double * double_ptr);
  67. int str2long(const char * str, int64_t * lng_ptr);
  68. int str2ulong(const char * str, uint64_t * ulng_ptr);
  69. int str2int(const char * str, int32_t * int_ptr);
  70. int str2uint(const char * str, uint32_t * uint_ptr);
  71. int str2short(const char * str, int16_t * shrt_ptr);
  72. int str2ushort(const char * str, uint16_t * ushrt_ptr);
  73. int str2char(const char * str, int8_t * chr_ptr);
  74. int str2uchar(const char * str, uint8_t * uchr_ptr);
  75. int eval_ccode(const int ccode);
  76. int is_fru_id(const char *argv_ptr, uint8_t *fru_id_ptr);
  77. int is_ipmi_channel_num(const char *argv_ptr, uint8_t *channel_ptr);
  78. int is_ipmi_user_id(const char *argv_ptr, uint8_t *ipmi_uid_ptr);
  79. int is_ipmi_user_priv_limit(const char *argv_ptr, uint8_t *ipmi_priv_limit_ptr);
  80. uint16_t str2val(const char * str, const struct valstr * vs);
  81. void print_valstr(const struct valstr * vs, const char * title, int loglevel);
  82. void print_valstr_2col(const struct valstr * vs, const char * title, int loglevel);
  83. uint16_t buf2short(uint8_t * buf);
  84. uint32_t buf2long(uint8_t * buf);
  85. #define BUF2STR_MAXIMUM_OUTPUT_SIZE (3*1024 + 1)
  86. const char * buf2str_extended(const uint8_t *buf, int len, const char *sep);
  87. const char * buf2str(const uint8_t *buf, int len);
  88. int str2mac(const char *arg, uint8_t *buf);
  89. const char * mac2str(const uint8_t *buf);
  90. int ipmi_parse_hex(const char *str, uint8_t *out, int size);
  91. void printbuf(const uint8_t * buf, int len, const char * desc);
  92. uint8_t ipmi_csum(uint8_t * d, int s);
  93. FILE * ipmi_open_file(const char * file, int rw);
  94. void ipmi_start_daemon(struct ipmi_intf *intf);
  95. uint16_t ipmi_get_oem_id(struct ipmi_intf *intf);
  96. #define ipmi_open_file_read(file) ipmi_open_file(file, 0)
  97. #define ipmi_open_file_write(file) ipmi_open_file(file, 1)
  98. #ifndef __min
  99. # define __min(a, b) ((a) < (b) ? (a) : (b))
  100. #endif
  101. #ifndef __max
  102. # define __max(a, b) ((a) > (b) ? (a) : (b))
  103. #endif
  104. #ifndef __minlen
  105. # define __minlen(a, b) ({ int x=strlen(a); int y=strlen(b); (x < y) ? x : y;})
  106. #endif
  107. #ifndef __maxlen
  108. # define __maxlen(a, b) ({ int x=strlen(a); int y=strlen(b); (x > y) ? x : y;})
  109. #endif
  110. #endif /* IPMI_HELPER_H */