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 33 #ifndef IPMI_HELPER_H 34 #define IPMI_HELPER_H 35 36 #include <sys/types.h> 37 #include <inttypes.h> 38 #include <stdio.h> 39 #include <string.h> 40 41 #ifndef TRUE 42 #define TRUE 1 43 #endif 44 45 #ifndef FALSE 46 #define FALSE 0 47 #endif 48 49 #ifndef tboolean 50 #define tboolean int 51 #endif 52 53 /* IPMI spec. - UID 0 reserved, 63 maximum UID which can be used */ 54 #ifndef IPMI_UID_MIN 55 # define IPMI_UID_MIN 1 56 #endif 57 #ifndef IPMI_UID_MAX 58 # define IPMI_UID_MAX 63 59 #endif 60 61 struct ipmi_intf; 62 63 struct valstr { 64 uint16_t val; 65 const char * str; 66 }; 67 struct oemvalstr { 68 uint32_t oem; 69 uint16_t val; 70 const char * str; 71 }; 72 73 const char * val2str(uint16_t val, const struct valstr * vs); 74 const char * oemval2str(uint32_t oem,uint16_t val, const struct oemvalstr * vs); 75 76 int str2double(const char * str, double * double_ptr); 77 int str2long(const char * str, int64_t * lng_ptr); 78 int str2ulong(const char * str, uint64_t * ulng_ptr); 79 int str2int(const char * str, int32_t * int_ptr); 80 int str2uint(const char * str, uint32_t * uint_ptr); 81 int str2short(const char * str, int16_t * shrt_ptr); 82 int str2ushort(const char * str, uint16_t * ushrt_ptr); 83 int str2char(const char * str, int8_t * chr_ptr); 84 int str2uchar(const char * str, uint8_t * uchr_ptr); 85 86 int eval_ccode(const int ccode); 87 88 int is_fru_id(const char *argv_ptr, uint8_t *fru_id_ptr); 89 int is_ipmi_channel_num(const char *argv_ptr, uint8_t *channel_ptr); 90 int is_ipmi_user_id(const char *argv_ptr, uint8_t *ipmi_uid_ptr); 91 int is_ipmi_user_priv_limit(const char *argv_ptr, uint8_t *ipmi_priv_limit_ptr); 92 93 uint16_t str2val(const char * str, const struct valstr * vs); 94 void print_valstr(const struct valstr * vs, const char * title, int loglevel); 95 void print_valstr_2col(const struct valstr * vs, const char * title, int loglevel); 96 97 98 uint16_t buf2short(uint8_t * buf); 99 uint32_t buf2long(uint8_t * buf); 100 const char * buf2str(uint8_t * buf, int len); 101 void printbuf(const uint8_t * buf, int len, const char * desc); 102 uint8_t ipmi_csum(uint8_t * d, int s); 103 FILE * ipmi_open_file(const char * file, int rw); 104 void ipmi_start_daemon(struct ipmi_intf *intf); 105 uint16_t ipmi_get_oem_id(struct ipmi_intf *intf); 106 107 #define ipmi_open_file_read(file) ipmi_open_file(file, 0) 108 #define ipmi_open_file_write(file) ipmi_open_file(file, 1) 109 110 #ifndef __min 111 # define __min(a, b) ((a) < (b) ? (a) : (b)) 112 #endif 113 114 #ifndef __max 115 # define __max(a, b) ((a) > (b) ? (a) : (b)) 116 #endif 117 118 #ifndef __minlen 119 # define __minlen(a, b) ({ int x=strlen(a); int y=strlen(b); (x < y) ? x : y;}) 120 #endif 121 122 #ifndef __maxlen 123 # define __maxlen(a, b) ({ int x=strlen(a); int y=strlen(b); (x > y) ? x : y;}) 124 #endif 125 126 #endif /* IPMI_HELPER_H */ 127