diff options
Diffstat (limited to 'lib/helper.c')
-rw-r--r-- | lib/helper.c | 78 |
1 files changed, 73 insertions, 5 deletions
diff --git a/lib/helper.c b/lib/helper.c index 95d641e..b9316c4 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -29,6 +29,7 @@ * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ +#define _POSIX_SOURCE #include <sys/types.h> #include <sys/stat.h> @@ -671,6 +672,43 @@ ipmi_start_daemon(struct ipmi_intf *intf) dup(fd); } +/* eval_ccode - evaluate return value of _ipmi_* functions and print error error + * message, if conditions are met. + * + * @ccode - return value of _ipmi_* function. + * + * returns - 0 if ccode is 0, otherwise (-1) and error might get printed-out. + */ +int +eval_ccode(const int ccode) +{ + if (ccode == 0) { + return 0; + } else if (ccode < 0) { + switch (ccode) { + case (-1): + lprintf(LOG_ERR, "IPMI response is NULL."); + break; + case (-2): + lprintf(LOG_ERR, "Unexpected data length received."); + break; + case (-3): + lprintf(LOG_ERR, "Invalid function parameter."); + break; + case (-4): + lprintf(LOG_ERR, "ipmitool: malloc failure."); + break; + default: + break; + } + return (-1); + } else { + lprintf(LOG_ERR, "IPMI command failed: %s", + val2str(ccode, completion_code_vals)); + return (-1); + } +} + /* is_fru_id - wrapper for str-2-int FRU ID conversion. Message is printed * on error. * FRU ID range: <0..255> @@ -700,9 +738,9 @@ is_fru_id(const char *argv_ptr, uint8_t *fru_id_ptr) /* is_ipmi_channel_num - wrapper for str-2-int Channel conversion. Message is * printed on error. * - * 6.3 Channel Numbers, p. 45, IPMIv2 spec. - * Valid channel numbers are: <0..7>, <E-F> - * Reserved channel numbers: <8-D> + * 6.3 Channel Numbers, p. 49, IPMIv2 spec. rev1.1 + * Valid channel numbers are: <0x0..0xB>, <0xE-0xF> + * Reserved channel numbers: <0xC-0xD> * * @argv_ptr: source string to convert from; usually argv * @channel_ptr: pointer where to store result @@ -719,14 +757,14 @@ is_ipmi_channel_num(const char *argv_ptr, uint8_t *channel_ptr) return (-1); } if ((str2uchar(argv_ptr, channel_ptr) == 0) - && ((*channel_ptr >= 0x0 && *channel_ptr <= 0x7) + && (*channel_ptr <= 0xB || (*channel_ptr >= 0xE && *channel_ptr <= 0xF))) { return 0; } lprintf(LOG_ERR, "Given Channel number '%s' is either invalid or out of range.", argv_ptr); - lprintf(LOG_ERR, "Channel number must be from ranges: <0..7>, <0xE..0xF>"); + lprintf(LOG_ERR, "Channel number must be from ranges: <0x0..0xB>, <0xE..0xF>"); return (-1); } @@ -760,6 +798,36 @@ is_ipmi_user_id(const char *argv_ptr, uint8_t *ipmi_uid_ptr) return (-1); } +/* is_ipmi_user_priv_limit - check whether given value is valid User Privilege + * Limit, eg. IPMI v2 spec, 22.27 Get User Access Command. + * + * @priv_limit: User Privilege Limit + * + * returns 0 if Priv Limit is valid + * returns (-1) when Priv Limit is invalid + */ +int +is_ipmi_user_priv_limit(const char *argv_ptr, uint8_t *ipmi_priv_limit_ptr) +{ + if (!argv_ptr || !ipmi_priv_limit_ptr) { + lprintf(LOG_ERR, + "is_ipmi_user_priv_limit(): invalid argument(s)."); + return (-1); + } + if ((str2uchar(argv_ptr, ipmi_priv_limit_ptr) != 0) + || ((*ipmi_priv_limit_ptr < 0x01 + || *ipmi_priv_limit_ptr > 0x05) + && *ipmi_priv_limit_ptr != 0x0F)) { + lprintf(LOG_ERR, + "Given Privilege Limit '%s' is invalid.", + argv_ptr); + lprintf(LOG_ERR, + "Privilege Limit is limited to <0x1..0x5> and <0xF>."); + return (-1); + } + return 0; +} + uint16_t ipmi_get_oem_id(struct ipmi_intf *intf) { |