summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/Makefile.in717
-rw-r--r--lib/dimm_spd.c49
-rw-r--r--lib/helper.c221
-rw-r--r--lib/ipmi_cfgp.c36
-rw-r--r--lib/ipmi_channel.c464
-rw-r--r--lib/ipmi_chassis.c1575
-rw-r--r--[-rwxr-xr-x]lib/ipmi_dcmi.c1265
-rw-r--r--lib/ipmi_delloem.c727
-rw-r--r--lib/ipmi_ekanalyzer.c384
-rw-r--r--lib/ipmi_event.c184
-rw-r--r--lib/ipmi_firewall.c94
-rw-r--r--lib/ipmi_fru.c949
-rw-r--r--lib/ipmi_fwum.c64
-rw-r--r--lib/ipmi_gendev.c65
-rw-r--r--lib/ipmi_hpmfwupg.c179
-rw-r--r--[-rwxr-xr-x]lib/ipmi_ime.c90
-rw-r--r--lib/ipmi_isol.c51
-rw-r--r--lib/ipmi_kontronoem.c75
-rw-r--r--lib/ipmi_lanp.c596
-rw-r--r--lib/ipmi_lanp6.c16
-rw-r--r--lib/ipmi_main.c206
-rw-r--r--lib/ipmi_mc.c774
-rw-r--r--lib/ipmi_oem.c49
-rw-r--r--lib/ipmi_pef.c429
-rw-r--r--lib/ipmi_picmg.c278
-rw-r--r--lib/ipmi_quantaoem.c184
-rw-r--r--lib/ipmi_raw.c33
-rw-r--r--lib/ipmi_sdr.c735
-rw-r--r--lib/ipmi_sdradd.c34
-rw-r--r--lib/ipmi_sel.c442
-rw-r--r--lib/ipmi_sensor.c390
-rw-r--r--lib/ipmi_session.c40
-rw-r--r--lib/ipmi_sol.c106
-rw-r--r--lib/ipmi_strings.c1117
-rw-r--r--lib/ipmi_sunoem.c205
-rw-r--r--lib/ipmi_time.c243
-rw-r--r--lib/ipmi_tsol.c33
-rw-r--r--lib/ipmi_user.c138
-rw-r--r--lib/ipmi_vita.c86
-rw-r--r--lib/log.c16
41 files changed, 8092 insertions, 5250 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index cc69a8f..49f5a8a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -41,8 +41,7 @@ libipmitool_la_SOURCES = helper.c ipmi_sdr.c ipmi_sel.c ipmi_sol.c ipmi_pef.c \
ipmi_main.c ipmi_tsol.c ipmi_firewall.c ipmi_kontronoem.c \
ipmi_hpmfwupg.c ipmi_sdradd.c ipmi_ekanalyzer.c ipmi_gendev.c \
ipmi_ime.c ipmi_delloem.c ipmi_dcmi.c hpm2.c ipmi_vita.c \
- ipmi_lanp6.c ipmi_cfgp.c \
- ../src/plugins/lan/md5.c ../src/plugins/lan/md5.h
+ ipmi_lanp6.c ipmi_cfgp.c ipmi_quantaoem.c ipmi_time.c
libipmitool_la_LDFLAGS = -export-dynamic
libipmitool_la_LIBADD = -lm
diff --git a/lib/Makefile.in b/lib/Makefile.in
deleted file mode 100644
index 0e2b6b2..0000000
--- a/lib/Makefile.in
+++ /dev/null
@@ -1,717 +0,0 @@
-# Makefile.in generated by automake 1.14.1 from Makefile.am.
-# @configure_input@
-
-# Copyright (C) 1994-2013 Free Software Foundation, Inc.
-
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
-@SET_MAKE@
-
-# Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# Redistribution of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# Redistribution in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# Neither the name of Sun Microsystems, Inc. or the names of
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# This software is provided "AS IS," without a warranty of any kind.
-# ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
-# INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
-# PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
-# SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
-# FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
-# OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
-# SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
-# OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
-# PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
-# 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.
-
-VPATH = @srcdir@
-am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
-am__make_running_with_option = \
- case $${target_option-} in \
- ?) ;; \
- *) echo "am__make_running_with_option: internal error: invalid" \
- "target option '$${target_option-}' specified" >&2; \
- exit 1;; \
- esac; \
- has_opt=no; \
- sane_makeflags=$$MAKEFLAGS; \
- if $(am__is_gnu_make); then \
- sane_makeflags=$$MFLAGS; \
- else \
- case $$MAKEFLAGS in \
- *\\[\ \ ]*) \
- bs=\\; \
- sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
- | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
- esac; \
- fi; \
- skip_next=no; \
- strip_trailopt () \
- { \
- flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
- }; \
- for flg in $$sane_makeflags; do \
- test $$skip_next = yes && { skip_next=no; continue; }; \
- case $$flg in \
- *=*|--*) continue;; \
- -*I) strip_trailopt 'I'; skip_next=yes;; \
- -*I?*) strip_trailopt 'I';; \
- -*O) strip_trailopt 'O'; skip_next=yes;; \
- -*O?*) strip_trailopt 'O';; \
- -*l) strip_trailopt 'l'; skip_next=yes;; \
- -*l?*) strip_trailopt 'l';; \
- -[dEDm]) skip_next=yes;; \
- -[JT]) skip_next=yes;; \
- esac; \
- case $$flg in \
- *$$target_option*) has_opt=yes; break;; \
- esac; \
- done; \
- test $$has_opt = yes
-am__make_dryrun = (target_option=n; $(am__make_running_with_option))
-am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
-pkgdatadir = $(datadir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkglibexecdir = $(libexecdir)/@PACKAGE@
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
-install_sh_DATA = $(install_sh) -c -m 644
-install_sh_PROGRAM = $(install_sh) -c
-install_sh_SCRIPT = $(install_sh) -c
-INSTALL_HEADER = $(INSTALL_DATA)
-transform = $(program_transform_name)
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-build_triplet = @build@
-host_triplet = @host@
-target_triplet = @target@
-subdir = lib
-DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
- $(top_srcdir)/depcomp
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/configure.ac
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
- $(ACLOCAL_M4)
-mkinstalldirs = $(install_sh) -d
-CONFIG_HEADER = $(top_builddir)/config.h
-CONFIG_CLEAN_FILES =
-CONFIG_CLEAN_VPATH_FILES =
-LTLIBRARIES = $(noinst_LTLIBRARIES)
-am__dirstamp = $(am__leading_dot)dirstamp
-am_libipmitool_la_OBJECTS = helper.lo ipmi_sdr.lo ipmi_sel.lo \
- ipmi_sol.lo ipmi_pef.lo ipmi_lanp.lo ipmi_fru.lo \
- ipmi_chassis.lo ipmi_mc.lo log.lo dimm_spd.lo ipmi_sensor.lo \
- ipmi_channel.lo ipmi_event.lo ipmi_session.lo ipmi_strings.lo \
- ipmi_user.lo ipmi_raw.lo ipmi_oem.lo ipmi_isol.lo \
- ipmi_sunoem.lo ipmi_fwum.lo ipmi_picmg.lo ipmi_main.lo \
- ipmi_tsol.lo ipmi_firewall.lo ipmi_kontronoem.lo \
- ipmi_hpmfwupg.lo ipmi_sdradd.lo ipmi_ekanalyzer.lo \
- ipmi_gendev.lo ipmi_ime.lo ipmi_delloem.lo ipmi_dcmi.lo \
- hpm2.lo ipmi_vita.lo ipmi_lanp6.lo ipmi_cfgp.lo \
- ../src/plugins/lan/md5.lo
-libipmitool_la_OBJECTS = $(am_libipmitool_la_OBJECTS)
-AM_V_lt = $(am__v_lt_@AM_V@)
-am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
-am__v_lt_0 = --silent
-am__v_lt_1 =
-libipmitool_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
- $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
- $(AM_CFLAGS) $(CFLAGS) $(libipmitool_la_LDFLAGS) $(LDFLAGS) -o \
- $@
-AM_V_P = $(am__v_P_@AM_V@)
-am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
-am__v_P_0 = false
-am__v_P_1 = :
-AM_V_GEN = $(am__v_GEN_@AM_V@)
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
-am__v_GEN_0 = @echo " GEN " $@;
-am__v_GEN_1 =
-AM_V_at = $(am__v_at_@AM_V@)
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
-am__v_at_0 = @
-am__v_at_1 =
-DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/depcomp
-am__depfiles_maybe = depfiles
-am__mv = mv -f
-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
- $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
- $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
- $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
- $(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_@AM_V@)
-am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
-am__v_CC_0 = @echo " CC " $@;
-am__v_CC_1 =
-CCLD = $(CC)
-LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
- $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
- $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_@AM_V@)
-am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
-am__v_CCLD_0 = @echo " CCLD " $@;
-am__v_CCLD_1 =
-SOURCES = $(libipmitool_la_SOURCES)
-DIST_SOURCES = $(libipmitool_la_SOURCES)
-am__can_run_installinfo = \
- case $$AM_UPDATE_INFO_DIR in \
- n|no|NO) false;; \
- *) (install-info --version) >/dev/null 2>&1;; \
- esac
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
-# Read a list of newline-separated strings from the standard input,
-# and print each of them once, without duplicates. Input order is
-# *not* preserved.
-am__uniquify_input = $(AWK) '\
- BEGIN { nonempty = 0; } \
- { items[$$0] = 1; nonempty = 1; } \
- END { if (nonempty) { for (i in items) print i; }; } \
-'
-# Make sure the list of sources is unique. This is necessary because,
-# e.g., the same source file might be shared among _SOURCES variables
-# for different programs/libraries.
-am__define_uniq_tagged_files = \
- list='$(am__tagged_files)'; \
- unique=`for i in $$list; do \
- if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
- done | $(am__uniquify_input)`
-ETAGS = etags
-CTAGS = ctags
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = @ACLOCAL@
-AMTAR = @AMTAR@
-AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
-AR = @AR@
-ARCH = @ARCH@
-AUTOCONF = @AUTOCONF@
-AUTOHEADER = @AUTOHEADER@
-AUTOMAKE = @AUTOMAKE@
-AWK = @AWK@
-BASEDIR = @BASEDIR@
-CC = @CC@
-CCDEPMODE = @CCDEPMODE@
-CFLAGS = @CFLAGS@
-CPP = @CPP@
-CPPFLAGS = @CPPFLAGS@
-CYGPATH_W = @CYGPATH_W@
-DEFS = @DEFS@
-DEPDIR = @DEPDIR@
-DISTRO = @DISTRO@
-DLLTOOL = @DLLTOOL@
-DSYMUTIL = @DSYMUTIL@
-DUMPBIN = @DUMPBIN@
-ECHO_C = @ECHO_C@
-ECHO_N = @ECHO_N@
-ECHO_T = @ECHO_T@
-EGREP = @EGREP@
-EXEEXT = @EXEEXT@
-FGREP = @FGREP@
-GREP = @GREP@
-INSTALL = @INSTALL@
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-INTF_BMC = @INTF_BMC@
-INTF_BMC_LIB = @INTF_BMC_LIB@
-INTF_DUMMY = @INTF_DUMMY@
-INTF_DUMMY_LIB = @INTF_DUMMY_LIB@
-INTF_FREE = @INTF_FREE@
-INTF_FREE_LIB = @INTF_FREE_LIB@
-INTF_IMB = @INTF_IMB@
-INTF_IMB_LIB = @INTF_IMB_LIB@
-INTF_LAN = @INTF_LAN@
-INTF_LANPLUS = @INTF_LANPLUS@
-INTF_LANPLUS_LIB = @INTF_LANPLUS_LIB@
-INTF_LAN_LIB = @INTF_LAN_LIB@
-INTF_LIPMI = @INTF_LIPMI@
-INTF_LIPMI_LIB = @INTF_LIPMI_LIB@
-INTF_OPEN = @INTF_OPEN@
-INTF_OPEN_LIB = @INTF_OPEN_LIB@
-INTF_SERIAL = @INTF_SERIAL@
-INTF_SERIAL_LIB = @INTF_SERIAL_LIB@
-INTF_USB = @INTF_USB@
-INTF_USB_LIB = @INTF_USB_LIB@
-IPMITOOL_INTF_LIB = @IPMITOOL_INTF_LIB@
-LD = @LD@
-LDFLAGS = @LDFLAGS@
-LIBOBJS = @LIBOBJS@
-LIBS = @LIBS@
-LIBTOOL = @LIBTOOL@
-LIPO = @LIPO@
-LN_S = @LN_S@
-LTLIBOBJS = @LTLIBOBJS@
-MAKEINFO = @MAKEINFO@
-MANIFEST_TOOL = @MANIFEST_TOOL@
-MKDIR_P = @MKDIR_P@
-NM = @NM@
-NMEDIT = @NMEDIT@
-OBJDUMP = @OBJDUMP@
-OBJEXT = @OBJEXT@
-OS = @OS@
-OTOOL = @OTOOL@
-OTOOL64 = @OTOOL64@
-PACKAGE = @PACKAGE@
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
-PACKAGE_NAME = @PACKAGE_NAME@
-PACKAGE_STRING = @PACKAGE_STRING@
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
-PACKAGE_URL = @PACKAGE_URL@
-PACKAGE_VERSION = @PACKAGE_VERSION@
-PATH_SEPARATOR = @PATH_SEPARATOR@
-POW_LIB = @POW_LIB@
-PSTAMP = @PSTAMP@
-RANLIB = @RANLIB@
-RPMBUILD = @RPMBUILD@
-RPM_RELEASE = @RPM_RELEASE@
-SED = @SED@
-SET_MAKE = @SET_MAKE@
-SHELL = @SHELL@
-STRIP = @STRIP@
-VERSION = @VERSION@
-abs_builddir = @abs_builddir@
-abs_srcdir = @abs_srcdir@
-abs_top_builddir = @abs_top_builddir@
-abs_top_srcdir = @abs_top_srcdir@
-ac_configure_args = @ac_configure_args@
-ac_ct_AR = @ac_ct_AR@
-ac_ct_CC = @ac_ct_CC@
-ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
-am__include = @am__include@
-am__leading_dot = @am__leading_dot@
-am__quote = @am__quote@
-am__tar = @am__tar@
-am__untar = @am__untar@
-bindir = @bindir@
-build = @build@
-build_alias = @build_alias@
-build_cpu = @build_cpu@
-build_os = @build_os@
-build_vendor = @build_vendor@
-builddir = @builddir@
-datadir = @datadir@
-datarootdir = @datarootdir@
-docdir = @docdir@
-dvidir = @dvidir@
-exec_prefix = @exec_prefix@
-host = @host@
-host_alias = @host_alias@
-host_cpu = @host_cpu@
-host_os = @host_os@
-host_vendor = @host_vendor@
-htmldir = @htmldir@
-includedir = @includedir@
-infodir = @infodir@
-install_sh = @install_sh@
-libdir = @libdir@
-libexecdir = @libexecdir@
-localedir = @localedir@
-localstatedir = @localstatedir@
-mandir = @mandir@
-mkdir_p = @mkdir_p@
-oldincludedir = @oldincludedir@
-pdfdir = @pdfdir@
-prefix = @prefix@
-program_transform_name = @program_transform_name@
-psdir = @psdir@
-sbindir = @sbindir@
-sharedstatedir = @sharedstatedir@
-srcdir = @srcdir@
-sysconfdir = @sysconfdir@
-target = @target@
-target_alias = @target_alias@
-target_cpu = @target_cpu@
-target_os = @target_os@
-target_vendor = @target_vendor@
-top_build_prefix = @top_build_prefix@
-top_builddir = @top_builddir@
-top_srcdir = @top_srcdir@
-AUTOMAKE_OPTIONS = subdir-objects
-AM_CPPFLAGS = -I$(top_srcdir)/include
-MAINTAINERCLEANFILES = Makefile.in
-noinst_LTLIBRARIES = libipmitool.la
-libipmitool_la_SOURCES = helper.c ipmi_sdr.c ipmi_sel.c ipmi_sol.c ipmi_pef.c \
- ipmi_lanp.c ipmi_fru.c ipmi_chassis.c ipmi_mc.c log.c \
- dimm_spd.c ipmi_sensor.c ipmi_channel.c ipmi_event.c \
- ipmi_session.c ipmi_strings.c ipmi_user.c ipmi_raw.c \
- ipmi_oem.c ipmi_isol.c ipmi_sunoem.c ipmi_fwum.c ipmi_picmg.c \
- ipmi_main.c ipmi_tsol.c ipmi_firewall.c ipmi_kontronoem.c \
- ipmi_hpmfwupg.c ipmi_sdradd.c ipmi_ekanalyzer.c ipmi_gendev.c \
- ipmi_ime.c ipmi_delloem.c ipmi_dcmi.c hpm2.c ipmi_vita.c \
- ipmi_lanp6.c ipmi_cfgp.c \
- ../src/plugins/lan/md5.c ../src/plugins/lan/md5.h
-
-libipmitool_la_LDFLAGS = -export-dynamic
-libipmitool_la_LIBADD = -lm
-libipmitool_la_DEPENDENCIES =
-all: all-am
-
-.SUFFIXES:
-.SUFFIXES: .c .lo .o .obj
-$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
- @for dep in $?; do \
- case '$(am__configure_deps)' in \
- *$$dep*) \
- ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
- && { if test -f $@; then exit 0; else break; fi; }; \
- exit 1;; \
- esac; \
- done; \
- echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/Makefile'; \
- $(am__cd) $(top_srcdir) && \
- $(AUTOMAKE) --foreign lib/Makefile
-.PRECIOUS: Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
- @case '$?' in \
- *config.status*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
- *) \
- echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
- cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
- esac;
-
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-
-$(top_srcdir)/configure: $(am__configure_deps)
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(ACLOCAL_M4): $(am__aclocal_m4_deps)
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(am__aclocal_m4_deps):
-
-clean-noinstLTLIBRARIES:
- -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
- @list='$(noinst_LTLIBRARIES)'; \
- locs=`for p in $$list; do echo $$p; done | \
- sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
- sort -u`; \
- test -z "$$locs" || { \
- echo rm -f $${locs}; \
- rm -f $${locs}; \
- }
-../src/plugins/lan/$(am__dirstamp):
- @$(MKDIR_P) ../src/plugins/lan
- @: > ../src/plugins/lan/$(am__dirstamp)
-../src/plugins/lan/$(DEPDIR)/$(am__dirstamp):
- @$(MKDIR_P) ../src/plugins/lan/$(DEPDIR)
- @: > ../src/plugins/lan/$(DEPDIR)/$(am__dirstamp)
-../src/plugins/lan/md5.lo: ../src/plugins/lan/$(am__dirstamp) \
- ../src/plugins/lan/$(DEPDIR)/$(am__dirstamp)
-
-libipmitool.la: $(libipmitool_la_OBJECTS) $(libipmitool_la_DEPENDENCIES) $(EXTRA_libipmitool_la_DEPENDENCIES)
- $(AM_V_CCLD)$(libipmitool_la_LINK) $(libipmitool_la_OBJECTS) $(libipmitool_la_LIBADD) $(LIBS)
-
-mostlyclean-compile:
- -rm -f *.$(OBJEXT)
- -rm -f ../src/plugins/lan/*.$(OBJEXT)
- -rm -f ../src/plugins/lan/*.lo
-
-distclean-compile:
- -rm -f *.tab.c
-
-@AMDEP_TRUE@@am__include@ @am__quote@../src/plugins/lan/$(DEPDIR)/md5.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dimm_spd.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/helper.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hpm2.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_cfgp.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_channel.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_chassis.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_dcmi.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_delloem.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_ekanalyzer.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_event.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_firewall.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_fru.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_fwum.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_gendev.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_hpmfwupg.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_ime.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_isol.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_kontronoem.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_lanp.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_lanp6.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_main.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_mc.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_oem.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_pef.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_picmg.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_raw.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_sdr.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_sdradd.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_sel.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_sensor.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_session.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_sol.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_strings.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_sunoem.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_tsol.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_user.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipmi_vita.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Plo@am__quote@
-
-.c.o:
-@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
-@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
-
-.c.obj:
-@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
-@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
-
-.c.lo:
-@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
-@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
-@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
-
-mostlyclean-libtool:
- -rm -f *.lo
-
-clean-libtool:
- -rm -rf .libs _libs
- -rm -rf ../src/plugins/lan/.libs ../src/plugins/lan/_libs
-
-ID: $(am__tagged_files)
- $(am__define_uniq_tagged_files); mkid -fID $$unique
-tags: tags-am
-TAGS: tags
-
-tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
- set x; \
- here=`pwd`; \
- $(am__define_uniq_tagged_files); \
- shift; \
- if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
- test -n "$$unique" || unique=$$empty_fix; \
- if test $$# -gt 0; then \
- $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
- "$$@" $$unique; \
- else \
- $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
- $$unique; \
- fi; \
- fi
-ctags: ctags-am
-
-CTAGS: ctags
-ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
- $(am__define_uniq_tagged_files); \
- test -z "$(CTAGS_ARGS)$$unique" \
- || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
- $$unique
-
-GTAGS:
- here=`$(am__cd) $(top_builddir) && pwd` \
- && $(am__cd) $(top_srcdir) \
- && gtags -i $(GTAGS_ARGS) "$$here"
-cscopelist: cscopelist-am
-
-cscopelist-am: $(am__tagged_files)
- list='$(am__tagged_files)'; \
- case "$(srcdir)" in \
- [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
- *) sdir=$(subdir)/$(srcdir) ;; \
- esac; \
- for i in $$list; do \
- if test -f "$$i"; then \
- echo "$(subdir)/$$i"; \
- else \
- echo "$$sdir/$$i"; \
- fi; \
- done >> $(top_builddir)/cscope.files
-
-distclean-tags:
- -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-
-distdir: $(DISTFILES)
- @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
- topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
- list='$(DISTFILES)'; \
- dist_files=`for file in $$list; do echo $$file; done | \
- sed -e "s|^$$srcdirstrip/||;t" \
- -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
- case $$dist_files in \
- */*) $(MKDIR_P) `echo "$$dist_files" | \
- sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
- sort -u` ;; \
- esac; \
- for file in $$dist_files; do \
- if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
- if test -d $$d/$$file; then \
- dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
- if test -d "$(distdir)/$$file"; then \
- find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
- fi; \
- if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
- cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
- find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
- fi; \
- cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
- else \
- test -f "$(distdir)/$$file" \
- || cp -p $$d/$$file "$(distdir)/$$file" \
- || exit 1; \
- fi; \
- done
-check-am: all-am
-check: check-am
-all-am: Makefile $(LTLIBRARIES)
-installdirs:
-install: install-am
-install-exec: install-exec-am
-install-data: install-data-am
-uninstall: uninstall-am
-
-install-am: all-am
- @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-
-installcheck: installcheck-am
-install-strip:
- if test -z '$(STRIP)'; then \
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
- install; \
- else \
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
- "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
- fi
-mostlyclean-generic:
-
-clean-generic:
-
-distclean-generic:
- -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
- -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
- -rm -f ../src/plugins/lan/$(DEPDIR)/$(am__dirstamp)
- -rm -f ../src/plugins/lan/$(am__dirstamp)
-
-maintainer-clean-generic:
- @echo "This command is intended for maintainers to use"
- @echo "it deletes files that may require special tools to rebuild."
- -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
-clean: clean-am
-
-clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
- mostlyclean-am
-
-distclean: distclean-am
- -rm -rf ../src/plugins/lan/$(DEPDIR) ./$(DEPDIR)
- -rm -f Makefile
-distclean-am: clean-am distclean-compile distclean-generic \
- distclean-tags
-
-dvi: dvi-am
-
-dvi-am:
-
-html: html-am
-
-html-am:
-
-info: info-am
-
-info-am:
-
-install-data-am:
-
-install-dvi: install-dvi-am
-
-install-dvi-am:
-
-install-exec-am:
-
-install-html: install-html-am
-
-install-html-am:
-
-install-info: install-info-am
-
-install-info-am:
-
-install-man:
-
-install-pdf: install-pdf-am
-
-install-pdf-am:
-
-install-ps: install-ps-am
-
-install-ps-am:
-
-installcheck-am:
-
-maintainer-clean: maintainer-clean-am
- -rm -rf ../src/plugins/lan/$(DEPDIR) ./$(DEPDIR)
- -rm -f Makefile
-maintainer-clean-am: distclean-am maintainer-clean-generic
-
-mostlyclean: mostlyclean-am
-
-mostlyclean-am: mostlyclean-compile mostlyclean-generic \
- mostlyclean-libtool
-
-pdf: pdf-am
-
-pdf-am:
-
-ps: ps-am
-
-ps-am:
-
-uninstall-am:
-
-.MAKE: install-am install-strip
-
-.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
- clean-libtool clean-noinstLTLIBRARIES cscopelist-am ctags \
- ctags-am distclean distclean-compile distclean-generic \
- distclean-libtool distclean-tags distdir dvi dvi-am html \
- html-am info info-am install install-am install-data \
- install-data-am install-dvi install-dvi-am install-exec \
- install-exec-am install-html install-html-am install-info \
- install-info-am install-man install-pdf install-pdf-am \
- install-ps install-ps-am install-strip installcheck \
- installcheck-am installdirs maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-compile \
- mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
- tags tags-am uninstall uninstall-am
-
-
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:
diff --git a/lib/dimm_spd.c b/lib/dimm_spd.c
index 41e30db..d496184 100644
--- a/lib/dimm_spd.c
+++ b/lib/dimm_spd.c
@@ -1620,8 +1620,10 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
struct ipmi_rs * rsp;
struct ipmi_rq req;
struct fru_info fru;
- uint8_t *spd_data, msg_data[4];
- int len, offset;
+ uint8_t *spd_data = NULL;
+ uint8_t msg_data[4];
+ uint32_t len, offset;
+ int rc = -1;
msg_data[0] = id;
@@ -1632,14 +1634,14 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
- return -1;
+ goto end;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
- return -1;
+ goto end;
}
fru.size = (rsp->data[1] << 8) | rsp->data[0];
@@ -1651,15 +1653,15 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
if (fru.size < 1) {
lprintf(LOG_ERR, " Invalid FRU size %d", fru.size);
- return -1;
+ goto end;
}
spd_data = malloc(fru.size);
- if (spd_data == NULL) {
+ if (!spd_data) {
printf(" Unable to malloc memory for spd array of size=%d\n",
fru.size);
- return -1;
+ goto end;
}
memset(&req, 0, sizeof(req));
@@ -1677,34 +1679,39 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
msg_data[3] = FRU_DATA_RQST_SIZE;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
- free(spd_data);
- spd_data = NULL;
- return -1;
+ goto end;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
- free(spd_data);
- spd_data = NULL;
/* Timeouts are acceptable. No DIMM in the socket */
if (rsp->ccode == 0xc3)
- return 1;
+ rc = 1;
- return -1;
+ goto end;
}
len = rsp->data[0];
+ if(rsp->data_len < 1
+ || len > rsp->data_len - 1
+ || len > fru.size - offset)
+ {
+ printf(" Not enough buffer size");
+ goto end;
+ }
memcpy(&spd_data[offset], rsp->data + 1, len);
offset += len;
} while (offset < fru.size);
/* now print spd info */
ipmi_spd_print(spd_data, offset);
- free(spd_data);
- spd_data = NULL;
+ rc = 0;
- return 0;
+end:
+ free_n(&spd_data);
+
+ return rc;
}
diff --git a/lib/helper.c b/lib/helper.c
index de91438..b547123 100644
--- a/lib/helper.c
+++ b/lib/helper.c
@@ -29,12 +29,6 @@
* 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
-#define /* glibc 2.19 and earlier */ _BSD_SOURCE || \
- /* Since glibc 2.20 */_DEFAULT_SOURCE || \
- _XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || \
- /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200112L \
#include <sys/types.h>
#include <sys/stat.h>
@@ -60,7 +54,7 @@
#ifdef HAVE_PATHS_H
# include <paths.h>
#else
-# define _PATH_VARRUN "/var/run/"
+# define _PATH_RUN "/run/"
#endif
#include <ipmitool/ipmi.h>
@@ -100,7 +94,7 @@ buf2str_extended(const uint8_t *buf, int len, const char *sep)
int left;
int sep_len;
- if (buf == NULL) {
+ if (!buf) {
snprintf(str, sizeof(str), "<NULL>");
return (const char *)str;
}
@@ -180,7 +174,7 @@ ipmi_parse_hex(const char *str, uint8_t *out, int size)
}
len /= 2; /* out bytes */
- if (out == NULL) {
+ if (!out) {
return -2;
}
@@ -234,6 +228,50 @@ void printbuf(const uint8_t * buf, int len, const char * desc)
fprintf(stderr, "\n");
}
+/*
+ * Unconditionally reverse the order of arbitrarily long strings of bytes
+ */
+uint8_t *array_byteswap(uint8_t *buffer, size_t length)
+{
+ size_t i;
+ uint8_t temp;
+ size_t max = length - 1;
+
+ for (i = 0; i < length / 2; ++i) {
+ temp = buffer[i];
+ buffer[i] = buffer[max - i];
+ buffer[max - i] = temp;
+ }
+
+ return buffer;
+}
+
+/* Convert data array from network (big-endian) to host byte order */
+uint8_t *array_ntoh(uint8_t *buffer, size_t length)
+{
+#if WORDS_BIGENDIAN
+ /* Big-endian host doesn't need conversion from big-endian network */
+ (void)length; /* Silence the compiler */
+ return buffer;
+#else
+ /* Little-endian host needs conversion from big-endian network */
+ return array_byteswap(buffer, length);
+#endif
+}
+
+/* Convert data array from little-endian to host byte order */
+uint8_t *array_letoh(uint8_t *buffer, size_t length)
+{
+#if WORDS_BIGENDIAN
+ /* Big-endian host needs conversion from little-endian IPMI */
+ return array_byteswap(buffer, length);
+#else
+ /* Little-endian host doesn't need conversion from little-endian IPMI */
+ (void)length; /* Silence the compiler */
+ return buffer;
+#endif
+}
+
/* str2mac - parse-out MAC address from given string and store it
* into buffer.
*
@@ -281,29 +319,77 @@ mac2str(const uint8_t *buf)
return buf2str_extended(buf, 6, ":");
}
-const char * val2str(uint16_t val, const struct valstr *vs)
+/**
+ * Find the index of value in a valstr array
+ *
+ * @param[in] val The value to search for
+ * @param[in] vs The valstr array to search in
+ * @return >=0 The index into \p vs
+ * @return -1 Error: value \p val was not found in \p vs
+ */
+static
+inline
+off_t find_val_idx(uint32_t val, const struct valstr *vs)
{
- static char un_str[32];
- int i;
-
- for (i = 0; vs[i].str != NULL; i++) {
- if (vs[i].val == val)
- return vs[i].str;
+ if (vs) {
+ for (off_t i = 0; vs[i].str; ++i) {
+ if (vs[i].val == val) {
+ return i;
+ }
+ }
}
+ return -1;
+}
+
+/**
+ * Generate a statically allocated 'Unknown' string for the provided value.
+ * The function is not thread-safe (as most of ipmitool).
+ *
+ * @param[in] val The value to put into the string
+ * @returns A pointer to a statically allocated string
+ */
+static
+inline
+const char *unknown_val_str(uint32_t val)
+{
+ static char un_str[32];
memset(un_str, 0, 32);
snprintf(un_str, 32, "Unknown (0x%02X)", val);
return un_str;
}
-const char * oemval2str(uint32_t oem, uint16_t val,
- const struct oemvalstr *vs)
+const char *
+specific_val2str(uint32_t val,
+ const struct valstr *specific,
+ const struct valstr *generic)
+{
+ int i;
+
+ if (0 <= (i = find_val_idx(val, specific))) {
+ return specific[i].str;
+ }
+
+ if (0 <= (i = find_val_idx(val, generic))) {
+ return generic[i].str;
+ }
+
+ return unknown_val_str(val);
+}
+
+const char *val2str(uint32_t val, const struct valstr *vs)
+{
+ return specific_val2str(val, NULL, vs);
+}
+
+
+const char *oemval2str(uint32_t oem, uint32_t val,
+ const struct oemvalstr *vs)
{
- static char un_str[32];
int i;
- for (i = 0; vs[i].oem != 0xffffff && vs[i].str != NULL; i++) {
+ for (i = 0; vs[i].oem != 0xffffff && vs[i].str; i++) {
/* FIXME: for now on we assume PICMG capability on all IANAs */
if ( (vs[i].oem == oem || vs[i].oem == IPMI_OEM_PICMG) &&
vs[i].val == val ) {
@@ -311,10 +397,7 @@ const char * oemval2str(uint32_t oem, uint16_t val,
}
}
- memset(un_str, 0, 32);
- snprintf(un_str, 32, "Unknown (0x%X)", val);
-
- return un_str;
+ return unknown_val_str(val);
}
/* str2double - safely convert string to double
@@ -559,12 +642,12 @@ int str2uchar(const char * str, uint8_t * uchr_ptr)
return 0;
} /* str2uchar(...) */
-uint16_t str2val(const char *str, const struct valstr *vs)
+uint32_t str2val32(const char *str, const struct valstr *vs)
{
int i;
- for (i = 0; vs[i].str != NULL; i++) {
- if (strncasecmp(vs[i].str, str, __maxlen(str, vs[i].str)) == 0)
+ for (i = 0; vs[i].str; i++) {
+ if (strcasecmp(vs[i].str, str) == 0)
return vs[i].val;
}
@@ -582,10 +665,10 @@ print_valstr(const struct valstr * vs, const char * title, int loglevel)
{
int i;
- if (vs == NULL)
+ if (!vs)
return;
- if (title != NULL) {
+ if (title) {
if (loglevel < 0)
printf("\n%s:\n\n", title);
else
@@ -600,7 +683,7 @@ print_valstr(const struct valstr * vs, const char * title, int loglevel)
lprintf(loglevel, "==============================================");
}
- for (i = 0; vs[i].str != NULL; i++) {
+ for (i = 0; vs[i].str; i++) {
if (loglevel < 0) {
if (vs[i].val < 256)
printf(" %d\t0x%02x\t%s\n", vs[i].val, vs[i].val, vs[i].str);
@@ -631,18 +714,18 @@ print_valstr_2col(const struct valstr * vs, const char * title, int loglevel)
{
int i;
- if (vs == NULL)
+ if (!vs)
return;
- if (title != NULL) {
+ if (title) {
if (loglevel < 0)
printf("\n%s:\n\n", title);
else
lprintf(loglevel, "\n%s:\n", title);
}
- for (i = 0; vs[i].str != NULL; i++) {
- if (vs[i+1].str == NULL) {
+ for (i = 0; vs[i].str; i++) {
+ if (!vs[i+1].str) {
/* last one */
if (loglevel < 0) {
printf(" %4d %-32s\n", vs[i].val, vs[i].str);
@@ -696,12 +779,12 @@ ipmi_open_file(const char * file, int rw)
struct stat st1, st2;
FILE * fp;
- /* verify existance */
+ /* verify existence */
if (lstat(file, &st1) < 0) {
if (rw) {
/* does not exist, ok to create */
fp = fopen(file, "w");
- if (fp == NULL) {
+ if (!fp) {
lperror(LOG_ERR, "Unable to open file %s "
"for write", file);
return NULL;
@@ -718,7 +801,7 @@ ipmi_open_file(const char * file, int rw)
if (!rw) {
/* on read skip the extra checks */
fp = fopen(file, "r");
- if (fp == NULL) {
+ if (!fp) {
lperror(LOG_ERR, "Unable to open file %s", file);
return NULL;
}
@@ -741,7 +824,7 @@ ipmi_open_file(const char * file, int rw)
}
fp = fopen(file, rw ? "w+" : "r");
- if (fp == NULL) {
+ if (!fp) {
lperror(LOG_ERR, "Unable to open file %s", file);
return NULL;
}
@@ -785,6 +868,7 @@ ipmi_start_daemon(struct ipmi_intf *intf)
{
pid_t pid;
int fd;
+ int ret;
#ifdef SIGHUP
sigset_t sighup;
#endif
@@ -828,7 +912,11 @@ ipmi_start_daemon(struct ipmi_intf *intf)
exit(0);
#endif
- chdir("/");
+ ret = chdir("/");
+ if (ret) {
+ lprintf(LOG_ERR, "chdir failed: %s (%d)", strerror(errno), errno);
+ exit(1);
+ }
umask(0);
for (fd=0; fd<64; fd++) {
@@ -837,9 +925,20 @@ ipmi_start_daemon(struct ipmi_intf *intf)
}
fd = open("/dev/null", O_RDWR);
- assert(0 == fd);
- dup(fd);
- dup(fd);
+ if (fd != STDIN_FILENO) {
+ lprintf(LOG_ERR, "failed to reset stdin: %s (%d)", strerror(errno), errno);
+ exit(1);
+ }
+ ret = dup(fd);
+ if (ret != STDOUT_FILENO) {
+ lprintf(LOG_ERR, "failed to reset stdout: %s (%d)", strerror(errno), errno);
+ exit(1);
+ }
+ ret = dup(fd);
+ if (ret != STDERR_FILENO) {
+ lprintf(LOG_ERR, "failed to reset stderr: %s (%d)", strerror(errno), errno);
+ exit(1);
+ }
}
/* eval_ccode - evaluate return value of _ipmi_* functions and print error error
@@ -852,7 +951,7 @@ ipmi_start_daemon(struct ipmi_intf *intf)
int
eval_ccode(const int ccode)
{
- if (ccode == 0) {
+ if (!ccode) {
return 0;
} else if (ccode < 0) {
switch (ccode) {
@@ -1012,11 +1111,11 @@ ipmi_get_oem_id(struct ipmi_intf *intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Board ID command failed");
return 0;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Board ID command failed: %#x %s",
rsp->ccode, val2str(rsp->ccode, completion_code_vals));
return 0;
@@ -1026,3 +1125,35 @@ ipmi_get_oem_id(struct ipmi_intf *intf)
return oem_id;
}
+
+/** Parse command line arguments as numeric byte values (dec or hex)
+ * and store them in a \p len sized buffer \p out.
+ *
+ * @param[in] argc Number of arguments
+ * @param[in] argv Array of arguments
+ * @param[out] out The output buffer
+ * @param[in] len Length of the output buffer in bytes (no null-termination
+ * is assumed, the input data is treated as raw byte values,
+ * not as a string.
+ *
+ * @returns A success status indicator
+ * @return false Error
+ * @return true Success
+ */
+bool
+args2buf(int argc, char *argv[], uint8_t *out, size_t len)
+{
+ size_t i;
+
+ for (i = 0; i < len && i < (size_t)argc; ++i) {
+ uint8_t byte;
+
+ if (str2uchar(argv[i], &byte)) {
+ lprintf(LOG_ERR, "Bad byte value: %s", argv[i]);
+ return false;
+ }
+
+ out[i] = byte;
+ }
+ return true;
+}
diff --git a/lib/ipmi_cfgp.c b/lib/ipmi_cfgp.c
index b8af80d..4131a65 100644
--- a/lib/ipmi_cfgp.c
+++ b/lib/ipmi_cfgp.c
@@ -30,7 +30,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <malloc.h>
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#else
+# include <stdlib.h>
+#endif
#include <string.h>
#include <ipmitool/helper.h>
@@ -49,7 +53,7 @@ ipmi_cfgp_init(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp *set,
unsigned int count, const char *cmdname,
ipmi_cfgp_handler_t handler, void *priv)
{
- if (ctx == NULL || set == NULL || handler == NULL || !cmdname) {
+ if (!ctx || !set || !handler || !cmdname) {
return -1;
}
@@ -74,7 +78,7 @@ ipmi_cfgp_uninit(struct ipmi_cfgp_ctx *ctx)
{
struct ipmi_cfgp_data *d;
- if (ctx == NULL) {
+ if (!ctx) {
return -1;
}
@@ -123,7 +127,7 @@ ipmi_cfgp_parse_sel(struct ipmi_cfgp_ctx *ctx,
{
const struct ipmi_cfgp *p;
- if (ctx == NULL || argv == NULL || sel == NULL) {
+ if (!ctx || !argv || !sel) {
return -1;
}
@@ -137,7 +141,7 @@ ipmi_cfgp_parse_sel(struct ipmi_cfgp_ctx *ctx,
}
p = lookup_cfgp(ctx, argv[0]);
- if (p == NULL) {
+ if (!p) {
lprintf(LOG_ERR, "invalid parameter");
return -1;
}
@@ -201,11 +205,11 @@ cfgp_add_data(struct ipmi_cfgp_ctx *ctx, struct ipmi_cfgp_data *data)
static void
cfgp_usage(const struct ipmi_cfgp *p, int write)
{
- if (p->name == NULL) {
+ if (!p->name) {
return;
}
- if (write && p->format == NULL) {
+ if (write && !p->format) {
return;
}
@@ -227,7 +231,7 @@ ipmi_cfgp_usage(const struct ipmi_cfgp *set, int count, int write)
const struct ipmi_cfgp *p;
int i;
- if (set == NULL) {
+ if (!set) {
return;
}
@@ -263,7 +267,7 @@ ipmi_cfgp_parse_data(struct ipmi_cfgp_ctx *ctx,
struct ipmi_cfgp_data *data;
struct ipmi_cfgp_action action;
- if (ctx == NULL || sel == NULL || argv == NULL) {
+ if (!ctx || !sel || !argv) {
return -1;
}
@@ -290,7 +294,7 @@ ipmi_cfgp_parse_data(struct ipmi_cfgp_ctx *ctx,
}
data = malloc(sizeof(struct ipmi_cfgp_data) + p->size);
- if (data == NULL) {
+ if (!data) {
return -1;
}
@@ -370,7 +374,7 @@ cfgp_get_param(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp *p,
do {
data = malloc(sizeof(struct ipmi_cfgp_data) + p->size);
- if (data == NULL) {
+ if (!data) {
return -1;
}
@@ -422,7 +426,7 @@ ipmi_cfgp_get(struct ipmi_cfgp_ctx *ctx, const struct ipmi_cfgp_sel *sel)
int i;
int ret;
- if (ctx == NULL || sel == NULL) {
+ if (!ctx || !sel) {
return -1;
}
@@ -461,7 +465,7 @@ cfgp_do_action(struct ipmi_cfgp_ctx *ctx, int action_type,
struct ipmi_cfgp_action action;
int ret;
- if (ctx == NULL || sel == NULL) {
+ if (!ctx || !sel) {
return -1;
}
@@ -470,7 +474,7 @@ cfgp_do_action(struct ipmi_cfgp_ctx *ctx, int action_type,
action.argv = NULL;
action.file = file;
- for (data = ctx->v; data != NULL; data = data->next) {
+ for (data = ctx->v; data; data = data->next) {
if (sel->param != -1 && sel->param != data->sel.param) {
continue;
}
@@ -523,7 +527,7 @@ int
ipmi_cfgp_save(struct ipmi_cfgp_ctx *ctx,
const struct ipmi_cfgp_sel *sel, FILE *file)
{
- if (file == NULL) {
+ if (!file) {
return -1;
}
@@ -534,7 +538,7 @@ int
ipmi_cfgp_print(struct ipmi_cfgp_ctx *ctx,
const struct ipmi_cfgp_sel *sel, FILE *file)
{
- if (file == NULL) {
+ if (!file) {
return -1;
}
diff --git a/lib/ipmi_channel.c b/lib/ipmi_channel.c
index fab2e54..bb7e60a 100644
--- a/lib/ipmi_channel.c
+++ b/lib/ipmi_channel.c
@@ -75,7 +75,7 @@ _ipmi_get_channel_access(struct ipmi_intf *intf,
struct ipmi_rq req = {0};
uint8_t data[2];
- if (channel_access == NULL) {
+ if (!channel_access) {
return (-3);
}
data[0] = channel_access->channel & 0x0F;
@@ -87,9 +87,9 @@ _ipmi_get_channel_access(struct ipmi_intf *intf,
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 2) {
return (-2);
@@ -118,7 +118,7 @@ _ipmi_get_channel_info(struct ipmi_intf *intf,
struct ipmi_rq req = {0};
uint8_t data[1];
- if (channel_info == NULL) {
+ if (!channel_info) {
return (-3);
}
data[0] = channel_info->channel & 0x0F;
@@ -128,9 +128,9 @@ _ipmi_get_channel_info(struct ipmi_intf *intf,
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 9) {
return (-2);
@@ -202,7 +202,7 @@ _ipmi_set_channel_access(struct ipmi_intf *intf,
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
}
return rsp->ccode;
@@ -225,7 +225,7 @@ iana_string(uint32_t iana)
* ipmi_1_5_authtypes
*
* Create a string describing the supported authentication types as
- * specificed by the parameter n
+ * specified by the parameter n
*/
static const char *
ipmi_1_5_authtypes(uint8_t n)
@@ -244,10 +244,28 @@ ipmi_1_5_authtypes(uint8_t n)
return supportedTypes;
}
-uint8_t
-ipmi_current_channel_medium(struct ipmi_intf *intf)
+void
+ipmi_current_channel_info(struct ipmi_intf *intf,
+ struct channel_info_t *chinfo)
{
- return ipmi_get_channel_medium(intf, 0xE);
+ int ccode = 0;
+
+ chinfo->channel = CH_CURRENT;
+ ccode = _ipmi_get_channel_info(intf, chinfo);
+ if (ccode) {
+ if (ccode != IPMI_CC_INV_DATA_FIELD_IN_REQ) {
+ if (ccode > 0) {
+ lprintf(LOG_ERR, "Get Channel Info command failed: %s",
+ val2str(ccode, completion_code_vals));
+ }
+ else {
+ eval_ccode(ccode);
+ }
+ }
+ chinfo->channel = CH_UNKNOWN;
+ chinfo->medium = IPMI_CHANNEL_MEDIUM_RESERVED;
+ }
+ return;
}
/**
@@ -276,7 +294,7 @@ ipmi_get_channel_auth_cap(struct ipmi_intf *intf, uint8_t channel, uint8_t priv)
rsp = intf->sendrecv(intf, &req);
- if ((rsp == NULL) || (rsp->ccode > 0)) {
+ if (!rsp || rsp->ccode) {
/*
* It's very possible that this failed because we asked for IPMI v2 data
* Ask again, without requesting IPMI v2 data
@@ -284,11 +302,11 @@ ipmi_get_channel_auth_cap(struct ipmi_intf *intf, uint8_t channel, uint8_t priv)
msg_data[0] &= 0x7F;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to Get Channel Authentication Capabilities");
return (-1);
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Channel Authentication Capabilities failed: %s",
val2str(rsp->ccode, completion_code_vals));
return (-1);
@@ -342,86 +360,152 @@ ipmi_get_channel_auth_cap(struct ipmi_intf *intf, uint8_t channel, uint8_t priv)
return 0;
}
-static int
-ipmi_get_channel_cipher_suites(struct ipmi_intf *intf, const char *payload_type,
- uint8_t channel)
+static inline size_t parse_cipher_suite(uint8_t *cipher_suite_data,
+ size_t data_len,
+ uint32_t *iana,
+ uint8_t *auth_alg,
+ uint8_t *integrity_alg,
+ uint8_t *crypt_alg,
+ enum cipher_suite_ids *cipher_suite_id)
+{
+ size_t size = 0;
+ const char *incomplete = "Incomplete data record in cipher suite data";
+
+ if (*cipher_suite_data == STANDARD_CIPHER_SUITE) {
+ struct std_cipher_suite_record_t *record =
+ (struct std_cipher_suite_record_t*)cipher_suite_data;
+
+ /* Verify that we have at least a full record left; id + 3 algs */
+ if (data_len < sizeof(*record)) {
+ lprintf(LOG_INFO, "%s", incomplete);
+ goto out;
+ }
+
+ /* IANA code remains default (0) */
+ *cipher_suite_id = record->cipher_suite_id;
+ *auth_alg = CIPHER_ALG_MASK & record->auth_alg;
+ *integrity_alg = CIPHER_ALG_MASK & record->integrity_alg;
+ *crypt_alg = CIPHER_ALG_MASK & record->crypt_alg;
+ size = sizeof(*record);
+ } else if (*cipher_suite_data == OEM_CIPHER_SUITE) {
+ /* OEM record type */
+ struct oem_cipher_suite_record_t *record =
+ (struct oem_cipher_suite_record_t*)cipher_suite_data;
+ /* Verify that we have at least a full record left
+ * id + iana + 3 algs
+ */
+ if (data_len < sizeof(*record)) {
+ lprintf(LOG_INFO, "%s", incomplete);
+ goto out;
+ }
+
+ /* Grab the IANA */
+ *iana = ipmi24toh(record->iana);
+ *cipher_suite_id = record->cipher_suite_id;
+ *auth_alg = CIPHER_ALG_MASK & record->auth_alg;
+ *integrity_alg = CIPHER_ALG_MASK & record->integrity_alg;
+ *crypt_alg = CIPHER_ALG_MASK & record->crypt_alg;
+ size = sizeof(*record);
+ } else {
+ lprintf(LOG_INFO, "Bad start of record byte in cipher suite data "
+ "(value %x)", *cipher_suite_data);
+ }
+
+out:
+ return size;
+}
+
+static size_t
+parse_channel_cipher_suite_data(uint8_t *cipher_suite_data, size_t data_len,
+ struct cipher_suite_info* suites,
+ size_t nr_suites)
+{
+ size_t count = 0;
+ size_t offset = 0;
+
+ /* Default everything to zeroes */
+ memset(suites, 0, sizeof(*suites) * nr_suites);
+
+ while (offset < data_len && count < nr_suites) {
+ size_t suite_size;
+
+ /* Set non-zero defaults */
+ suites[count].auth_alg = IPMI_AUTH_RAKP_NONE;
+ suites[count].integrity_alg = IPMI_INTEGRITY_NONE;
+ suites[count].crypt_alg = IPMI_CRYPT_NONE;
+
+ /* Update fields from cipher suite data */
+ suite_size = parse_cipher_suite(cipher_suite_data + offset,
+ data_len - offset,
+ &suites[count].iana,
+ &suites[count].auth_alg,
+ &suites[count].integrity_alg,
+ &suites[count].crypt_alg,
+ &suites[count].cipher_suite_id);
+
+ if (!suite_size) {
+ lprintf(LOG_INFO,
+ "Failed to parse cipher suite data at offset %d",
+ offset);
+ break;
+ }
+
+ offset += suite_size;
+ count++;
+ }
+ return count;
+}
+
+int
+ipmi_get_channel_cipher_suites(struct ipmi_intf *intf,
+ const char *payload_type,
+ uint8_t channel,
+ struct cipher_suite_info *suites,
+ size_t *count)
{
struct ipmi_rs *rsp;
struct ipmi_rq req;
uint8_t rqdata[3];
- uint32_t iana;
- uint8_t auth_alg, integrity_alg, crypt_alg;
- uint8_t cipher_suite_id;
uint8_t list_index = 0;
/* 0x40 sets * 16 bytes per set */
- uint8_t cipher_suite_data[1024];
- uint16_t offset = 0;
- /* how much was returned, total */
- uint16_t cipher_suite_data_length = 0;
+ uint8_t cipher_suite_data[MAX_CIPHER_SUITE_RECORD_OFFSET *
+ MAX_CIPHER_SUITE_DATA_LEN];
+ size_t offset = 0;
+ size_t nr_suites = 0;
+
+ if (!suites || !count || !*count)
+ return -1;
+ nr_suites = *count;
+ *count = 0;
memset(cipher_suite_data, 0, sizeof(cipher_suite_data));
-
+
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = IPMI_GET_CHANNEL_CIPHER_SUITES;
req.msg.data = rqdata;
- req.msg.data_len = 3;
+ req.msg.data_len = sizeof(rqdata);
rqdata[0] = channel;
- rqdata[1] = ((strncmp(payload_type, "ipmi", 4) == 0)? 0: 1);
- /* Always ask for cipher suite format */
- rqdata[2] = 0x80;
-
- rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- lprintf(LOG_ERR, "Unable to Get Channel Cipher Suites");
- return -1;
- }
- if (rsp->ccode > 0) {
- lprintf(LOG_ERR, "Get Channel Cipher Suites failed: %s",
- val2str(rsp->ccode, completion_code_vals));
- return -1;
- }
-
-
- /*
- * Grab the returned channel number once. We assume it's the same
- * in future calls.
- */
- if (rsp->data_len >= 1) {
- channel = rsp->data[0];
- }
-
- while ((rsp->data_len > 1) && (rsp->data_len == 17) && (list_index < 0x3F)) {
- /*
- * We got back cipher suite data -- store it.
- * printf("copying data to offset %d\n", offset);
- * printbuf(rsp->data + 1, rsp->data_len - 1, "this is the data");
- */
- memcpy(cipher_suite_data + offset, rsp->data + 1, rsp->data_len - 1);
- offset += rsp->data_len - 1;
-
- /*
- * Increment our list for the next call
- */
- ++list_index;
- rqdata[2] = (rqdata[2] & 0x80) + list_index;
+ rqdata[1] = strcmp(payload_type, "ipmi") ? 1 : 0;
+ do {
+ /* Always ask for cipher suite format */
+ rqdata[2] = LIST_ALGORITHMS_BY_CIPHER_SUITE | list_index;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to Get Channel Cipher Suites");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode
+ || rsp->data_len < 1
+ || rsp->data_len > sizeof(uint8_t) + MAX_CIPHER_SUITE_DATA_LEN)
+ {
lprintf(LOG_ERR, "Get Channel Cipher Suites failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
}
- }
-
- /* Copy last chunk */
- if(rsp->data_len > 1) {
/*
* We got back cipher suite data -- store it.
* printf("copying data to offset %d\n", offset);
@@ -429,88 +513,49 @@ ipmi_get_channel_cipher_suites(struct ipmi_intf *intf, const char *payload_type,
*/
memcpy(cipher_suite_data + offset, rsp->data + 1, rsp->data_len - 1);
offset += rsp->data_len - 1;
- }
- /* We can chomp on all our data now. */
- cipher_suite_data_length = offset;
- offset = 0;
+ /*
+ * Increment our list for the next call
+ */
+ ++list_index;
+ } while ((rsp->data_len == (sizeof(uint8_t) + MAX_CIPHER_SUITE_DATA_LEN))
+ && (list_index < MAX_CIPHER_SUITE_RECORD_OFFSET));
- if (! csv_output) {
- printf("ID IANA Auth Alg Integrity Alg Confidentiality Alg\n");
- }
- while (offset < cipher_suite_data_length) {
- if (cipher_suite_data[offset++] == 0xC0) {
- /* standard type */
- iana = 0;
+ *count = parse_channel_cipher_suite_data(cipher_suite_data, offset, suites,
+ nr_suites);
+ return 0;
+}
- /* Verify that we have at least a full record left; id + 3 algs */
- if ((cipher_suite_data_length - offset) < 4) {
- lprintf(LOG_ERR, "Incomplete data record in cipher suite data");
- return -1;
- }
- cipher_suite_id = cipher_suite_data[offset++];
- } else if (cipher_suite_data[offset++] == 0xC1) {
- /* OEM record type */
- /* Verify that we have at least a full record left
- * id + iana + 3 algs
- */
- if ((cipher_suite_data_length - offset) < 4) {
- lprintf(LOG_ERR, "Incomplete data record in cipher suite data");
- return -1;
- }
+static int
+ipmi_print_channel_cipher_suites(struct ipmi_intf *intf,
+ const char *payload_type,
+ uint8_t channel)
+{
+ int rc;
+ size_t i = 0;
+ struct cipher_suite_info suites[MAX_CIPHER_SUITE_COUNT];
+ size_t nr_suites = sizeof(*suites);
+ const char *header_str =
+"ID IANA Auth Alg Integrity Alg Confidentiality Alg";
- cipher_suite_id = cipher_suite_data[offset++];
+ rc = ipmi_get_channel_cipher_suites(intf, payload_type, channel,
+ suites, &nr_suites);
- /* Grab the IANA */
- iana =
- cipher_suite_data[offset] |
- (cipher_suite_data[offset + 1] << 8) |
- (cipher_suite_data[offset + 2] << 16);
- offset += 3;
- } else {
- lprintf(LOG_ERR, "Bad start of record byte in cipher suite data");
- return -1;
- }
+ if (rc < 0)
+ return rc;
- /*
- * Grab the algorithms for this cipher suite. I guess we can't be
- * sure of what order they'll come in. Also, I suppose we default
- * to the NONE algorithm if one were absent. This part of the spec is
- * poorly written -- I have read the errata document. For now, I'm only
- * allowing one algorithm per type (auth, integrity, crypt) because I
- * don't I understand how it could be otherwise.
- */
- auth_alg = IPMI_AUTH_RAKP_NONE;
- integrity_alg = IPMI_INTEGRITY_NONE;
- crypt_alg = IPMI_CRYPT_NONE;
-
- while (((cipher_suite_data[offset] & 0xC0) != 0xC0) &&
- ((cipher_suite_data_length - offset) > 0))
- {
- switch (cipher_suite_data[offset] & 0xC0)
- {
- case 0x00:
- /* Authentication algorithm specifier */
- auth_alg = cipher_suite_data[offset++] & 0x3F;
- break;
- case 0x40:
- /* Interity algorithm specifier */
- integrity_alg = cipher_suite_data[offset++] & 0x3F;
- break;
- case 0x80:
- /* Confidentiality algorithm specifier */
- crypt_alg = cipher_suite_data[offset++] & 0x3F;
- break;
- }
- }
+ if (!csv_output) {
+ printf("%s\n", header_str);
+ }
+ for (i = 0; i < nr_suites; i++) {
/* We have everything we need to spit out a cipher suite record */
- printf((csv_output? "%d,%s,%s,%s,%s\n" :
- "%-4d %-7s %-15s %-15s %-15s\n"),
- cipher_suite_id,
- iana_string(iana),
- val2str(auth_alg, ipmi_auth_algorithms),
- val2str(integrity_alg, ipmi_integrity_algorithms),
- val2str(crypt_alg, ipmi_encryption_algorithms));
+ printf(csv_output ? "%d,%s,%s,%s,%s\n"
+ : "%-4d %-7s %-15s %-15s %-15s\n",
+ suites[i].cipher_suite_id,
+ iana_string(suites[i].iana),
+ val2str(suites[i].auth_alg, ipmi_auth_algorithms),
+ val2str(suites[i].integrity_alg, ipmi_integrity_algorithms),
+ val2str(suites[i].crypt_alg, ipmi_encryption_algorithms));
}
return 0;
}
@@ -648,8 +693,9 @@ ipmi_get_channel_info(struct ipmi_intf *intf, uint8_t channel)
*
* @channel - IPMI Channel
*
- * returns - IPMI Channel Medium, IPMI_CHANNEL_MEDIUM_RESERVED if ccode > 0,
- * 0 on error.
+ * @returns IPMI Channel Medium
+ * @retval IPMI_CHANNEL_MEDIUM_RESERVED if ccode was not IPMI_CC_OK
+ * @retval 0 on error
*/
uint8_t
ipmi_get_channel_medium(struct ipmi_intf *intf, uint8_t channel)
@@ -659,13 +705,16 @@ ipmi_get_channel_medium(struct ipmi_intf *intf, uint8_t channel)
channel_info.channel = channel;
ccode = _ipmi_get_channel_info(intf, &channel_info);
- if (ccode == 0xCC) {
- return IPMI_CHANNEL_MEDIUM_RESERVED;
- } else if (ccode < 0 && eval_ccode(ccode) != 0) {
- return 0;
- } else if (ccode > 0) {
- lprintf(LOG_ERR, "Get Channel Info command failed: %s",
- val2str(ccode, completion_code_vals));
+ if (ccode) {
+ if (ccode != IPMI_CC_INV_DATA_FIELD_IN_REQ) {
+ if (ccode > 0) {
+ lprintf(LOG_ERR, "Get Channel Info command failed: %s",
+ val2str(ccode, completion_code_vals));
+ }
+ else {
+ eval_ccode(ccode);
+ }
+ }
return IPMI_CHANNEL_MEDIUM_RESERVED;
}
lprintf(LOG_DEBUG, "Channel type: %s",
@@ -754,9 +803,27 @@ ipmi_set_user_access(struct ipmi_intf *intf, int argc, char **argv)
int ccode = 0;
int i = 0;
uint8_t channel = 0;
- uint8_t priv = 0;
uint8_t user_id = 0;
- if (argc > 0 && strncmp(argv[0], "help", 4) == 0) {
+ struct {
+ const char *option;
+ enum {
+ UA_INTEGER, /* direct integer value */
+ UA_BOOLEAN, /* off/disable = false, on/enable = true */
+ UA_BOOLEAN_INVERSE /* off/disable = true, on/enable = false */
+ } type;
+ uint8_t *val;
+ uint8_t min; /* minimum value for UA_INTEGER options */
+ uint8_t max; /* maximum value for UA_INTEGER options */
+ } options[] = {
+ { "callin=", UA_BOOLEAN_INVERSE, &user_access.callin_callback, 0, 0},
+ { "link=", UA_BOOLEAN, &user_access.link_auth, 0, 0},
+ { "ipmi=", UA_BOOLEAN, &user_access.ipmi_messaging, 0, 0},
+ { "privilege=", UA_INTEGER, &user_access.privilege_limit
+ , IPMI_SESSION_PRIV_CALLBACK
+ , IPMI_SESSION_PRIV_NOACCESS },
+ };
+
+ if (argc > 0 && !strcmp(argv[0], "help")) {
printf_channel_usage();
return 0;
} else if (argc < 3) {
@@ -778,33 +845,46 @@ ipmi_set_user_access(struct ipmi_intf *intf, int argc, char **argv)
return (-1);
}
for (i = 2; i < argc; i ++) {
- if (strncmp(argv[i], "callin=", 7) == 0) {
- if (strncmp(argv[i] + 7, "off", 3) == 0) {
- user_access.callin_callback = 1;
- } else {
- user_access.callin_callback = 0;
- }
- } else if (strncmp(argv[i], "link=", 5) == 0) {
- if (strncmp(argv[i] + 5, "off", 3) == 0) {
- user_access.link_auth = 0;
- } else {
- user_access.link_auth = 1;
- }
- } else if (strncmp(argv[i], "ipmi=", 5) == 0) {
- if (strncmp(argv[i] + 5, "off", 3) == 0) {
- user_access.ipmi_messaging = 0;
- } else {
- user_access.ipmi_messaging = 1;
- }
- } else if (strncmp(argv[i], "privilege=", 10) == 0) {
- if (str2uchar(argv[i] + 10, &priv) != 0) {
- lprintf(LOG_ERR,
- "Numeric value expected, but '%s' given.",
- argv[i] + 10);
- return (-1);
+ size_t j;
+ for (j = 0; j < ARRAY_SIZE(options); ++j) {
+ const char *opt = argv[i];
+ const int optlen = strlen(options[j].option);
+ if (!strncmp(opt, options[j].option, optlen)) {
+ const char *optval = opt + optlen;
+ uint16_t val;
+
+ if (UA_INTEGER != options[j].type) {
+ bool boolval = (UA_BOOLEAN_INVERSE == options[j].type)
+ ? false
+ : true;
+ *options[j].val = boolval;
+ if (!strcmp(optval, "off")
+ || !strcmp(optval, "disable")
+ || !strcmp(optval, "no"))
+ {
+ boolval = !boolval;
+ }
+ } else if (UINT8_MAX
+ != (val = str2val(optval, ipmi_privlvl_vals)))
+ {
+ *options[j].val = (uint8_t)val;
+ } else if (str2uchar(optval, options[j].val)) {
+ lprintf(LOG_ERR
+ , "Numeric [%hhu-%hhu] value expected, "
+ "but '%s' given."
+ , options[j].min
+ , options[j].max
+ , optval);
+ return (-1);
+ }
+ lprintf(LOG_DEBUG
+ , "Option %s=%hhu"
+ , options[j].option
+ , *options[j].val);
+ break;
}
- user_access.privilege_limit = priv;
- } else {
+ }
+ if (ARRAY_SIZE(options) == j) {
lprintf(LOG_ERR, "Invalid option: %s\n", argv[i]);
return (-1);
}
@@ -831,10 +911,10 @@ ipmi_channel_main(struct ipmi_intf *intf, int argc, char **argv)
lprintf(LOG_ERR, "Not enough parameters given.");
printf_channel_usage();
return (-1);
- } else if (strncmp(argv[0], "help", 4) == 0) {
+ } else if (!strcmp(argv[0], "help")) {
printf_channel_usage();
return 0;
- } else if (strncmp(argv[0], "authcap", 7) == 0) {
+ } else if (!strcmp(argv[0], "authcap")) {
if (argc != 3) {
printf_channel_usage();
return (-1);
@@ -844,7 +924,7 @@ ipmi_channel_main(struct ipmi_intf *intf, int argc, char **argv)
return (-1);
}
retval = ipmi_get_channel_auth_cap(intf, channel, priv);
- } else if (strncmp(argv[0], "getaccess", 10) == 0) {
+ } else if (!strcmp(argv[0], "getaccess")) {
uint8_t user_id = 0;
if ((argc < 2) || (argc > 3)) {
lprintf(LOG_ERR, "Not enough parameters given.");
@@ -860,9 +940,9 @@ ipmi_channel_main(struct ipmi_intf *intf, int argc, char **argv)
}
}
retval = ipmi_get_user_access(intf, channel, user_id);
- } else if (strncmp(argv[0], "setaccess", 9) == 0) {
+ } else if (!strcmp(argv[0], "setaccess")) {
return ipmi_set_user_access(intf, (argc - 1), &(argv[1]));
- } else if (strncmp(argv[0], "info", 4) == 0) {
+ } else if (!strcmp(argv[0], "info")) {
channel = 0xE;
if (argc > 2) {
printf_channel_usage();
@@ -874,11 +954,11 @@ ipmi_channel_main(struct ipmi_intf *intf, int argc, char **argv)
}
}
retval = ipmi_get_channel_info(intf, channel);
- } else if (strncmp(argv[0], "getciphers", 10) == 0) {
+ } else if (!strcmp(argv[0], "getciphers")) {
/* channel getciphers <ipmi|sol> [channel] */
channel = 0xE;
if ((argc < 2) || (argc > 3) ||
- (strncmp(argv[1], "ipmi", 4) && strncmp(argv[1], "sol", 3))) {
+ (strcmp(argv[1], "ipmi") && strcmp(argv[1], "sol"))) {
printf_channel_usage();
return (-1);
}
@@ -887,9 +967,9 @@ ipmi_channel_main(struct ipmi_intf *intf, int argc, char **argv)
return (-1);
}
}
- retval = ipmi_get_channel_cipher_suites(intf,
- argv[1], /* ipmi | sol */
- channel);
+ retval = ipmi_print_channel_cipher_suites(intf,
+ argv[1], /* ipmi | sol */
+ channel);
} else {
lprintf(LOG_ERR, "Invalid CHANNEL command: %s\n", argv[0]);
printf_channel_usage();
diff --git a/lib/ipmi_chassis.c b/lib/ipmi_chassis.c
index 7b5c2a8..7ac6770 100644
--- a/lib/ipmi_chassis.c
+++ b/lib/ipmi_chassis.c
@@ -29,13 +29,13 @@
* 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 _SVID_SOURCE || _BSD_SOURCE || _POSIX_C_SOURCE >= 1 || \
- _XOPEN_SOURCE || _POSIX_SOURCE
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
+#include <errno.h>
+#include <limits.h>
#include <ipmitool/bswap.h>
#include <ipmitool/helper.h>
@@ -44,9 +44,132 @@
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi_strings.h>
#include <ipmitool/ipmi_chassis.h>
+#include <ipmitool/ipmi_time.h>
+
+#define CHASSIS_BOOT_MBOX_IANA_SZ 3
+#define CHASSIS_BOOT_MBOX_BLOCK_SZ 16
+#define CHASSIS_BOOT_MBOX_BLOCK0_SZ \
+ (CHASSIS_BOOT_MBOX_BLOCK_SZ - CHASSIS_BOOT_MBOX_IANA_SZ)
+#define CHASSIS_BOOT_MBOX_MAX_BLOCK 0xFF
+#define CHASSIS_BOOT_MBOX_MAX_BLOCKS (CHASSIS_BOOT_MBOX_MAX_BLOCK + 1)
+
+/* Get/Set system boot option boot flags bit definitions */
+/* Boot flags byte 1 bits */
+#define BF1_VALID_SHIFT 7
+#define BF1_INVALID 0
+#define BF1_VALID (1 << BF1_VALID_SHIFT)
+#define BF1_VALID_MASK BF1_VALID
+
+#define BF1_PERSIST_SHIFT 6
+#define BF1_ONCE 0
+#define BF1_PERSIST (1 << BF1_PERSIST_SHIFT)
+#define BF1_PERSIST_MASK BF1_PERSIST
+
+#define BF1_BOOT_TYPE_SHIFT 5
+#define BF1_BOOT_TYPE_LEGACY 0
+#define BF1_BOOT_TYPE_EFI (1 << BF1_BOOT_TYPE_SHIFT)
+#define BF1_BOOT_TYPE_MASK BF1_BOOT_TYPE_EFI
+
+/* Boot flags byte 2 bits */
+#define BF2_CMOS_CLEAR_SHIFT 7
+#define BF2_CMOS_CLEAR (1 << BF2_CMOS_CLEAR_SHIFT)
+#define BF2_CMOS_CLEAR_MASK BF2_CMOS_CLEAR
+
+#define BF2_KEYLOCK_SHIFT 6
+#define BF2_KEYLOCK (1 << BF2_KEYLOCK_SHIFT)
+#define BF2_KEYLOCK_MASK BF2_KEYLOCK
+
+#define BF2_BOOTDEV_SHIFT 2
+#define BF2_BOOTDEV_DEFAULT (0 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_PXE (1 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_HDD (2 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_HDD_SAFE (3 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_DIAG_PART (4 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_CDROM (5 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_SETUP (6 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_REMOTE_FDD (7 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_REMOTE_CDROM (8 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_REMOTE_PRIMARY_MEDIA (9 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_REMOTE_HDD (11 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_FDD (15 << BF2_BOOTDEV_SHIFT)
+#define BF2_BOOTDEV_MASK (0xF << BF2_BOOTDEV_SHIFT)
+
+#define BF2_BLANK_SCREEN_SHIFT 1
+#define BF2_BLANK_SCREEN (1 << BF2_BLANK_SCREEN_SHIFT)
+#define BF2_BLANK_SCREEN_MASK BF2_BLANK_SCREEN
+
+#define BF2_RESET_LOCKOUT_SHIFT 0
+#define BF2_RESET_LOCKOUT (1 << BF2_RESET_LOCKOUT_SHIFT)
+#define BF2_RESET_LOCKOUT_MASK BF2_RESET_LOCKOUT
+
+/* Boot flags byte 3 bits */
+#define BF3_POWER_LOCKOUT_SHIFT 7
+#define BF3_POWER_LOCKOUT (1 << BF3_POWER_LOCKOUT_SHIFT)
+#define BF3_POWER_LOCKOUT_MASK BF3_POWER_LOCKOUT
+
+#define BF3_VERBOSITY_SHIFT 5
+#define BF3_VERBOSITY_DEFAULT (0 << BF3_VERBOSITY_SHIFT)
+#define BF3_VERBOSITY_QUIET (1 << BF3_VERBOSITY_SHIFT)
+#define BF3_VERBOSITY_VERBOSE (2 << BF3_VERBOSITY_SHIFT)
+#define BF3_VERBOSITY_MASK (3 << BF3_VERBOSITY_SHIFT)
+
+#define BF3_EVENT_TRAPS_SHIFT 4
+#define BF3_EVENT_TRAPS (1 << BF3_EVENT_TRAPS_SHIFT)
+#define BF3_EVENT_TRAPS_MASK BF3_EVENT_TRAPS
+
+#define BF3_PASSWD_BYPASS_SHIFT 3
+#define BF3_PASSWD_BYPASS (1 << BF3_PASSWD_BYPASS_SHIFT)
+#define BF3_PASSWD_BYPASS_MASK BF3_PASSWD_BYPASS
+
+#define BF3_SLEEP_LOCKOUT_SHIFT 2
+#define BF3_SLEEP_LOCKOUT (1 << BF3_SLEEP_LOCKOUT_SHIFT)
+#define BF3_SLEEP_LOCKOUT_MASK BF3_SLEEP_LOCKOUT
+
+#define BF3_CONSOLE_REDIR_SHIFT 0
+#define BF3_CONSOLE_REDIR_DEFAULT (0 << BF3_CONSOLE_REDIR_SHIFT)
+#define BF3_CONSOLE_REDIR_SUPPRESS (1 << BF3_CONSOLE_REDIR_SHIFT)
+#define BF3_CONSOLE_REDIR_ENABLE (2 << BF3_CONSOLE_REDIR_SHIFT)
+#define BF3_CONSOLE_REDIR_MASK (3 << BF3_CONSOLE_REDIR_SHIFT)
+
+/* Boot flags byte 4 bits */
+#define BF4_SHARED_MODE_SHIFT 3
+#define BF4_SHARED_MODE (1 << BF4_SHARED_MODE_SHIFT)
+#define BF4_SHARED_MODE_MASK BF4_SHARED_MODE
+
+#define BF4_BIOS_MUX_SHIFT 0
+#define BF4_BIOS_MUX_DEFAULT (0 << BF4_BIOS_MUX_SHIFT)
+#define BF4_BIOS_MUX_BMC (1 << BF4_BIOS_MUX_SHIFT)
+#define BF4_BIOS_MUX_SYSTEM (2 << BF4_BIOS_MUX_SHIFT)
+#define BF4_BIOS_MUX_MASK (7 << BF4_BIOS_MUX_SHIFT)
+
+
+typedef struct {
+ uint8_t iana[CHASSIS_BOOT_MBOX_IANA_SZ];
+ uint8_t data[CHASSIS_BOOT_MBOX_BLOCK0_SZ];
+} mbox_b0_data_t;
+
+typedef struct {
+ uint8_t block;
+ union {
+ uint8_t data[CHASSIS_BOOT_MBOX_BLOCK_SZ];
+ mbox_b0_data_t b0;
+ };
+} mbox_t;
extern int verbose;
+static const struct valstr get_bootparam_cc_vals[] = {
+ { 0x80, "Unsupported parameter" },
+ { 0x00, NULL }
+};
+
+static const struct valstr set_bootparam_cc_vals[] = {
+ { 0x80, "Unsupported parameter" },
+ { 0x81, "Attempt to set 'in progress' while not in 'complete' state" },
+ { 0x82, "Parameter is read-only" },
+ { 0x00, NULL }
+};
+
int
ipmi_chassis_power_status(struct ipmi_intf * intf)
{
@@ -59,11 +182,11 @@ ipmi_chassis_power_status(struct ipmi_intf * intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to get Chassis Power Status");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Chassis Power Status failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -98,12 +221,12 @@ ipmi_chassis_power_control(struct ipmi_intf * intf, uint8_t ctl)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to set Chassis Power Control to %s",
val2str(ctl, ipmi_chassis_power_control_vals));
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Set Chassis Power Control to %s failed: %s",
val2str(ctl, ipmi_chassis_power_control_vals),
val2str(rsp->ccode, completion_code_vals));
@@ -131,8 +254,8 @@ ipmi_chassis_identify(struct ipmi_intf * intf, char * arg)
req.msg.netfn = IPMI_NETFN_CHASSIS;
req.msg.cmd = 0x4;
- if (arg != NULL) {
- if (strncmp(arg, "force", 5) == 0) {
+ if (arg) {
+ if (!strcmp(arg, "force")) {
identify_data.force_on = 1;
} else {
if ( (rc = str2uchar(arg, &identify_data.interval)) != 0) {
@@ -154,11 +277,11 @@ ipmi_chassis_identify(struct ipmi_intf * intf, char * arg)
}
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to set Chassis Identify");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Set Chassis Identify failed: %s",
val2str(rsp->ccode, completion_code_vals));
if (identify_data.force_on != 0) {
@@ -172,7 +295,7 @@ ipmi_chassis_identify(struct ipmi_intf * intf, char * arg)
}
printf("Chassis identify interval: ");
- if (arg == NULL) {
+ if (!arg) {
printf("default (15 seconds)\n");
} else {
if (identify_data.force_on != 0) {
@@ -202,11 +325,11 @@ ipmi_chassis_poh(struct ipmi_intf * intf)
req.msg.cmd = 0xf;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to get Chassis Power-On-Hours");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Chassis Power-On-Hours failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -245,52 +368,18 @@ ipmi_chassis_restart_cause(struct ipmi_intf * intf)
req.msg.cmd = 0x7;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to get Chassis Restart Cause");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Chassis Restart Cause failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
}
- printf("System restart cause: ");
-
- switch (rsp->data[0] & 0xf) {
- case 0:
- printf("unknown\n");
- break;
- case 1:
- printf("chassis power control command\n");
- break;
- case 2:
- printf("reset via pushbutton\n");
- break;
- case 3:
- printf("power-up via pushbutton\n");
- break;
- case 4:
- printf("watchdog expired\n");
- break;
- case 5:
- printf("OEM\n");
- break;
- case 6:
- printf("power-up due to always-restore power policy\n");
- break;
- case 7:
- printf("power-up due to restore-previous power policy\n");
- break;
- case 8:
- printf("reset via PEF\n");
- break;
- case 9:
- printf("power-cycle via PEF\n");
- break;
- default:
- printf("invalid\n");
- }
+ printf("System restart cause: %s\n",
+ val2str(rsp->data[0] & 0xf, ipmi_chassis_restart_cause_vals));
return 0;
}
@@ -306,11 +395,11 @@ ipmi_chassis_status(struct ipmi_intf * intf)
req.msg.cmd = 0x1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error sending Chassis Status command");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error sending Chassis Status command: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -389,11 +478,11 @@ ipmi_chassis_selftest(struct ipmi_intf * intf)
req.msg.cmd = 0x4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error sending Get Self Test command");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error sending Get Self Test command: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -447,61 +536,166 @@ ipmi_chassis_selftest(struct ipmi_intf * intf)
}
static int
-ipmi_chassis_set_bootparam(struct ipmi_intf * intf, uint8_t param, uint8_t * data, int len)
+ipmi_chassis_set_bootparam(struct ipmi_intf * intf,
+ uint8_t param, void *data, int len)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
- uint8_t msg_data[16];
+ struct {
+ uint8_t param;
+ uint8_t data[];
+ } *msg_data;
+ int rc = -1;
+ size_t msgsize = 1 + len; /* Single-byte parameter plus the data */
+ static const uint8_t BOOTPARAM_MASK = 0x7F;
+
+ msg_data = malloc(msgsize);
+ if (!msg_data) {
+ goto out;
+ }
+ memset(msg_data, 0, msgsize);
- memset(msg_data, 0, 16);
- msg_data[0] = param & 0x7f;
- memcpy(msg_data+1, data, len);
+ msg_data->param = param & BOOTPARAM_MASK;
+ memcpy(msg_data->data, data, len);
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_CHASSIS;
req.msg.cmd = 0x8;
- req.msg.data = msg_data;
- req.msg.data_len = len + 1;
+ req.msg.data = (uint8_t *)msg_data;
+ req.msg.data_len = msgsize;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting Chassis Boot Parameter %d", param);
return -1;
}
- if (rsp->ccode > 0) {
+
+ rc = rsp->ccode;
+ if (rc) {
if (param != 0) {
- lprintf(LOG_ERR, "Set Chassis Boot Parameter %d failed: %s",
- param, val2str(rsp->ccode, completion_code_vals));
+ lprintf(LOG_ERR,
+ "Set Chassis Boot Parameter %d failed: %s",
+ param,
+ specific_val2str(rsp->ccode,
+ set_bootparam_cc_vals,
+ completion_code_vals));
}
- return -1;
+ goto out;
}
lprintf(LOG_DEBUG, "Chassis Set Boot Parameter %d to %s", param, buf2str(data, len));
- return 0;
+
+out:
+ free_n(&msg_data);
+ return rc;
+}
+
+/* Flags to ipmi_chassis_get_bootparam() */
+typedef enum {
+ PARAM_NO_GENERIC_INFO, /* Do not print generic boot parameter info */
+ PARAM_NO_DATA_DUMP, /* Do not dump parameter data */
+ PARAM_NO_RANGE_ERROR, /* Do not report out of range info to user */
+ PARAM_SPECIFIC /* Parameter-specific flags start with this */
+} chassis_bootparam_flags_t;
+
+/* Flags to ipmi_chassis_get_bootparam() for Boot Mailbox parameter (7) */
+typedef enum {
+ MBOX_PARSE_USE_TEXT = PARAM_SPECIFIC, /* Use text output vs. hex */
+ MBOX_PARSE_ALLBLOCKS /* Parse all blocks, not just one */
+} chassis_bootmbox_parse_t;
+
+#define BP_FLAG(x) (1 << (x))
+
+static
+void
+chassis_bootmailbox_parse(void *buf, size_t len, int flags)
+{
+ void *blockdata;
+ size_t datalen;
+ bool use_text = flags & BP_FLAG(MBOX_PARSE_USE_TEXT);
+ bool all_blocks = flags & BP_FLAG(MBOX_PARSE_ALLBLOCKS);
+
+ mbox_t *mbox;
+
+ if (!buf || !len) {
+ return;
+ }
+
+ mbox = buf;
+ blockdata = mbox->data;
+ datalen = len - sizeof(mbox->block);
+ if (!all_blocks) {
+ /* Print block selector only if a single block is printed */
+ printf(" Selector : %d\n", mbox->block);
+ }
+ if (!mbox->block) {
+ uint32_t iana = ipmi24toh(mbox->b0.iana);
+ /* For block zero print the IANA Private Enterprise Number */
+ printf(" IANA PEN : %" PRIu32 " [%s]\n",
+ iana,
+ val2str(iana, ipmi_oem_info));
+ blockdata = mbox->b0.data;
+ datalen -= sizeof(mbox->b0.iana);
+ }
+
+ printf(" Block ");
+ if (all_blocks) {
+ printf("%3" PRIu8 " Data : ", mbox->block);
+ }
+ else {
+ printf("Data : ");
+ }
+ if (use_text) {
+ /* Ensure the data string is null-terminated */
+ unsigned char text[CHASSIS_BOOT_MBOX_BLOCK_SZ + 1] = { 0 };
+ memcpy(text, blockdata, datalen);
+ printf("'%s'\n", text);
+ }
+ else {
+ printf("%s\n", buf2str(blockdata, datalen));
+ }
}
static int
-ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
+ipmi_chassis_get_bootparam(struct ipmi_intf * intf,
+ int argc, char *argv[], int flags)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[3];
uint8_t param_id = 0;
+ bool skip_generic = flags & BP_FLAG(PARAM_NO_GENERIC_INFO);
+ bool skip_data = flags & BP_FLAG(PARAM_NO_DATA_DUMP);
+ bool skip_range = flags & BP_FLAG(PARAM_NO_RANGE_ERROR);
+ int rc = -1;
- if (arg == NULL)
- return -1;
+ if (argc < 1 || !argv[0]) {
+ goto out;
+ }
- if (str2uchar(arg, &param_id) != 0) {
- lprintf(LOG_ERR, "Invalid parameter '%s' given instead of bootparam.",
- arg);
- return (-1);
+ if (str2uchar(argv[0], &param_id)) {
+ lprintf(LOG_ERR,
+ "Invalid parameter '%s' given instead of bootparam.",
+ argv[0]);
+ goto out;
}
+ --argc;
+ ++argv;
+
memset(msg_data, 0, 3);
msg_data[0] = param_id & 0x7f;
- msg_data[1] = 0;
- msg_data[2] = 0;
+
+ if (argc) {
+ if (str2uchar(argv[0], &msg_data[1])) {
+ lprintf(LOG_ERR,
+ "Invalid argument '%s' given to"
+ " bootparam %" PRIu8,
+ argv[0], msg_data[1]);
+ goto out;
+ }
+ }
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_CHASSIS;
@@ -510,13 +704,22 @@ ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- lprintf(LOG_ERR, "Error Getting Chassis Boot Parameter %s", arg);
+ if (!rsp) {
+ lprintf(LOG_ERR,
+ "Error Getting Chassis Boot Parameter %" PRIu8,
+ msg_data[0]);
return -1;
}
- if (rsp->ccode > 0) {
- lprintf(LOG_ERR, "Get Chassis Boot Parameter %s failed: %s",
- arg, val2str(rsp->ccode, completion_code_vals));
+ if (IPMI_CC_PARAM_OUT_OF_RANGE == rsp->ccode && skip_range) {
+ return -1;
+ }
+ if (rsp->ccode) {
+ lprintf(LOG_ERR,
+ "Get Chassis Boot Parameter %" PRIu8 " failed: %s",
+ msg_data[0],
+ specific_val2str(rsp->ccode,
+ get_bootparam_cc_vals,
+ completion_code_vals));
return -1;
}
@@ -526,10 +729,17 @@ ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
param_id = 0;
param_id = (rsp->data[1] & 0x7f);
- printf("Boot parameter version: %d\n", rsp->data[0]);
- printf("Boot parameter %d is %s\n", rsp->data[1] & 0x7f,
- (rsp->data[1] & 0x80) ? "invalid/locked" : "valid/unlocked");
- printf("Boot parameter data: %s\n", buf2str(rsp->data+2, rsp->data_len - 2));
+ if (!skip_generic) {
+ printf("Boot parameter version: %d\n", rsp->data[0]);
+ printf("Boot parameter %d is %s\n", rsp->data[1] & 0x7f,
+ (rsp->data[1] & 0x80)
+ ? "invalid/locked"
+ : "valid/unlocked");
+ if (!skip_data) {
+ printf("Boot parameter data: %s\n",
+ buf2str(rsp->data+2, rsp->data_len - 2));
+ }
+ }
switch(param_id)
{
@@ -622,132 +832,181 @@ ipmi_chassis_get_bootparam(struct ipmi_intf * intf, char * arg)
{
printf( " Boot Flags :\n");
- if((rsp->data[2]&0x80) == 0x80)
+ if(rsp->data[2] & BF1_VALID)
printf(" - Boot Flag Valid\n");
else
printf(" - Boot Flag Invalid\n");
- if((rsp->data[2]&0x40) == 0x40)
+ if(rsp->data[2] & BF1_PERSIST)
printf(" - Options apply to all future boots\n");
else
printf(" - Options apply to only next boot\n");
- if((rsp->data[2]&0x20) == 0x20)
+ if(rsp->data[2] & BF1_BOOT_TYPE_EFI)
printf(" - BIOS EFI boot \n");
else
printf(" - BIOS PC Compatible (legacy) boot \n");
- if((rsp->data[3]&0x80) == 0x80)
+ if(rsp->data[3] & BF2_CMOS_CLEAR)
printf(" - CMOS Clear\n");
- if((rsp->data[3]&0x40) == 0x40)
+ if(rsp->data[3] & BF2_KEYLOCK)
printf(" - Lock Keyboard\n");
printf(" - Boot Device Selector : ");
- switch( ((rsp->data[3]>>2)&0x0f))
+ switch(rsp->data[3] & BF2_BOOTDEV_MASK)
{
- case 0: printf("No override\n"); break;
- case 1: printf("Force PXE\n"); break;
- case 2: printf("Force Boot from default Hard-Drive\n"); break;
- case 3: printf("Force Boot from default Hard-Drive, request Safe-Mode\n"); break;
- case 4: printf("Force Boot from Diagnostic Partition\n"); break;
- case 5: printf("Force Boot from CD/DVD\n"); break;
- case 6: printf("Force Boot into BIOS Setup\n"); break;
- case 15: printf("Force Boot from Floppy/primary removable media\n"); break;
- default: printf("Flag error\n"); break;
+ case BF2_BOOTDEV_DEFAULT:
+ printf("No override\n");
+ break;
+ case BF2_BOOTDEV_PXE:
+ printf("Force PXE\n");
+ break;
+ case BF2_BOOTDEV_HDD:
+ printf("Force Boot from default Hard-Drive\n");
+ break;
+ case BF2_BOOTDEV_HDD_SAFE:
+ printf("Force Boot from default Hard-Drive, "
+ "request Safe-Mode\n");
+ break;
+ case BF2_BOOTDEV_DIAG_PART:
+ printf("Force Boot from Diagnostic Partition\n");
+ break;
+ case BF2_BOOTDEV_CDROM:
+ printf("Force Boot from CD/DVD\n");
+ break;
+ case BF2_BOOTDEV_SETUP:
+ printf("Force Boot into BIOS Setup\n");
+ break;
+ case BF2_BOOTDEV_REMOTE_FDD:
+ printf("Force Boot from remotely connected "
+ "Floppy/primary removable media\n");
+ break;
+ case BF2_BOOTDEV_REMOTE_CDROM:
+ printf("Force Boot from remotely connected "
+ "CD/DVD\n");
+ break;
+ case BF2_BOOTDEV_REMOTE_PRIMARY_MEDIA:
+ printf("Force Boot from primary remote media\n");
+ break;
+ case BF2_BOOTDEV_REMOTE_HDD:
+ printf("Force Boot from remotely connected "
+ "Hard-Drive\n");
+ break;
+ case BF2_BOOTDEV_FDD:
+ printf("Force Boot from Floppy/primary "
+ "removable media\n");
+ break;
+ default:
+ printf("Flag error\n");
+ break;
}
- if((rsp->data[3]&0x02) == 0x02)
+ if(rsp->data[3] & BF2_BLANK_SCREEN)
printf(" - Screen blank\n");
- if((rsp->data[3]&0x01) == 0x01)
+ if(rsp->data[3] & BF2_RESET_LOCKOUT)
printf(" - Lock out Reset buttons\n");
- if((rsp->data[4]&0x80) == 0x80)
- printf(" - Lock out (power off/sleep request) vi Power Button\n");
- printf(" - Console Redirection control : ");
- switch( ((rsp->data[4]>>5)&0x03))
+ if(rsp->data[4] & BF3_POWER_LOCKOUT)
+ printf(" - Lock out (power off/sleep "
+ "request) via Power Button\n");
+
+ printf(" - BIOS verbosity : ");
+ switch(rsp->data[4] & BF3_VERBOSITY_MASK)
{
- case 0: printf("System Default\n"); break;
- case 1: printf("Request Quiet Display\n"); break;
- case 2: printf("Request Verbose Display\n"); break;
- default: printf("Flag error\n"); break;
+ case BF3_VERBOSITY_DEFAULT:
+ printf("System Default\n");
+ break;
+ case BF3_VERBOSITY_QUIET:
+ printf("Request Quiet Display\n");
+ break;
+ case BF3_VERBOSITY_VERBOSE:
+ printf("Request Verbose Display\n");
+ break;
+ default:
+ printf("Flag error\n");
+ break;
}
- if((rsp->data[4]&0x10) == 0x10)
+ if(rsp->data[4] & BF3_EVENT_TRAPS)
printf(" - Force progress event traps\n");
- if((rsp->data[4]&0x08) == 0x08)
+ if(rsp->data[4] & BF3_PASSWD_BYPASS)
printf(" - User password bypass\n");
- if((rsp->data[4]&0x04) == 0x04)
+ if(rsp->data[4] & BF3_SLEEP_LOCKOUT)
printf(" - Lock Out Sleep Button\n");
- if((rsp->data[4]&0x02) == 0x02)
- printf(" - Lock Out Sleep Button\n");
- printf(" - BIOS verbosity : ");
- switch( ((rsp->data[4]>>0)&0x03))
+ printf(" - Console Redirection control : ");
+ switch(rsp->data[4] & BF3_CONSOLE_REDIR_MASK)
{
- case 0: printf("Console redirection occurs per BIOS configuration setting (default)\n"); break;
- case 1: printf("Suppress (skip) console redirection if enabled\n"); break;
- case 2: printf("Request console redirection be enabled\n"); break;
- default: printf("Flag error\n"); break;
+ case BF3_CONSOLE_REDIR_DEFAULT:
+ printf(
+ "Console redirection occurs per BIOS "
+ "configuration setting (default)\n");
+ break;
+ case BF3_CONSOLE_REDIR_SUPPRESS:
+ printf("Suppress (skip) console redirection "
+ "if enabled\n");
+ break;
+ case BF3_CONSOLE_REDIR_ENABLE:
+ printf("Request console redirection be "
+ "enabled\n");
+ break;
+ default:
+ printf("Flag error\n");
+ break;
}
- if((rsp->data[5]&0x08) == 0x08)
+ if(rsp->data[5] & BF4_SHARED_MODE)
printf(" - BIOS Shared Mode Override\n");
printf(" - BIOS Mux Control Override : ");
- switch( ((rsp->data[5]>>0)&0x07))
- {
- case 0: printf("BIOS uses recommended setting of the mux at the end of POST\n"); break;
- case 1: printf("Requests BIOS to force mux to BMC at conclusion of POST/start of OS boot\n"); break;
- case 2: printf("Requests BIOS to force mux to system at conclusion of POST/start of OS boot\n"); break;
- default: printf("Flag error\n"); break;
+ switch (rsp->data[5] & BF4_BIOS_MUX_MASK) {
+ case BF4_BIOS_MUX_DEFAULT:
+ printf("BIOS uses recommended setting of the "
+ "mux at the end of POST\n");
+ break;
+ case BF4_BIOS_MUX_BMC:
+ printf(
+ "Requests BIOS to force mux to BMC at "
+ "conclusion of POST/start of OS boot\n");
+ break;
+ case BF4_BIOS_MUX_SYSTEM:
+ printf(
+ "Requests BIOS to force mux to system "
+ "at conclusion of POST/start of "
+ "OS boot\n");
+ break;
+ default:
+ printf("Flag error\n");
+ break;
}
}
break;
case 6:
{
unsigned long session_id;
- unsigned long timestamp;
- char time_buf[40];
- time_t out_time;
+ uint32_t timestamp;
session_id = ((unsigned long) rsp->data[3]);
session_id |= (((unsigned long) rsp->data[4])<<8);
session_id |= (((unsigned long) rsp->data[5])<<16);
session_id |= (((unsigned long) rsp->data[6])<<24);
- timestamp = ((unsigned long) rsp->data[7]);
- timestamp |= (((unsigned long) rsp->data[8])<<8);
- timestamp |= (((unsigned long) rsp->data[9])<<16);
- timestamp |= (((unsigned long) rsp->data[10])<<24);
-
- memset(time_buf, 0, 40);
- strftime(
- time_buf,
- sizeof(time_buf),
- "%m/%d/%Y %H:%M:%S", localtime(&out_time)
- );
+ timestamp = ipmi32toh(&rsp->data[7]);
printf(" Boot Initiator Info :\n");
printf(" Channel Number : %d\n", (rsp->data[2] & 0x0f));
printf(" Session Id : %08lXh\n",session_id);
- if(timestamp != 0)
- {
- printf(" Timestamp : %08lXh, %s\n",timestamp,time_buf);
- }
- else
- {
- printf(" Timestamp : %08lXh, undefined\n",timestamp);
- }
-
+ printf(" Timestamp : %s\n", ipmi_timestamp_numeric(timestamp));
}
break;
case 7:
- {
- printf(" Selector : %d\n", rsp->data[2] );
- printf(" Block Data : %s\n", buf2str(rsp->data+3, rsp->data_len - 2));
- }
- break;
+ chassis_bootmailbox_parse(rsp->data + 2,
+ rsp->data_len - 2,
+ flags);
+ break;
default:
- printf(" Undefined byte\n");
+ printf(" Unsupported parameter %" PRIu8 "\n", param_id);
break;
}
- return 0;
+ rc = IPMI_CC_OK;
+out:
+ return rc;
}
static int
@@ -777,24 +1036,25 @@ get_bootparam_options(char *optstring,
{NULL} /* End marker */
}, *op;
+ const char *optkw = "options=";
- if (strncmp(optstring, "options=", 8) != 0) {
+ if (strncmp(optstring, optkw, strlen(optkw))) {
lprintf(LOG_ERR, "No options= keyword found \"%s\"", optstring);
return -1;
}
token = strtok_r(optstring + 8, ",", &saveptr);
- while (token != NULL) {
+ while (token) {
int setbit = 0;
- if (strcmp(token, "help") == 0) {
+ if (!strcmp(token, "help")) {
optionError = 1;
break;
}
- if (strncmp(token, "no-", 3) == 0) {
+ if (!strcmp(token, "no-")) {
setbit = 1;
token += 3;
}
- for (op = options; op->name != NULL; ++op) {
- if (strncmp(token, op->name, strlen(op->name)) == 0) {
+ for (op = options; op->name; ++op) {
+ if (!strcmp(token, op->name)) {
if (setbit) {
*set_flag |= op->value;
} else {
@@ -803,7 +1063,7 @@ get_bootparam_options(char *optstring,
break;
}
}
- if (op->name == NULL) {
+ if (!op->name) {
/* Option not found */
optionError = 1;
if (setbit) {
@@ -816,7 +1076,7 @@ get_bootparam_options(char *optstring,
if (optionError) {
lprintf(LOG_NOTICE, " Legal options are:");
lprintf(LOG_NOTICE, " %-8s: print this message", "help");
- for (op = options; op->name != NULL; ++op) {
+ for (op = options; op->name; ++op) {
lprintf(LOG_NOTICE, " %-8s: %s", op->name, op->desc);
}
lprintf(LOG_NOTICE, " Any Option may be prepended with no-"
@@ -846,14 +1106,17 @@ ipmi_chassis_get_bootvalid(struct ipmi_intf * intf)
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Error Getting Chassis Boot Parameter %d", param_id);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Chassis Boot Parameter %d failed: %s",
- param_id, val2str(rsp->ccode, completion_code_vals));
+ param_id,
+ specific_val2str(rsp->ccode,
+ get_bootparam_cc_vals,
+ completion_code_vals));
return -1;
}
@@ -863,77 +1126,97 @@ ipmi_chassis_get_bootvalid(struct ipmi_intf * intf)
return(rsp->data[2]);
}
+typedef enum {
+ SET_COMPLETE,
+ SET_IN_PROGRESS,
+ COMMIT_WRITE,
+ RESERVED
+} progress_t;
+
+
+static
+void
+chassis_bootparam_set_in_progress(struct ipmi_intf *intf, progress_t progress)
+{
+ /*
+ * By default try to set/clear set-in-progress parameter before/after
+ * changing any boot parameters. If setting fails, the code will set
+ * this flag to false and stop trying to fiddle with it for future
+ * requests.
+ */
+ static bool use_progress = true;
+ uint8_t flag = progress;
+ int rc;
+
+ if (!use_progress) {
+ return;
+ }
+
+ rc = ipmi_chassis_set_bootparam(intf,
+ IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
+ &flag, 1);
+
+ /*
+ * Only disable future checks if set in progress status setting failed.
+ * Setting of other statuses may fail legitimately.
+ */
+ if (rc && SET_IN_PROGRESS == progress) {
+ use_progress = false;
+ }
+}
+
+typedef enum {
+ BIOS_POST_ACK = 1 << 0,
+ OS_LOADER_ACK = 1 << 1,
+ OS_SERVICE_PARTITION_ACK = 1 << 2,
+ SMS_ACK = 1 << 3,
+ OEM_ACK = 1 << 4,
+ RESERVED_ACK_MASK = 7 << 5
+} bootinfo_ack_t;
+
+static
+int
+chassis_bootparam_clear_ack(struct ipmi_intf *intf, bootinfo_ack_t flag)
+{
+ uint8_t flags[2] = { flag & ~RESERVED_ACK_MASK,
+ flag & ~RESERVED_ACK_MASK };
+
+ return ipmi_chassis_set_bootparam(intf,
+ IPMI_CHASSIS_BOOTPARAM_INFO_ACK,
+ flags, 2);
+}
+
static int
ipmi_chassis_set_bootvalid(struct ipmi_intf *intf, uint8_t set_flag, uint8_t clr_flag)
{
int bootvalid;
- uint8_t flags[5];
- int rc = 0;
- int use_progress = 1;
- uint8_t param_id = IPMI_CHASSIS_BOOTPARAM_FLAG_VALID;
+ uint8_t flags[2];
+ int rc;
- if (use_progress) {
- /* set set-in-progress flag */
- memset(flags, 0, 5);
- flags[0] = 0x01;
- rc = ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS, flags, 1);
- if (rc < 0)
- use_progress = 0;
- }
-
- memset(flags, 0, 5);
- flags[0] = 0x01;
- flags[1] = 0x01;
- rc = ipmi_chassis_set_bootparam(intf, IPMI_CHASSIS_BOOTPARAM_INFO_ACK,
- flags, 2);
+ chassis_bootparam_set_in_progress(intf, SET_IN_PROGRESS);
+ rc = chassis_bootparam_clear_ack(intf, BIOS_POST_ACK);
- if (rc < 0) {
- if (use_progress) {
- /* set-in-progress = set-complete */
- memset(flags, 0, 5);
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
- }
- return -1;
+ if (rc) {
+ goto out;
}
bootvalid = ipmi_chassis_get_bootvalid(intf);
-
if (bootvalid < 0) {
- if (use_progress) {
- /* set-in-progress = set-complete */
- memset(flags, 0, 5);
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
- }
- return -1;
- }
- flags[0] = (bootvalid & ~clr_flag) | set_flag;
-
- rc = ipmi_chassis_set_bootparam(intf, param_id, flags, 1);
-
- if (rc == 0) {
- if (use_progress) {
- /* set-in-progress = commit-write */
- memset(flags, 0, 5);
- flags[0] = 0x02;
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
- }
+ lprintf(LOG_ERR, "Failed to read boot valid flag");
+ rc = bootvalid;
+ goto out;
}
- if (use_progress) {
- /* set-in-progress = set-complete */
- memset(flags, 0, 5);
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
+ flags[0] = (bootvalid & ~clr_flag) | set_flag;
+ rc = ipmi_chassis_set_bootparam(intf,
+ IPMI_CHASSIS_BOOTPARAM_FLAG_VALID,
+ flags, 1);
+ if (IPMI_CC_OK == rc) {
+ chassis_bootparam_set_in_progress(intf, COMMIT_WRITE);
}
+out:
+ chassis_bootparam_set_in_progress(intf, SET_COMPLETE);
return rc;
}
@@ -941,107 +1224,372 @@ static int
ipmi_chassis_set_bootdev(struct ipmi_intf * intf, char * arg, uint8_t *iflags)
{
uint8_t flags[5];
- int rc = 0;
- int use_progress = 1;
+ int rc;
- if (use_progress) {
- /* set set-in-progress flag */
- memset(flags, 0, 5);
- flags[0] = 0x01;
- rc = ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS, flags, 1);
- if (rc < 0)
- use_progress = 0;
- }
-
- memset(flags, 0, 5);
- flags[0] = 0x01;
- flags[1] = 0x01;
- rc = ipmi_chassis_set_bootparam(intf, IPMI_CHASSIS_BOOTPARAM_INFO_ACK,
- flags, 2);
+ chassis_bootparam_set_in_progress(intf, SET_IN_PROGRESS);
+ rc = chassis_bootparam_clear_ack(intf, BIOS_POST_ACK);
if (rc < 0) {
- if (use_progress) {
- /* set-in-progress = set-complete */
- memset(flags, 0, 5);
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
- }
- return -1;
+ goto out;
}
- if (iflags == NULL)
- memset(flags, 0, 5);
+ if (!iflags)
+ memset(flags, 0, sizeof(flags));
else
memcpy(flags, iflags, sizeof (flags));
- if (arg == NULL)
+ if (!arg)
flags[1] |= 0x00;
- else if (strncmp(arg, "none", 4) == 0)
+ else if (!strcmp(arg, "none"))
flags[1] |= 0x00;
- else if (strncmp(arg, "pxe", 3) == 0 ||
- strncmp(arg, "force_pxe", 9) == 0)
+ else if (!strcmp(arg, "pxe") ||
+ !strcmp(arg, "force_pxe"))
+ {
flags[1] |= 0x04;
- else if (strncmp(arg, "disk", 4) == 0 ||
- strncmp(arg, "force_disk", 10) == 0)
+ }
+ else if (!strcmp(arg, "disk") ||
+ !strcmp(arg, "force_disk"))
+ {
flags[1] |= 0x08;
- else if (strncmp(arg, "safe", 4) == 0 ||
- strncmp(arg, "force_safe", 10) == 0)
+ }
+ else if (!strcmp(arg, "safe") ||
+ !strcmp(arg, "force_safe"))
+ {
flags[1] |= 0x0c;
- else if (strncmp(arg, "diag", 4) == 0 ||
- strncmp(arg, "force_diag", 10) == 0)
+ }
+ else if (!strcmp(arg, "diag") ||
+ !strcmp(arg, "force_diag"))
+ {
flags[1] |= 0x10;
- else if (strncmp(arg, "cdrom", 5) == 0 ||
- strncmp(arg, "force_cdrom", 11) == 0)
+ }
+ else if (!strcmp(arg, "cdrom") ||
+ !strcmp(arg, "force_cdrom"))
+ {
flags[1] |= 0x14;
- else if (strncmp(arg, "floppy", 6) == 0 ||
- strncmp(arg, "force_floppy", 12) == 0)
+ }
+ else if (!strcmp(arg, "floppy") ||
+ !strcmp(arg, "force_floppy"))
+ {
flags[1] |= 0x3c;
- else if (strncmp(arg, "bios", 4) == 0 ||
- strncmp(arg, "force_bios", 10) == 0)
+ }
+ else if (!strcmp(arg, "bios") ||
+ !strcmp(arg, "force_bios"))
+ {
flags[1] |= 0x18;
+ }
else {
lprintf(LOG_ERR, "Invalid argument: %s", arg);
- if (use_progress) {
- /* set-in-progress = set-complete */
- memset(flags, 0, 5);
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
- }
- return -1;
+ rc = -1;
+ goto out;
}
/* set flag valid bit */
flags[0] |= 0x80;
- rc = ipmi_chassis_set_bootparam(intf, IPMI_CHASSIS_BOOTPARAM_BOOT_FLAGS,
- flags, 5);
- if (rc == 0) {
- if (use_progress) {
- /* set-in-progress = commit-write */
- memset(flags, 0, 5);
- flags[0] = 0x02;
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
+ rc = ipmi_chassis_set_bootparam(intf,
+ IPMI_CHASSIS_BOOTPARAM_BOOT_FLAGS,
+ flags, 5);
+ if (IPMI_CC_OK == rc) {
+ chassis_bootparam_set_in_progress(intf, COMMIT_WRITE);
+ printf("Set Boot Device to %s\n", arg);
+ }
+
+out:
+ chassis_bootparam_set_in_progress(intf, SET_COMPLETE);
+ return rc;
+}
+
+static void chassis_bootmailbox_help()
+{
+ lprintf(LOG_NOTICE,
+"bootmbox get [text] [block <block>]\n"
+" Read the entire Boot Initiator Mailbox or the specified <block>.\n"
+" If 'text' option is specified, the data is output as plain text, otherwise\n"
+" hex dump mode is used.\n"
+"\n"
+"bootmbox set text [block <block>] <IANA_PEN> \"<data_string>\"\n"
+"bootmbox set [block <block>] <IANA_PEN> <data_byte> [<data_byte> ...]\n"
+" Write the specified <block> or the entire Boot Initiator Mailbox.\n"
+" It is required to specify a decimal IANA Enterprise Number recognized\n"
+" by the boot initiator on the target system. Refer to your target system\n"
+" manufacturer for details. The rest of the arguments are either separate\n"
+" data byte values separated by spaces, or a single text string argument.\n"
+"\n"
+" When single block write is requested, the total length of <data> may not\n"
+" exceed 13 bytes for block 0, or 16 bytes otherwise.\n"
+"\n"
+"bootmbox help\n"
+" Show this help.");
+}
+
+static
+int
+chassis_set_bootmailbox(struct ipmi_intf *intf, int16_t block, bool use_text,
+ int argc, char *argv[])
+{
+ int rc = -1;
+ int32_t iana = 0;
+ size_t blocks = 0;
+ size_t datasize = 0;
+ off_t string_offset = 0;
+
+ lprintf(LOG_INFO, "Writing Boot Mailbox...");
+
+ if (argc < 1 || str2int(argv[0], &iana)) {
+ lprintf(LOG_ERR,
+ "No valid IANA PEN specified!\n");
+ chassis_bootmailbox_help();
+ goto out;
+ }
+ ++argv;
+ --argc;
+
+ if (argc < 1) {
+ lprintf(LOG_ERR,
+ "No data provided!\n");
+ chassis_bootmailbox_help();
+ goto out;
+ }
+
+ /*
+ * Initialize the data size. For text mode it is just the
+ * single argument string length plus one byte for \0 termination.
+ * For byte mode the length is the number of byte arguments without
+ * any additional termination.
+ */
+ if (!use_text) {
+ datasize = argc;
+ }
+ else {
+ datasize = strlen(argv[0]) + 1; /* Include the terminator */
+ }
+
+ lprintf(LOG_INFO, "Data size: %u", datasize);
+
+ /* Decide how many blocks we will be writing */
+ if (block >= 0) {
+ blocks = 1;
+ }
+ else {
+ /*
+ * We need to write all data, so calculate the data
+ * size in blocks and set the starting block to zero.
+ */
+ blocks = CHASSIS_BOOT_MBOX_IANA_SZ;
+ blocks += datasize;
+ blocks += CHASSIS_BOOT_MBOX_BLOCK_SZ - 1;
+ blocks /= CHASSIS_BOOT_MBOX_BLOCK_SZ;
+
+ block = 0;
+ }
+
+ lprintf(LOG_INFO, "Blocks to write: %d", blocks);
+
+ if (blocks > CHASSIS_BOOT_MBOX_MAX_BLOCKS) {
+ lprintf(LOG_ERR,
+ "Data size %zu exceeds maximum (%d)",
+ datasize,
+ (CHASSIS_BOOT_MBOX_BLOCK_SZ
+ * CHASSIS_BOOT_MBOX_MAX_BLOCKS)
+ - CHASSIS_BOOT_MBOX_IANA_SZ);
+ goto out;
+ }
+
+ /* Indicate that we're touching the boot parameters */
+ chassis_bootparam_set_in_progress(intf, SET_IN_PROGRESS);
+
+ for (size_t bindex = 0;
+ datasize > 0 && bindex < blocks;
+ ++bindex, ++block)
+ {
+ /* The request data structure */
+ mbox_t mbox = { .block = block, {{0}} };
+
+ /* Destination for input data */
+ uint8_t *data = mbox.data;
+
+ /* The maximum amount of data this block may hold */
+ size_t maxblocksize = sizeof(mbox.data);
+
+ /* The actual amount of data in this block */
+ size_t blocksize;
+ off_t unused = 0;
+
+ /* Block 0 needs special care as it has IANA PEN specifier */
+ if (!block) {
+ data = mbox.b0.data;
+ maxblocksize = sizeof(mbox.b0.data);
+ htoipmi24(iana, mbox.b0.iana);
}
- printf("Set Boot Device to %s\n", arg);
+ /*
+ * Find out how many bytes we are going to write to this
+ * block.
+ */
+ if (datasize > maxblocksize) {
+ blocksize = maxblocksize;
+ }
+ else {
+ blocksize = datasize;
+ }
+
+ /* Remember how much data remains */
+ datasize -= blocksize;
+
+ if (!use_text) {
+ args2buf(argc, argv, data, blocksize);
+ argc -= blocksize;
+ argv += blocksize;
+ }
+ else {
+ memcpy(data, argv[0] + string_offset, blocksize);
+ string_offset += blocksize;
+ }
+
+ lprintf(LOG_INFO, "Block %3" PRId16 ": %s", block,
+ buf2str_extended(data, blocksize, " "));
+
+ unused = maxblocksize - blocksize;
+ rc = ipmi_chassis_set_bootparam(intf,
+ IPMI_CHASSIS_BOOTPARAM_INIT_MBOX,
+ &mbox,
+ sizeof(mbox) - unused);
+ if (IPMI_CC_PARAM_OUT_OF_RANGE == rc) {
+ lprintf(LOG_ERR,
+ "Hit end of mailbox writing block %" PRId16,
+ block);
+ }
+ if (rc) {
+ goto complete;
+ }
}
- if (use_progress) {
- /* set-in-progress = set-complete */
- memset(flags, 0, 5);
- ipmi_chassis_set_bootparam(intf,
- IPMI_CHASSIS_BOOTPARAM_SET_IN_PROGRESS,
- flags, 1);
+ lprintf(LOG_INFO,
+ "Wrote %zu blocks of Boot Initiator Mailbox",
+ blocks);
+ chassis_bootparam_set_in_progress(intf, COMMIT_WRITE);
+
+ rc = chassis_bootparam_clear_ack(intf, BIOS_POST_ACK | OS_LOADER_ACK);
+
+complete:
+ chassis_bootparam_set_in_progress(intf, SET_COMPLETE);
+out:
+ return rc;
+}
+
+static
+int
+chassis_get_bootmailbox(struct ipmi_intf *intf,
+ int16_t block, bool use_text)
+{
+ int rc = IPMI_CC_UNSPECIFIED_ERROR;
+ char param_str[2]; /* Max "7" */
+ char block_str[4]; /* Max "255" */
+ char *bpargv[] = { param_str, block_str };
+ int flags;
+
+ flags = use_text ? BP_FLAG(MBOX_PARSE_USE_TEXT) : 0;
+
+ snprintf(param_str, sizeof(param_str),
+ "%" PRIu8, IPMI_CHASSIS_BOOTPARAM_INIT_MBOX);
+
+ if (block >= 0) {
+ snprintf(block_str, sizeof(block_str),
+ "%" PRIu8, (uint8_t)block);
+
+ rc = ipmi_chassis_get_bootparam(intf,
+ ARRAY_SIZE(bpargv),
+ bpargv,
+ flags);
+ }
+ else {
+ int currblk;
+
+ flags |= BP_FLAG(MBOX_PARSE_ALLBLOCKS);
+ for (currblk = 0; currblk <= UCHAR_MAX; ++currblk) {
+ snprintf(block_str, sizeof(block_str),
+ "%" PRIu8, (uint8_t)currblk);
+
+ if (currblk) {
+ /*
+ * If block 0 succeeded, we don't want to
+ * print generic info for each next block,
+ * and we don't want range error to be
+ * reported when we hit the end of blocks.
+ */
+ flags |= BP_FLAG(PARAM_NO_GENERIC_INFO);
+ flags |= BP_FLAG(PARAM_NO_RANGE_ERROR);
+ }
+
+ rc = ipmi_chassis_get_bootparam(intf,
+ ARRAY_SIZE(bpargv),
+ bpargv,
+ flags);
+
+ if (rc) {
+ if (currblk) {
+ rc = IPMI_CC_OK;
+ }
+ break;
+ }
+ }
}
return rc;
}
+static
+int
+chassis_bootmailbox(struct ipmi_intf *intf, int argc, char *argv[])
+{
+ int rc = IPMI_CC_UNSPECIFIED_ERROR;
+ bool use_text = false; /* Default to data dump I/O mode */
+ int16_t block = -1; /* By default print all blocks */
+ const char *cmd;
+
+ if ((argc < 1) || !strcmp(argv[0], "help")) {
+ chassis_bootmailbox_help();
+ goto out;
+ } else {
+ cmd = argv[0];
+ ++argv;
+ --argc;
+
+ if (argc > 0 && !strcmp(argv[0], "text")) {
+ use_text = true;
+ ++argv;
+ --argc;
+ }
+
+ if (argc > 0 && !strcmp(argv[0], "block")) {
+ if (argc < 2) {
+ chassis_bootmailbox_help();
+ goto out;
+ }
+ if(str2short(argv[1], &block)) {
+ lprintf(LOG_ERR,
+ "Invalid block %s", argv[1]);
+ goto out;
+ }
+ argv += 2;
+ argc -= 2;
+
+ }
+
+ if (!strcmp(cmd, "get")) {
+ rc = chassis_get_bootmailbox(intf, block, use_text);
+ }
+ else if (!strcmp(cmd, "set")) {
+ rc = chassis_set_bootmailbox(intf, block, use_text,
+ argc, argv);
+ }
+ }
+
+out:
+ return rc;
+}
+
+
static int
ipmi_chassis_power_policy(struct ipmi_intf * intf, uint8_t policy)
{
@@ -1055,11 +1603,11 @@ ipmi_chassis_power_policy(struct ipmi_intf * intf, uint8_t policy)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in Power Restore Policy command");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Power Restore Policy command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -1100,25 +1648,25 @@ ipmi_power_main(struct ipmi_intf * intf, int argc, char ** argv)
int rc = 0;
uint8_t ctl = 0;
- if ((argc < 1) || (strncmp(argv[0], "help", 4) == 0)) {
+ if (argc < 1 || !strcmp(argv[0], "help")) {
lprintf(LOG_NOTICE, "chassis power Commands: status, on, off, cycle, reset, diag, soft");
return 0;
}
- if (strncmp(argv[0], "status", 6) == 0) {
+ if (!strcmp(argv[0], "status")) {
rc = ipmi_chassis_print_power_status(intf);
return rc;
}
- if ((strncmp(argv[0], "up", 2) == 0) || (strncmp(argv[0], "on", 2) == 0))
+ if (!strcmp(argv[0], "up") || !strcmp(argv[0], "on"))
ctl = IPMI_CHASSIS_CTL_POWER_UP;
- else if ((strncmp(argv[0], "down", 4) == 0) || (strncmp(argv[0], "off", 3) == 0))
+ else if (!strcmp(argv[0], "down") || !strcmp(argv[0], "off"))
ctl = IPMI_CHASSIS_CTL_POWER_DOWN;
- else if (strncmp(argv[0], "cycle", 5) == 0)
+ else if (!strcmp(argv[0], "cycle"))
ctl = IPMI_CHASSIS_CTL_POWER_CYCLE;
- else if (strncmp(argv[0], "reset", 5) == 0)
+ else if (!strcmp(argv[0], "reset"))
ctl = IPMI_CHASSIS_CTL_HARD_RESET;
- else if (strncmp(argv[0], "diag", 4) == 0)
+ else if (!strcmp(argv[0], "diag"))
ctl = IPMI_CHASSIS_CTL_PULSE_DIAG;
- else if ((strncmp(argv[0], "acpi", 4) == 0) || (strncmp(argv[0], "soft", 4) == 0))
+ else if (!strcmp(argv[0], "acpi") || !strcmp(argv[0], "soft"))
ctl = IPMI_CHASSIS_CTL_ACPI_SOFT;
else {
lprintf(LOG_ERR, "Invalid chassis power command: %s", argv[0]);
@@ -1146,55 +1694,270 @@ ipmi_chassis_set_bootflag_help()
get_bootparam_options("options=help", &set_flag, &clr_flag);
}
+/*
+ * Sugar. Macros for internal use by bootdev_parse_options() to make
+ * the structure initialization look better. Can't use scope-limited
+ * static consts for initializers with gcc5, alas.
+ */
+#define BF1_OFFSET 0
+#define BF2_OFFSET 1
+#define BF3_OFFSET 2
+#define BF4_OFFSET 3
+#define BF_BYTE_COUNT 5
+
+/* A helper for ipmi_chassis_main() to parse bootdev options */
+static
+bool
+bootdev_parse_options(char *optstring, uint8_t flags[])
+{
+ char *token;
+ char *saveptr = NULL;
+ int optionError = 0;
+
+ static const struct bootdev_opt_s {
+ char *name;
+ off_t offset;
+ unsigned char mask;
+ unsigned char value;
+ char *desc;
+ } *op;
+ static const struct bootdev_opt_s options[] = {
+ /* data 1 */
+ {
+ "valid",
+ BF1_OFFSET,
+ BF1_VALID_MASK,
+ BF1_VALID,
+ "Boot flags valid"
+ },
+ {
+ "persistent",
+ BF1_OFFSET,
+ BF1_PERSIST_MASK,
+ BF1_PERSIST,
+ "Changes are persistent for "
+ "all future boots"
+ },
+ {
+ "efiboot",
+ BF1_OFFSET,
+ BF1_BOOT_TYPE_MASK,
+ BF1_BOOT_TYPE_EFI,
+ "Extensible Firmware Interface "
+ "Boot (EFI)"
+ },
+ /* data 2 */
+ {
+ "clear-cmos",
+ BF2_OFFSET,
+ BF2_CMOS_CLEAR_MASK,
+ BF2_CMOS_CLEAR,
+ "CMOS clear"
+ },
+ {
+ "lockkbd",
+ BF2_OFFSET,
+ BF2_KEYLOCK_MASK,
+ BF2_KEYLOCK,
+ "Lock Keyboard"
+ },
+ /* data2[5:2] is parsed elsewhere */
+ {
+ "screenblank",
+ BF2_OFFSET,
+ BF2_BLANK_SCREEN_MASK,
+ BF2_BLANK_SCREEN,
+ "Screen Blank"
+ },
+ {
+ "lockoutreset",
+ BF2_OFFSET,
+ BF2_RESET_LOCKOUT_MASK,
+ BF2_RESET_LOCKOUT,
+ "Lock out Reset buttons"
+ },
+ /* data 3 */
+ {
+ "lockout_power",
+ BF3_OFFSET,
+ BF3_POWER_LOCKOUT_MASK,
+ BF3_POWER_LOCKOUT,
+ "Lock out (power off/sleep "
+ "request) via Power Button"
+ },
+ {
+ "verbose=default",
+ BF3_OFFSET,
+ BF3_VERBOSITY_MASK,
+ BF3_VERBOSITY_DEFAULT,
+ "Request quiet BIOS display"
+ },
+ {
+ "verbose=no",
+ BF3_OFFSET,
+ BF3_VERBOSITY_MASK,
+ BF3_VERBOSITY_QUIET,
+ "Request quiet BIOS display"
+ },
+ {
+ "verbose=yes",
+ BF3_OFFSET,
+ BF3_VERBOSITY_MASK,
+ BF3_VERBOSITY_VERBOSE,
+ "Request verbose BIOS display"
+ },
+ {
+ "force_pet",
+ BF3_OFFSET,
+ BF3_EVENT_TRAPS_MASK,
+ BF3_EVENT_TRAPS,
+ "Force progress event traps"
+ },
+ {
+ "upw_bypass",
+ BF3_OFFSET,
+ BF3_PASSWD_BYPASS_MASK,
+ BF3_PASSWD_BYPASS,
+ "User password bypass"
+ },
+ {
+ "lockout_sleep",
+ BF3_OFFSET,
+ BF3_SLEEP_LOCKOUT_MASK,
+ BF3_SLEEP_LOCKOUT,
+ "Lock out the Sleep button"
+ },
+ {
+ "cons_redirect=default",
+ BF3_OFFSET,
+ BF3_CONSOLE_REDIR_MASK,
+ BF3_CONSOLE_REDIR_DEFAULT,
+ "Console redirection occurs per "
+ "BIOS configuration setting"
+ },
+ {
+ "cons_redirect=skip",
+ BF3_OFFSET,
+ BF3_CONSOLE_REDIR_MASK,
+ BF3_CONSOLE_REDIR_SUPPRESS,
+ "Suppress (skip) console "
+ "redirection if enabled"
+ },
+ {
+ "cons_redirect=enable",
+ BF3_OFFSET,
+ BF3_CONSOLE_REDIR_MASK,
+ BF3_CONSOLE_REDIR_ENABLE,
+ "Request console redirection "
+ "be enabled"
+ },
+ /* data 4 */
+ /* data4[7:4] reserved */
+ /* data4[3] BIOS Shared Mode Override, not implemented here */
+ /* data4[2:0] BIOS Mux Control Override, not implemented here */
+
+ /* data5 reserved */
+
+ {NULL} /* End marker */
+ };
+
+ memset(&flags[0], 0, BF_BYTE_COUNT);
+ token = strtok_r(optstring, ",", &saveptr);
+ while (token) {
+ if (!strcmp(token, "help")) {
+ optionError = 1;
+ break;
+ }
+ for (op = options; op->name; ++op) {
+ if (!strcmp(token, op->name)) {
+ flags[op->offset] &= ~(op->mask);
+ flags[op->offset] |= op->value;
+ break;
+ }
+ }
+ if (!op->name) {
+ /* Option not found */
+ optionError = 1;
+ lprintf(LOG_ERR, "Invalid option: %s", token);
+ }
+ token = strtok_r(NULL, ",", &saveptr);
+ }
+ if (optionError) {
+ lprintf(LOG_NOTICE, "Legal options settings are:");
+ lprintf(LOG_NOTICE, " %-22s: %s",
+ "help",
+ "print this message");
+ for (op = options; op->name; ++op) {
+ lprintf(LOG_NOTICE, " %-22s: %s", op->name, op->desc);
+ }
+ return false;
+ }
+
+ return true;
+}
+
int
ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
{
- int rc = 0;
+ int rc = -1;
- if ((argc == 0) || (strncmp(argv[0], "help", 4) == 0)) {
- lprintf(LOG_NOTICE, "Chassis Commands: status, power, identify, policy, restart_cause, poh, bootdev, bootparam, selftest");
+ if (!argc || !strcmp(argv[0], "help")) {
+ lprintf(LOG_NOTICE, "Chassis Commands:\n"
+ " status, power, policy, restart_cause\n"
+ " poh, identify, selftest,\n"
+ " bootdev, bootparam, bootmbox");
}
- else if (strncmp(argv[0], "status", 6) == 0) {
+ else if (!strcmp(argv[0], "status")) {
rc = ipmi_chassis_status(intf);
}
- else if (strncmp(argv[0], "selftest", 8) == 0) {
+ else if (!strcmp(argv[0], "selftest")) {
rc = ipmi_chassis_selftest(intf);
}
- else if (strncmp(argv[0], "power", 5) == 0) {
+ else if (!strcmp(argv[0], "power")) {
uint8_t ctl = 0;
- if ((argc < 2) || (strncmp(argv[1], "help", 4) == 0)) {
+ if (argc < 2 || !strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE, "chassis power Commands: status, on, off, cycle, reset, diag, soft");
- return 0;
+ rc = 0;
+ goto out;
}
- if (strncmp(argv[1], "status", 6) == 0) {
+ if (!strcmp(argv[1], "status")) {
rc = ipmi_chassis_print_power_status(intf);
- return rc;
+ goto out;
}
- if ((strncmp(argv[1], "up", 2) == 0) || (strncmp(argv[1], "on", 2) == 0))
+ if (!strcmp(argv[1], "up") ||
+ !strcmp(argv[1], "on"))
+ {
ctl = IPMI_CHASSIS_CTL_POWER_UP;
- else if ((strncmp(argv[1], "down", 4) == 0) || (strncmp(argv[1], "off", 3) == 0))
+ }
+ else if (!strcmp(argv[1], "down") ||
+ !strcmp(argv[1], "off"))
+ {
ctl = IPMI_CHASSIS_CTL_POWER_DOWN;
- else if (strncmp(argv[1], "cycle", 5) == 0)
+ }
+ else if (!strcmp(argv[1], "cycle"))
ctl = IPMI_CHASSIS_CTL_POWER_CYCLE;
- else if (strncmp(argv[1], "reset", 5) == 0)
+ else if (!strcmp(argv[1], "reset"))
ctl = IPMI_CHASSIS_CTL_HARD_RESET;
- else if (strncmp(argv[1], "diag", 4) == 0)
+ else if (!strcmp(argv[1], "diag"))
ctl = IPMI_CHASSIS_CTL_PULSE_DIAG;
- else if ((strncmp(argv[1], "acpi", 4) == 0) || (strncmp(argv[1], "soft", 4) == 0))
+ else if (!strcmp(argv[1], "acpi") ||
+ !strcmp(argv[1], "soft"))
+ {
ctl = IPMI_CHASSIS_CTL_ACPI_SOFT;
+ }
else {
lprintf(LOG_ERR, "Invalid chassis power command: %s", argv[1]);
- return -1;
+ goto out;
}
rc = ipmi_chassis_power_control(intf, ctl);
}
- else if (strncmp(argv[0], "identify", 8) == 0) {
+ else if (!strcmp(argv[0], "identify")) {
if (argc < 2) {
rc = ipmi_chassis_identify(intf, NULL);
}
- else if (strncmp(argv[1], "help", 4) == 0) {
+ else if (!strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE, "chassis identify <interval>");
lprintf(LOG_NOTICE, " default is 15 seconds");
lprintf(LOG_NOTICE, " 0 to turn off");
@@ -1203,14 +1966,14 @@ ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = ipmi_chassis_identify(intf, argv[1]);
}
}
- else if (strncmp(argv[0], "poh", 3) == 0) {
+ else if (!strcmp(argv[0], "poh")) {
rc = ipmi_chassis_poh(intf);
}
- else if (strncmp(argv[0], "restart_cause", 13) == 0) {
+ else if (!strcmp(argv[0], "restart_cause")) {
rc = ipmi_chassis_restart_cause(intf);
}
- else if (strncmp(argv[0], "policy", 4) == 0) {
- if ((argc < 2) || (strncmp(argv[1], "help", 4) == 0)) {
+ else if (!strcmp(argv[0], "policy")) {
+ if (argc < 2 || !strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE, "chassis policy <state>");
lprintf(LOG_NOTICE, " list : return supported policies");
lprintf(LOG_NOTICE, " always-on : turn on when power is restored");
@@ -1218,13 +1981,13 @@ ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_NOTICE, " always-off : stay off after power is restored");
} else {
uint8_t ctl;
- if (strncmp(argv[1], "list", 4) == 0)
+ if (!strcmp(argv[1], "list"))
ctl = IPMI_CHASSIS_POLICY_NO_CHANGE;
- else if (strncmp(argv[1], "always-on", 9) == 0)
+ else if (!strcmp(argv[1], "always-on"))
ctl = IPMI_CHASSIS_POLICY_ALWAYS_ON;
- else if (strncmp(argv[1], "previous", 8) == 0)
+ else if (!strcmp(argv[1], "previous"))
ctl = IPMI_CHASSIS_POLICY_PREVIOUS;
- else if (strncmp(argv[1], "always-off", 10) == 0)
+ else if (!strcmp(argv[1], "always-off"))
ctl = IPMI_CHASSIS_POLICY_ALWAYS_OFF;
else {
lprintf(LOG_ERR, "Invalid chassis policy: %s", argv[1]);
@@ -1233,21 +1996,26 @@ ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = ipmi_chassis_power_policy(intf, ctl);
}
}
- else if (strncmp(argv[0], "bootparam", 9) == 0) {
- if ((argc < 3) || (strncmp(argv[1], "help", 4) == 0)) {
+ else if (!strcmp(argv[0], "bootparam")) {
+ if (argc < 3 || !strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE, "bootparam get <param #>");
ipmi_chassis_set_bootflag_help();
}
else {
- if (strncmp(argv[1], "get", 3) == 0) {
- rc = ipmi_chassis_get_bootparam(intf, argv[2]);
+ if (!strcmp(argv[1], "get")) {
+ rc = ipmi_chassis_get_bootparam(intf,
+ argc - 2,
+ argv + 2,
+ 0);
}
- else if (strncmp(argv[1], "set", 3) == 0) {
+ else if (!strcmp(argv[1], "set")) {
unsigned char set_flag=0;
unsigned char clr_flag=0;
- if (strncmp(argv[2], "help", 4) == 0 ||
- argc < 4 || (argc >= 4 &&
- strncmp(argv[2], "bootflag", 8) != 0)) {
+ if (!strcmp(argv[2], "help")
+ || argc < 4
+ || (argc >= 4
+ && strcmp(argv[2], "bootflag")))
+ {
ipmi_chassis_set_bootflag_help();
} else {
if (argc == 5) {
@@ -1263,8 +2031,8 @@ ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_NOTICE, "bootparam get|set <option> [value ...]");
}
}
- else if (strncmp(argv[0], "bootdev", 7) == 0) {
- if ((argc < 2) || (strncmp(argv[1], "help", 4) == 0)) {
+ else if (!strcmp(argv[0], "bootdev")) {
+ if (argc < 2 || !strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE, "bootdev <device> [clear-cmos=yes|no]");
lprintf(LOG_NOTICE, "bootdev <device> [options=help,...]");
lprintf(LOG_NOTICE, " none : Do not change boot device order");
@@ -1276,114 +2044,39 @@ ipmi_chassis_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_NOTICE, " bios : Force boot into BIOS Setup");
lprintf(LOG_NOTICE, " floppy: Force boot from Floppy/primary removable media");
} else {
- if (argc < 3)
- rc = ipmi_chassis_set_bootdev(intf, argv[1], NULL);
- else if (strncmp(argv[2], "clear-cmos=", 11) == 0) {
- if (strncmp(argv[2]+11, "yes", 3) == 0) {
- uint8_t flags[5] = {0, (1<<7), 0, 0, 0};
- rc = ipmi_chassis_set_bootdev(intf, argv[1], flags);
- } else
- rc = ipmi_chassis_set_bootdev(intf, argv[1], NULL);
- }
- else if (strncmp(argv[2], "options=", 8) == 0) {
- char *token;
- char *saveptr = NULL;
- int optionError = 0;
- unsigned char flags[5];
- static struct {
- char *name;
- int i;
- unsigned char mask;
- unsigned char value;
- char *desc;
- } options[] = {
- /* data 1 */
- {"valid", 0, (1<<7), (1<<7),
- "Boot flags valid"},
- {"persistent", 0, (1<<6), (1<<6),
- "Changes are persistent for all future boots"},
- {"efiboot", 0, (1<<5), (1<<5),
- "Extensible Firmware Interface Boot (EFI)"},
- /* data 2 */
- {"clear-cmos", 1, (1<<7), (1<<7),
- "CMOS clear"},
- {"lockkbd", 1, (1<<6), (1<<6),
- "Lock Keyboard"},
- /* data2[5:2] is parsed elsewhere */
- {"screenblank", 1, (1<<1), (1<<1),
- "Screen Blank"},
- {"lockoutreset", 1, (1<<0), (1<<0),
- "Lock out Resetbuttons"},
- /* data 3 */
- {"lockout_power", 2, (1<<7), (1<<7),
- "Lock out (power off/sleep request) via Power Button"},
- {"verbose=default", 2, (3<<5), (0<<5),
- "Request quiet BIOS display"},
- {"verbose=no", 2, (3<<5), (1<<5),
- "Request quiet BIOS display"},
- {"verbose=yes", 2, (3<<5), (2<<5),
- "Request verbose BIOS display"},
- {"force_pet", 2, (1<<4), (1<<4),
- "Force progress event traps"},
- {"upw_bypass", 2, (1<<3), (1<<3),
- "User password bypass"},
- {"lockout_sleep", 2, (1<<2), (1<<2),
- "Log Out Sleep Button"},
- {"cons_redirect=default", 2, (3<<0), (0<<0),
- "Console redirection occurs per BIOS configuration setting"},
- {"cons_redirect=skip", 2, (3<<0), (1<<0),
- "Suppress (skip) console redirection if enabled"},
- {"cons_redirect=enable", 2, (3<<0), (2<<0),
- "Suppress (skip) console redirection if enabled"},
- /* data 4 */
- /* data4[7:4] reserved */
- /* data4[3] BIOS Shared Mode Override, not implemented here */
- /* data4[2:0] BIOS Mux Control Override, not implemented here */
-
- /* data5 reserved */
-
- {NULL} /* End marker */
- }, *op;
-
- memset(&flags[0], 0, sizeof(flags));
- token = strtok_r(argv[2] + 8, ",", &saveptr);
- while (token != NULL) {
- if (strcmp(token, "help") == 0) {
- optionError = 1;
- break;
- }
- for (op = options; op->name != NULL; ++op) {
- if (strcmp(token, op->name) == 0) {
- flags[op->i] &= op->mask;
- flags[op->i] |= op->value;
- break;
- }
+ static const char *kw = "options=";
+ char *optstr = NULL;
+ uint8_t flags[BF_BYTE_COUNT];
+ bool use_flags = false;
+
+ if (argc >= 3) {
+ if (!strcmp(argv[2], "clear-cmos=yes")) {
+ /* Exclusive clear-cmos, no other flags */
+ optstr = "clear-cmos";
}
- if (op->name == NULL) {
- /* Option not found */
- optionError = 1;
- lprintf(LOG_ERR, "Invalid option: %s", token);
+ else if (!strncmp(argv[2], kw, strlen(kw))) {
+ optstr = argv[2] + strlen(kw);
}
- token = strtok_r(NULL, ",", &saveptr);
}
- if (optionError) {
- lprintf(LOG_NOTICE, "Legal options settings are:");
- lprintf(LOG_NOTICE, "\thelp:\tprint this message");
- for (op = options; op->name != NULL; ++op) {
- lprintf(LOG_NOTICE, "\t%s:\t%s", op->name, op->desc);
- }
- return (-1);
+ if (optstr) {
+ if (!bootdev_parse_options(optstr, flags))
+ goto out;
+
+ use_flags = true;
}
- rc = ipmi_chassis_set_bootdev(intf, argv[1], flags);
- }
- else
- rc = ipmi_chassis_set_bootdev(intf, argv[1], NULL);
+ rc = ipmi_chassis_set_bootdev(intf, argv[1],
+ use_flags
+ ? flags
+ : NULL);
}
}
+ else if (!strcmp(argv[0], "bootmbox")) {
+ rc = chassis_bootmailbox(intf, argc -1, argv + 1);
+ }
else {
lprintf(LOG_ERR, "Invalid chassis command: %s", argv[0]);
- return -1;
}
+out:
return rc;
}
diff --git a/lib/ipmi_dcmi.c b/lib/ipmi_dcmi.c
index 2cfe48f..8ed87a9 100755..100644
--- a/lib/ipmi_dcmi.c
+++ b/lib/ipmi_dcmi.c
@@ -36,7 +36,6 @@
* This code conforms to the 1.0 DCMI Specification
* released by Hari Ramachandran of the Intel Corporation
*/
-#define _BSD_SOURCE
#include <stdlib.h>
#include <string.h>
@@ -57,6 +56,7 @@
#include <ipmitool/ipmi_entity.h>
#include <ipmitool/ipmi_constants.h>
#include <ipmitool/ipmi_sensor.h>
+#include <ipmitool/ipmi_time.h>
#include "../src/plugins/lanplus/lanplus.h"
@@ -74,31 +74,40 @@ static int ipmi_print_sensor_info(struct ipmi_intf *intf, uint16_t rec_id);
* to change a lot of the code in the main(). *
******************************************************************************/
+/*
+ * This is a termination macro for all struct dcmi_cmd arrays,
+ * def argument is the default value returned by str2val2()
+ * when string is not found in the array
+ */
+#define DCMI_CMD_END(def) { (def), NULL, NULL }
+
/* Main set of DCMI commands */
const struct dcmi_cmd dcmi_cmd_vals[] = {
- { 0x00, "discover", " Used to discover supported DCMI capabilities" },
- { 0x01, "power", " Platform power limit command options" },
- { 0x02, "sensors", " Prints the available DCMI sensors" },
- { 0x03, "asset_tag", " Prints the platform's asset tag" },
- { 0x04, "set_asset_tag", " Sets the platform's asset tag" },
- { 0x05, "get_mc_id_string", " Get management controller ID string" },
- { 0x06, "set_mc_id_string", " Set management controller ID string" },
- { 0x07, "thermalpolicy", " Thermal policy get/set" },
- { 0x08, "get_temp_reading", " Get Temperature Readings" },
- { 0x09, "get_conf_param", " Get DCMI Config Parameters" },
- { 0x0A, "set_conf_param", " Set DCMI Config Parameters" },
- { 0x0B, "oob_discover", " Ping/Pong Message for DCMI Discovery" },
- { 0xFF, NULL, NULL }
+ { 0x00, "discover", "Used to discover supported DCMI capabilities" },
+ { 0x01, "power", "Platform power limit command options" },
+ { 0x02, "sensors", "Prints the available DCMI sensors" },
+ { 0x03, "asset_tag", "Prints the platform's asset tag" },
+ { 0x04, "set_asset_tag", "Sets the platform's asset tag" },
+ { 0x05, "get_mc_id_string", "Get management controller ID string" },
+ { 0x06, "set_mc_id_string", "Set management controller ID string" },
+ { 0x07, "thermalpolicy", "Thermal policy get/set" },
+ { 0x08, "get_temp_reading", "Get Temperature Readings" },
+ { 0x09, "get_conf_param", "Get DCMI Config Parameters" },
+ { 0x0A, "set_conf_param", "Set DCMI Config Parameters" },
+ { 0x0B, "oob_discover", "Ping/Pong Message for DCMI Discovery" },
+
+ DCMI_CMD_END(0xFF)
};
-/* get capabilites */
+/* get capabilities */
const struct dcmi_cmd dcmi_capable_vals[] = {
- { 0x01, "platform", " Lists the system capabilities" },
+ { 0x01, "platform", "Lists the system capabilities" },
{ 0x02, "mandatory_attributes", "Lists SEL, identification and"
- "temperature attributes" },
- { 0x03, "optional_attributes", " Lists power capabilities" },
- { 0x04, "managebility access", " Lists OOB channel information" },
- { 0xFF, NULL, NULL }
+ "temperature attributes" },
+ { 0x03, "optional_attributes", "Lists power capabilities" },
+ { 0x04, "managebility access", "Lists OOB channel information" },
+
+ DCMI_CMD_END(0xFF)
};
/* platform capabilities
@@ -107,54 +116,60 @@ const struct dcmi_cmd dcmi_capable_vals[] = {
*/
const struct dcmi_cmd dcmi_mandatory_platform_capabilities[] = {
{ 0x01, "Identification support available", "" },
- { 0x02, "SEL logging available", "" },
- { 0x03, "Chassis power available", "" },
- { 0x04, "Temperature monitor available", "" },
- { 0xFF, NULL, NULL }
+ { 0x02, "SEL logging available", "" },
+ { 0x03, "Chassis power available", "" },
+ { 0x04, "Temperature monitor available", "" },
+
+ DCMI_CMD_END(0xFF)
};
/* optional capabilities */
const struct dcmi_cmd dcmi_optional_platform_capabilities[] = {
- { 0x01, "Power management available", "" },
- { 0xFF, NULL, NULL }
+ { 0x01, "Power management available", "" },
+
+ DCMI_CMD_END(0xFF)
};
-/* access capabilties */
+/* access capabilities */
const struct dcmi_cmd dcmi_management_access_capabilities[] = {
- { 0x01, "In-band KCS channel available", "" },
- { 0x02, "Out-of-band serial TMODE available", "" },
+ { 0x01, "In-band KCS channel available", "" },
+ { 0x02, "Out-of-band serial TMODE available", "" },
{ 0x03, "Out-of-band secondary LAN channel available", "" },
- { 0x04, "Out-of-band primary LAN channel available", "" },
- { 0x05, "SOL enabled", "" },
- { 0x06, "VLAN capable", "" },
- { 0xFF, NULL, NULL }
+ { 0x04, "Out-of-band primary LAN channel available", "" },
+ { 0x05, "SOL enabled", "" },
+ { 0x06, "VLAN capable", "" },
+
+ DCMI_CMD_END(0xFF)
};
/* identification capabilities */
const struct dcmi_cmd dcmi_id_capabilities_vals[] = {
- { 0x01, "GUID", "" },
+ { 0x01, "GUID", "" },
{ 0x02, "DHCP hostname", "" },
- { 0x03, "Asset tag", "" },
- { 0xFF, NULL, NULL }
+ { 0x03, "Asset tag", "" },
+
+ DCMI_CMD_END(0xFF)
};
/* Configuration parameters*/
const struct dcmi_cmd dcmi_conf_param_vals[] = {
- { 0x01, "activate_dhcp", "\tActivate DHCP"},
- { 0x02, "dhcp_config", "\tDHCP Configuration" },
- { 0x03, "init", "\t\tInitial timeout interval" },
- { 0x04, "timeout", "\t\tServer contact timeout interval" },
- { 0x05, "retry", "\t\tServer contact retry interval" },
- { 0xFF, NULL, NULL }
+ { 0x01, "activate_dhcp", "\tActivate DHCP" },
+ { 0x02, "dhcp_config", "\tDHCP Configuration" },
+ { 0x03, "init", "\t\tInitial timeout interval" },
+ { 0x04, "timeout", "\t\tServer contact timeout interval" },
+ { 0x05, "retry", "\t\tServer contact retry interval" },
+
+ DCMI_CMD_END(0xFF)
};
/* temperature monitoring capabilities */
const struct dcmi_cmd dcmi_temp_monitoring_vals[] = {
- { 0x01, "inlet", " Inlet air temperature sensors" },
- { 0x02, "cpu", " CPU temperature sensors" },
- { 0x03, "baseboard", "Baseboard temperature sensors" },
- { 0xff, NULL, NULL }
+ { 0x01, "inlet", "Inlet air temperature sensors" },
+ { 0x02, "cpu", "CPU temperature sensors" },
+ { 0x03, "baseboard", "Baseboard temperature sensors" },
+
+ DCMI_CMD_END(0xFF)
};
/* These are not comands. These are the DCMI temp sensors and their numbers
@@ -162,113 +177,121 @@ const struct dcmi_cmd dcmi_temp_monitoring_vals[] = {
* sensor number
*/
const struct dcmi_cmd dcmi_discvry_snsr_vals[] = {
- { 0x40, "Inlet", " Inlet air temperature sensors" },
- { 0x41, "CPU", " CPU temperature sensors" },
- { 0x42, "Baseboard", "Baseboard temperature sensors" },
- { 0xff, NULL, NULL }
+ { 0x40, "Inlet", "Inlet air temperature sensors" },
+ { 0x41, "CPU", "CPU temperature sensors" },
+ { 0x42, "Baseboard", "Baseboard temperature sensors" },
+
+ DCMI_CMD_END(0xFF)
};
/* Temperature Readings */
const struct dcmi_cmd dcmi_temp_read_vals[] = {
- { 0x40, "Inlet", "Inlet air temperature(40h) " },
- { 0x41, "CPU", "CPU temperature sensors(41h) " },
- { 0x42, "Baseboard", "Baseboard temperature sensors(42h) " },
- { 0xff, NULL, NULL }
+ { 0x40, "Inlet", "Inlet air temperature(40h)" },
+ { 0x41, "CPU", "CPU temperature sensors(41h)" },
+ { 0x42, "Baseboard", "Baseboard temperature sensors(42h)" },
+
+ DCMI_CMD_END(0xFF)
};
/* power management/control commands */
const struct dcmi_cmd dcmi_pwrmgmt_vals[] = {
- { 0x00, "reading", " Get power related readings from the system" },
- { 0x01, "get_limit", " Get the configured power limits" },
- { 0x02, "set_limit", " Set a power limit option" },
- { 0x03, "activate", " Activate the set power limit" },
- { 0x04, "deactivate", "Deactivate the set power limit" },
- { 0xFF, NULL, NULL }
+ { 0x00, "reading", "Get power related readings from the system" },
+ { 0x01, "get_limit", "Get the configured power limits" },
+ { 0x02, "set_limit", "Set a power limit option" },
+ { 0x03, "activate", "Activate the set power limit" },
+ { 0x04, "deactivate", "Deactivate the set power limit" },
+
+ DCMI_CMD_END(0xFF)
};
/* set power limit commands */
const struct dcmi_cmd dcmi_pwrmgmt_set_usage_vals[] = {
- { 0x00, "action", " <no_action | sel_logging | power_off>" },
- { 0x01, "limit", " <number in Watts>" },
+ { 0x00, "action", "<no_action | sel_logging | power_off>" },
+ { 0x01, "limit", "<number in Watts>" },
{ 0x02, "correction", "<number in milliseconds>" },
- { 0x03, "sample", " <number in seconds>" },
- { 0xFF, NULL, NULL }
+ { 0x03, "sample", "<number in seconds>" },
+
+ DCMI_CMD_END(0xFF)
};
/* power management/get action commands */
const struct dcmi_cmd dcmi_pwrmgmt_get_action_vals[] = {
- { 0x00, "No Action", ""},
- { 0x01, "Hard Power Off & Log Event to SEL", ""},
-
- { 0x02, "OEM reserved (02h)", ""},
- { 0x03, "OEM reserved (03h)", ""},
- { 0x04, "OEM reserved (04h)", ""},
- { 0x05, "OEM reserved (05h)", ""},
- { 0x06, "OEM reserved (06h)", ""},
- { 0x07, "OEM reserved (07h)", ""},
- { 0x08, "OEM reserved (08h)", ""},
- { 0x09, "OEM reserved (09h)", ""},
- { 0x0a, "OEM reserved (0ah)", ""},
- { 0x0b, "OEM reserved (0bh)", ""},
- { 0x0c, "OEM reserved (0ch)", ""},
- { 0x0d, "OEM reserved (0dh)", ""},
- { 0x0e, "OEM reserved (0eh)", ""},
- { 0x0f, "OEM reserved (0fh)", ""},
- { 0x10, "OEM reserved (10h)", ""},
-
- { 0x11, "Log Event to SEL", ""},
- { 0xFF, NULL, NULL }
+ { 0x00, "No Action", "" },
+ { 0x01, "Hard Power Off & Log Event to SEL", "" },
+
+ { 0x02, "OEM reserved (02h)", "" },
+ { 0x03, "OEM reserved (03h)", "" },
+ { 0x04, "OEM reserved (04h)", "" },
+ { 0x05, "OEM reserved (05h)", "" },
+ { 0x06, "OEM reserved (06h)", "" },
+ { 0x07, "OEM reserved (07h)", "" },
+ { 0x08, "OEM reserved (08h)", "" },
+ { 0x09, "OEM reserved (09h)", "" },
+ { 0x0a, "OEM reserved (0ah)", "" },
+ { 0x0b, "OEM reserved (0bh)", "" },
+ { 0x0c, "OEM reserved (0ch)", "" },
+ { 0x0d, "OEM reserved (0dh)", "" },
+ { 0x0e, "OEM reserved (0eh)", "" },
+ { 0x0f, "OEM reserved (0fh)", "" },
+ { 0x10, "OEM reserved (10h)", "" },
+
+ { 0x11, "Log Event to SEL", "" },
+
+ DCMI_CMD_END(0xFF)
};
/* power management/set action commands */
const struct dcmi_cmd dcmi_pwrmgmt_action_vals[] = {
- { 0x00, "no_action", "No Action"},
- { 0x01, "power_off", "Hard Power Off & Log Event to SEL"},
- { 0x11, "sel_logging", "Log Event to SEL"},
-
- { 0x02, "oem_02", "OEM reserved (02h)"},
- { 0x03, "oem_03", "OEM reserved (03h)"},
- { 0x04, "oem_04", "OEM reserved (04h)"},
- { 0x05, "oem_05", "OEM reserved (05h)"},
- { 0x06, "oem_06", "OEM reserved (06h)"},
- { 0x07, "oem_07", "OEM reserved (07h)"},
- { 0x08, "oem_08", "OEM reserved (08h)"},
- { 0x09, "oem_09", "OEM reserved (09h)"},
- { 0x0a, "oem_0a", "OEM reserved (0ah)"},
- { 0x0b, "oem_0b", "OEM reserved (0bh)"},
- { 0x0c, "oem_0c", "OEM reserved (0ch)"},
- { 0x0d, "oem_0d", "OEM reserved (0dh)"},
- { 0x0e, "oem_0e", "OEM reserved (0eh)"},
- { 0x0f, "oem_0f", "OEM reserved (0fh)"},
- { 0x10, "oem_10", "OEM reserved (10h)"},
-
- { 0xFF, NULL, NULL }
+ { 0x00, "no_action", "No Action" },
+ { 0x01, "power_off", "Hard Power Off & Log Event to SEL" },
+ { 0x11, "sel_logging", "Log Event to SEL" },
+
+ { 0x02, "oem_02", "OEM reserved (02h)" },
+ { 0x03, "oem_03", "OEM reserved (03h)" },
+ { 0x04, "oem_04", "OEM reserved (04h)" },
+ { 0x05, "oem_05", "OEM reserved (05h)" },
+ { 0x06, "oem_06", "OEM reserved (06h)" },
+ { 0x07, "oem_07", "OEM reserved (07h)" },
+ { 0x08, "oem_08", "OEM reserved (08h)" },
+ { 0x09, "oem_09", "OEM reserved (09h)" },
+ { 0x0a, "oem_0a", "OEM reserved (0ah)" },
+ { 0x0b, "oem_0b", "OEM reserved (0bh)" },
+ { 0x0c, "oem_0c", "OEM reserved (0ch)" },
+ { 0x0d, "oem_0d", "OEM reserved (0dh)" },
+ { 0x0e, "oem_0e", "OEM reserved (0eh)" },
+ { 0x0f, "oem_0f", "OEM reserved (0fh)" },
+ { 0x10, "oem_10", "OEM reserved (10h)" },
+
+ DCMI_CMD_END(0xFF)
};
/* thermal policy action commands */
const struct dcmi_cmd dcmi_thermalpolicy_vals[] = {
- { 0x00, "get", "Get thermal policy" },
- { 0x01, "set", "Set thermal policy" },
- { 0xFF, NULL, NULL }
+ { 0x00, "get", "Get thermal policy" },
+ { 0x01, "set", "Set thermal policy" },
+
+ DCMI_CMD_END(0xFF)
};
/* thermal policy action commands */
const struct dcmi_cmd dcmi_confparameters_vals[] = {
- { 0x00, "get", "Get configuration parameters" },
- { 0x01, "set", "Set configuration parameters" },
- { 0xFF, NULL, NULL }
+ { 0x00, "get", "Get configuration parameters" },
+ { 0x01, "set", "Set configuration parameters" },
+
+ DCMI_CMD_END(0xFF)
};
/* entityIDs used in thermap policy */
const struct dcmi_cmd dcmi_thermalpolicy_set_parameters_vals[] = {
- { 0x00, "volatile", " Current Power Cycle" },
- { 0x01, "nonvolatile", "Set across power cycles" },
- { 0x01, "poweroff", " Hard Power Off system" },
- { 0x00, "nopoweroff", " No 'Hard Power Off' action" },
- { 0x01, "sel", " Log event to SEL" },
- { 0x00, "nosel", " No 'Log event to SEL' action" },
- { 0x00, "disabled", " Disabled" },
- { 0x00, NULL, NULL }
+ { 0x00, "volatile", "Current Power Cycle" },
+ { 0x01, "nonvolatile", "Set across power cycles" },
+ { 0x01, "poweroff", "Hard Power Off system" },
+ { 0x00, "nopoweroff", "No 'Hard Power Off' action" },
+ { 0x01, "sel", "Log event to SEL" },
+ { 0x00, "nosel", "No 'Log event to SEL' action" },
+ { 0x00, "disabled", "Disabled" },
+
+ DCMI_CMD_END(0)
};
@@ -301,54 +324,59 @@ const struct valstr dcmi_ccode_vals[] = {
*/
const struct dcmi_cmd dcmi_sampling_vals[] = {
- { 0x05, "5_sec", "" },
+ { 0x05, "5_sec", "" },
{ 0x0f, "15_sec", "" },
{ 0x1E, "30_sec", "" },
- { 0x41, "1_min", "" },
- { 0x43, "3_min", "" },
- { 0x47, "7_min", "" },
+ { 0x41, "1_min", "" },
+ { 0x43, "3_min", "" },
+ { 0x47, "7_min", "" },
{ 0x4F, "15_min", "" },
{ 0x5E, "30_min", "" },
- { 0x81, "1_hour", ""},
- { 0x00, NULL, NULL },
+ { 0x81, "1_hour", "" },
+
+ DCMI_CMD_END(0)
};
/* Primary Node Manager commands */
const struct dcmi_cmd nm_cmd_vals[] = {
- { 0x00, "discover", "Discover Node Manager " },
+ { 0x00, "discover", "Discover Node Manager" },
{ 0x01, "capability", "Get Node Manager Capabilities" },
- { 0x02, "control", "Enable/Disable Policy Control" },
- { 0x03, "policy", "Add/Remove Policies" },
+ { 0x02, "control", "Enable/Disable Policy Control" },
+ { 0x03, "policy", "Add/Remove Policies" },
{ 0x04, "statistics", "Get Statistics" },
- { 0x05, "power", "Set Power Draw Range" },
- { 0x06, "suspend", "Set/Get Policy suspend periods" },
- { 0x07, "reset", "Reset Statistics" },
- { 0x08, "alert", "Set/Get/Clear Alert destination" },
- { 0x09, "threshold", "Set/Get Alert Thresholds" },
- { 0xFF, NULL, NULL },
+ { 0x05, "power", "Set Power Draw Range" },
+ { 0x06, "suspend", "Set/Get Policy suspend periods" },
+ { 0x07, "reset", "Reset Statistics" },
+ { 0x08, "alert", "Set/Get/Clear Alert destination" },
+ { 0x09, "threshold", "Set/Get Alert Thresholds" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_ctl_cmds[] = {
- { 0x01, "enable", " <control scope>" },
- { 0x00, "disable", "<control scope>"},
- { 0xFF, NULL, NULL },
+ { 0x01, "enable", "<control scope>" },
+ { 0x00, "disable", "<control scope>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_ctl_domain[] = {
- { 0x00, "global", "" },
+ { 0x00, "global", "" },
{ 0x02, "per_domain", "<platform|CPU|Memory> (default is platform)" },
- { 0x04, "per_policy", "<0-7>" },
- { 0xFF, NULL, NULL },
+ { 0x04, "per_policy", "<0-255>" },
+
+ DCMI_CMD_END(0xFF),
};
/* Node Manager Domain codes */
const struct dcmi_cmd nm_domain_vals[] = {
- { 0x00, "platform", "" },
- { 0x01, "CPU", "" },
- { 0x02, "Memory", "" },
+ { 0x00, "platform", "" },
+ { 0x01, "CPU", "" },
+ { 0x02, "Memory", "" },
{ 0x03, "protection", "" },
- { 0x04, "I/O", "" },
- { 0xFF, NULL, NULL },
+ { 0x04, "I/O", "" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_version_vals[] = {
@@ -357,76 +385,90 @@ const struct dcmi_cmd nm_version_vals[] = {
{ 0x03, "2.0", "" },
{ 0x04, "2.5", "" },
{ 0x05, "3.0", "" },
- { 0xFF, NULL, NULL },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_capability_opts[] = {
- { 0x01, "domain", "<platform|CPU|Memory> (default is platform)" },
- { 0x02, "inlet", "Inlet temp trigger" },
+ { 0x01, "domain", "<platform|CPU|Memory> (default is platform)" },
+ { 0x02, "inlet", "Inlet temp trigger" },
{ 0x03, "missing", "Missing Power reading trigger" },
- { 0x04, "reset", "Time after Host reset trigger" },
- { 0x05, "boot", "Boot time policy" },
- { 0xFF, NULL, NULL },
+ { 0x04, "reset", "Time after Host reset trigger" },
+ { 0x05, "boot", "Boot time policy" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_policy_type_vals[] = {
- { 0x00, "No trigger, use Power Limit", "" },
- { 0x01, "Inlet temp trigger", "" },
- { 0x02, "Missing Power reading trigger", "" },
- { 0x03, "Time after Host reset trigger", "" },
+ { 0x00, "No trigger, use Power Limit", "" },
+ { 0x01, "Inlet temp trigger", "" },
+ { 0x02, "Missing Power reading trigger", "" },
+ { 0x03, "Time after Host reset trigger", "" },
{ 0x04, "number of cores to disable at boot time", "" },
- { 0xFF, NULL, NULL },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_stats_opts[] = {
- { 0x01, "domain", "<platform|CPU|Memory> (default is platform)" },
- { 0x02, "policy_id", "<0-7>" },
- { 0xFF, NULL, NULL },
+ { 0x01, "domain", "<platform|CPU|Memory> (default is platform)" },
+ { 0x02, "policy_id", "<0-255>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_stats_mode[] = {
- { 0x01, "power", "global power" },
- { 0x02, "temps", "inlet temperature" },
- { 0x11, "policy_power", "per policy power" },
- { 0x12, "policy_temps", "per policy inlet temp" },
- { 0x13, "policy_throt", "per policy throttling stats" },
- { 0x1B, "requests", "unhandled requests" },
- { 0x1C, "response", "response time" },
+ { 0x01, "power", "global power" },
+ { 0x02, "temps", "inlet temperature" },
+ { 0x11, "policy_power", "per policy power" },
+ { 0x12, "policy_temps", "per policy inlet temp" },
+ { 0x13, "policy_throt", "per policy throttling stats" },
+ { 0x1B, "requests", "unhandled requests" },
+ { 0x1C, "response", "response time" },
{ 0x1D, "cpu_throttling", "CPU throttling" },
{ 0x1E, "mem_throttling", "memory throttling" },
- { 0x1F, "comm_fail", "host communication failures" },
- { 0xFF, NULL, NULL },
+ { 0x1F, "comm_fail", "host communication failures" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_policy_action[] = {
- { 0x00, "get", "nm policy get policy_id <0-7> [domain <platform|CPU|Memory>]" },
- { 0x04, "add", "nm policy add policy_id <0-7> [domain <platform|CPU|Memory>] correction auto|soft|hard power <watts>|inlet <temp> trig_lim <param> stats <seconds> enable|disable" },
- { 0x05, "remove", "nm policy remove policy_id <0-7> [domain <platform|CPU|Memory>]" },
+ { 0x00, "get", "nm policy get policy_id <0-255> "
+ "[domain <platform|CPU|Memory>]" },
+ { 0x04, "add", "nm policy add policy_id <0-255> "
+ "[domain <platform|CPU|Memory>] "
+ "correction auto|soft|hard power <watts> | "
+ "inlet <temp> trig_lim <param> "
+ "stats <seconds> enable|disable" },
+ { 0x05, "remove", "nm policy remove policy_id <0-255> "
+ "[domain <platform|CPU|Memory>]" },
{ 0x06, "limiting", "nm policy limiting [domain <platform|CPU|Memory>]" },
- { 0xFF, NULL, NULL },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_policy_options[] = {
- { 0x01, "enable", "" },
- { 0x02, "disable", "" },
- { 0x03, "domain", "" },
- { 0x04, "inlet", "inlet air temp full limiting (SCRAM)"},
- { 0x06, "correction", "auto, soft, hard" },
- { 0x08, "power", "power limit in watts" },
- { 0x09, "trig_lim", "time to send alert" },
- { 0x0A, "stats", "moving window averaging time" },
+ { 0x01, "enable", "" },
+ { 0x02, "disable", "" },
+ { 0x03, "domain", "" },
+ { 0x04, "inlet", "inlet air temp full limiting (SCRAM)" },
+ { 0x06, "correction","auto, soft, hard" },
+ { 0x08, "power", "power limit in watts" },
+ { 0x09, "trig_lim", "time to send alert" },
+ { 0x0A, "stats", "moving window averaging time" },
{ 0x0B, "policy_id", "policy number" },
- { 0x0C, "volatile", "save policy in volatiel memory" },
+ { 0x0C, "volatile", "save policy in volatiel memory" },
{ 0x0D, "cores_off", "at boot time, disable N cores" },
- { 0xFF, NULL, NULL },
+
+ DCMI_CMD_END(0xFF),
};
/* if "trigger" command used from nm_policy_options */
const struct dcmi_cmd nm_trigger[] = {
- { 0x00, "none", "" },
- { 0x01, "temp", "" },
+ { 0x00, "none", "" },
+ { 0x01, "temp", "" },
{ 0x02, "reset", "" },
- { 0x03, "boot", "" },
- { 0xFF, NULL, NULL },
+ { 0x03, "boot", "" },
+
+ DCMI_CMD_END(0xFF),
};
/* if "correction" used from nm_policy_options */
@@ -434,86 +476,105 @@ const struct dcmi_cmd nm_correction[] = {
{ 0x00, "auto", "" },
{ 0x01, "soft", "" },
{ 0x02, "hard", "" },
- { 0xFF, NULL, NULL },
+
+ DCMI_CMD_END(0xFF),
};
/* returned codes from get policy */
const struct dcmi_cmd nm_correction_vals[] = {
{ 0x00, "no T-state use", "" },
{ 0x01, "no T-state use", "" },
- { 0x02, "use T-states", "" },
- { 0xFF, NULL, NULL },
+ { 0x02, "use T-states", "" },
+
+ DCMI_CMD_END(0xFF),
};
/* if "exception" used from nm_policy_options */
const struct dcmi_cmd nm_exception[] = {
- { 0x00, "none", "" },
- { 0x01, "alert", "" },
+ { 0x00, "none", "" },
+ { 0x01, "alert", "" },
{ 0x02, "shutdown", "" },
- { 0xFF, NULL, NULL },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_reset_mode[] = {
- { 0x00, "global", "" },
+ { 0x00, "global", "" },
{ 0x01, "per_policy", "" },
- { 0x1B, "requests", "" },
- { 0x1C, "response", "" },
+ { 0x1B, "requests", "" },
+ { 0x1C, "response", "" },
{ 0x1D, "throttling", "" },
- { 0x1E, "memory", "", },
- { 0x1F, "comm", "" },
- { 0xFF, NULL, NULL },
+ { 0x1E, "memory", "" },
+ { 0x1F, "comm", "" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_power_range[] = {
{ 0x01, "domain", "domain <platform|CPU|Memory> (default is platform)" },
- { 0x02, "min", " min <integer value>" },
- { 0x03, "max", "max <integer value>" },
- { 0xFF, NULL, NULL },
+ { 0x02, "min", "min <integer value>" },
+ { 0x03, "max", "max <integer value>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_alert_opts[] = {
- { 0x01, "set", "nm alert set chan <chan> dest <dest> string <string>" },
- { 0x02, "get", "nm alert get" },
+ { 0x01, "set", "nm alert set chan <chan> dest <dest> string <string>" },
+ { 0x02, "get", "nm alert get" },
{ 0x03, "clear", "nm alert clear dest <dest>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_set_alert_param[] = {
- { 0x01, "chan", "chan <channel>" },
- { 0x02, "dest", "dest <destination>" },
+ { 0x01, "chan", "chan <channel>" },
+ { 0x02, "dest", "dest <destination>" },
{ 0x03, "string", "string <string>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_thresh_cmds[] = {
- { 0x01, "set", "nm thresh set [domain <platform|CPU|Memory>] policy_id <policy> thresh_array" },
- { 0x02, "get", "nm thresh get [domain <platform|CPU|Memory>] policy_id <policy>" },
+ { 0x01, "set", "nm thresh set [domain <platform|CPU|Memory>] "
+ "policy_id <policy> thresh_array" },
+ { 0x02, "get", "nm thresh get [domain <platform|CPU|Memory>] "
+ "policy_id <policy>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_thresh_param[] = {
- { 0x01, "domain", "<platform|CPU|Memory> (default is platform)" },
- { 0x02, "policy_id", "<0-7>" },
- { 0xFF, NULL, NULL },
+ { 0x01, "domain", "<platform|CPU|Memory> (default is platform)" },
+ { 0x02, "policy_id", "<0-255>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct dcmi_cmd nm_suspend_cmds[] = {
- { 0x01, "set", "nm suspend set [domain <platform|CPU|Memory]> policy_id <policy> <start> <stop> <pattern>" },
- { 0x02, "get", "nm suspend get [domain <platform|CPU|Memory]> policy_id <policy>" },
+ { 0x01, "set", "nm suspend set [domain <platform|CPU|Memory]> "
+ "policy_id <policy> <start> "
+ "<stop> <pattern>" },
+ { 0x02, "get", "nm suspend get [domain <platform|CPU|Memory]> "
+ "policy_id <policy>" },
+
+ DCMI_CMD_END(0xFF),
};
const struct valstr nm_ccode_vals[] = {
- { 0x80, "Policy ID Invalid"},
- { 0x81, "Domain ID Invalid"},
- { 0x82, "Unknown policy trigger type"},
- { 0x84, "Power Limit out of range"},
- { 0x85, "Correction Time out of range"},
- { 0x86, "Policy Trigger value out of range"},
- { 0x88, "Invalid Mode"},
- { 0x89, "Statistics Reporting Period out of range"},
- { 0x8B, "Invalid value for Aggressive CPU correction field"},
- { 0xA1, "No policy is currently limiting for the specified domain ID"},
- { 0xC4, "No space available"},
- { 0xD4, "Insufficient privledge level due wrong responder LUN"},
- { 0xD5, "Policy exists and param unchangeable while enabled"},
- { 0xD6, "Command subfunction disabled or unavailable"},
+ { 0x80, "Policy ID Invalid" },
+ { 0x81, "Domain ID Invalid" },
+ { 0x82, "Unknown policy trigger type" },
+ { 0x84, "Power Limit out of range" },
+ { 0x85, "Correction Time out of range" },
+ { 0x86, "Policy Trigger value out of range" },
+ { 0x88, "Invalid Mode" },
+ { 0x89, "Statistics Reporting Period out of range" },
+ { 0x8B, "Invalid value for Aggressive CPU correction field" },
+ { 0xA1, "No policy is currently limiting for the specified domain ID" },
+ { 0xC4, "No space available" },
+ { 0xD4, "Insufficient privilege level due wrong responder LUN" },
+ { 0xD5, "Policy exists and param unchangeable while enabled" },
+ { 0xD6, "Command subfunction disabled or unavailable" },
{ 0xFF, NULL },
};
@@ -533,20 +594,20 @@ const struct valstr nm_ccode_vals[] = {
*/
void
print_strs(const struct dcmi_cmd * vs, const char * title, int loglevel,
- int verthorz)
+ int verthorz)
{
int i;
- if (vs == NULL)
+ if (!vs)
return;
- if (title != NULL) {
+ if (title) {
if (loglevel < 0)
printf("\n%s\n", title);
else
lprintf(loglevel, "\n%s", title);
}
- for (i = 0; vs[i].str != NULL; i++) {
+ for (i = 0; vs[i].str; i++) {
if (loglevel < 0) {
if (vs[i].val < 256)
if (verthorz == 0)
@@ -566,7 +627,7 @@ print_strs(const struct dcmi_cmd * vs, const char * title, int loglevel,
/* Check to see if this is NOT the last element in vs.str if true
* print the | else don't print anything.
*/
- if ((verthorz == 1) && (vs[i+1].str != NULL))
+ if (verthorz == 1 && vs[i+1].str)
printf(" | ");
}
if (verthorz == 0) {
@@ -590,14 +651,12 @@ uint16_t
str2val2(const char *str, const struct dcmi_cmd *vs)
{
int i;
- if (vs == NULL || str == NULL) {
+ if (!vs || !str) {
return 0;
}
- for (i = 0; vs[i].str != NULL; i++) {
- if (strncasecmp(vs[i].str, str,
- __maxlen(str, vs[i].str)) == 0) {
+ for (i = 0; vs[i].str; i++) {
+ if (strcasecmp(vs[i].str, str) == 0)
return vs[i].val;
- }
}
return vs[i].val;
}
@@ -616,10 +675,10 @@ val2str2(uint16_t val, const struct dcmi_cmd *vs)
static char un_str[32];
int i;
- if (vs == NULL)
+ if (!vs)
return NULL;
- for (i = 0; vs[i].str != NULL; i++) {
+ for (i = 0; vs[i].str; i++) {
if (vs[i].val == val)
return vs[i].str;
}
@@ -637,7 +696,7 @@ chk_rsp(struct ipmi_rs * rsp)
/* if the response from the intf is NULL then the BMC is experiencing
* some issue and cannot complete the command
*/
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "\n Unable to get DCMI information");
return 1;
}
@@ -647,16 +706,17 @@ chk_rsp(struct ipmi_rs * rsp)
*/
if ((rsp->ccode >= 0x80) && (rsp->ccode <= 0x8F)) {
lprintf(LOG_ERR, "\n DCMI request failed because: %s (%x)",
- val2str(rsp->ccode, dcmi_ccode_vals), rsp->ccode);
+ val2str(rsp->ccode, dcmi_ccode_vals), rsp->ccode);
return 1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "\n DCMI request failed because: %s (%x)",
- val2str(rsp->ccode, completion_code_vals), rsp->ccode);
+ val2str(rsp->ccode, completion_code_vals), rsp->ccode);
return 1;
}
/* check to make sure this is a DCMI firmware */
if(rsp->data[0] != IPMI_DCMI) {
- printf("\n A valid DCMI command was not returned! (%x)", rsp->data[0]);
+ printf("\n A valid DCMI command was not returned! (%x)",
+ rsp->data[0]);
return 1;
}
return 0;
@@ -671,7 +731,7 @@ chk_nm_rsp(struct ipmi_rs * rsp)
/* if the response from the intf is NULL then the BMC is experiencing
* some issue and cannot complete the command
*/
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "\n No response to NM request");
return 1;
}
@@ -683,7 +743,7 @@ chk_nm_rsp(struct ipmi_rs * rsp)
lprintf(LOG_ERR, "\n NM request failed because: %s (%x)",
val2str(rsp->ccode, nm_ccode_vals), rsp->ccode);
return 1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "\n NM request failed because: %s (%x)",
val2str(rsp->ccode, completion_code_vals), rsp->ccode);
return 1;
@@ -753,11 +813,11 @@ ipmi_dcmi_prnt_oobDiscover(struct ipmi_intf * intf)
# else
struct ipmi_session_params *p;
- if (intf->opened == 0 && intf->open != NULL) {
+ if (intf->opened == 0 && intf->open) {
if (intf->open(intf) < 0)
return (-1);
}
- if (intf == NULL || intf->session == NULL)
+ if (!intf || !intf->session)
return -1;
p = &intf->ssn_params;
@@ -771,7 +831,7 @@ ipmi_dcmi_prnt_oobDiscover(struct ipmi_intf * intf)
if (p->retry == 0)
p->retry = IPMI_LAN_RETRY;
- if (p->hostname == NULL || strlen((const char *)p->hostname) == 0) {
+ if (!p->hostname || strlen((const char *)p->hostname) == 0) {
lprintf(LOG_ERR, "No hostname specified!");
return -1;
}
@@ -786,7 +846,7 @@ ipmi_dcmi_prnt_oobDiscover(struct ipmi_intf * intf)
if (intf->fd < 0) {
lperror(LOG_ERR, "Connect to %s failed",
- p->hostname);
+ p->hostname);
intf->close(intf);
return -1;
}
@@ -822,16 +882,17 @@ ipmi_dcmi_prnt_getcapabilities(struct ipmi_intf * intf, uint8_t selector)
memcpy(&reply, rsp->data, sizeof (reply));
/* check to make sure that this is a 1.0/1.1/1.5 command */
if ((cape.conformance != IPMI_DCMI_CONFORM)
- && (cape.conformance != IPMI_DCMI_1_1_CONFORM)
- && (cape.conformance != IPMI_DCMI_1_5_CONFORM)) {
+ && (cape.conformance != IPMI_DCMI_1_1_CONFORM)
+ && (cape.conformance != IPMI_DCMI_1_5_CONFORM))
+ {
lprintf(LOG_ERR,
- "ERROR! This command is not available on this platform");
+ "ERROR! This command is not available on this platform");
return -1;
}
/* check to make sure that this is a rev .01 or .02 */
if (cape.revision != 0x01 && cape.revision != 0x02) {
lprintf(LOG_ERR,
- "ERROR! This command is not compatible with this version");
+ "ERROR! This command is not compatible with this version");
return -1;
}
/* 0x01 - platform capabilities
@@ -847,21 +908,21 @@ ipmi_dcmi_prnt_getcapabilities(struct ipmi_intf * intf, uint8_t selector)
/* loop through each of the entries in the first byte from the
* struct
*/
- printf("\n Mandatory platform capabilties\n");
- display_capabilities_attributes(
- dcmi_mandatory_platform_capabilities, cape.data_byte1);
+ printf("\n Mandatory platform capabilities\n");
+ display_capabilities_attributes(dcmi_mandatory_platform_capabilities,
+ cape.data_byte1);
/* loop through each of the entries in the second byte from the
* struct
*/
- printf("\n Optional platform capabilties\n");
- display_capabilities_attributes(
- dcmi_optional_platform_capabilities, cape.data_byte2);
+ printf("\n Optional platform capabilities\n");
+ display_capabilities_attributes(dcmi_optional_platform_capabilities,
+ cape.data_byte2);
/* loop through each of the entries in the third byte from the
* struct
*/
- printf("\n Managebility access capabilties\n");
- display_capabilities_attributes(
- dcmi_management_access_capabilities, cape.data_byte3);
+ printf("\n Managebility access capabilities\n");
+ display_capabilities_attributes(dcmi_management_access_capabilities,
+ cape.data_byte3);
break;
case 0x02:
printf("\n Mandatory platform attributes:\n");
@@ -885,12 +946,12 @@ ipmi_dcmi_prnt_getcapabilities(struct ipmi_intf * intf, uint8_t selector)
printf("\n %d SEL entries\n", sel_entries & 0xFFF);
/* byte 3 data */
printf("\n Identification Attributes: \n");
- display_capabilities_attributes(
- dcmi_id_capabilities_vals, cape.data_byte3);
+ display_capabilities_attributes(dcmi_id_capabilities_vals,
+ cape.data_byte3);
/* byte 4 data */
printf("\n Temperature Monitoring Attributes: \n");
display_capabilities_attributes(dcmi_temp_monitoring_vals,
- cape.data_byte4);
+ cape.data_byte4);
break;
case 0x03:
printf("\n Optional Platform Attributes: \n");
@@ -900,19 +961,19 @@ ipmi_dcmi_prnt_getcapabilities(struct ipmi_intf * intf, uint8_t selector)
printf(" Slave address of device: 20h (BMC)\n" );
} else {
printf(" Slave address of device: %xh (8bits)"
- "(Satellite/External controller)\n",
- cape.data_byte1);
+ "(Satellite/External controller)\n",
+ cape.data_byte1);
}
/* Controller channel number (4-7) bits */
if ((cape.data_byte2>>4) == 0x00) {
printf(" Channel number is 0h (Primary BMC)\n");
} else {
printf(" Channel number is %xh \n",
- (cape.data_byte2>>4));
+ (cape.data_byte2 >> 4));
}
/* Device revision (0-3) */
printf(" Device revision is %d \n",
- cape.data_byte2 &0xf);
+ cape.data_byte2 & 0xf);
break;
case 0x04:
/* LAN */
@@ -921,20 +982,20 @@ ipmi_dcmi_prnt_getcapabilities(struct ipmi_intf * intf, uint8_t selector)
printf(" Primary LAN channel is not available for OOB\n");
} else {
printf(" Primary LAN channel number: %d is available\n",
- cape.data_byte1);
+ cape.data_byte1);
}
if (cape.data_byte2 == 0xFF) {
printf(" Secondary LAN channel is not available for OOB\n");
} else {
printf(" Secondary LAN channel number: %d is available\n",
- cape.data_byte2);
+ cape.data_byte2);
}
/* serial */
if (cape.data_byte3 == 0xFF) {
printf(" No serial channel is available\n");
} else {
printf(" Serial channel number: %d is available\n",
- cape.data_byte3);
+ cape.data_byte3);
}
break;
case 0x05:
@@ -943,7 +1004,7 @@ ipmi_dcmi_prnt_getcapabilities(struct ipmi_intf * intf, uint8_t selector)
printf(" DCMI Specification %d.%d\n", reply[1], reply[2]);
printf(" Rolling average time period options: %d\n", reply[4]);
printf(" Sample time options: ");
- for (j = 1; dcmi_sampling_vals[j-1].str != NULL; j++)
+ for (j = 1; dcmi_sampling_vals[j-1].str; j++)
printf(" %s ", val2str2(reply[4+j],dcmi_sampling_vals));
printf("\n");
break;
@@ -1008,13 +1069,14 @@ ipmi_dcmi_prnt_getassettag(struct ipmi_intf * intf)
taglength = rsp->data[1];
printf("\n Asset tag: ");
while (taglength) {
- getlength = taglength / DCMI_MAX_BYTE_SIZE ?
- DCMI_MAX_BYTE_SIZE : taglength%DCMI_MAX_BYTE_SIZE;
+ /* TODO: Add parentheses for clarity */
+ getlength = taglength / DCMI_MAX_BYTE_SIZE ? DCMI_MAX_BYTE_SIZE
+ : taglength % DCMI_MAX_BYTE_SIZE;
rsp = ipmi_dcmi_getassettag(intf, offset, getlength);
/* macro has no effect here where can generate sig segv
* if rsp occurs with null
*/
- if (rsp != NULL) {
+ if (rsp) {
GOOD_ASSET_TAG_CCODE(rsp->ccode);
}
if (chk_rsp(rsp)) {
@@ -1081,8 +1143,9 @@ ipmi_dcmi_prnt_setassettag(struct ipmi_intf * intf, uint8_t * data)
}
printf("\n Set Asset Tag: ");
while (taglength) {
- getlength = taglength / DCMI_MAX_BYTE_SIZE ?
- DCMI_MAX_BYTE_SIZE : taglength%DCMI_MAX_BYTE_SIZE;
+ /* TODO: Use a macro or an inline for this repeating calculation */
+ getlength = taglength / DCMI_MAX_BYTE_SIZE ? DCMI_MAX_BYTE_SIZE
+ : taglength % DCMI_MAX_BYTE_SIZE;
memcpy(tmpData, data + offset, getlength);
rsp = ipmi_dcmi_setassettag(intf, offset, getlength, tmpData);
if (chk_rsp(rsp)) {
@@ -1146,8 +1209,9 @@ ipmi_dcmi_prnt_getmngctrlids(struct ipmi_intf * intf)
printf("\n Get Management Controller Identifier String: ");
while (taglength) {
- getlength = taglength / DCMI_MAX_BYTE_SIZE ?
- DCMI_MAX_BYTE_SIZE : taglength%DCMI_MAX_BYTE_SIZE;
+ /* TODO: Use a macro or an inline for this repeating calculation */
+ getlength = taglength / DCMI_MAX_BYTE_SIZE ? DCMI_MAX_BYTE_SIZE
+ : taglength % DCMI_MAX_BYTE_SIZE;
rsp = ipmi_dcmi_getmngctrlids(intf, offset, getlength);
if (chk_rsp(rsp)) {
@@ -1223,14 +1287,15 @@ ipmi_dcmi_prnt_setmngctrlids(struct ipmi_intf * intf, uint8_t * data)
printf("\n Set Management Controller Identifier String Command: ");
while (taglength) {
- getlength = taglength / DCMI_MAX_BYTE_SIZE ?
- DCMI_MAX_BYTE_SIZE : taglength%DCMI_MAX_BYTE_SIZE;
+ /* TODO: Use a macro or an inline for this repeating calculation */
+ getlength = taglength / DCMI_MAX_BYTE_SIZE ? DCMI_MAX_BYTE_SIZE
+ : taglength % DCMI_MAX_BYTE_SIZE;
memcpy(tmpData, data + offset, getlength);
rsp = ipmi_dcmi_setmngctrlids(intf, offset, getlength, tmpData);
/* because after call "Set mc id string" RMCP+ will go down
* we have no "rsp"
*/
- if (strncmp(intf->name, "lanplus", 7)) {
+ if (strcmp(intf->name, "lanplus")) {
if (chk_rsp(rsp)) {
return -1;
}
@@ -1250,7 +1315,7 @@ ipmi_dcmi_prnt_setmngctrlids(struct ipmi_intf * intf, uint8_t * data)
*
* @intf: ipmi interface handler
* @isnsr: entity ID
- * @offset: offset (Entity instace start)
+ * @offset: offset (Entity instance start)
*
* returns ipmi_rs structure
*/
@@ -1264,7 +1329,7 @@ ipmi_dcmi_discvry_snsr(struct ipmi_intf * intf, uint8_t isnsr, uint8_t offset)
msg_data[1] = 0x01; /* Senser Type = Temp (01h) */
msg_data[2] = isnsr; /* Sensor Number */
msg_data[3] = 0x00; /* Entity Instance, set to read all instances */
- msg_data[4] = offset; /* Entity instace start */
+ msg_data[4] = offset; /* Entity instance start */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_DCGRP;
@@ -1299,9 +1364,9 @@ ipmi_dcmi_prnt_discvry_snsr(struct ipmi_intf * intf, uint8_t isnsr)
}
instances = rsp->data[1];
printf("\n%s: %d temperature sensor%s found:\n",
- val2str2(isnsr, dcmi_discvry_snsr_vals),
- instances,
- (instances > 1) ? "s" : "");
+ val2str2(isnsr, dcmi_discvry_snsr_vals),
+ instances,
+ (instances > 1) ? "s" : "");
while(instances > 0) {
ipmi_dcmi_discvry_snsr(intf, isnsr, offset);
if (chk_rsp(rsp)) {
@@ -1335,11 +1400,7 @@ ipmi_dcmi_pwr_rd(struct ipmi_intf * intf, uint8_t sample_time)
struct ipmi_rs * rsp;
struct ipmi_rq req;
struct power_reading val;
- struct tm tm_t;
- time_t t;
uint8_t msg_data[4]; /* number of request data bytes */
- memset(&tm_t, 0, sizeof(tm_t));
- memset(&t, 0, sizeof(t));
msg_data[0] = IPMI_DCMI; /* Group Extension Identification */
if (sample_time) {
@@ -1365,19 +1426,17 @@ ipmi_dcmi_pwr_rd(struct ipmi_intf * intf, uint8_t sample_time)
/* rsp->data[0] is equal to response data byte 2 in spec */
/* printf("Group Extension Identification: %02x\n", rsp->data[0]); */
memcpy(&val, rsp->data, sizeof (val));
- t = val.time_stamp;
- gmtime_r(&t, &tm_t);
printf("\n");
printf(" Instantaneous power reading: %8d Watts\n",
- val.curr_pwr);
+ val.curr_pwr);
printf(" Minimum during sampling period: %8d Watts\n",
- val.min_sample);
+ val.min_sample);
printf(" Maximum during sampling period: %8d Watts\n",
- val.max_sample);
+ val.max_sample);
printf(" Average power reading over sample period: %8d Watts\n",
- val.avg_pwr);
+ val.avg_pwr);
printf(" IPMI timestamp: %s",
- asctime(&tm_t));
+ ipmi_timestamp_numeric(ipmi32toh(&val.time_stamp)));
printf(" Sampling period: ");
if (sample_time)
printf("%s \n", val2str2(val.sample,dcmi_sampling_vals));
@@ -1428,16 +1487,16 @@ ipmi_dcmi_getthermalpolicy(struct ipmi_intf * intf, uint8_t entityID,
memcpy(&val, rsp->data, sizeof (val));
printf("\n");
printf(" Persistence flag is: %s\n",
- ((val.exceptionActions & 0x80) ? "set" : "notset"));
+ ((val.exceptionActions & 0x80) ? "set" : "notset"));
printf(" Exception Actions, taken if the Temperature Limit exceeded:\n");
printf(" Hard Power Off system and log event: %s\n",
- ((val.exceptionActions & 0x40) ? "active":"inactive"));
+ ((val.exceptionActions & 0x40) ? "active":"inactive"));
printf(" Log event to SEL only: %s\n",
- ((val.exceptionActions & 0x20) ? "active":"inactive"));
+ ((val.exceptionActions & 0x20) ? "active":"inactive"));
printf(" Temperature Limit %d degrees\n",
- val.tempLimit);
+ val.tempLimit);
printf(" Exception Time %d seconds\n",
- val.exceptionTime);
+ val.exceptionTime);
printf("\n\n");
return 0;
}
@@ -1448,14 +1507,14 @@ ipmi_dcmi_getthermalpolicy(struct ipmi_intf * intf, uint8_t entityID,
*/
int
ipmi_dcmi_setthermalpolicy(struct ipmi_intf * intf,
- uint8_t entityID,
- uint8_t entityInst,
- uint8_t persistanceFlag,
- uint8_t actionHardPowerOff,
- uint8_t actionLogToSEL,
- uint8_t tempLimit,
- uint8_t samplingTimeLSB,
- uint8_t samplingTimeMSB)
+ uint8_t entityID,
+ uint8_t entityInst,
+ uint8_t persistanceFlag,
+ uint8_t actionHardPowerOff,
+ uint8_t actionLogToSEL,
+ uint8_t tempLimit,
+ uint8_t samplingTimeLSB,
+ uint8_t samplingTimeMSB)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -1464,10 +1523,10 @@ ipmi_dcmi_setthermalpolicy(struct ipmi_intf * intf,
msg_data[0] = IPMI_DCMI; /* Group Extension Identification */
msg_data[1] = entityID; /* Inlet Temperature DCMI ID*/
msg_data[2] = entityInst; /* Entity Instance */
- /* persistance and actions or disabled if no actions */
+ /* persistence and actions or disabled if no actions */
msg_data[3] = (((persistanceFlag ? 1 : 0) << 7) |
- ((actionHardPowerOff? 1 : 0) << 6) |
- ((actionLogToSEL ? 1 : 0) << 5));
+ ((actionHardPowerOff? 1 : 0) << 6) |
+ ((actionLogToSEL ? 1 : 0) << 5));
msg_data[4] = tempLimit;
msg_data[5] = samplingTimeLSB;
msg_data[6] = samplingTimeMSB;
@@ -1486,7 +1545,7 @@ ipmi_dcmi_setthermalpolicy(struct ipmi_intf * intf,
}
/* rsp->data[0] is equal to response data byte 2 in spec */
printf("\nThermal policy %d for %0Xh entity successfully set.\n\n",
- entityInst, entityID);
+ entityInst, entityID);
return 0;
}
@@ -1498,9 +1557,9 @@ ipmi_dcmi_setthermalpolicy(struct ipmi_intf * intf,
*/
struct ipmi_rs *
ipmi_dcmi_get_temp_readings(struct ipmi_intf * intf,
- uint8_t entityID,
- uint8_t entityInst,
- uint8_t entityInstStart)
+ uint8_t entityID,
+ uint8_t entityInst,
+ uint8_t entityInstStart)
{
struct ipmi_rq req;
uint8_t msg_data[5]; /* number of request data bytes */
@@ -1527,10 +1586,11 @@ ipmi_dcmi_prnt_get_temp_readings(struct ipmi_intf * intf)
int i,j, tota_inst, get_inst, offset = 0;
/* Print sensor description */
printf("\n\tEntity ID\t\t\tEntity Instance\t Temp. Readings");
- for (i = 0; dcmi_temp_read_vals[i].str != NULL; i++) {
+ for (i = 0; dcmi_temp_read_vals[i].str; i++) {
/* get all of the information about this sensor */
rsp = ipmi_dcmi_get_temp_readings(intf,
- dcmi_temp_read_vals[i].val, 0, 0);
+ dcmi_temp_read_vals[i].val,
+ 0, 0);
if (chk_rsp(rsp)) {
continue;
}
@@ -1539,10 +1599,11 @@ ipmi_dcmi_prnt_get_temp_readings(struct ipmi_intf * intf)
tota_inst = rsp->data[1];
while (tota_inst > 0) {
get_inst = ((tota_inst / DCMI_MAX_BYTE_TEMP_READ_SIZE) ?
- DCMI_MAX_BYTE_TEMP_READ_SIZE :
- (tota_inst % DCMI_MAX_BYTE_TEMP_READ_SIZE));
+ DCMI_MAX_BYTE_TEMP_READ_SIZE :
+ (tota_inst % DCMI_MAX_BYTE_TEMP_READ_SIZE));
rsp = ipmi_dcmi_get_temp_readings(intf,
- dcmi_temp_read_vals[i].val, offset, 0);
+ dcmi_temp_read_vals[i].val,
+ offset, 0);
if (chk_rsp(rsp)) {
continue;
}
@@ -1553,8 +1614,9 @@ ipmi_dcmi_prnt_get_temp_readings(struct ipmi_intf * intf)
/* Print Instance temperature info */
printf("\n%s",dcmi_temp_read_vals[i].desc);
printf("\t\t%i\t\t%c%i C", rsp->data[j+4],
- ((rsp->data[j+3]) >> 7) ?
- '-' : '+', (rsp->data[j+3] & 127));
+ ((rsp->data[j+3]) >> 7) ? '-'
+ : '+',
+ (rsp->data[j+3] & 127));
}
offset += get_inst;
tota_inst -= get_inst;
@@ -1599,8 +1661,10 @@ ipmi_dcmi_prnt_getconfparam(struct ipmi_intf * intf)
int param_selector;
uint16_t tmp_value = 0;
/* We are not interested in parameter 1 which always will return 0 */
- for (param_selector = 2 ; param_selector <= dcmi_conf_params;
- param_selector++) {
+ for (param_selector = 2;
+ param_selector <= dcmi_conf_params;
+ param_selector++)
+ {
rsp = ipmi_dcmi_getconfparam(intf, param_selector);
if (chk_rsp(rsp)) {
return -1;
@@ -1611,9 +1675,10 @@ ipmi_dcmi_prnt_getconfparam(struct ipmi_intf * intf)
tmp_value = (rsp->data[4])& 1;
printf("\n\tDHCP Discovery method\t: ");
printf("\n\t\tManagement Controller ID String is %s",
- tmp_value ? "enabled" : "disabled");
- printf("\n\t\tVendor class identifier DCMI IANA and Vendor class-specific Informationa are %s",
- ((rsp->data[4])& 2) ? "enabled" : "disabled" );
+ tmp_value ? "enabled" : "disabled");
+ printf("\n\t\tVendor class identifier DCMI IANA and Vendor "
+ "class-specific Informationa are %s",
+ ((rsp->data[4])& 2) ? "enabled" : "disabled" );
break;
case 3:
printf("\n\tInitial timeout interval\t: %i seconds",
@@ -1621,11 +1686,11 @@ ipmi_dcmi_prnt_getconfparam(struct ipmi_intf * intf)
break;
case 4:
printf("\n\tServer contact timeout interval\t: %i seconds",
- rsp->data[4] + (rsp->data[5]<<8));
+ rsp->data[4] + (rsp->data[5]<<8));
break;
case 5:
printf("\n\tServer contact retry interval\t: %i seconds",
- rsp->data[4] + (rsp->data[5] << 8));
+ rsp->data[4] + (rsp->data[5] << 8));
break;
default:
printf("\n\tConfiguration Parameter not supported.");
@@ -1724,7 +1789,7 @@ ipmi_dcmi_pwr_prnt_glimit(struct ipmi_intf * intf)
/* rsp can be a null so check response before any operation
* on it to avoid sig segv
*/
- if (rsp != NULL) {
+ if (rsp) {
realCc = rsp->ccode;
GOOD_PWR_GLIMIT_CCODE(rsp->ccode);
}
@@ -1735,10 +1800,10 @@ ipmi_dcmi_pwr_prnt_glimit(struct ipmi_intf * intf)
/* printf("Group Extension Identification: %02x\n", rsp->data[0]); */
memcpy(&val, rsp->data, sizeof (val));
printf("\n Current Limit State: %s\n",
- (realCc == 0) ?
- "Power Limit Active" : "No Active Power Limit");
+ (realCc == 0) ?
+ "Power Limit Active" : "No Active Power Limit");
printf(" Exception actions: %s\n",
- val2str2(val.action, dcmi_pwrmgmt_get_action_vals));
+ val2str2(val.action, dcmi_pwrmgmt_get_action_vals));
printf(" Power Limit: %i Watts\n", val.limit);
printf(" Correction time: %i milliseconds\n", val.correction);
printf(" Sampling period: %i seconds\n", val.sample);
@@ -1772,7 +1837,7 @@ ipmi_dcmi_pwr_slimit(struct ipmi_intf * intf, const char * option,
/* rsp can be a null so check response before any operation on it to
* avoid sig segv
*/
- if (rsp != NULL) {
+ if (rsp) {
GOOD_PWR_GLIMIT_CCODE(rsp->ccode);
}
if (chk_rsp(rsp)) {
@@ -1796,8 +1861,8 @@ ipmi_dcmi_pwr_slimit(struct ipmi_intf * intf, const char * option,
* val.sample = *(uint16_t*)(&rsp->data[12]);
*/
lprintf(LOG_INFO,
- "DCMI IN Limit=%d Correction=%d Action=%d Sample=%d\n",
- val.limit, val.correction, val.action, val.sample);
+ "DCMI IN Limit=%d Correction=%d Action=%d Sample=%d\n",
+ val.limit, val.correction, val.action, val.sample);
switch (str2val2(option, dcmi_pwrmgmt_set_usage_vals)) {
case 0x00:
/* action */
@@ -1877,7 +1942,7 @@ ipmi_dcmi_pwr_slimit(struct ipmi_intf * intf, const char * option,
case 0xFF:
/* error - not a string we knew what to do with */
lprintf(LOG_ERR, "Given %s '%s' is invalid.",
- option, value);
+ option, value);
return -1;
}
break;
@@ -1885,7 +1950,7 @@ ipmi_dcmi_pwr_slimit(struct ipmi_intf * intf, const char * option,
/* limit */
if (str2uint(value, &lvalue) != 0) {
lprintf(LOG_ERR, "Given %s '%s' is invalid.",
- option, value);
+ option, value);
return (-1);
}
val.limit = *(uint16_t*)(&lvalue);
@@ -1894,7 +1959,7 @@ ipmi_dcmi_pwr_slimit(struct ipmi_intf * intf, const char * option,
/* correction */
if (str2uint(value, &lvalue) != 0) {
lprintf(LOG_ERR, "Given %s '%s' is invalid.",
- option, value);
+ option, value);
return (-1);
}
val.correction = *(uint32_t*)(&lvalue);
@@ -1903,7 +1968,7 @@ ipmi_dcmi_pwr_slimit(struct ipmi_intf * intf, const char * option,
/* sample */
if (str2uint(value, &lvalue) != 0) {
lprintf(LOG_ERR, "Given %s '%s' is invalid.",
- option, value);
+ option, value);
return (-1);
}
val.sample = *(uint16_t*)(&lvalue);
@@ -2024,7 +2089,8 @@ _ipmi_nm_discover(struct ipmi_intf * intf, struct nm_discover *disc)
* @caps: fills in capability struct
*/
static int
-_ipmi_nm_getcapabilities(struct ipmi_intf * intf, uint8_t domain, uint8_t trigger, struct nm_capability *caps)
+_ipmi_nm_getcapabilities(struct ipmi_intf * intf, uint8_t domain,
+ uint8_t trigger, struct nm_capability *caps)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2049,7 +2115,8 @@ _ipmi_nm_getcapabilities(struct ipmi_intf * intf, uint8_t domain, uint8_t trigge
}
static int
-_ipmi_nm_get_policy(struct ipmi_intf * intf, uint8_t domain, uint8_t policy_id, struct nm_get_policy *policy)
+_ipmi_nm_get_policy(struct ipmi_intf * intf, uint8_t domain,
+ uint8_t policy_id, struct nm_get_policy *policy)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2083,7 +2150,9 @@ _ipmi_nm_set_policy(struct ipmi_intf * intf, struct nm_policy *policy)
req.msg.cmd = IPMI_NM_SET_POLICY;
req.msg.data = (uint8_t *)policy;
req.msg.data_len = sizeof(struct nm_policy);
- policy->intel_id[0] = 0x57; policy->intel_id[1] =1; policy->intel_id[2] =0;
+ policy->intel_id[0] = 0x57;
+ policy->intel_id[1] = 1;
+ policy->intel_id[2] = 0;
rsp = intf->sendrecv(intf, &req);
if (chk_nm_rsp(rsp)) {
return -1;
@@ -2117,7 +2186,8 @@ _ipmi_nm_policy_limiting(struct ipmi_intf * intf, uint8_t domain)
}
static int
-_ipmi_nm_control(struct ipmi_intf * intf, uint8_t scope, uint8_t domain, uint8_t policy_id)
+_ipmi_nm_control(struct ipmi_intf * intf, uint8_t scope,
+ uint8_t domain, uint8_t policy_id)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2151,7 +2221,8 @@ _ipmi_nm_control(struct ipmi_intf * intf, uint8_t scope, uint8_t domain, uint8_t
* @selector: Parameter selector
*/
static int
-_ipmi_nm_statistics(struct ipmi_intf * intf, uint8_t mode, uint8_t domain, uint8_t policy_id, struct nm_statistics *caps)
+_ipmi_nm_statistics(struct ipmi_intf * intf, uint8_t mode, uint8_t domain,
+ uint8_t policy_id, struct nm_statistics *caps)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2177,7 +2248,8 @@ _ipmi_nm_statistics(struct ipmi_intf * intf, uint8_t mode, uint8_t domain, uint8
}
static int
-_ipmi_nm_reset_stats(struct ipmi_intf * intf, uint8_t mode, uint8_t domain, uint8_t policy_id)
+_ipmi_nm_reset_stats(struct ipmi_intf * intf, uint8_t mode,
+ uint8_t domain, uint8_t policy_id)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2202,7 +2274,8 @@ _ipmi_nm_reset_stats(struct ipmi_intf * intf, uint8_t mode, uint8_t domain, uint
}
static int
-_nm_set_range(struct ipmi_intf * intf, uint8_t domain, uint16_t minimum, uint16_t maximum)
+_nm_set_range(struct ipmi_intf * intf, uint8_t domain,
+ uint16_t minimum, uint16_t maximum)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2284,7 +2357,8 @@ _ipmi_nm_set_alert(struct ipmi_intf * intf, struct nm_set_alert *alert)
* This array is filled in for valid thresholds returned.
*/
static int
-_ipmi_nm_get_thresh(struct ipmi_intf * intf, uint8_t domain, uint8_t policy_id, uint16_t *list)
+_ipmi_nm_get_thresh(struct ipmi_intf * intf, uint8_t domain,
+ uint8_t policy_id, uint16_t *list)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2357,7 +2431,8 @@ _ipmi_nm_set_thresh(struct ipmi_intf * intf, struct nm_thresh * thresh)
*
*/
static int
-_ipmi_nm_get_suspend(struct ipmi_intf * intf, uint8_t domain, uint8_t policy_id, int *count, struct nm_period *periods)
+_ipmi_nm_get_suspend(struct ipmi_intf * intf, uint8_t domain,
+ uint8_t policy_id, int *count, struct nm_period *periods)
{
struct ipmi_rq req; /* request data to send to the BMC */
struct ipmi_rs *rsp;
@@ -2400,9 +2475,12 @@ _ipmi_nm_set_suspend(struct ipmi_intf * intf, struct nm_suspend *suspend)
msg_data[1] = 1;
msg_data[2] = 0;
msg_data[3] = suspend->domain;
- msg_data[4] = suspend->policy_id;
+ msg_data[4] = suspend->policy_id;
msg_data[5] = suspend->count;
- for (i = 0, periods = &suspend->period[0]; i < (suspend->count*3); i += 3, periods++) {
+ for (i = 0, periods = &suspend->period[0];
+ i < (suspend->count*3);
+ i += 3, periods++)
+ {
msg_data[6+i] = periods->start;
msg_data[7+i] = periods->stop;
msg_data[8+i] = periods->repeat;
@@ -2412,8 +2490,8 @@ _ipmi_nm_set_suspend(struct ipmi_intf * intf, struct nm_suspend *suspend)
req.msg.netfn = IPMI_NETFN_OEM;
req.msg.cmd = IPMI_NM_SET_SUSPEND;
req.msg.data = msg_data;
- rsp = intf->sendrecv(intf, &req);
- if (chk_nm_rsp(rsp)) {
+ rsp = intf->sendrecv(intf, &req);
+ if (chk_nm_rsp(rsp)) {
return -1;
}
return 0;
@@ -2427,9 +2505,9 @@ ipmi_nm_getcapabilities(struct ipmi_intf * intf, int argc, char **argv)
uint8_t trigger = 0; /* default power policy (no trigger) */
struct nm_capability caps;
- while (--argc > 0) {
+ while (--argc > 0) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if ((option = str2val2(argv[0], nm_capability_opts)) == 0xFF) {
print_strs(nm_capability_opts, "Capability commands", LOG_ERR, 0);
return -1;
@@ -2465,35 +2543,35 @@ ipmi_nm_getcapabilities(struct ipmi_intf * intf, int argc, char **argv)
return -1;
if (csv_output) {
printf("%d,%u,%u,%u,%u,%u,%u,%s\n",
- caps.max_settings, caps.max_value,caps.min_value,
- caps.min_corr/1000, caps.max_corr/1000,
- caps.min_stats, caps.max_stats,
- val2str2(caps.scope&0xF, nm_domain_vals));
+ caps.max_settings, caps.max_value,caps.min_value,
+ caps.min_corr/1000, caps.max_corr/1000,
+ caps.min_stats, caps.max_stats,
+ val2str2(caps.scope&0xF, nm_domain_vals));
return 0;
}
printf(" power policies:\t\t%d\n", caps.max_settings);
switch (trigger&0xF) {
case 0: /* power */
printf(" max_power\t\t%7u Watts\n min_power\t\t%7u Watts\n",
- caps.max_value, caps.min_value);
+ caps.max_value, caps.min_value);
break;
case 1: /* Inlet */
printf(" max_temp\t\t%7u C\n min_temp\t\t%7u C\n",
- caps.max_value, caps.min_value);
+ caps.max_value, caps.min_value);
break;
case 2: /* Missing reading time */
case 3: /* Time after host reset */
printf(" max_time\t\t%7u Secs\n min_time\t\t%7u Secs\n",
- caps.max_value/10, caps.min_value/10);
+ caps.max_value/10, caps.min_value/10);
break;
case 4: /* boot time policy does not use these values */
default:
break;
}
printf(" min_corr\t\t%7u secs\n max_corr\t\t%7u secs\n",
- caps.min_corr/1000, caps.max_corr/1000);
+ caps.min_corr/1000, caps.max_corr/1000);
printf(" min_stats\t\t%7u secs\n max_stats\t\t%7u secs\n",
- caps.min_stats, caps.max_stats);
+ caps.min_stats, caps.max_stats);
printf(" domain scope:\t%s\n", val2str2(caps.scope&0xF, nm_domain_vals));
return 0;
}
@@ -2504,13 +2582,14 @@ ipmi_nm_get_policy(struct ipmi_intf * intf, int argc, char **argv)
uint8_t option;
uint8_t domain = 0; /* default domain of platform */
uint8_t policy_id = -1;
+ uint8_t have_policy_id = FALSE;
struct nm_get_policy policy;
memset(&policy, 0, sizeof(policy));
while (--argc) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if ((option = str2val2(argv[0], nm_policy_options)) == 0xFF) {
print_strs(nm_policy_options, "Get Policy commands", LOG_ERR, 0);
return -1;
@@ -2525,9 +2604,10 @@ ipmi_nm_get_policy(struct ipmi_intf * intf, int argc, char **argv)
break;
case 0x0B: /* policy id */
if (str2uchar(argv[1], &policy_id) < 0) {
- lprintf(LOG_ERR," Policy ID must be a positive integer 0-7.\n");
+ lprintf(LOG_ERR," Policy ID must be a positive integer (0-255)\n");
return -1;
}
+ have_policy_id = TRUE;
break;
default:
printf(" Unknown command 0x%x, skipping.\n", option);
@@ -2536,53 +2616,54 @@ ipmi_nm_get_policy(struct ipmi_intf * intf, int argc, char **argv)
argc--;
argv++;
}
- if (policy_id == 0xFF) {
+ if (!have_policy_id) {
print_strs(nm_stats_opts, "Missing policy_id parameter:", LOG_ERR, 0);
- return -1;
- }
+ return -1;
+ }
if (_ipmi_nm_get_policy(intf, policy.domain, policy_id, &policy))
return -1;
if (csv_output) {
printf("%s,0x%x,%s,%s,%s,%u,%u,%u,%u,%s\n",
- val2str2(policy.domain&0xF, nm_domain_vals),
- policy.domain,
- (policy.policy_type & 0x10) ? "power" : "nopower ",
- val2str2(policy.policy_type & 0xF, nm_policy_type_vals),
- val2str2(policy.policy_exception, nm_exception),
- policy.policy_limits,
- policy.corr_time,
- policy.trigger_limit,
- policy.stats_period,
- policy.policy_type & 0x80 ? "volatile" : "non-volatile");
+ val2str2(policy.domain&0xF, nm_domain_vals),
+ policy.domain,
+ (policy.policy_type & 0x10) ? "power" : "nopower ",
+ val2str2(policy.policy_type & 0xF, nm_policy_type_vals),
+ val2str2(policy.policy_exception, nm_exception),
+ policy.policy_limits,
+ policy.corr_time,
+ policy.trigger_limit,
+ policy.stats_period,
+ policy.policy_type & 0x80 ? "volatile" : "non-volatile");
return 0;
}
printf(" Power domain: %s\n",
- val2str2(policy.domain&0xF, nm_domain_vals));
+ val2str2(policy.domain&0xF, nm_domain_vals));
printf(" Policy is %s %s%s%s\n",
- policy.domain&0x10 ? "enabled" : "not enabled",
- policy.domain&0x20 ? "per Domain " : "",
- policy.domain&0x40 ? "Globally " : "",
- policy.domain&0x80 ? "via DCMI api " : "");
- printf(" Policy is %sa power control type.\n", (policy.policy_type & 0x10) ? "" : "not ");
+ policy.domain&0x10 ? "enabled" : "not enabled",
+ policy.domain&0x20 ? "per Domain " : "",
+ policy.domain&0x40 ? "Globally " : "",
+ policy.domain&0x80 ? "via DCMI api " : "");
+ printf(" Policy is %sa power control type.\n",
+ (policy.policy_type & 0x10) ? "" : "not ");
printf(" Policy Trigger Type: %s\n",
- val2str2(policy.policy_type & 0xF, nm_policy_type_vals));
+ val2str2(policy.policy_type & 0xF, nm_policy_type_vals));
printf(" Correction Aggressiveness: %s\n",
- val2str2((policy.policy_type>> 5) & 0x3, nm_correction_vals));
+ val2str2((policy.policy_type>> 5) & 0x3, nm_correction_vals));
printf(" Policy Exception Actions: %s\n",
- val2str2(policy.policy_exception, nm_exception));
+ val2str2(policy.policy_exception, nm_exception));
printf(" Power Limit: %u Watts\n",
- policy.policy_limits);
+ policy.policy_limits);
printf(" Correction Time Limit: %u milliseconds\n",
- policy.corr_time);
+ policy.corr_time);
printf(" Trigger Limit: %u units\n",
- policy.trigger_limit);
+ policy.trigger_limit);
printf(" Statistics Reporting Period: %u seconds\n",
- policy.stats_period);
+ policy.stats_period);
printf(" Policy retention: %s\n",
- policy.policy_type & 0x80 ? "volatile" : "non-volatile");
+ policy.policy_type & 0x80 ? "volatile" : "non-volatile");
if ( (policy_id == 0) && ((policy.domain & 0xf) == 0x3) )
printf(" HW Prot Power domain: %s\n",
- policy.policy_type & 0x80 ? "Secondary" : "Primary");
+ policy.policy_type & 0x80 ? "Secondary" : "Primary");
return 0;
}
@@ -2594,6 +2675,7 @@ ipmi_nm_policy(struct ipmi_intf * intf, int argc, char **argv)
uint8_t correction;
uint8_t domain = 0; /* default domain of platform */
uint8_t policy_id = -1;
+ uint8_t have_policy_id = FALSE;
uint16_t power, period, inlet;
uint16_t cores;
uint32_t limit;
@@ -2601,8 +2683,9 @@ ipmi_nm_policy(struct ipmi_intf * intf, int argc, char **argv)
argv++;
argc--;
- if ((argv[0] == NULL) ||
- ((action = str2val2(argv[0], nm_policy_action)) == 0xFF)) {
+ if (!argv[0] ||
+ 0xFF == (action = str2val2(argv[0], nm_policy_action)))
+ {
print_strs(nm_policy_action, "Policy commands", LOG_ERR, 0);
return -1;
}
@@ -2610,13 +2693,15 @@ ipmi_nm_policy(struct ipmi_intf * intf, int argc, char **argv)
return (ipmi_nm_get_policy(intf, argc, argv));
memset(&policy, 0, sizeof(policy));
/*
- * nm policy add [domain <param>] enable|disable policy_id <param> correction <opt> power <watts> limit <param> period <param>
+ * nm policy add [domain <param>] enable|disable policy_id <param>
+ * correction <opt> power <watts> limit <param>
+ * period <param>
* nm policy remove [domain <param>] policy_id <param>
* nm policy limiting {domain <param>]
*/
while (--argc > 0) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if ((option = str2val2(argv[0], nm_policy_options)) == 0xFF) {
print_strs(nm_policy_options, "Policy options", LOG_ERR, 0);
return -1;
@@ -2676,10 +2761,11 @@ ipmi_nm_policy(struct ipmi_intf * intf, int argc, char **argv)
break;
case 0x0B: /* policy ID */
if (str2uchar(argv[1], &policy_id) < 0) {
- printf("Policy ID must be a positive integer 0-7.\n");
+ printf("Policy ID must be a positive integer (0-255)\n");
return -1;
}
policy.policy_id = policy_id;
+ have_policy_id = TRUE;
break;
case 0x0C: /* volatile */
policy.policy_type |= 0x80;
@@ -2709,7 +2795,7 @@ ipmi_nm_policy(struct ipmi_intf * intf, int argc, char **argv)
printf("limit %x\n", limit);
return 0;
}
- if (policy_id == 0xFF) {
+ if (!have_policy_id) {
print_strs(nm_stats_opts, "Missing policy_id parameter:", LOG_ERR, 0);
return -1;
}
@@ -2728,12 +2814,14 @@ ipmi_nm_control(struct ipmi_intf * intf, int argc, char **argv)
uint8_t scope = 0; /* default control scope of global */
uint8_t domain = 0; /* default domain of platform */
uint8_t policy_id = -1;
+ uint8_t have_policy_id = FALSE;
argv++;
argc--;
/* nm_ctl_cmds returns 0 for disable, 1 for enable */
- if ((argv[0] == NULL) ||
- ((action = str2val2(argv[0], nm_ctl_cmds)) == 0xFF)) {
+ if (!argv[0] ||
+ 0xFF == (action = str2val2(argv[0], nm_ctl_cmds)))
+ {
print_strs(nm_ctl_cmds, "Control parameters:", LOG_ERR, 0);
print_strs(nm_ctl_domain, "control Scope (required):", LOG_ERR, 0);
return -1;
@@ -2741,30 +2829,31 @@ ipmi_nm_control(struct ipmi_intf * intf, int argc, char **argv)
argv++;
while (--argc) {
/* nm_ctl_domain returns correct bit field except for action */
- if ((argv[0] == NULL) ||
- ((scope = str2val2(argv[0], nm_ctl_domain)) == 0xFF)) {
+ if (!argv[0] ||
+ 0xFF == (scope = str2val2(argv[0], nm_ctl_domain)))
+ {
print_strs(nm_ctl_domain, "Control Scope (required):", LOG_ERR, 0);
return -1;
}
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if (scope == 0x02) { /* domain */
if ((domain = str2val2(argv[0], nm_domain_vals)) == 0xFF) {
print_strs(nm_domain_vals, "Domain Scope:", LOG_ERR, 0);
return -1;
}
} else if (scope == 0x04) { /* per_policy */
-
if (str2uchar(argv[0], &policy_id) < 0) {
- lprintf(LOG_ERR,"Policy ID must be a positive integer.\n");
+ lprintf(LOG_ERR,"Policy ID must be a positive integer (0-255)\n");
return -1;
}
+ have_policy_id = TRUE;
break;
}
argc--;
argv++;
}
- if ((scope == 0x04) && (policy_id == 0xFF)) {
+ if ((scope == 0x04) && !have_policy_id) {
print_strs(nm_stats_opts, "Missing policy_id parameter:", LOG_ERR, 0);
return -1;
}
@@ -2780,25 +2869,23 @@ ipmi_nm_get_statistics(struct ipmi_intf * intf, int argc, char **argv)
uint8_t option;
uint8_t domain = 0; /* default domain of platform */
uint8_t policy_id = -1;
+ uint8_t have_policy_id = FALSE;
int policy_mode = 0;
- int cut;
char *units = "";
- char datebuf[27];
struct nm_statistics stats;
- struct tm tm_t;
- time_t t;
argv++;
- if ((argv[0] == NULL) ||
- ((mode = str2val2(argv[0], nm_stats_mode)) == 0xFF)) {
+ if (!argv[0] ||
+ 0xFF == (mode = str2val2(argv[0], nm_stats_mode)))
+ {
print_strs(nm_stats_mode, "Statistics commands", LOG_ERR, 0);
return -1;
}
while (--argc) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if ((option = str2val2(argv[0], nm_stats_opts)) == 0xFF) {
- print_strs(nm_stats_opts, "Control Scope options", LOG_ERR, 0);
+ print_strs(nm_stats_opts, "Control Scope options", LOG_ERR, 0);
return -1;
}
switch (option) {
@@ -2810,9 +2897,10 @@ ipmi_nm_get_statistics(struct ipmi_intf * intf, int argc, char **argv)
break;
case 0x02: /* policy ID */
if (str2uchar(argv[1], &policy_id) < 0) {
- lprintf(LOG_ERR,"Policy ID must be a positive integer.\n");
+ lprintf(LOG_ERR,"Policy ID must be a positive integer (0-255)\n");
return -1;
}
+ have_policy_id = TRUE;
break;
default:
break;
@@ -2836,7 +2924,7 @@ ipmi_nm_get_statistics(struct ipmi_intf * intf, int argc, char **argv)
case 0x13:
policy_mode = 1;
units = (mode == 0x11) ? "Watts" : (mode == 0x12) ? "Celsius" : " %";
- if (policy_id == 0xFF) {
+ if (!have_policy_id) {
print_strs(nm_stats_opts, "Missing policy_id parameter:", LOG_ERR, 0);
return -1;
}
@@ -2846,47 +2934,53 @@ ipmi_nm_get_statistics(struct ipmi_intf * intf, int argc, char **argv)
}
if (_ipmi_nm_statistics(intf, mode, domain, policy_id, &stats))
return -1;
- t = stats.time_stamp;
- gmtime_r(&t, &tm_t);
- sprintf(datebuf, "%s", asctime(&tm_t));
- cut = strlen(datebuf) -1;
- datebuf[cut] = 0;
if (csv_output) {
printf("%s,%s,%s,%s,%s,%d,%d,%d,%d,%s,%d\n",
- val2str2(stats.id_state & 0xF, nm_domain_vals),
- ((stats.id_state >> 4) & 1) ? (policy_mode ? "Policy Enabled" : "Globally Enabled") : "Disabled" ,
- ((stats.id_state >> 5) & 1) ? "active" : "suspended",
- ((stats.id_state >> 6) & 1) ? "in progress" : "suspended",
- ((stats.id_state >> 7) & 1) ? "triggered" : "not triggered",
- stats.curr_value,
- stats.min_value,
- stats.max_value,
- stats.ave_value,
- datebuf,
- stats.stat_period);
+ val2str2(stats.id_state & 0xF, nm_domain_vals),
+ ((stats.id_state >> 4) & 1) ? (policy_mode ? "Policy Enabled"
+ : "Globally Enabled")
+ : "Disabled" ,
+ ((stats.id_state >> 5) & 1) ? "active"
+ : "suspended",
+ ((stats.id_state >> 6) & 1) ? "in progress"
+ : "suspended",
+ ((stats.id_state >> 7) & 1) ? "triggered"
+ : "not triggered",
+ stats.curr_value,
+ stats.min_value,
+ stats.max_value,
+ stats.ave_value,
+ ipmi_timestamp_numeric(ipmi32toh(&stats.time_stamp)),
+ stats.stat_period);
return 0;
}
printf(" Power domain: %s\n",
- val2str2(stats.id_state & 0xF, nm_domain_vals));
+ val2str2(stats.id_state & 0xF, nm_domain_vals));
printf(" Policy/Global Admin state %s\n",
- ((stats.id_state >> 4) & 1) ? (policy_mode ? "Policy Enabled" : "Globally Enabled") : "Disabled" );
+ ((stats.id_state >> 4) & 1) ? (policy_mode ? "Policy Enabled"
+ : "Globally Enabled")
+ : "Disabled" );
printf(" Policy/Global Operational state %s\n",
- ((stats.id_state >> 5) & 1) ? "active" : "suspended");
+ ((stats.id_state >> 5) & 1) ? "active"
+ : "suspended");
printf(" Policy/Global Measurement state %s\n",
- ((stats.id_state >> 6) & 1) ? "in progress" : "suspended");
+ ((stats.id_state >> 6) & 1) ? "in progress"
+ : "suspended");
printf(" Policy Activation state %s\n",
- ((stats.id_state >> 7) & 1) ? "triggered" : "not triggered");
+ ((stats.id_state >> 7) & 1) ? "triggered"
+ : "not triggered");
printf(" Instantaneous reading: %8d %s\n",
- stats.curr_value, units);
+ stats.curr_value, units);
printf(" Minimum during sampling period: %8d %s\n",
- stats.min_value, units);
+ stats.min_value, units);
printf(" Maximum during sampling period: %8d %s\n",
- stats.max_value, units);
+ stats.max_value, units);
printf(" Average reading over sample period: %8d %s\n",
- stats.ave_value, units);
+ stats.ave_value, units);
printf(" IPMI timestamp: %s\n",
- datebuf);
- printf(" Sampling period: %08d Seconds.\n", stats.stat_period);
+ ipmi_timestamp_numeric(ipmi32toh(&stats.time_stamp)));
+ printf(" Sampling period: %08d Seconds.\n",
+ stats.stat_period);
printf("\n");
return 0;
}
@@ -2898,16 +2992,18 @@ ipmi_nm_reset_statistics(struct ipmi_intf * intf, int argc, char **argv)
uint8_t option;
uint8_t domain = 0; /* default domain of platform */
uint8_t policy_id = -1;
+ uint8_t have_policy_id = FALSE;
argv++;
- if ((argv[0] == NULL) ||
- ((mode = str2val2(argv[0], nm_reset_mode)) == 0xFF)) {
+ if (!argv[0] ||
+ 0xFF == (mode = str2val2(argv[0], nm_reset_mode)))
+ {
print_strs(nm_reset_mode, "Reset Statistics Modes:", LOG_ERR, 0);
return -1;
}
while (--argc) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if ((option = str2val2(argv[0], nm_stats_opts)) == 0xFF) {
print_strs(nm_stats_opts, "Reset Scope options", LOG_ERR, 0);
return -1;
@@ -2921,9 +3017,10 @@ ipmi_nm_reset_statistics(struct ipmi_intf * intf, int argc, char **argv)
break;
case 0x02: /* policy ID */
if (str2uchar(argv[1], &policy_id) < 0) {
- lprintf(LOG_ERR,"Policy ID must be a positive integer.\n");
+ lprintf(LOG_ERR,"Policy ID must be a positive integer (0-255)\n");
return -1;
}
+ have_policy_id = TRUE;
break;
default:
break;
@@ -2931,7 +3028,7 @@ ipmi_nm_reset_statistics(struct ipmi_intf * intf, int argc, char **argv)
argc--;
argv++;
}
- if (mode && (policy_id == 0xFF)) {
+ if (mode && !have_policy_id) {
print_strs(nm_stats_opts, "Missing policy_id parameter:", LOG_ERR, 0);
return -1;
}
@@ -2950,7 +3047,7 @@ ipmi_nm_set_range(struct ipmi_intf * intf, int argc, char **argv)
while (--argc) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if ((param = str2val2(argv[0], nm_power_range)) == 0xFF) {
print_strs(nm_power_range, "power range parameters:", LOG_ERR, 0);
return -1;
@@ -2981,7 +3078,8 @@ ipmi_nm_set_range(struct ipmi_intf * intf, int argc, char **argv)
argv++;
}
if ((minimum == 0xFFFF) || (maximum == 0xFFFF)) {
- lprintf(LOG_ERR,"Missing parameters: nm power range min <minimum> max <maximum>.\n");
+ lprintf(LOG_ERR,"Missing parameters: nm power range min <minimum> "
+ "max <maximum>.\n");
return -1;
}
if (_nm_set_range(intf, domain, minimum, maximum) < 0)
@@ -2999,23 +3097,25 @@ ipmi_nm_get_alert(struct ipmi_intf * intf)
return -1;
if (csv_output) {
printf("%d,%s,0x%x,%s,0x%x\n",
- alert.chan&0xF,
- (alert.chan >> 7) ? "not registered" : "registered",
- alert.dest,
- (alert.string >> 7) ? "yes" : "no",
- alert.string & 0x7F);
+ alert.chan & 0xF,
+ (alert.chan >> 7) ? "not registered"
+ : "registered",
+ alert.dest,
+ (alert.string >> 7) ? "yes"
+ : "no",
+ alert.string & 0x7F);
return 0;
}
printf(" Alert Chan: %d\n",
- alert.chan&0xF);
+ alert.chan & 0xF);
printf(" Alert Receiver: %s\n",
- (alert.chan >> 7) ? "not registered" : "registered");
+ (alert.chan >> 7) ? "not registered" : "registered");
printf(" Alert Lan Destination: 0x%x\n",
- alert.dest);
+ alert.dest);
printf(" Use Alert String: %s\n",
- (alert.string >> 7) ? "yes" : "no");
+ (alert.string >> 7) ? "yes" : "no");
printf(" Alert String Selector: 0x%x\n",
- alert.string & 0x7F);
+ alert.string & 0x7F);
return 0;
}
@@ -3031,8 +3131,9 @@ ipmi_nm_alert(struct ipmi_intf * intf, int argc, char **argv)
argv++;
argc--;
- if ((argv[0] == NULL) ||
- ((action = str2val2(argv[0], nm_alert_opts)) == 0xFF)) {
+ if (!argv[0] ||
+ 0xFF == (action = str2val2(argv[0], nm_alert_opts)))
+ {
print_strs(nm_alert_opts, "Alert commands", LOG_ERR, 0);
return -1;
}
@@ -3042,19 +3143,19 @@ ipmi_nm_alert(struct ipmi_intf * intf, int argc, char **argv)
memset(&alert, 0, sizeof(alert));
while (--argc) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
if ((param = str2val2(argv[0], nm_set_alert_param)) == 0xFF) {
print_strs(nm_set_alert_param, "Set alert Parameters:", LOG_ERR, 0);
return -1;
}
switch (param) {
- case 0x01: /* channnel */
+ case 0x01: /* channel */
if (str2uchar(argv[1], &chan) < 0) {
lprintf(LOG_ERR,"Alert Lan chan must be a positive integer.\n");
return -1;
}
if (action == 0x03) /* Clear */
- chan |= 0x80; /* deactivate alert reciever */
+ chan |= 0x80; /* deactivate alert receiver */
break;
case 0x02: /* dest */
if (str2uchar(argv[1], &dest) < 0) {
@@ -3096,15 +3197,15 @@ ipmi_nm_get_thresh(struct ipmi_intf *intf, uint8_t domain, uint8_t policy_id)
return -1;
printf(" Alert Threshold domain: %s\n",
- val2str2(domain, nm_domain_vals));
+ val2str2(domain, nm_domain_vals));
printf(" Alert Threshold Policy ID: %d\n",
- policy_id);
+ policy_id);
printf(" Alert Threshold 1: %d\n",
- list[0]);
+ list[0]);
printf(" Alert Threshold 2: %d\n",
- list[1]);
+ list[1]);
printf(" Alert Threshold 3: %d\n",
- list[2]);
+ list[2]);
return 0;
}
@@ -3115,21 +3216,23 @@ ipmi_nm_thresh(struct ipmi_intf * intf, int argc, char **argv)
uint8_t action;
uint8_t domain = 0; /* default domain of platform */
uint8_t policy_id = -1;
+ uint8_t have_policy_id = FALSE;
struct nm_thresh thresh;
int i = 0;
argv++;
argc--;
/* set or get */
- if ((argv[0] == NULL) || (argc < 3) ||
- ((action = str2val2(argv[0], nm_thresh_cmds)) == 0xFF)) {
- print_strs(nm_thresh_cmds, "Theshold commands", LOG_ERR, 0);
+ if (!argv[0] || argc < 3
+ || 0xFF == (action = str2val2(argv[0], nm_thresh_cmds)))
+ {
+ print_strs(nm_thresh_cmds, "Threshold commands", LOG_ERR, 0);
return -1;
}
memset(&thresh, 0, sizeof(thresh));
while (--argc) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
option = str2val2(argv[0], nm_thresh_param);
switch (option) {
case 0x01: /* get domain scope */
@@ -3142,9 +3245,10 @@ ipmi_nm_thresh(struct ipmi_intf * intf, int argc, char **argv)
break;
case 0x02: /* policy ID */
if (str2uchar(argv[1], &policy_id) < 0) {
- lprintf(LOG_ERR,"Policy ID must be a positive integer.\n");
+ lprintf(LOG_ERR,"Policy ID must be a positive integer (0-255)\n");
return -1;
}
+ have_policy_id = TRUE;
argc--;
argv++;
break;
@@ -3161,7 +3265,7 @@ ipmi_nm_thresh(struct ipmi_intf * intf, int argc, char **argv)
break;
}
}
- if (policy_id == 0xFF) {
+ if (!have_policy_id) {
print_strs(nm_stats_opts, "Missing policy_id parameter:", LOG_ERR, 0);
return -1;
}
@@ -3213,9 +3317,10 @@ ipmi_nm_get_suspend(struct ipmi_intf *intf, uint8_t domain, uint8_t policy_id)
}
for (i = 0; i < count; i++) {
printf(" Suspend Period %d: %02d:%02d to %02d:%02d",
- i, click2hour(periods[i].start), click2min(periods[i].start),
- click2hour(periods[i].stop), click2min(periods[i].stop));
- if (periods[i].repeat) printf(", ");
+ i, click2hour(periods[i].start), click2min(periods[i].start),
+ click2hour(periods[i].stop), click2min(periods[i].stop));
+ if (periods[i].repeat)
+ printf(", ");
for (j = 0; j < 7; j++)
printf("%s", (periods[i].repeat >> j)&1 ? days[j] : "");
printf("\n");
@@ -3230,6 +3335,7 @@ ipmi_nm_suspend(struct ipmi_intf * intf, int argc, char **argv)
uint8_t action;
uint8_t domain = 0; /* default domain of platform */
uint8_t policy_id = -1;
+ uint8_t have_policy_id = FALSE;
uint8_t count = 0;
struct nm_suspend suspend;
int i;
@@ -3237,15 +3343,16 @@ ipmi_nm_suspend(struct ipmi_intf * intf, int argc, char **argv)
argv++;
argc--;
/* set or get */
- if ((argv[0] == NULL) || (argc < 3) ||
- ((action = str2val2(argv[0], nm_suspend_cmds)) == 0xFF)) {
+ if (!argv[0] || argc < 3 ||
+ 0xFF == (action = str2val2(argv[0], nm_suspend_cmds)))
+ {
print_strs(nm_suspend_cmds, "Suspend commands", LOG_ERR, 0);
return -1;
}
memset(&suspend, 0, sizeof(suspend));
while (--argc > 0) {
argv++;
- if (argv[0] == NULL) break;
+ if (!argv[0]) break;
option = str2val2(argv[0], nm_thresh_param);
switch (option) {
case 0x01: /* get domain scope */
@@ -3258,13 +3365,14 @@ ipmi_nm_suspend(struct ipmi_intf * intf, int argc, char **argv)
break;
case 0x02: /* policy ID */
if (str2uchar(argv[1], &policy_id) < 0) {
- lprintf(LOG_ERR,"Policy ID must be a positive integer.\n");
+ lprintf(LOG_ERR,"Policy ID must be a positive integer (0-255)\n");
return -1;
}
+ have_policy_id = TRUE;
argc--;
argv++;
break;
- case 0xFF: /* process periods */
+ case 0xFF: /* process periods */
for (i = 0; count < IPMI_NM_SUSPEND_PERIOD_MAX; i += 3, count++) {
if (argc < 3) {
lprintf(LOG_ERR,"Error: suspend period requires a start, stop, and repeat values.\n");
@@ -3289,10 +3397,16 @@ ipmi_nm_suspend(struct ipmi_intf * intf, int argc, char **argv)
if (argc <= 0)
break;
break;
- default:
- break;
- }
- }
+ default:
+ break;
+ }
+ }
+
+ if (!have_policy_id) {
+ print_strs(nm_stats_opts, "Missing policy_id parameter:", LOG_ERR, 0);
+ return -1;
+ }
+
if (action == 0x02) /* get */
return (ipmi_nm_get_suspend(intf, domain, policy_id));
@@ -3349,7 +3463,7 @@ ipmi_dcmi_set_limit(struct ipmi_intf * intf, int argc, char **argv)
case 0xFF:
/* error - not a string we knew what to do with */
lprintf(LOG_ERR, "Given Action '%s' is invalid.",
- argv[2]);
+ argv[2]);
return -1;
}
/* limit */
@@ -3364,8 +3478,8 @@ ipmi_dcmi_set_limit(struct ipmi_intf * intf, int argc, char **argv)
/* correction */
if (str2uint(argv[6], &correction) != 0) {
lprintf(LOG_ERR,
- "Given Correction '%s' is invalid.",
- argv[6]);
+ "Given Correction '%s' is invalid.",
+ argv[6]);
return (-1);
}
data[7] = correction >> 0;
@@ -3377,8 +3491,8 @@ ipmi_dcmi_set_limit(struct ipmi_intf * intf, int argc, char **argv)
/* sample */
if (str2ushort(argv[8], &sample) != 0) {
lprintf(LOG_ERR,
- "Given Sample '%s' is invalid.",
- argv[8]);
+ "Given Sample '%s' is invalid.",
+ argv[8]);
return (-1);
}
data[13] = sample >> 0;
@@ -3390,12 +3504,12 @@ ipmi_dcmi_set_limit(struct ipmi_intf * intf, int argc, char **argv)
}
} else {
/* loop through each parameter and value until we have neither */
- while ((argv[1] != NULL) && (argv[2] != NULL)) {
+ while (argv[1] && argv[2]) {
rc = ipmi_dcmi_pwr_slimit(intf, argv[1], argv[2]);
/* catch any error that the set limit function returned */
if (rc > 0) {
print_strs(dcmi_pwrmgmt_set_usage_vals,
- "set_limit <parameter> <value>", LOG_ERR, 0);
+ "set_limit <parameter> <value>", LOG_ERR, 0);
return -1;
}
/* the first argument is the command and the second is the
@@ -3416,11 +3530,11 @@ ipmi_dcmi_parse_power(struct ipmi_intf * intf, int argc, char **argv)
switch (str2val2(argv[0], dcmi_pwrmgmt_vals)) {
case 0x00:
/* get reading */
- if (argv[1] != NULL) {
+ if (argv[1]) {
if (!(sample_time = str2val2(argv[1], dcmi_sampling_vals))) {
print_strs(dcmi_sampling_vals,
- "Invalid sample time. Valid times are: ",
- LOG_ERR, 1);
+ "Invalid sample time. Valid times are: ",
+ LOG_ERR, 1);
printf("\n");
return -1;
}
@@ -3439,8 +3553,8 @@ ipmi_dcmi_parse_power(struct ipmi_intf * intf, int argc, char **argv)
/* set limit */
if (argc < 4) {
print_strs(dcmi_pwrmgmt_set_usage_vals,
- "set_limit <parameter> <value>",
- LOG_ERR, 0);
+ "set_limit <parameter> <value>",
+ LOG_ERR, 0);
return -1;
}
if (ipmi_dcmi_set_limit(intf, argc, argv) < 0)
@@ -3458,7 +3572,7 @@ ipmi_dcmi_parse_power(struct ipmi_intf * intf, int argc, char **argv)
default:
/* no valid options */
print_strs(dcmi_pwrmgmt_vals,
- "power <command>", LOG_ERR, 0);
+ "power <command>", LOG_ERR, 0);
break;
}
return rc;
@@ -3488,14 +3602,14 @@ ipmi_dcmi_thermalpolicy(struct ipmi_intf * intf, int argc, char **argv)
}
if (str2uchar(argv[2], &entityID) != 0) {
lprintf(LOG_ERR,
- "Given Entity ID '%s' is invalid.",
- argv[2]);
+ "Given Entity ID '%s' is invalid.",
+ argv[2]);
return (-1);
}
if (str2uchar(argv[3], &entityInst) != 0) {
lprintf(LOG_ERR,
- "Given Instance ID '%s' is invalid.",
- argv[3]);
+ "Given Instance ID '%s' is invalid.",
+ argv[3]);
return (-1);
}
rc = ipmi_dcmi_getthermalpolicy(intf, entityID, entityInst);
@@ -3505,24 +3619,24 @@ ipmi_dcmi_thermalpolicy(struct ipmi_intf * intf, int argc, char **argv)
lprintf(LOG_NOTICE, "Set <entityID> <instanceID>");
return -1;
} else if (argc < 9) {
- print_strs(dcmi_thermalpolicy_set_parameters_vals,
- "Set thermalpolicy instance parameters: "
- "<volatile/nonvolatile/disabled> "
- "<poweroff/nopoweroff/disabled> "
- "<sel/nosel/disabled> <templimitByte> <exceptionTime>",
- LOG_ERR, 0);
+ print_strs(dcmi_thermalpolicy_set_parameters_vals,
+ "Set thermalpolicy instance parameters: "
+ "<volatile/nonvolatile/disabled> "
+ "<poweroff/nopoweroff/disabled> "
+ "<sel/nosel/disabled> <templimitByte> <exceptionTime>",
+ LOG_ERR, 0);
return -1;
}
if (str2uchar(argv[2], &entityID) != 0) {
lprintf(LOG_ERR,
- "Given Entity ID '%s' is invalid.",
- argv[2]);
+ "Given Entity ID '%s' is invalid.",
+ argv[2]);
return (-1);
}
if (str2uchar(argv[3], &entityInst) != 0) {
lprintf(LOG_ERR,
- "Given Instance ID '%s' is invalid.",
- argv[3]);
+ "Given Instance ID '%s' is invalid.",
+ argv[3]);
return (-1);
}
persistanceFlag = (uint8_t) str2val2(argv[4], dcmi_thermalpolicy_set_parameters_vals);
@@ -3530,14 +3644,14 @@ ipmi_dcmi_thermalpolicy(struct ipmi_intf * intf, int argc, char **argv)
actionLogToSEL = (uint8_t) str2val2(argv[6], dcmi_thermalpolicy_set_parameters_vals);
if (str2uchar(argv[7], &tempLimit) != 0) {
lprintf(LOG_ERR,
- "Given Temp Limit '%s' is invalid.",
- argv[7]);
+ "Given Temp Limit '%s' is invalid.",
+ argv[7]);
return (-1);
}
if (str2ushort(argv[8], &samplingTime) != 0) {
lprintf(LOG_ERR,
- "Given Sampling Time '%s' is invalid.",
- argv[8]);
+ "Given Sampling Time '%s' is invalid.",
+ argv[8]);
return (-1);
}
samplingTimeLSB = (samplingTime & 0xFF);
@@ -3556,8 +3670,8 @@ ipmi_dcmi_thermalpolicy(struct ipmi_intf * intf, int argc, char **argv)
break;
default:
print_strs(dcmi_thermalpolicy_vals,
- "thermalpolicy <command>",
- LOG_ERR, 0);
+ "thermalpolicy <command>",
+ LOG_ERR, 0);
return -1;
}
return rc;
@@ -3576,20 +3690,20 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
int i;
struct ipmi_rs *rsp;
- if ((argc == 0) || (strncmp(argv[0], "help", 4) == 0)) {
+ if (!argc || !strcmp(argv[0], "help")) {
print_strs(dcmi_cmd_vals,
- "Data Center Management Interface commands",
- LOG_ERR, 0);
+ "Data Center Management Interface commands",
+ LOG_ERR, 0);
return -1;
}
/* start the cmd requested */
switch (str2val2(argv[0], dcmi_cmd_vals)) {
case 0x00:
/* discover capabilities*/
- for (i = 1; dcmi_capable_vals[i-1].str != NULL; i++) {
+ for (i = 1; dcmi_capable_vals[i-1].str; i++) {
if (ipmi_dcmi_prnt_getcapabilities(intf, i) < 0) {
lprintf(LOG_ERR,"Error discovering %s capabilities!\n",
- val2str2(i, dcmi_capable_vals));
+ val2str2(i, dcmi_capable_vals));
return -1;
}
}
@@ -3597,9 +3711,9 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
case 0x01:
/* power */
argv++;
- if (argv[0] == NULL) {
+ if (!argv[0]) {
print_strs(dcmi_pwrmgmt_vals, "power <command>",
- LOG_ERR, 0);
+ LOG_ERR, 0);
return -1;
}
rc = ipmi_dcmi_parse_power(intf, argc, argv);
@@ -3611,10 +3725,10 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
* and if it exists, print the sdr record id(s) for it.
* Use the val from each one as the sensor number.
*/
- for (i = 0; dcmi_discvry_snsr_vals[i].str != NULL; i++) {
+ for (i = 0; dcmi_discvry_snsr_vals[i].str; i++) {
/* get all of the information about this sensor */
rc = ipmi_dcmi_prnt_discvry_snsr(intf,
- dcmi_discvry_snsr_vals[i].val);
+ dcmi_discvry_snsr_vals[i].val);
}
break;
/* end sensor print */
@@ -3631,8 +3745,8 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
/* set asset tag */
if (argc == 1 ) {
print_strs(dcmi_cmd_vals,
- "Data Center Management Interface commands",
- LOG_ERR, 0);
+ "Data Center Management Interface commands",
+ LOG_ERR, 0);
return -1;
}
if (ipmi_dcmi_prnt_setassettag(intf, (uint8_t *)argv[1]) < 0) {
@@ -3646,7 +3760,7 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
/* get management controller identifier string */
if (ipmi_dcmi_prnt_getmngctrlids(intf) < 0) {
lprintf(LOG_ERR,
- "Error getting management controller identifier string!");
+ "Error getting management controller identifier string!");
return -1;
}
break;
@@ -3656,13 +3770,13 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
/* set management controller identifier string */
if (argc == 1 ) {
print_strs(dcmi_cmd_vals,
- "Data Center Management Interface commands",
- LOG_ERR, 0);
+ "Data Center Management Interface commands",
+ LOG_ERR, 0);
return -1;
}
if (ipmi_dcmi_prnt_setmngctrlids(intf, (uint8_t *)argv[1]) < 0) {
lprintf(LOG_ERR,
- "Error setting management controller identifier string!");
+ "Error setting management controller identifier string!");
return -1;
}
break;
@@ -3675,14 +3789,14 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
case 0x08:
if(ipmi_dcmi_prnt_get_temp_readings(intf) < 0 ) {
lprintf(LOG_ERR,
- "Error get temperature readings!");
+ "Error get temperature readings!");
return -1;
}
break;
case 0x09:
if(ipmi_dcmi_prnt_getconfparam(intf) < 0 ) {
lprintf(LOG_ERR,
- "Error Get DCMI Configuration Parameters!");
+ "Error Get DCMI Configuration Parameters!");
return -1;
};
break;
@@ -3690,46 +3804,44 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
{
switch (argc) {
case 2:
- if (strncmp(argv[1], "activate_dhcp", 13) != 0) {
+ if (strcmp(argv[1], "activate_dhcp")) {
print_strs( dcmi_conf_param_vals,
- "DCMI Configuration Parameters",
- LOG_ERR, 0);
+ "DCMI Configuration Parameters",
+ LOG_ERR, 0);
return -1;
}
break;
default:
- if (argc != 3 || strncmp(argv[1], "help", 4) == 0) {
+ if (argc != 3 || !strcmp(argv[1], "help")) {
print_strs(dcmi_conf_param_vals,
- "DCMI Configuration Parameters",
- LOG_ERR, 0);
+ "DCMI Configuration Parameters",
+ LOG_ERR, 0);
return -1;
}
}
- if (strncmp(argv[1], "activate_dhcp", 13) == 0) {
+ if (!strcmp(argv[1], "activate_dhcp")) {
rsp = ipmi_dcmi_setconfparam(intf, 1, 1);
} else {
uint16_t tmp_val = 0;
if (str2ushort(argv[2], &tmp_val) != 0) {
- lprintf(LOG_ERR,
- "Given %s '%s' is invalid.",
- argv[1], argv[2]);
+ lprintf(LOG_ERR, "Given %s '%s' is invalid.",
+ argv[1], argv[2]);
return (-1);
}
rsp = ipmi_dcmi_setconfparam(intf,
- str2val2(argv[1], dcmi_conf_param_vals),
- tmp_val);
+ str2val2(argv[1], dcmi_conf_param_vals),
+ tmp_val);
}
if (chk_rsp(rsp)) {
- lprintf(LOG_ERR,
- "Error Set DCMI Configuration Parameters!");
+ lprintf(LOG_ERR, "Error Set DCMI Configuration Parameters!");
}
break;
}
case 0x0B:
{
- if (intf->session == NULL) {
+ if (!intf->session) {
lprintf(LOG_ERR,
- "\nOOB discovery is available only via RMCP interface.");
+ "\nOOB discovery is available only via RMCP interface.");
return -1;
}
if(ipmi_dcmi_prnt_oobDiscover(intf) < 0) {
@@ -3741,8 +3853,8 @@ ipmi_dcmi_main(struct ipmi_intf * intf, int argc, char **argv)
default:
/* couldn't detect what the user entered */
print_strs(dcmi_cmd_vals,
- "Data Center Management Interface commands",
- LOG_ERR, 0);
+ "Data Center Management Interface commands",
+ LOG_ERR, 0);
return -1;
break;
}
@@ -3761,10 +3873,10 @@ ipmi_nm_main(struct ipmi_intf * intf, int argc, char **argv)
{
struct nm_discover disc;
- if ((argc == 0) || (strncmp(argv[0], "help", 4) == 0)) {
+ if (!argc || !strcmp(argv[0], "help")) {
print_strs(nm_cmd_vals,
- "Node Manager Interface commands",
- LOG_ERR, 0);
+ "Node Manager Interface commands",
+ LOG_ERR, 0);
return -1;
}
@@ -3775,7 +3887,7 @@ ipmi_nm_main(struct ipmi_intf * intf, int argc, char **argv)
return -1;
printf(" Node Manager Version %s\n", val2str2(disc.nm_version, nm_version_vals));
printf(" revision %d.%d%d patch version %d\n", disc.major_rev,
- disc.minor_rev>>4, disc.minor_rev&0xf, disc.patch_version);
+ disc.minor_rev>>4, disc.minor_rev&0xf, disc.patch_version);
break;
/* capability */
case 0x01:
@@ -3846,37 +3958,38 @@ ipmi_print_sensor_info(struct ipmi_intf *intf, uint16_t rec_id)
uint8_t *rec = NULL;
itr = ipmi_sdr_start(intf, 0);
- if (itr == NULL) {
+ if (!itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return (-1);
}
- while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, itr))) {
if (header->id == rec_id) {
break;
}
}
- if (header == NULL) {
+ if (!header) {
lprintf(LOG_DEBUG, "header == NULL");
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
return (-1);
}
/* yes, we found the SDR for this record ID, now get full record */
rec = ipmi_sdr_get_record(intf, header, itr);
- if (rec == NULL) {
+ if (!rec) {
lprintf(LOG_DEBUG, "rec == NULL");
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
return (-1);
}
if ((header->type == SDR_RECORD_TYPE_FULL_SENSOR) ||
- (header->type == SDR_RECORD_TYPE_COMPACT_SENSOR)) {
+ (header->type == SDR_RECORD_TYPE_COMPACT_SENSOR))
+ {
rc = ipmi_sdr_print_rawentry(intf, header->type,
- rec, header->length);
+ rec, header->length);
} else {
rc = (-1);
}
free(rec);
rec = NULL;
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
return rc;
}
diff --git a/lib/ipmi_delloem.c b/lib/ipmi_delloem.c
index bc78c1d..e868913 100644
--- a/lib/ipmi_delloem.c
+++ b/lib/ipmi_delloem.c
@@ -62,6 +62,7 @@
#include <ipmitool/ipmi_entity.h>
#include <ipmitool/ipmi_fru.h>
#include <ipmitool/ipmi_sensor.h>
+#include <ipmitool/ipmi_time.h>
#define DELL_OEM_NETFN (uint8_t)(0x30)
#define GET_IDRAC_VIRTUAL_MAC (uint8_t)(0xC9)
@@ -170,12 +171,10 @@ static int ipmi_lcd_get_status(struct ipmi_intf *intf);
static int ipmi_lcd_set_kvm(struct ipmi_intf *intf, char status);
static int ipmi_lcd_set_lock(struct ipmi_intf *intf, char lock);
static int ipmi_lcd_set_single_line_text(struct ipmi_intf *intf, char *text);
-static int ipmi_lcd_set_text(struct ipmi_intf *intf, char *text,
- int line_number);
+static int ipmi_lcd_set_text(struct ipmi_intf *intf, char *text);
static int ipmi_lcd_configure_wh(struct ipmi_intf *intf, uint32_t mode,
- uint16_t lcdquallifier, uint8_t errordisp, int8_t line_number, char *text);
-static int ipmi_lcd_configure(struct ipmi_intf *intf, int command,
- int8_t line_number, char *text);
+ uint16_t lcdquallifier, uint8_t errordisp, char *text);
+static int ipmi_lcd_configure(struct ipmi_intf *intf, int command, char *text);
static void ipmi_lcd_usage(void);
/* MAC Function prototypes */
static int ipmi_delloem_mac_main(struct ipmi_intf *intf, int argc, char **argv);
@@ -201,7 +200,6 @@ static int ipmi_lan_set_nic_selection_12g(struct ipmi_intf *intf,
/* Power monitor Function prototypes */
static int ipmi_delloem_powermonitor_main(struct ipmi_intf *intf, int argc,
char **argv);
-static void ipmi_time_to_str(time_t rawTime, char *strTime);
static int ipmi_get_sensor_reading(struct ipmi_intf *intf,
unsigned char sensorNumber, SensorReadingType *pSensorReadingData);
static int ipmi_get_power_capstatus_command(struct ipmi_intf *intf);
@@ -271,25 +269,25 @@ ipmi_delloem_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int rc = 0;
current_arg = 0;
- if (argc == 0 || strncmp(argv[0], "help\0", 5) == 0) {
+ if (!argc || !strcmp(argv[0], "help")) {
usage();
return 0;
}
- if (0 ==strncmp(argv[current_arg], "lcd\0", 4)) {
+ if (0 ==strcmp(argv[current_arg], "lcd")) {
rc = ipmi_delloem_lcd_main(intf,argc,argv);
- } else if (strncmp(argv[current_arg], "mac\0", 4) == 0) {
+ } else if (!strcmp(argv[current_arg], "mac")) {
/* mac address*/
rc = ipmi_delloem_mac_main(intf,argc,argv);
- } else if (strncmp(argv[current_arg], "lan\0", 4) == 0) {
+ } else if (!strcmp(argv[current_arg], "lan")) {
/* lan address*/
rc = ipmi_delloem_lan_main(intf,argc,argv);
- } else if (strncmp(argv[current_arg], "setled\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "setled")) {
/* SetLED support */
rc = ipmi_delloem_setled_main(intf,argc,argv);
- } else if (strncmp(argv[current_arg], "powermonitor\0", 13) == 0) {
+ } else if (!strcmp(argv[current_arg], "powermonitor")) {
/*Powermanagement report processing*/
rc = ipmi_delloem_powermonitor_main(intf,argc,argv);
- } else if (strncmp(argv[current_arg], "vFlash\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "vFlash")) {
/* vFlash Support */
rc = ipmi_delloem_vFlash_main(intf,argc,argv);
} else {
@@ -361,7 +359,7 @@ ipmi_delloem_lcd_main(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
/* ipmitool delloem lcd info*/
- if (argc == 1 || strcmp(argv[current_arg], "help") == 0) {
+ if (argc == 1 || !strcmp(argv[current_arg], "help")) {
ipmi_lcd_usage();
return 0;
}
@@ -370,15 +368,15 @@ ipmi_delloem_lcd_main(struct ipmi_intf * intf, int argc, char ** argv)
if (!IsLCDSupported()) {
lprintf(LOG_ERR, "lcd is not supported on this system.");
return -1;
- } else if (strncmp(argv[current_arg], "info\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "info")) {
if (iDRAC_FLAG_ALL) {
rc = ipmi_lcd_get_info_wh(intf);
} else {
rc = ipmi_lcd_get_info(intf);
}
- } else if (strncmp(argv[current_arg], "status\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "status")) {
rc = ipmi_lcd_get_status(intf);
- } else if (strncmp(argv[current_arg], "set\0", 4) == 0) {
+ } else if (!strcmp(argv[current_arg], "set")) {
/* ipmitool delloem lcd set*/
uint8_t line_number = 0;
current_arg++;
@@ -386,7 +384,7 @@ ipmi_delloem_lcd_main(struct ipmi_intf * intf, int argc, char ** argv)
ipmi_lcd_usage();
return -1;
}
- if (strncmp(argv[current_arg], "line\0", 5) == 0) {
+ if (!strcmp(argv[current_arg], "line")) {
current_arg++;
if (argc <= current_arg) {
usage();
@@ -404,164 +402,170 @@ ipmi_delloem_lcd_main(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
}
- if ((strncmp(argv[current_arg], "mode\0", 5) == 0)
- && (iDRAC_FLAG_ALL)) {
+ if (!strcmp(argv[current_arg], "mode")
+ && iDRAC_FLAG_ALL)
+ {
current_arg++;
if (argc <= current_arg) {
ipmi_lcd_usage();
return -1;
}
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_lcd_usage();
return -1;
}
- if (strncmp(argv[current_arg], "none\0", 5) == 0) {
+ if (!strcmp(argv[current_arg], "none")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_CONFIG_NONE, 0xFF,
- 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "modelname\0", 10) == 0) {
+ 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "modelname")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_CONFIG_DEFAULT, 0xFF,
- 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "userdefined\0", 12) == 0) {
+ 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "userdefined")) {
current_arg++;
if (argc <= current_arg) {
ipmi_lcd_usage();
return -1;
}
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_CONFIG_USER_DEFINED,
- 0xFF, 0XFF, line_number, argv[current_arg]);
- } else if (strncmp(argv[current_arg], "ipv4address\0", 12) == 0) {
+ 0xFF, 0XFF, argv[current_arg]);
+ } else if (!strcmp(argv[current_arg], "ipv4address")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_iDRAC_IPV4ADRESS,
- 0xFF, 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "macaddress\0", 11) == 0) {
+ 0xFF, 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "macaddress")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_IDRAC_MAC_ADDRESS,
- 0xFF, 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "systemname\0", 11) == 0) {
+ 0xFF, 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "systemname")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_OS_SYSTEM_NAME, 0xFF,
- 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "servicetag\0", 11) == 0) {
+ 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "servicetag")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_SERVICE_TAG, 0xFF,
- 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "ipv6address\0", 12) == 0) {
+ 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "ipv6address")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_iDRAC_IPV6ADRESS,
- 0xFF, 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "ambienttemp\0", 12) == 0) {
+ 0xFF, 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "ambienttemp")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_AMBEINT_TEMP, 0xFF,
- 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "systemwatt\0", 11) == 0) {
+ 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "systemwatt")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_SYSTEM_WATTS, 0xFF,
- 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "assettag\0", 9) == 0) {
+ 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "assettag")) {
rc = ipmi_lcd_configure_wh(intf, IPMI_DELL_LCD_ASSET_TAG, 0xFF,
- 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "help\0", 5) == 0) {
+ 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "help")) {
ipmi_lcd_usage();
} else {
lprintf(LOG_ERR, "Invalid DellOEM command: %s",
argv[current_arg]);
ipmi_lcd_usage();
}
- } else if ((strncmp(argv[current_arg], "lcdqualifier\0", 13) == 0)
- && (iDRAC_FLAG_ALL)) {
+ } else if (!strcmp(argv[current_arg], "lcdqualifier")
+ && iDRAC_FLAG_ALL)
+ {
current_arg++;
if (argc <= current_arg) {
ipmi_lcd_usage();
return -1;
}
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_lcd_usage();
return -1;
}
- if (strncmp(argv[current_arg], "watt\0", 5) == 0) {
- rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x00, 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "btuphr\0",7) == 0) {
- rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x01, 0XFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "celsius\0", 8) == 0) {
- rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x02, 0xFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "fahrenheit", 11) == 0) {
- rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x03, 0xFF, 0, NULL);
- } else if (strncmp(argv[current_arg], "help\0", 5) == 0) {
+ if (!strcmp(argv[current_arg], "watt")) {
+ rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x00, 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "btuphr")) {
+ rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x01, 0XFF, NULL);
+ } else if (!strcmp(argv[current_arg], "celsius")) {
+ rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x02, 0xFF, NULL);
+ } else if (!strcmp(argv[current_arg], "fahrenheit")) {
+ rc = ipmi_lcd_configure_wh(intf, 0xFF, 0x03, 0xFF, NULL);
+ } else if (!strcmp(argv[current_arg], "help")) {
ipmi_lcd_usage();
} else {
lprintf(LOG_ERR, "Invalid DellOEM command: %s",
argv[current_arg]);
ipmi_lcd_usage();
}
- } else if ((strncmp(argv[current_arg], "errordisplay\0", 13) == 0)
- && (iDRAC_FLAG_ALL)) {
+ } else if (!strcmp(argv[current_arg], "errordisplay")
+ && iDRAC_FLAG_ALL)
+ {
current_arg++;
if (argc <= current_arg) {
ipmi_lcd_usage();
return -1;
}
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_lcd_usage();
return -1;
}
- if (strncmp(argv[current_arg], "sel\0", 4) == 0) {
+ if (!strcmp(argv[current_arg], "sel")) {
rc = ipmi_lcd_configure_wh(intf, 0xFF, 0xFF,
- IPMI_DELL_LCD_ERROR_DISP_SEL, 0, NULL);
- } else if (strncmp(argv[current_arg], "simple\0", 7) == 0) {
+ IPMI_DELL_LCD_ERROR_DISP_SEL, NULL);
+ } else if (!strcmp(argv[current_arg], "simple")) {
rc = ipmi_lcd_configure_wh(intf, 0xFF, 0xFF,
- IPMI_DELL_LCD_ERROR_DISP_VERBOSE, 0, NULL);
- } else if (strncmp(argv[current_arg], "help\0", 5) == 0) {
+ IPMI_DELL_LCD_ERROR_DISP_VERBOSE, NULL);
+ } else if (!strcmp(argv[current_arg], "help")) {
ipmi_lcd_usage();
} else {
lprintf(LOG_ERR, "Invalid DellOEM command: %s",
argv[current_arg]);
ipmi_lcd_usage();
}
- } else if ((strncmp(argv[current_arg], "none\0", 5) == 0)
- && (iDRAC_FLAG==0)) {
- rc = ipmi_lcd_configure(intf, IPMI_DELL_LCD_CONFIG_NONE, 0, NULL);
- } else if ((strncmp(argv[current_arg], "default\0", 8) == 0)
- && (iDRAC_FLAG==0)) {
- rc = ipmi_lcd_configure(intf, IPMI_DELL_LCD_CONFIG_DEFAULT, 0, NULL);
- } else if ((strncmp(argv[current_arg], "custom\0", 7) == 0)
- && (iDRAC_FLAG==0)) {
+ } else if (!strcmp(argv[current_arg], "none")
+ && iDRAC_FLAG==0)
+ {
+ rc = ipmi_lcd_configure(intf, IPMI_DELL_LCD_CONFIG_NONE, NULL);
+ } else if (!strcmp(argv[current_arg], "default")
+ && iDRAC_FLAG==0)
+ {
+ rc = ipmi_lcd_configure(intf, IPMI_DELL_LCD_CONFIG_DEFAULT, NULL);
+ } else if (!strcmp(argv[current_arg], "custom")
+ && iDRAC_FLAG==0)
+ {
current_arg++;
if (argc <= current_arg) {
ipmi_lcd_usage();
return -1;
}
rc = ipmi_lcd_configure(intf, IPMI_DELL_LCD_CONFIG_USER_DEFINED,
- line_number, argv[current_arg]);
- } else if (strncmp(argv[current_arg], "vkvm\0", 5) == 0) {
+ argv[current_arg]);
+ } else if (!strcmp(argv[current_arg], "vkvm")) {
current_arg++;
if (argc <= current_arg) {
ipmi_lcd_usage();
return -1;
}
- if (strncmp(argv[current_arg], "active\0", 7) == 0) {
+ if (!strcmp(argv[current_arg], "active")) {
rc = ipmi_lcd_set_kvm(intf, 1);
- } else if (strncmp(argv[current_arg], "inactive\0", 9) == 0) {
+ } else if (!strcmp(argv[current_arg], "inactive")) {
rc = ipmi_lcd_set_kvm(intf, 0);
- } else if (strncmp(argv[current_arg], "help\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "help")) {
ipmi_lcd_usage();
} else {
lprintf(LOG_ERR, "Invalid DellOEM command: %s",
argv[current_arg]);
ipmi_lcd_usage();
}
- } else if (strncmp(argv[current_arg], "frontpanelaccess\0", 17) == 0) {
+ } else if (!strcmp(argv[current_arg], "frontpanelaccess")) {
current_arg++;
if (argc <= current_arg) {
ipmi_lcd_usage();
return -1;
}
- if (strncmp(argv[current_arg], "viewandmodify\0", 14) == 0) {
+ if (!strcmp(argv[current_arg], "viewandmodify")) {
rc = ipmi_lcd_set_lock(intf, 0);
- } else if (strncmp(argv[current_arg], "viewonly\0", 9)==0) {
+ } else if (strcmp(argv[current_arg], "viewonly")==0) {
rc = ipmi_lcd_set_lock(intf, 1);
- } else if (strncmp(argv[current_arg], "disabled\0", 9)==0) {
+ } else if (strcmp(argv[current_arg], "disabled")==0) {
rc = ipmi_lcd_set_lock(intf, 2);
- } else if (strncmp(argv[current_arg], "help\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "help")) {
ipmi_lcd_usage();
} else {
lprintf(LOG_ERR, "Invalid DellOEM command: %s",
argv[current_arg]);
ipmi_lcd_usage();
}
- } else if( (strncmp(argv[current_arg], "help\0", 5) == 0)
+ } else if( (!strcmp(argv[current_arg], "help"))
&& (iDRAC_FLAG==0)) {
ipmi_lcd_usage();
} else {
@@ -1201,17 +1205,17 @@ ipmi_lcd_set_kvm(struct ipmi_intf * intf, char status)
req.msg.data_len = 5;
req.msg.data = data;
data[0] = IPMI_DELL_LCD_STATUS_SELECTOR;
- data[1] = status; /* active- incative*/
+ data[1] = status; /* active- inactive */
data[2] = lcdstatus.lock_status; /* full-veiw-locked */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting LCD status");
rc= -1;
} else if ((rsp->ccode == 0xc1) || (rsp->ccode == 0xcb)) {
lprintf(LOG_ERR, "Error getting LCD status: "
"Command not supported on this system.");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error setting LCD status: %s",
val2str(rsp->ccode, completion_code_vals));
rc= -1;
@@ -1223,7 +1227,7 @@ ipmi_lcd_set_kvm(struct ipmi_intf * intf, char status)
*
* Description: This function sets lcd access mode
* Input: intf - ipmi interface
- * lock - View and modify / View only / Diabled
+ * lock - View and modify / View only / Disabled
* Output:
* Return: -1 on error
* 0 if successful
@@ -1247,17 +1251,17 @@ ipmi_lcd_set_lock(struct ipmi_intf * intf, char lock)
req.msg.data_len = 5;
req.msg.data = data;
data[0] = IPMI_DELL_LCD_STATUS_SELECTOR;
- data[1] = lcdstatus.vKVM_status; /* active- incative */
+ data[1] = lcdstatus.vKVM_status; /* active- inactive */
data[2] = lock; /* full- veiw-locked */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting LCD status");
rc = -1;
} else if ((rsp->ccode == 0xc1) || (rsp->ccode == 0xcb)) {
lprintf(LOG_ERR, "Error getting LCD status: "
"Command not supported on this system.");
rc = -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error setting LCD status: %s",
val2str(rsp->ccode, completion_code_vals));
rc= -1;
@@ -1332,13 +1336,12 @@ ipmi_lcd_set_single_line_text(struct ipmi_intf * intf, char * text)
* Description: This function sets lcd line text
* Input: intf - ipmi interface
* text - lcd string
- * line_number- line number
* Output:
* Return: -1 on error
* 0 if successful
*/
static int
-ipmi_lcd_set_text(struct ipmi_intf * intf, char * text, int line_number)
+ipmi_lcd_set_text(struct ipmi_intf * intf, char * text)
{
int rc = 0;
IPMI_DELL_LCD_CAPS lcd_caps;
@@ -1367,7 +1370,6 @@ ipmi_lcd_set_text(struct ipmi_intf * intf, char * text, int line_number)
* Input: intf - ipmi interface
* lcdquallifier- lcd quallifier
* errordisp - error number
- * line_number-line number
* text - lcd string
* Output:
* Return: -1 on error
@@ -1375,12 +1377,12 @@ ipmi_lcd_set_text(struct ipmi_intf * intf, char * text, int line_number)
*/
static int
ipmi_lcd_configure_wh(struct ipmi_intf * intf, uint32_t mode,
- uint16_t lcdquallifier, uint8_t errordisp, int8_t line_number, char * text)
+ uint16_t lcdquallifier, uint8_t errordisp, char * text)
{
int rc = 0;
if (IPMI_DELL_LCD_CONFIG_USER_DEFINED == mode) {
/* Any error was reported earlier. */
- rc = ipmi_lcd_set_text(intf, text, line_number);
+ rc = ipmi_lcd_set_text(intf, text);
}
if (rc == 0) {
rc = ipmi_lcd_set_configure_command_wh(intf, mode ,lcdquallifier,errordisp);
@@ -1393,19 +1395,17 @@ ipmi_lcd_configure_wh(struct ipmi_intf * intf, uint32_t mode,
* Description: This function updates the current lcd configuration
* Input: intf - ipmi interface
* command- lcd command
- * line_number-line number
* text - lcd string
* Output:
* Return: -1 on error
* 0 if successful
*/
static int
-ipmi_lcd_configure(struct ipmi_intf * intf, int command,
- int8_t line_number, char * text)
+ipmi_lcd_configure(struct ipmi_intf * intf, int command, char * text)
{
int rc = 0;
if (IPMI_DELL_LCD_CONFIG_USER_DEFINED == command) {
- rc = ipmi_lcd_set_text(intf, text, line_number);
+ rc = ipmi_lcd_set_text(intf, text);
}
if (rc == 0) {
rc = ipmi_lcd_set_configure_command(intf, command);
@@ -1515,18 +1515,18 @@ ipmi_delloem_mac_main(struct ipmi_intf * intf, int argc, char ** argv)
int rc = 0;
int currIdInt = -1;
current_arg++;
- if (argc > 1 && strcmp(argv[current_arg], "help") == 0) {
+ if (argc > 1 && !strcmp(argv[current_arg], "help")) {
ipmi_mac_usage();
return 0;
}
ipmi_idracvalidator_command(intf);
if (argc == 1) {
rc = ipmi_macinfo(intf, 0xff);
- } else if (strncmp(argv[current_arg], "list\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "list")) {
rc = ipmi_macinfo(intf, 0xff);
- } else if (strncmp(argv[current_arg], "get\0", 4) == 0) {
+ } else if (!strcmp(argv[current_arg], "get")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_mac_usage();
return -1;
}
@@ -1595,24 +1595,22 @@ ipmi_macinfo_drac_idrac_virtual_mac(struct ipmi_intf* intf,uint8_t NicNum)
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- return -1;
- }
- if (rsp->ccode > 0) {
+ if (!rsp || rsp->ccode) {
return -1;
}
+
if ((IMC_IDRAC_12G_MODULAR == IMC_Type)
|| (IMC_IDRAC_12G_MONOLITHIC== IMC_Type)
|| (IMC_IDRAC_13G_MODULAR == IMC_Type)
|| (IMC_IDRAC_13G_MONOLITHIC== IMC_Type)) {
- /* Get the Chasiss Assigned MAC Addresss for 12g Only */
+ /* Get the Chasiss Assigned MAC Address for 12g Only */
memcpy(VirtualMacAddress, ((rsp->data) + 1), MACADDRESSLENGH);
for (i = 0; i < MACADDRESSLENGH; i++) {
if (VirtualMacAddress[i] != 0) {
UseVirtualMacAddress = 1;
}
}
- /* Get the Server Assigned MAC Addresss for 12g Only */
+ /* Get the Server Assigned MAC Address for 12g Only */
if (!UseVirtualMacAddress) {
memcpy(VirtualMacAddress, ((rsp->data) + 1 + MACADDRESSLENGH),
MACADDRESSLENGH);
@@ -1690,11 +1688,11 @@ ipmi_macinfo_drac_idrac_mac(struct ipmi_intf* intf,uint8_t NicNum)
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting MAC Address");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting MAC Address (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -1756,11 +1754,11 @@ ipmi_macinfo_10g(struct ipmi_intf* intf, uint8_t NicNum)
req.msg.data = msg_data;
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting MAC Address");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting MAC Address (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -1830,11 +1828,11 @@ ipmi_macinfo_11g(struct ipmi_intf* intf, uint8_t NicNum)
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting MAC Address");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting MAC Address (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -1861,11 +1859,11 @@ ipmi_macinfo_11g(struct ipmi_intf* intf, uint8_t NicNum)
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting MAC Address");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting MAC Address (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -1950,7 +1948,7 @@ ipmi_mac_usage(void)
*
* Description: This function processes the delloem lan command
* Input: intf - ipmi interface
- * argc - no of arguments
+ * argc - no of arguments (unused, left in for calling consistency)
* argv - argument string array
* Output:
*
@@ -1958,13 +1956,13 @@ ipmi_mac_usage(void)
* -1 - failure
*/
static int
-ipmi_delloem_lan_main(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_delloem_lan_main(struct ipmi_intf * intf, int __UNUSED__(argc), char ** argv)
{
int rc = 0;
int nic_selection = 0;
char nic_set[2] = {0};
current_arg++;
- if (argv[current_arg] == NULL || strcmp(argv[current_arg], "help") == 0) {
+ if (!argv[current_arg] || !strcmp(argv[current_arg], "help")) {
ipmi_lan_usage();
return 0;
}
@@ -1972,9 +1970,9 @@ ipmi_delloem_lan_main(struct ipmi_intf * intf, int argc, char ** argv)
if (!IsLANSupported()) {
lprintf(LOG_ERR, "lan is not supported on this system.");
return -1;
- } else if (strncmp(argv[current_arg], "set\0", 4) == 0) {
+ } else if (!strcmp(argv[current_arg], "set")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_lan_usage();
return -1;
}
@@ -2008,12 +2006,12 @@ ipmi_delloem_lan_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = ipmi_lan_set_nic_selection(intf,nic_selection);
}
return 0;
- } else if (strncmp(argv[current_arg], "get\0", 4) == 0) {
+ } else if (!strcmp(argv[current_arg], "get")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
rc = ipmi_lan_get_nic_selection(intf);
return rc;
- } else if (strncmp(argv[current_arg], "active\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "active")) {
rc = ipmi_lan_get_active_nic(intf);
return rc;
} else {
@@ -2053,47 +2051,47 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg,
req.msg.data = msg_data;
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting nic selection");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting nic selection (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
}
nic_set[0] = rsp->data[0];
nic_set[1] = rsp->data[1];
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "dedicated\0", 10) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "dedicated")) {
nic_set[0] = 1;
nic_set[1] = 0;
return 0;
}
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "shared\0", 7) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "shared")) {
/* placeholder */
} else {
return INVALID;
}
current_arg++;
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "with\0", 5) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "with")) {
/* placeholder */
} else {
return INVALID;
}
current_arg++;
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "failover\0", 9) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "failover")) {
failover = 1;
}
if (failover) {
current_arg++;
}
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "lom1\0", 5) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "lom1")) {
if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) {
return INVAILD_SHARED_MODE;
}
@@ -2111,8 +2109,8 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg,
}
}
return 0;
- } else if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "lom2\0", 5) == 0) {
+ } else if (argv[current_arg]
+ && !strcmp(argv[current_arg], "lom2")) {
if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) {
return INVAILD_SHARED_MODE;
}
@@ -2130,8 +2128,8 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg,
}
}
return 0;
- } else if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "lom3\0", 5) == 0) {
+ } else if (argv[current_arg]
+ && !strcmp(argv[current_arg], "lom3")) {
if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) {
return INVAILD_SHARED_MODE;
}
@@ -2149,8 +2147,8 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg,
}
}
return 0;
- } else if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "lom4\0", 5) == 0) {
+ } else if (argv[current_arg]
+ && !strcmp(argv[current_arg], "lom4")) {
if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) {
return INVAILD_SHARED_MODE;
}
@@ -2168,8 +2166,8 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg,
}
}
return 0;
- } else if (failover && argv[current_arg] != NULL
- && strncmp(argv[current_arg], "none\0", 5) == 0) {
+ } else if (failover && argv[current_arg]
+ && !strcmp(argv[current_arg], "none")) {
if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type) ) {
return INVAILD_SHARED_MODE;
}
@@ -2180,16 +2178,16 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg,
nic_set[1] = 0;
}
return 0;
- } else if (failover && argv[current_arg] != NULL
- && strncmp(argv[current_arg], "all\0", 4) == 0) {
+ } else if (failover && argv[current_arg]
+ && !strcmp(argv[current_arg], "all")) {
/* placeholder */
} else {
return INVALID;
}
current_arg++;
- if (failover && argv[current_arg] != NULL
- && strncmp(argv[current_arg], "loms\0", 5) == 0) {
+ if (failover && argv[current_arg]
+ && !strcmp(argv[current_arg], "loms")) {
if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_13G_MODULAR == IMC_Type)) {
return INVAILD_SHARED_MODE;
}
@@ -2205,47 +2203,47 @@ get_nic_selection_mode_12g(struct ipmi_intf* intf,int current_arg,
static int
get_nic_selection_mode(int current_arg, char ** argv)
{
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "dedicated\0", 10) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "dedicated")) {
return DEDICATED;
}
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "shared\0", 7) == 0) {
- if (argv[current_arg+1] == NULL) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "shared")) {
+ if (!argv[current_arg+1]) {
return SHARED;
}
}
current_arg++;
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "with\0", 5) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "with")) {
/* place holder */
} else {
return INVALID;
}
current_arg++;
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "failover\0", 9) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "failover")) {
/* place holder */
} else {
return INVALID;
}
current_arg++;
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "lom2\0", 5) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "lom2")) {
return SHARED_WITH_FAILOVER_LOM2;
- } else if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "all\0", 4) == 0) {
+ } else if (argv[current_arg]
+ && !strcmp(argv[current_arg], "all")) {
/* place holder */
} else {
return INVALID;
}
current_arg++;
- if (argv[current_arg] != NULL
- && strncmp(argv[current_arg], "loms\0", 5) == 0) {
+ if (argv[current_arg]
+ && !strcmp(argv[current_arg], "loms")) {
return SHARED_WITH_FAILOVER_ALL_LOMS;
}
return INVALID;
@@ -2268,7 +2266,7 @@ ipmi_lan_set_nic_selection_12g(struct ipmi_intf * intf, uint8_t * nic_selection)
req.msg.data = msg_data;
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in setting nic selection");
return -1;
} else if( (nic_selection[0] == 1)
@@ -2278,7 +2276,7 @@ ipmi_lan_set_nic_selection_12g(struct ipmi_intf * intf, uint8_t * nic_selection)
lprintf(LOG_ERR,
"FM001 : A required license is missing or expired");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error in setting nic selection (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2303,10 +2301,10 @@ ipmi_lan_set_nic_selection(struct ipmi_intf * intf, uint8_t nic_selection)
req.msg.data = msg_data;
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in setting nic selection");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error in setting nic selection (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2336,10 +2334,10 @@ ipmi_lan_get_nic_selection(struct ipmi_intf * intf)
req.msg.data = msg_data;
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting nic selection");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting nic selection (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2392,10 +2390,10 @@ ipmi_lan_get_active_nic(struct ipmi_intf * intf)
req.msg.data = msg_data;
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting Active LOM Status");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting Active LOM Status (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2411,10 +2409,10 @@ ipmi_lan_get_active_nic(struct ipmi_intf * intf)
req.msg.data = msg_data;
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting Active LOM Status");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting Active LOM Status (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2505,68 +2503,68 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int rc = 0;
current_arg++;
- if (argc > 1 && strcmp(argv[current_arg], "help") == 0) {
+ if (argc > 1 && !strcmp(argv[current_arg], "help")) {
ipmi_powermonitor_usage();
return 0;
}
ipmi_idracvalidator_command(intf);
if (argc == 1) {
rc = ipmi_powermgmt(intf);
- } else if (strncmp(argv[current_arg], "status\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "status")) {
rc = ipmi_powermgmt(intf);
- } else if (strncmp(argv[current_arg], "clear\0", 6) == 0) {
+ } else if (!strcmp(argv[current_arg], "clear")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_powermonitor_usage();
return -1;
- } else if (strncmp(argv[current_arg], "peakpower\0", 10) == 0) {
+ } else if (!strcmp(argv[current_arg], "peakpower")) {
rc = ipmi_powermgmt_clear(intf, 1);
- } else if (strncmp(argv[current_arg], "cumulativepower\0", 16) == 0) {
+ } else if (!strcmp(argv[current_arg], "cumulativepower")) {
rc = ipmi_powermgmt_clear(intf, 0);
} else {
ipmi_powermonitor_usage();
return -1;
}
- } else if (strncmp(argv[current_arg], "powerconsumption\0", 17) == 0) {
+ } else if (!strcmp(argv[current_arg], "powerconsumption")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
rc = ipmi_print_get_power_consmpt_data(intf,watt);
- } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "watt")) {
rc = ipmi_print_get_power_consmpt_data(intf, watt);
- } else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "btuphr")) {
rc = ipmi_print_get_power_consmpt_data(intf, btuphr);
} else {
ipmi_powermonitor_usage();
return -1;
}
- } else if (strncmp(argv[current_arg], "powerconsumptionhistory\0", 23) == 0) {
+ } else if (!strcmp(argv[current_arg], "powerconsumptionhistory")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
rc = ipmi_print_power_consmpt_history(intf,watt);
- } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "watt")) {
rc = ipmi_print_power_consmpt_history(intf, watt);
- } else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "btuphr")) {
rc = ipmi_print_power_consmpt_history(intf, btuphr);
} else {
ipmi_powermonitor_usage();
return -1;
}
- } else if (strncmp(argv[current_arg], "getpowerbudget\0", 15) == 0) {
+ } else if (!strcmp(argv[current_arg], "getpowerbudget")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
rc=ipmi_print_power_cap(intf,watt);
- } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "watt")) {
rc = ipmi_print_power_cap(intf, watt);
- } else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "btuphr")) {
rc = ipmi_print_power_cap(intf, btuphr);
} else {
ipmi_powermonitor_usage();
return -1;
}
- } else if (strncmp(argv[current_arg], "setpowerbudget\0", 15) == 0) {
+ } else if (!strcmp(argv[current_arg], "setpowerbudget")) {
int val;
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_powermonitor_usage();
return -1;
}
@@ -2581,21 +2579,21 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_powermonitor_usage();
- } else if (strncmp(argv[current_arg], "watt\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "watt")) {
rc = ipmi_set_power_cap(intf,watt,val);
- } else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0) {
+ } else if (!strcmp(argv[current_arg], "btuphr")) {
rc = ipmi_set_power_cap(intf, btuphr,val);
- } else if (strncmp(argv[current_arg], "percent\0", 8) == 0) {
+ } else if (!strcmp(argv[current_arg], "percent")) {
rc = ipmi_set_power_cap(intf,percent,val);
} else {
ipmi_powermonitor_usage();
return -1;
}
- } else if (strncmp(argv[current_arg], "enablepowercap\0", 15) == 0) {
+ } else if (!strcmp(argv[current_arg], "enablepowercap")) {
ipmi_set_power_capstatus_command(intf,1);
- } else if (strncmp(argv[current_arg], "disablepowercap\0", 16) == 0) {
+ } else if (!strcmp(argv[current_arg], "disablepowercap")) {
ipmi_set_power_capstatus_command(intf,0);
} else {
ipmi_powermonitor_usage();
@@ -2603,24 +2601,7 @@ ipmi_delloem_powermonitor_main(struct ipmi_intf * intf, int argc, char ** argv)
}
return rc;
}
-/*
- * Function Name: ipmi_time_to_str
- *
- * Description: This function converts ipmi time format into gmtime format
- * Input: rawTime - ipmi time format
- * Output: strTime - gmtime format
- *
- * Return:
- */
-static void
-ipmi_time_to_str(time_t rawTime, char * strTime)
-{
- struct tm *tm;
- char *temp;
- tm = gmtime(&rawTime);
- temp = asctime(tm);
- strcpy(strTime,temp);
-}
+
/*
* Function Name: ipmi_get_sensor_reading
*
@@ -2645,19 +2626,19 @@ ipmi_get_sensor_reading(struct ipmi_intf *intf, unsigned char sensorNumber,
req.msg.cmd = GET_SENSOR_READING;
req.msg.data = &sensorNumber;
req.msg.data_len = 1;
- if (pSensorReadingData == NULL) {
+ if (!pSensorReadingData) {
return -1;
}
memset(pSensorReadingData, 0, sizeof(SensorReadingType));
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return 1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
return 1;
}
memcpy(pSensorReadingData, rsp->data, sizeof(SensorReadingType));
/* if there is an error transmitting ipmi command, return error */
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
rc = 1;
}
/* if sensor messages are disabled, return error*/
@@ -2690,14 +2671,14 @@ ipmi_get_power_capstatus_command(struct ipmi_intf * intf)
data[0] = 01;
data[1] = 0xFF;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error getting powercap status");
return -1;
} else if (( iDRAC_FLAG_12_13 ) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
lprintf(LOG_ERR,
"FM001 : A required license is missing or expired");
return -1; /* Return Error as unlicensed */
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error getting powercap statusr: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2741,14 +2722,14 @@ ipmi_set_power_capstatus_command(struct ipmi_intf * intf, uint8_t val)
data[0] = 00;
data[1] = val;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting powercap status");
return -1;
} else if ((iDRAC_FLAG_12_13) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
lprintf(LOG_ERR,
"FM001 : A required license is missing or expired");
return -1; /* return unlicensed Error code */
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error setting powercap statusr: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2770,24 +2751,15 @@ ipmi_powermgmt(struct ipmi_intf * intf)
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[2];
- uint32_t cumStartTimeConv;
- uint32_t cumReadingConv;
- uint32_t maxPeakStartTimeConv;
- uint32_t ampPeakTimeConv;
- uint16_t ampReadingConv;
- uint32_t wattPeakTimeConv;
- uint32_t wattReadingConv;
- uint32_t bmctimeconv;
- uint32_t * bmctimeconvval;
+ uint32_t cumStartTime;
+ uint32_t cumReading;
+ uint32_t maxPeakStartTime;
+ uint32_t ampPeakTime;
+ uint32_t wattPeakTime;
+ uint32_t bmctime;
IPMI_POWER_MONITOR * pwrMonitorInfo;
- char cumStartTime[26];
- char maxPeakStartTime[26];
- char ampPeakTime[26];
- char wattPeakTime[26];
- char bmctime[26];
-
int ampReading;
int ampReadingRemainder;
int remainder;
@@ -2799,22 +2771,17 @@ ipmi_powermgmt(struct ipmi_intf * intf)
req.msg.cmd = IPMI_CMD_GET_SEL_TIME;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error getting BMC time info.");
return -1;
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR,
"Error getting power management information, return code %x",
rsp->ccode);
return -1;
}
- bmctimeconvval=(uint32_t*)rsp->data;
-# if WORDS_BIGENDIAN
- bmctimeconv=BSWAP_32(*bmctimeconvval);
-# else
- bmctimeconv=*bmctimeconvval;
-# endif
+ bmctime = ipmi32toh(rsp->data);
/* get powermanagement info*/
req.msg.netfn = DELL_OEM_NETFN;
@@ -2828,7 +2795,7 @@ ipmi_powermgmt(struct ipmi_intf * intf)
msg_data[1] = 0x01;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error getting power management information.");
return -1;
}
@@ -2841,7 +2808,7 @@ ipmi_powermgmt(struct ipmi_intf * intf)
lprintf(LOG_ERR, "Error getting power management information: "
"Command not supported on this system.");
return -1;
- }else if (rsp->ccode != 0) {
+ }else if (rsp->ccode) {
lprintf(LOG_ERR,
"Error getting power management information, return code %x",
rsp->ccode);
@@ -2849,54 +2816,35 @@ ipmi_powermgmt(struct ipmi_intf * intf)
}
pwrMonitorInfo = (IPMI_POWER_MONITOR*)rsp->data;
-# if WORDS_BIGENDIAN
- cumStartTimeConv = BSWAP_32(pwrMonitorInfo->cumStartTime);
- cumReadingConv = BSWAP_32(pwrMonitorInfo->cumReading);
- maxPeakStartTimeConv = BSWAP_32(pwrMonitorInfo->maxPeakStartTime);
- ampPeakTimeConv = BSWAP_32(pwrMonitorInfo->ampPeakTime);
- ampReadingConv = BSWAP_16(pwrMonitorInfo->ampReading);
- wattPeakTimeConv = BSWAP_32(pwrMonitorInfo->wattPeakTime);
- wattReadingConv = BSWAP_16(pwrMonitorInfo->wattReading);
-# else
- cumStartTimeConv = pwrMonitorInfo->cumStartTime;
- cumReadingConv = pwrMonitorInfo->cumReading;
- maxPeakStartTimeConv = pwrMonitorInfo->maxPeakStartTime;
- ampPeakTimeConv = pwrMonitorInfo->ampPeakTime;
- ampReadingConv = pwrMonitorInfo->ampReading;
- wattPeakTimeConv = pwrMonitorInfo->wattPeakTime;
- wattReadingConv = pwrMonitorInfo->wattReading;
-# endif
-
- ipmi_time_to_str(cumStartTimeConv, cumStartTime);
- ipmi_time_to_str(maxPeakStartTimeConv, maxPeakStartTime);
- ipmi_time_to_str(ampPeakTimeConv, ampPeakTime);
- ipmi_time_to_str(wattPeakTimeConv, wattPeakTime);
- ipmi_time_to_str(bmctimeconv, bmctime);
+ cumStartTime = ipmi32toh(&pwrMonitorInfo->cumStartTime);
+ cumReading = ipmi32toh(&pwrMonitorInfo->cumReading);
+ maxPeakStartTime = ipmi32toh(&pwrMonitorInfo->maxPeakStartTime);
+ ampPeakTime = ipmi32toh(&pwrMonitorInfo->ampPeakTime);
+ ampReading = ipmi16toh(&pwrMonitorInfo->ampReading);
+ wattPeakTime = ipmi32toh(&pwrMonitorInfo->wattPeakTime);
+ wattReading = ipmi16toh(&pwrMonitorInfo->wattReading);
- remainder = (cumReadingConv % 1000);
- cumReadingConv = cumReadingConv / 1000;
+ remainder = (cumReading % 1000);
+ cumReading = cumReading / 1000;
remainder = (remainder + 50) / 100;
- ampReading = ampReadingConv;
- ampReadingRemainder = ampReading%10;
- ampReading = ampReading/10;
-
- wattReading = wattReadingConv;
+ ampReadingRemainder = ampReading % 10;
+ ampReading = ampReading / 10;
printf("Power Tracking Statistics\n");
printf("Statistic : Cumulative Energy Consumption\n");
- printf("Start Time : %s", cumStartTime);
- printf("Finish Time : %s", bmctime);
- printf("Reading : %d.%d kWh\n\n", cumReadingConv, remainder);
+ printf("Start Time : %s", ipmi_timestamp_numeric(cumStartTime));
+ printf("Finish Time : %s", ipmi_timestamp_numeric(bmctime));
+ printf("Reading : %d.%d kWh\n\n", cumReading, remainder);
printf("Statistic : System Peak Power\n");
- printf("Start Time : %s", maxPeakStartTime);
- printf("Peak Time : %s", wattPeakTime);
+ printf("Start Time : %s", ipmi_timestamp_numeric(maxPeakStartTime));
+ printf("Peak Time : %s", ipmi_timestamp_numeric(wattPeakTime));
printf("Peak Reading : %d W\n\n", wattReading);
printf("Statistic : System Peak Amperage\n");
- printf("Start Time : %s", maxPeakStartTime);
- printf("Peak Time : %s", ampPeakTime);
+ printf("Start Time : %s", ipmi_timestamp_numeric(maxPeakStartTime));
+ printf("Peak Time : %s", ipmi_timestamp_numeric(ampPeakTime));
printf("Peak Reading : %d.%d A\n", ampReading, ampReadingRemainder);
return 0;
}
@@ -2932,7 +2880,7 @@ ipmi_powermgmt_clear(struct ipmi_intf * intf, uint8_t clearValue)
msg_data[2] = clearType;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error clearing power values.");
return -1;
} else if ((iDRAC_FLAG_12_13)
@@ -2944,7 +2892,7 @@ ipmi_powermgmt_clear(struct ipmi_intf * intf, uint8_t clearValue)
lprintf(LOG_ERR,
"Error clearing power values, command not supported on this system.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error clearing power values: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -3010,7 +2958,7 @@ ipmi_get_power_headroom_command(struct ipmi_intf * intf,uint8_t unit)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error getting power headroom status");
return -1;
} else if ((iDRAC_FLAG_12_13)
@@ -3022,7 +2970,7 @@ ipmi_get_power_headroom_command(struct ipmi_intf * intf,uint8_t unit)
lprintf(LOG_ERR, "Error getting power headroom status: "
"Command not supported on this system ");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error getting power headroom status: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -3077,7 +3025,7 @@ ipmi_get_power_consumption_data(struct ipmi_intf * intf,uint8_t unit)
int status = 0;
int sensor_number = 0;
sdr = ipmi_sdr_find_sdr_byid(intf, "System Level");
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR,
"Error : Can not access the System Level sensor data");
return -1;
@@ -3089,7 +3037,7 @@ ipmi_get_power_consumption_data(struct ipmi_intf * intf,uint8_t unit)
sdr->record.common->keys.owner_id,
sdr->record.common->keys.lun,
sdr->record.common->keys.channel);
- if (rsp == NULL || rsp->ccode != 0) {
+ if (!rsp || rsp->ccode) {
lprintf(LOG_ERR,
"Error : Can not access the System Level sensor data");
return -1;
@@ -3144,7 +3092,7 @@ ipmi_get_instan_power_consmpt_data(struct ipmi_intf * intf,
msg_data[1] = 0x00;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error getting instantaneous power consumption data .");
return -1;
} else if ((iDRAC_FLAG_12_13)
@@ -3156,7 +3104,7 @@ ipmi_get_instan_power_consmpt_data(struct ipmi_intf * intf,
lprintf(LOG_ERR, "Error getting instantaneous power consumption data: "
"Command not supported on this system.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error getting instantaneous power consumption data: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -3396,12 +3344,7 @@ ipmi_get_minpower_consmpt_history(struct ipmi_intf * intf,
static int
ipmi_print_power_consmpt_history(struct ipmi_intf * intf, int unit)
{
- char timestr[30];
- uint32_t lastminutepeakpower;
- uint32_t lasthourpeakpower;
- uint32_t lastdaypeakpower;
- uint32_t lastweekpeakpower;
- uint64_t tempbtuphrconv;
+ uint64_t tmp;
int rc = 0;
IPMI_AVGPOWER_CONSUMP_HISTORY avgpower;
@@ -3426,101 +3369,91 @@ ipmi_print_power_consmpt_history(struct ipmi_intf * intf, int unit)
return rc;
}
printf("Power Consumption History\n\n");
- /* The fields are alligned manually changing the spaces will alter
+ /* The fields are aligned manually changing the spaces will alter
* the alignment*/
printf("Statistic Last Minute Last Hour "
"Last Day Last Week\n\n");
if (unit == btuphr) {
printf("Average Power Consumption ");
- tempbtuphrconv = watt_to_btuphr_conversion(avgpower.lastminutepower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(avgpower.lasthourpower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(avgpower.lastdaypower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(avgpower.lastweakpower);
- printf("%4" PRId64 " BTU/hr\n", tempbtuphrconv);
+ tmp = watt_to_btuphr_conversion(avgpower.lastminutepower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(avgpower.lasthourpower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(avgpower.lastdaypower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(avgpower.lastweakpower);
+ printf("%4" PRId64 " BTU/hr\n", tmp);
printf("Max Power Consumption ");
- tempbtuphrconv = watt_to_btuphr_conversion(stPeakpower.lastminutepower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(stPeakpower.lasthourpower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(stPeakpower.lastdaypower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(stPeakpower.lastweakpower);
- printf("%4" PRId64 " BTU/hr\n", tempbtuphrconv);
+ tmp = watt_to_btuphr_conversion(stPeakpower.lastminutepower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(stPeakpower.lasthourpower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(stPeakpower.lastdaypower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(stPeakpower.lastweakpower);
+ printf("%4" PRId64 " BTU/hr\n", tmp);
printf("Min Power Consumption ");
- tempbtuphrconv = watt_to_btuphr_conversion(stMinpower.lastminutepower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(stMinpower.lasthourpower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(stMinpower.lastdaypower);
- printf("%4" PRId64 " BTU/hr ", tempbtuphrconv);
- tempbtuphrconv = watt_to_btuphr_conversion(stMinpower.lastweakpower);
- printf("%4" PRId64 " BTU/hr\n\n", tempbtuphrconv);
+ tmp = watt_to_btuphr_conversion(stMinpower.lastminutepower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(stMinpower.lasthourpower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(stMinpower.lastdaypower);
+ printf("%4" PRId64 " BTU/hr ", tmp);
+ tmp = watt_to_btuphr_conversion(stMinpower.lastweakpower);
+ printf("%4" PRId64 " BTU/hr\n\n", tmp);
} else {
printf("Average Power Consumption ");
- tempbtuphrconv = (avgpower.lastminutepower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (avgpower.lasthourpower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (avgpower.lastdaypower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv=(avgpower.lastweakpower);
- printf("%4" PRId64 " W \n", tempbtuphrconv);
+ tmp = avgpower.lastminutepower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = avgpower.lasthourpower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = avgpower.lastdaypower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = avgpower.lastweakpower;
+ printf("%4" PRId64 " W \n", tmp);
printf("Max Power Consumption ");
- tempbtuphrconv = (stPeakpower.lastminutepower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (stPeakpower.lasthourpower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (stPeakpower.lastdaypower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (stPeakpower.lastweakpower);
- printf("%4" PRId64 " W \n", tempbtuphrconv);
+ tmp = stPeakpower.lastminutepower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = stPeakpower.lasthourpower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = stPeakpower.lastdaypower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = stPeakpower.lastweakpower;
+ printf("%4" PRId64 " W \n", tmp);
printf("Min Power Consumption ");
- tempbtuphrconv = (stMinpower.lastminutepower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (stMinpower.lasthourpower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (stMinpower.lastdaypower);
- printf("%4" PRId64 " W ", tempbtuphrconv);
- tempbtuphrconv = (stMinpower.lastweakpower);
- printf("%4" PRId64 " W \n\n", tempbtuphrconv);
+ tmp = stMinpower.lastminutepower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = stMinpower.lasthourpower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = stMinpower.lastdaypower;
+ printf("%4" PRId64 " W ", tmp);
+ tmp = stMinpower.lastweakpower;
+ printf("%4" PRId64 " W \n\n", tmp);
}
- lastminutepeakpower = stPeakpower.lastminutepowertime;
- lasthourpeakpower = stPeakpower.lasthourpowertime;
- lastdaypeakpower = stPeakpower.lastdaypowertime;
- lastweekpeakpower = stPeakpower.lastweekpowertime;
-
printf("Max Power Time\n");
- ipmi_time_to_str(lastminutepeakpower, timestr);
- printf("Last Minute : %s",timestr);
- ipmi_time_to_str(lasthourpeakpower, timestr);
- printf("Last Hour : %s",timestr);
- ipmi_time_to_str(lastdaypeakpower, timestr);
- printf("Last Day : %s",timestr);
- ipmi_time_to_str(lastweekpeakpower, timestr);
- printf("Last Week : %s",timestr);
-
- lastminutepeakpower=stMinpower.lastminutepowertime;
- lasthourpeakpower=stMinpower.lasthourpowertime;
- lastdaypeakpower=stMinpower.lastdaypowertime;
- lastweekpeakpower=stMinpower.lastweekpowertime;
+ printf("Last Minute : %s",
+ ipmi_timestamp_numeric(stPeakpower.lastminutepowertime));
+ printf("Last Hour : %s",
+ ipmi_timestamp_numeric(stPeakpower.lasthourpowertime));
+ printf("Last Day : %s",
+ ipmi_timestamp_numeric(stPeakpower.lastdaypowertime));
+ printf("Last Week : %s",
+ ipmi_timestamp_numeric(stPeakpower.lastweekpowertime));
printf("Min Power Time\n");
- ipmi_time_to_str(lastminutepeakpower, timestr);
- printf("Last Minute : %s", timestr);
- ipmi_time_to_str(lasthourpeakpower, timestr);
- printf("Last Hour : %s", timestr);
- ipmi_time_to_str(lastdaypeakpower, timestr);
- printf("Last Day : %s", timestr);
- ipmi_time_to_str(lastweekpeakpower, timestr);
- printf("Last Week : %s", timestr);
+ printf("Last Minute : %s",
+ ipmi_timestamp_numeric(stMinpower.lastminutepowertime));
+ printf("Last Hour : %s",
+ ipmi_timestamp_numeric(stMinpower.lasthourpowertime));
+ printf("Last Day : %s",
+ ipmi_timestamp_numeric(stMinpower.lastdaypowertime));
+ printf("Last Week : %s",
+ ipmi_timestamp_numeric(stMinpower.lastweekpowertime));
return rc;
}
/*
@@ -3688,7 +3621,7 @@ ipmi_set_power_cap(struct ipmi_intf * intf, int unit, int val)
val = btuphr_to_watt_conversion(val);
} else if (unit == percent) {
if ((val < 0) || (val > 100)) {
- lprintf(LOG_ERR, "Cap value is out of boundary conditon it "
+ lprintf(LOG_ERR, "Cap value is out of boundary condition it "
"should be between 0 - 100");
return -1;
}
@@ -3703,7 +3636,7 @@ ipmi_set_power_cap(struct ipmi_intf * intf, int unit, int val)
if (((val < ipmipowercap.MinimumPowerConsmp)
|| (val > ipmipowercap.MaximumPowerConsmp)) && (unit == watt)) {
lprintf(LOG_ERR,
- "Cap value is out of boundary conditon it should be between %d - %d",
+ "Cap value is out of boundary condition it should be between %d - %d",
ipmipowercap.MinimumPowerConsmp, ipmipowercap.MaximumPowerConsmp);
return -1;
} else if (((val < ipmipowercap.MinimumPowerConsmp)
@@ -3711,7 +3644,7 @@ ipmi_set_power_cap(struct ipmi_intf * intf, int unit, int val)
minpowerbtuphr = watt_to_btuphr_conversion(ipmipowercap.MinimumPowerConsmp);
maxpowerbtuphr = watt_to_btuphr_conversion(ipmipowercap.MaximumPowerConsmp);
lprintf(LOG_ERR,
- "Cap value is out of boundary conditon it should be between %d",
+ "Cap value is out of boundary condition it should be between %d",
minpowerbtuphr);
lprintf(LOG_ERR, " -%d", maxpowerbtuphr);
return -1;
@@ -3808,7 +3741,7 @@ ipmi_powermonitor_usage(void)
*
* Description: This function processes the delloem vFlash command
* Input: intf - ipmi interface
- * argc - no of arguments
+ * argc - no of arguments (unused)
* argv - argument string array
* Output:
*
@@ -3816,7 +3749,7 @@ ipmi_powermonitor_usage(void)
* -1 - failure
*/
static int
-ipmi_delloem_vFlash_main(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_delloem_vFlash_main(struct ipmi_intf * intf, int __UNUSED__(argc), char ** argv)
{
int rc = 0;
current_arg++;
@@ -3837,7 +3770,7 @@ get_vFlash_compcode_str(uint8_t vflashcompcode, const struct vFlashstr *vs)
{
static char un_str[32];
int i;
- for (i = 0; vs[i].str != NULL; i++) {
+ for (i = 0; vs[i].str; i++) {
if (vs[i].val == vflashcompcode)
return vs[i].str;
}
@@ -3871,10 +3804,10 @@ ipmi_get_sd_card_info(struct ipmi_intf * intf) {
req.msg.data_len = input_length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in getting SD Card Extended Information");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error in getting SD Card Extended Information (%s)",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -3935,26 +3868,26 @@ static int
ipmi_delloem_vFlash_process(struct ipmi_intf * intf, int current_arg, char ** argv)
{
int rc;
- if (strncmp(intf->name,"wmi\0",4) && strncmp(intf->name, "open\0",5)) {
+ if (strcmp(intf->name,"wmi") && strcmp(intf->name, "open")) {
lprintf(LOG_ERR,
"vFlash support is enabled only for wmi and open interface.");
lprintf(LOG_ERR, "Its not enabled for lan and lanplus interface.");
return -1;
}
- if (argv[current_arg] == NULL || strcmp(argv[current_arg], "help") == 0) {
+ if (!argv[current_arg] || !strcmp(argv[current_arg], "help")) {
ipmi_vFlash_usage();
return 0;
}
ipmi_idracvalidator_command(intf);
- if (!strncmp(argv[current_arg], "info\0", 5)) {
+ if (!strcmp(argv[current_arg], "info")) {
current_arg++;
- if (argv[current_arg] == NULL) {
+ if (!argv[current_arg]) {
ipmi_vFlash_usage();
return -1;
- } else if (strncmp(argv[current_arg], "Card\0", 5) == 0) {
+ } else if (!strcmp(argv[current_arg], "Card")) {
current_arg++;
- if (argv[current_arg] != NULL) {
+ if (argv[current_arg]) {
ipmi_vFlash_usage();
return -1;
}
@@ -4052,7 +3985,7 @@ CheckSetLEDSupport(struct ipmi_intf * intf)
data[9] = 0x00;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL || rsp->ccode != 0) {
+ if (!rsp || rsp->ccode) {
return;
}
SetLEDSupported = 1;
@@ -4094,10 +4027,10 @@ ipmi_getdrivemap(struct ipmi_intf * intf, int b, int d, int f, int *bay,
data[7] = (d << 3) + f; /* devfn */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error issuing getdrivemap command.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error issuing getdrivemap command: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -4149,10 +4082,10 @@ ipmi_setled_state(struct ipmi_intf * intf, int bayId, int slotId, int state)
data[11] = state >> 8; /* state MSB; */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error issuing setled command.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error issuing setled command: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -4217,7 +4150,7 @@ ipmi_delloem_setled_main(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
/* ipmitool delloem setled info*/
- if (argc == 1 || strcmp(argv[current_arg], "help") == 0) {
+ if (argc == 1 || !strcmp(argv[current_arg], "help")) {
ipmi_setled_usage();
return 0;
}
diff --git a/lib/ipmi_ekanalyzer.c b/lib/ipmi_ekanalyzer.c
index 7a6c63d..dbc76b4 100644
--- a/lib/ipmi_ekanalyzer.c
+++ b/lib/ipmi_ekanalyzer.c
@@ -37,10 +37,14 @@
#include <ipmitool/log.h>
#include <ipmitool/helper.h>
#include <ipmitool/ipmi_strings.h>
+#include <ipmitool/ipmi_fru.h>
+#include <ipmitool/ipmi_time.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <fcntl.h>
+#include <sys/stat.h>
#define NO_MORE_INFO_FIELD 0xc1
#define TYPE_CODE 0xc0 /*Language code*/
@@ -193,7 +197,7 @@ struct ipmi_ek_amc_p2p_connectivity_record{
struct fru_picmgext_amc_channel_desc_record * ch_desc;
unsigned char link_desc_count;
struct fru_picmgext_amc_link_desc_record * link_desc;
- int * matching_result; /*For link descriptor comparision*/
+ int * matching_result; /*For link descriptor comparison*/
};
/*****************************************************************************
@@ -216,8 +220,7 @@ static void ipmi_ek_add_record2list( struct ipmi_ek_multi_header ** record,
struct ipmi_ek_multi_header ** list_last );
static void ipmi_ek_display_record( struct ipmi_ek_multi_header * record,
- struct ipmi_ek_multi_header * list_head,
- struct ipmi_ek_multi_header * list_last );
+ struct ipmi_ek_multi_header * list_head);
static void ipmi_ek_remove_record_from_list(
struct ipmi_ek_multi_header * record,
@@ -234,7 +237,7 @@ static int ipmi_ekanalyzer_fru_file2structure( char * filename,
*****************************************************************************/
static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
struct ipmi_ek_multi_header ** list_head,
- struct ipmi_ek_multi_header ** list_last, char * opt,
+ char * opt,
struct ipmi_ek_multi_header * pphysical );
static int ipmi_ek_get_resource_descriptor( int port_count, int index,
@@ -450,11 +453,11 @@ ipmi_ek_get_file_type(char *argument)
*
* Global: None
*
-* Return: OK_STATUS as succes or ERROR_STATUS as error
+* Return: OK_STATUS as success or ERROR_STATUS as error
*
***************************************************************************/
int
-ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
+ipmi_ekanalyzer_main(struct ipmi_intf *__UNUSED__(intf), int argc, char **argv)
{
int rc = ERROR_STATUS;
int file_type[MAX_FILE_NUMBER];
@@ -475,11 +478,12 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
return (-1);
}
- if (strcmp(argv[argument_offset], "help") == 0) {
+ if (!strcmp(argv[argument_offset], "help")) {
ipmi_ekanalyzer_usage();
return 0;
- } else if ((strcmp(argv[argument_offset], "frushow") == 0)
- && (argc > (MIN_ARGUMENT-1))) {
+ } else if (!strcmp(argv[argument_offset], "frushow")
+ && (argc > (MIN_ARGUMENT-1)))
+ {
for (type_offset = 0; type_offset < (argc-1); type_offset++ ) {
argument_offset++;
file_type[type_offset] = ipmi_ek_get_file_type(argv[argument_offset]);
@@ -495,7 +499,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
*/
filename[type_offset] = malloc(strlen(argv[argument_offset])
+ 1 - SIZE_OF_FILE_TYPE);
- if (filename[type_offset] == NULL) {
+ if (!filename[type_offset]) {
lprintf(LOG_ERR, "malloc failure");
return (-1);
}
@@ -511,9 +515,9 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
/* Convert from binary data into multi record structure */
rc = ipmi_ekanalyzer_fru_file2structure (filename[type_offset],
&list_head, &list_record, &list_last );
- ipmi_ek_display_record(list_record, list_head, list_last);
+ ipmi_ek_display_record(list_record, list_head);
/* Remove record of list */
- while (list_head != NULL) {
+ while (list_head) {
ipmi_ek_remove_record_from_list(list_head,
&list_head,&list_last );
if (verbose > 1) {
@@ -524,8 +528,9 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
free(filename[type_offset]);
filename[type_offset] = NULL;
}
- } else if ((strcmp(argv[argument_offset], "print") == 0)
- || (strcmp(argv[argument_offset], "summary") == 0)) {
+ } else if (!strcmp(argv[argument_offset], "print")
+ || !strcmp(argv[argument_offset], "summary"))
+ {
/* Display help text for corresponding command
* if not enough parameters were given.
*/
@@ -537,7 +542,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
int filename_size=0;
if (argc < MIN_ARGUMENT) {
lprintf(LOG_ERR, "Not enough parameters given.");
- if (strcmp(argv[argument_offset], "print") == 0) {
+ if (!strcmp(argv[argument_offset], "print")) {
lprintf(LOG_ERR,
" ekanalyzer print [carrier/power/all]"
" <xx=frufile> <xx=frufile> [xx=frufile]");
@@ -549,18 +554,20 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
return ERROR_STATUS;
}
argument_offset++;
- if ((strcmp(argv[argument_offset], "carrier") == 0)
- || (strcmp(argv[argument_offset], "power") == 0)
- || (strcmp(argv[argument_offset], "all") == 0)) {
+ if (!strcmp(argv[argument_offset], "carrier")
+ || !strcmp(argv[argument_offset], "power")
+ || !strcmp(argv[argument_offset], "all"))
+ {
option = argv[argument_offset];
index ++;
argc--;
- } else if ((strcmp(argv[argument_offset], "match") == 0)
- || ( strcmp(argv[argument_offset], "unmatch") == 0)) {
+ } else if (!strcmp(argv[argument_offset], "match")
+ || !strcmp(argv[argument_offset], "unmatch"))
+ {
option = argv[argument_offset];
index ++;
argc--;
- } else if ( strncmp(&argv[argument_offset][2], "=", 1) == 0) {
+ } else if ('=' == argv[argument_offset][2]) {
/* since the command line must receive xx=filename,
* so the position of "=" sign is 2
*/
@@ -573,7 +580,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
option = "invalid";
printf("Invalid option '%s'\n", argv[argument_offset]);
argument_offset--;
- if (strcmp(argv[0], "print") == 0) {
+ if (!strcmp(argv[0], "print")) {
lprintf (LOG_ERR,
" ekanalyzer print [carrier/power/all]"
" <xx=frufile> <xx=frufile> [xx=frufile]");
@@ -584,12 +591,12 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
}
rc = ERROR_STATUS;
}
- if (strcmp(option, "invalid") != 0) {
+ if (strcmp(option, "invalid")) {
int i=0;
for (i = 0; i < (argc-1); i++) {
file_type[i] = ipmi_ek_get_file_type (argv[index]);
if (file_type[i] == ERROR_STATUS) {
- /* display the first 2 charactors (file type) of argument */
+ /* display the first 2 characters (file type) of argument */
lprintf(LOG_ERR, "Invalid file type: %c%c\n",
argv[index][0],
argv[index][1]);
@@ -603,7 +610,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
filename_size = strlen(argv[index]) - SIZE_OF_FILE_TYPE + 1;
if (filename_size > 0) {
filename[i] = malloc( filename_size );
- if (filename[i] != NULL) {
+ if (filename[i]) {
strcpy(filename[i], &argv[index][SIZE_OF_FILE_TYPE]);
} else {
lprintf(LOG_ERR, "ipmitool: malloc failure");
@@ -623,7 +630,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
printf("file name: %s\n", filename[i]);
}
}
- if (strcmp(argv[0], "print") == 0) {
+ if (!strcmp(argv[0], "print")) {
rc = ipmi_ekanalyzer_print((argc-1),
option, filename, file_type);
} else {
@@ -631,7 +638,7 @@ ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
option, filename, file_type);
}
for (i = 0; i < (argc-1); i++) {
- if (filename[i] != NULL) {
+ if (filename[i]) {
free(filename[i]);
filename[i] = NULL;
}
@@ -674,7 +681,7 @@ ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type)
{
int return_value = OK_STATUS;
/* Display carrier topology */
- if ((strcmp(opt, "carrier") == 0) || (strcmp(opt, "default") == 0)) {
+ if (!strcmp(opt, "carrier") || !strcmp(opt, "default")) {
tboolean found_flag = FALSE;
int index = 0;
int index_name[argc];
@@ -714,8 +721,9 @@ ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type)
*/
tboolean first_data = TRUE;
for (list_record[i] = list_head[i];
- list_record[i] != NULL;
- list_record[i] = list_record[i]->next) {
+ list_record[i];
+ list_record[i] = list_record[i]->next)
+ {
if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_P2P) {
if (first_data) {
printf("%s\n", STAR_LINE_LIMITER);
@@ -724,7 +732,7 @@ ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type)
}
return_value = ipmi_ek_display_carrier_connectivity(list_record[i]);
} else if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_INFO) {
- /*See AMC.0 specification Table3-3 for mor detail*/
+ /*See AMC.0 specification Table3-3 for more detail*/
#define COUNT_OFFSET 6
if (first_data) {
printf("From Carrier file: %s\n", filename[index_name[i]]);
@@ -737,7 +745,7 @@ ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type)
}
/*Destroy the list of record*/
for (i = 0; i < argc; i++) {
- while (list_head[i] != NULL) {
+ while (list_head[i]) {
ipmi_ek_remove_record_from_list(list_head[i],
&list_head[i], &list_last[i]);
}
@@ -749,10 +757,10 @@ ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type)
}
}
}
- } else if (strcmp(opt, "power") == 0) {
+ } else if (!strcmp(opt, "power")) {
printf("Print power information\n");
return_value = ipmi_ek_display_power(argc, opt, filename, file_type);
- } else if (strcmp(opt, "all") == 0) {
+ } else if (!strcmp(opt, "all")) {
printf("Print all information\n");
return_value = ipmi_ek_display_power(argc, opt, filename, file_type);
} else {
@@ -787,7 +795,7 @@ ipmi_ek_display_carrier_connectivity(struct ipmi_ek_multi_header *record)
int offset = START_DATA_OFFSET;
struct fru_picmgext_carrier_p2p_record rsc_desc;
struct fru_picmgext_carrier_p2p_descriptor *port_desc;
- if (record == NULL) {
+ if (!record) {
lprintf(LOG_ERR, "P2P connectivity record is invalid\n");
return ERROR_STATUS;
}
@@ -915,14 +923,14 @@ ipmi_ek_display_power( int argc, char * opt, char ** filename, int * file_type )
return_value = ipmi_ekanalyzer_fru_file2structure( filename[num_file],
&list_head[num_file], &list_record[num_file], &list_last[num_file]);
- if ( list_head[num_file] != NULL ){
+ if (list_head[num_file]){
for ( list_record[num_file] = list_head[num_file];
- list_record[num_file] != NULL;
- list_record[num_file] = list_record[num_file]->next
- ){
- if ( ( strcmp(opt, "all") == 0 )
- && ( file_type[num_file] == ON_CARRIER_FRU_FILE )
- ){
+ list_record[num_file];
+ list_record[num_file] = list_record[num_file]->next)
+ {
+ if (!strcmp(opt, "all")
+ && file_type[num_file] == ON_CARRIER_FRU_FILE)
+ {
if ( list_record[num_file]->data[PICMG_ID_OFFSET]
==
FRU_AMC_CARRIER_P2P
@@ -989,7 +997,7 @@ ipmi_ek_display_power( int argc, char * opt, char ** filename, int * file_type )
return_value = OK_STATUS;
/*Destroy the list of record*/
for ( index = 0; index < argc; index++ ){
- while ( list_head[index] != NULL ){
+ while (list_head[index]) {
ipmi_ek_remove_record_from_list ( list_head[index],
&list_head[index],&list_last[index] );
}
@@ -1081,7 +1089,7 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
{
tboolean return_value = FALSE;
- if ( (strcmp(opt, "carrier") == 0 ) || (strcmp(opt, "power") == 0) ){
+ if (!strcmp(opt, "carrier") || !strcmp(opt, "power")) {
lprintf(LOG_ERR, " ekanalyzer summary [match/ unmatch/ all]"\
" <xx=frufile> <xx=frufile> [xx=frufile]");
return_value = ERROR_STATUS;
@@ -1152,13 +1160,13 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
/*Get Carrier p2p connectivity record for physical check*/
for (num_file=0; num_file < argc; num_file++){
if (file_type[num_file] == ON_CARRIER_FRU_FILE ){
- for ( pcarrier_p2p=list_head[num_file];
- pcarrier_p2p != NULL ;
- pcarrier_p2p = pcarrier_p2p->next
- ){
- if ( pcarrier_p2p->data[PICMG_ID_OFFSET]
- == FRU_AMC_CARRIER_P2P
- ){
+ for (pcarrier_p2p = list_head[num_file];
+ pcarrier_p2p;
+ pcarrier_p2p = pcarrier_p2p->next)
+ {
+ if (FRU_AMC_CARRIER_P2P ==
+ pcarrier_p2p->data[PICMG_ID_OFFSET])
+ {
break;
}
}
@@ -1185,14 +1193,14 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
}
return_value = ipmi_ek_matching_process( file_type,
match_pair, num_file, list_head,
- list_last, opt, pcarrier_p2p);
+ opt, pcarrier_p2p);
}
}
}
match_pair ++;
}
for( num_file=0; num_file < argc; num_file++ ){
- if (list_head[num_file] != NULL ){
+ if (list_head[num_file]) {
ipmi_ek_remove_record_from_list( list_head[num_file],
&list_record[num_file], &list_last[num_file]);
}
@@ -1221,8 +1229,6 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
* index2: position of the second record in the list of the record
* ipmi_ek_multi_header ** list_head: pointer to the header of a
* linked list that contain FRU multi record
-* ipmi_ek_multi_header ** list_last: pointer to the tale of a
-* linked list that contain FRU multi record
* opt: string that contain display option such as "match", "unmatch", or
* "all".
* pphysical: a pointer that contain a carrier p2p connectivity record
@@ -1238,7 +1244,7 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
***************************************************************************/
static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
struct ipmi_ek_multi_header ** list_head,
- struct ipmi_ek_multi_header ** list_last, char * opt,
+ char * opt,
struct ipmi_ek_multi_header * pphysical )
{
int result = ERROR_STATUS;
@@ -1254,13 +1260,13 @@ static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
index2 = index_temp; /*index2 indcate an AMC*/
}
/*Calculate record size for Carrier file*/
- for ( record=list_head[index1]; record != NULL;record = record->next ){
+ for (record = list_head[index1]; record; record = record->next ){
if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
num_amc_record2++;
}
}
/*Calculate record size for amc file*/
- for ( record=list_head[index2]; record != NULL;record = record->next){
+ for (record = list_head[index2]; record; record = record->next){
if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
num_amc_record1++;
}
@@ -1278,17 +1284,17 @@ static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
amc_record2 = malloc ( num_amc_record2 * \
sizeof(struct ipmi_ek_amc_p2p_connectivity_record));
- for (record=list_head[index2]; record != NULL;record = record->next){
+ for (record = list_head[index2]; record; record = record->next) {
if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
result = ipmi_ek_create_amc_p2p_record( record,
&amc_record1[index_record1] );
if (result != ERROR_STATUS){
struct ipmi_ek_multi_header * current_record = NULL;
- for ( current_record=list_head[index1];
- current_record != NULL ;
- current_record = current_record->next
- ){
+ for (current_record=list_head[index1];
+ current_record;
+ current_record = current_record->next)
+ {
if ( current_record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
result = ipmi_ek_create_amc_p2p_record( current_record,
&amc_record2[index_record2] );
@@ -1358,7 +1364,7 @@ ipmi_ek_check_physical_connectivity(
{
int return_status = OK_STATUS;
- if ( record == NULL ){
+ if (!record){
printf("NO Carrier p2p connectivity !\n");
return_status = ERROR_STATUS;
}
@@ -1423,7 +1429,7 @@ ipmi_ek_check_physical_connectivity(
rsc_desc.p2p_count );
}
- if ( (port_desc != NULL) && (return_status != ERROR_STATUS) ){
+ if (port_desc && return_status != ERROR_STATUS) {
int j=0;
for ( j = 0; j < rsc_desc.p2p_count; j++ ){
@@ -1450,7 +1456,7 @@ ipmi_ek_check_physical_connectivity(
(filetype1 ==(port_desc[j].remote_resource_id &0x0f))
)
){
- if ( ! (strcmp(option, "unmatch") == 0) ){
+ if (strcmp(option, "unmatch")){
printf("%s port %d ==> %s port %d\n",
val2str(filetype2, ipmi_ekanalyzer_module_type),
record1.ch_desc[index1].lane0port,
@@ -1473,7 +1479,7 @@ ipmi_ek_check_physical_connectivity(
&&
(filetype2 == (port_desc[j].remote_resource_id & 0x0f))
){
- if ( ! (strcmp(option, "unmatch") == 0) ){
+ if (strcmp(option, "unmatch")){
printf("%s port %d ==> %s port %d\n",
val2str(filetype2, ipmi_ekanalyzer_module_type),
record1.ch_desc[index1].lane0port,
@@ -1487,7 +1493,7 @@ ipmi_ek_check_physical_connectivity(
&&
(record2.rsc_id == (port_desc[j].remote_resource_id))
){
- if ( ! (strcmp(option, "unmatch") == 0) ){
+ if (strcmp(option, "unmatch")){
printf("%s port %d ==> %s %x port %d\n",
val2str(filetype2, ipmi_ekanalyzer_module_type),
record1.ch_desc[index1].lane0port,
@@ -1523,7 +1529,7 @@ ipmi_ek_check_physical_connectivity(
}
return_status = ERROR_STATUS;
}
- if (port_desc != NULL){
+ if (port_desc) {
free(port_desc);
port_desc = NULL;
}
@@ -1603,10 +1609,10 @@ ipmi_ek_compare_link( struct ipmi_ek_multi_header * physic_record,
physic_record, file_type1, file_type2, opt );
if ( result == OK_STATUS ){
/*Display the result if option = match or all*/
- if ( (strcmp( opt, "match" ) == 0)
- || (strcmp( opt, "all" ) == 0)
- || (strcmp( opt, "default" ) == 0)
- ){
+ if (!strcmp(opt, "match")
+ || !strcmp(opt, "all")
+ || !strcmp(opt, "default"))
+ {
tboolean isOEMtype = FALSE;
printf(" Matching Result\n");
isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
@@ -1663,10 +1669,10 @@ ipmi_ek_compare_link( struct ipmi_ek_multi_header * physic_record,
record1, index_ch_desc1, record2, index_ch_desc2,
physic_record, file_type1, file_type2, opt );
if ( result == OK_STATUS ){
- if ( (strcmp( opt, "match" ) == 0)
- || (strcmp( opt, "all" ) == 0)
- || (strcmp( opt, "default" ) == 0)
- ){
+ if (!strcmp( opt, "match" )
+ || !strcmp(opt, "all")
+ || !strcmp(opt, "default"))
+ {
tboolean isOEMtype = FALSE;
printf(" Matching Result\n");
isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
@@ -1694,7 +1700,7 @@ ipmi_ek_compare_link( struct ipmi_ek_multi_header * physic_record,
}
}
- if ( (strcmp(opt, "unmatch") == 0) || (strcmp(opt, "all") == 0) ){
+ if (!strcmp(opt, "unmatch") || !strcmp(opt, "all")) {
int isOEMtype = FALSE;
printf(" Unmatching result\n");
for (index1 = 0; index1 < record1.link_desc_count; index1++){
@@ -1939,12 +1945,12 @@ ipmi_ek_compare_link_descriptor(
*
* Function name: ipmi_ek_compare_asym
*
-* Description: This function compares 2 asymetric match of 2
+* Description: This function compares 2 asymmetric match of 2
* amc link descriptors
*
* Restriction: None
*
-* Input: asym[COMPARE_CANDIDATE]: Contain 2 asymetric match for comparison
+* Input: asym[COMPARE_CANDIDATE]: Contain 2 asymmetric match for comparison
*
* Output: None
*
@@ -2055,7 +2061,7 @@ ipmi_ek_compare_number_of_enable_port(
* destination (its value = "To"). ( it is set to "" if it is not
* a source nor destination
* link_desc: AMC link descriptor
-* asym: asymetric match
+* asym: asymmetric match
*
* Output: None
*
@@ -2208,7 +2214,7 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
int index_oem = 0;
amc_record->oem_guid = malloc(amc_record->guid_count * \
sizeof(struct fru_picmgext_guid));
- if (amc_record->oem_guid == NULL) {
+ if (!amc_record->oem_guid) {
return ERROR_STATUS;
}
for (index_oem = 0; index_oem < amc_record->guid_count;
@@ -2238,7 +2244,7 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
int ch_index = 0;
amc_record->ch_desc = malloc((amc_record->ch_count) * \
sizeof(struct fru_picmgext_amc_channel_desc_record));
- if (amc_record->ch_desc == NULL) {
+ if (!amc_record->ch_desc) {
return ERROR_STATUS;
}
for (ch_index = 0; ch_index < amc_record->ch_count;
@@ -2264,7 +2270,7 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
int i=0;
amc_record->link_desc = malloc(amc_record->link_desc_count * \
sizeof(struct fru_picmgext_amc_link_desc_record));
- if (amc_record->link_desc == NULL) {
+ if (!amc_record->link_desc) {
return ERROR_STATUS;
}
for (i = 0; i< amc_record->link_desc_count; i++) {
@@ -2347,7 +2353,7 @@ ipmi_ek_get_resource_descriptor(int port_count, int index,
*
* Global: None
*
-* Return: Return OK_STATUS on sucess, ERROR_STATUS on error
+* Return: Return OK_STATUS on success, ERROR_STATUS on error
*
***************************************************************************/
static int
@@ -2358,7 +2364,7 @@ ipmi_ek_display_fru_header(char *filename)
int ret = 0;
input_file = fopen(filename, "r");
- if (input_file == NULL) {
+ if (!input_file) {
lprintf(LOG_ERR, "File '%s' not found.", filename);
return (ERROR_STATUS);
}
@@ -2413,7 +2419,7 @@ ipmi_ek_display_fru_header_detail(char *filename)
FILE *input_file;
size_t file_offset = 0;
struct fru_header header;
- time_t tval;
+ time_t ts;
int ret = 0;
unsigned char data = 0;
unsigned char lan_code = 0;
@@ -2421,7 +2427,7 @@ ipmi_ek_display_fru_header_detail(char *filename)
unsigned int board_length = 0;
input_file = fopen(filename, "r");
- if (input_file == NULL) {
+ if (!input_file) {
lprintf(LOG_ERR, "File '%s' not found.", filename);
return (-1);
}
@@ -2439,6 +2445,8 @@ ipmi_ek_display_fru_header_detail(char *filename)
if (header.offset.internal != 0) {
unsigned char format_version;
unsigned long len = 0;
+ uint8_t *area_offset;
+ uint8_t next_offset = UINT8_MAX;
printf("%s\n", EQUAL_LINE_LIMITER);
printf("FRU Internal Use Info\n");
@@ -2452,12 +2460,46 @@ ipmi_ek_display_fru_header_detail(char *filename)
}
printf("Format Version: %d\n", (format_version & 0x0f));
- if (header.offset.chassis > 0) {
- len = (header.offset.chassis * FACTOR_OFFSET)
- - (header.offset.internal * FACTOR_OFFSET);
- } else {
- len = (header.offset.board * FACTOR_OFFSET)
- - (header.offset.internal * FACTOR_OFFSET);
+ /* Internal use area doesn't contain the size byte.
+ * We need to calculate its size by finding the area
+ * that is next. Areas may not follow the same order
+ * as their offsets listed in the header, so we need
+ * to find the area that is physically next to the
+ * internal use area.
+ */
+ for (area_offset = &header.offset.internal + 1;
+ area_offset <= &header.offset.multi;
+ ++area_offset)
+ {
+ /* If the area is closer to us than the previously
+ * checked one, make it our best candidate
+ */
+ if (*area_offset < next_offset
+ && *area_offset > header.offset.internal)
+ {
+ next_offset = *area_offset;
+ }
+ }
+
+ /* If there was at least one area after internal use one,
+ * then we must have found it and can use it to calculate
+ * length. Otherwise, everything till the end of file is
+ * internal use area expect for the last (checksum) byte.
+ */
+ if (next_offset < UINT8_MAX) {
+ len = (next_offset - header.offset.internal) * FACTOR_OFFSET;
+ --len; /* First byte of internal use area is version and we've
+ already read it */
+ }
+ else {
+ struct stat fs;
+ long curpos = ftell(input_file);
+ if (curpos < 0 || 0 > fstat(fileno(input_file), &fs)) {
+ lprintf(LOG_ERR, "Failed to determine FRU file size");
+ fclose(input_file);
+ return -1;
+ }
+ len = fs.st_size - curpos - 1; /* Last byte is checksum */
}
printf("Length: %ld\n", len);
printf("Data dump:\n");
@@ -2541,33 +2583,40 @@ ipmi_ek_display_fru_header_detail(char *filename)
fclose(input_file);
return (-1);
}
- tval = ((mfg_date[2] << 16) + (mfg_date[1] << 8)
- + (mfg_date[0]));
- tval = tval * 60;
- tval = tval + secs_from_1970_1996;
- printf("Board Mfg Date: %ld, %s", tval,
- asctime(localtime(&tval)));
+
+ ts = ipmi_fru2time_t(mfg_date);
+ printf("Board Mfg Date: %ld, %s\n",
+ (IPMI_TIME_UNSPECIFIED == ts)
+ ? FRU_BOARD_DATE_UNSPEC
+ : ts,
+ ipmi_timestamp_numeric(ts));
board_length -= SIZE_MFG_DATE;
+
/* Board Mfg */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Manufacture Data", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
+
/* Board Product */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Product Name", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
+
/* Board Serial */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Serial Number", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
+
/* Board Part */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Board Part Number", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
+
/* FRU file ID */
file_offset = ipmi_ek_display_board_info_area(
input_file, "FRU File ID", &board_length);
ret = fseek(input_file, file_offset, SEEK_SET);
+
/* Additional Custom Mfg. */
file_offset = ipmi_ek_display_board_info_area(
input_file, "Custom", &board_length);
@@ -2614,7 +2663,7 @@ ipmi_ek_display_chassis_info_area(FILE *input_file, long offset)
unsigned char ch_type = 0;
unsigned int len;
- if (input_file == NULL) {
+ if (!input_file) {
lprintf(LOG_ERR, "No file stream to read.");
return (-1);
}
@@ -2696,12 +2745,18 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
int ret = 0;
unsigned char len = 0;
unsigned int size_board = 0;
- if (input_file == NULL || board_type == NULL
- || board_length == NULL) {
+ int custom_fields = 0;
+ if (!input_file || !board_type || !board_length) {
return (size_t)(-1);
}
file_offset = ftell(input_file);
+ /*
+ * TODO: This whole file's code is extremely dirty and wicked.
+ * Must eventually switch to using ipmi_fru.c code or some
+ * specialized FRU library.
+ */
+
/* Board length*/
ret = fread(&len, 1, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
@@ -2710,21 +2765,22 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
}
(*board_length)--;
- /* Bit 5:0 of Board Mfg type represent legnth */
+ /* Bit 5:0 of Board Mfg type represent length */
size_board = (len & 0x3f);
if (size_board == 0) {
printf("%s: None\n", board_type);
goto out;
}
- if (strncmp(board_type, "Custom", 6 ) != 0) {
- unsigned char *data;
+ if (strcmp(board_type, "Custom")) {
+ unsigned char *data, *str;
unsigned int i = 0;
- data = malloc(size_board);
- if (data == NULL) {
+ data = malloc(size_board + 1); /* Make room for type/length field */
+ if (!data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (size_t)(-1);
}
- ret = fread(data, size_board, 1, input_file);
+ data[0] = len; /* Save the type/length byte in 'data' */
+ ret = fread(data + 1, size_board, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid board type size!");
free(data);
@@ -2733,17 +2789,11 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
}
printf("%s type: 0x%02x\n", board_type, len);
printf("%s: ", board_type);
- for (i = 0; i < size_board; i++) {
- if ((len & TYPE_CODE) == TYPE_CODE) {
- printf("%c", data[i]);
- } else {
- /* other than language code (binary, BCD,
- * ASCII 6 bit...) is not supported
- */
- printf("%02x", data[i]);
- }
- }
- printf("\n");
+ i = 0;
+ str = (unsigned char *)get_fru_area_str(data, &i);
+ printf("%s\n", str);
+ free(str);
+ str = NULL;
free(data);
data = NULL;
(*board_length) -= size_board;
@@ -2756,7 +2806,12 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
/* take the rest of data in the area minus 1 byte of
* checksum
*/
- printf("Additional Custom Mfg. length: 0x%02x\n", len);
+ if (custom_fields) {
+ printf("End of Custom Mfg. fields (0x%02x)\n", len);
+ } else {
+ printf("No Additional Custom Mfg. fields (0x%02x)\n", len);
+ }
+
padding = (*board_length) - 1;
if ((padding > 0) && (!feof(input_file))) {
printf("Unused space: %d (bytes)\n", padding);
@@ -2770,36 +2825,47 @@ ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
printf("Checksum: 0x%02x\n", checksum);
goto out;
}
+ custom_fields++;
printf("Additional Custom Mfg. length: 0x%02x\n", len);
if ((size_board > 0) && (size_board < (*board_length))) {
- unsigned char * additional_data = NULL;
+ unsigned char *additional_data, *str;
unsigned int i = 0;
- additional_data = malloc(size_board);
- if (additional_data == NULL) {
+ additional_data = malloc(size_board + 1); /* Make room for type/length field */
+ if (!additional_data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (size_t)(-1);
}
- ret = fread(additional_data, size_board, 1, input_file);
+ additional_data[0] = len;
+ ret = fread(additional_data + 1, size_board, 1, input_file);
if ((ret != 1) || ferror(input_file)) {
lprintf(LOG_ERR, "Invalid Additional Data!");
- if (additional_data != NULL) {
+ if (additional_data) {
free(additional_data);
additional_data = NULL;
}
goto out;
}
- printf("Additional Custom Mfg. Data: %02x",
- additional_data[0]);
- for (i = 1; i < size_board; i++) {
- printf("-%02x", additional_data[i]);
- }
- printf("\n");
+ printf("Additional Custom Mfg. Data: ");
+ i = 0;
+ str = (unsigned char *)get_fru_area_str(additional_data, &i);
+ printf("%s\n", str);
+ free(str);
+ str = NULL;
free(additional_data);
additional_data = NULL;
+
(*board_length) -= size_board;
+ ret = fread(&len, 1, 1, input_file);
+ if ((ret != 1) || ferror(input_file)) {
+ lprintf(LOG_ERR, "Invalid Length!");
+ goto out;
+ }
+ (*board_length)--;
+ size_board = (len & 0x3f);
}
else {
- printf("No Additional Custom Mfg. %d\n", *board_length);
+ printf("ERROR: File has insufficient data (%d bytes) for the "
+ "Additional Custom Mfg. field\n", *board_length);
goto out;
}
}
@@ -2838,7 +2904,7 @@ ipmi_ek_display_product_info_area(FILE *input_file, long offset)
unsigned char data = 0;
unsigned int len = 0;
- if (input_file == NULL) {
+ if (!input_file) {
lprintf(LOG_ERR, "No file stream to read.");
return (-1);
}
@@ -2924,7 +2990,6 @@ ipmi_ek_display_product_info_area(FILE *input_file, long offset)
*
* Input: record: a pointer to current record
* list_head: a pointer to header of the list
-* list_last: a pointer to tale of the list
*
* Output: None
*
@@ -2935,17 +3000,16 @@ ipmi_ek_display_product_info_area(FILE *input_file, long offset)
***************************************************************************/
static void
ipmi_ek_display_record(struct ipmi_ek_multi_header *record,
- struct ipmi_ek_multi_header *list_head,
- struct ipmi_ek_multi_header *list_last)
+ struct ipmi_ek_multi_header *list_head)
{
- if (list_head == NULL) {
+ if (!list_head) {
printf("***empty list***\n");
return;
}
printf("%s\n", EQUAL_LINE_LIMITER);
printf("FRU Multi Info area\n");
printf("%s\n", EQUAL_LINE_LIMITER);
- for (record = list_head; record != NULL; record = record->next) {
+ for (record = list_head; record; record = record->next) {
printf("Record Type ID: 0x%02x\n", record->header.type);
printf("Record Format version: 0x%02x\n",
record->header.format);
@@ -3398,7 +3462,7 @@ ipmi_ek_display_board_p2p_record(struct ipmi_ek_multi_header *record)
printf("ShMC Cross-connect (two-pair)\n");
break;
default:
- printf("Unknwon\n");
+ printf("Unknown\n");
break;
}
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET) {
@@ -3413,17 +3477,17 @@ ipmi_ek_display_board_p2p_record(struct ipmi_ek_multi_header *record)
printf("FC-PI\n");
break;
default:
- printf("Unknwon\n");
+ printf("Unknown\n");
break;
}
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND) {
- printf("Unknwon\n");
+ printf("Unknown\n");
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR) {
- printf("Unknwon\n");
+ printf("Unknown\n");
} else if (d->type == FRU_PICMGEXT_LINK_TYPE_PCIE) {
- printf("Unknwon\n");
+ printf("Unknown\n");
} else {
- printf("Unknwon\n");
+ printf("Unknown\n");
}
printf("\tLink Type:\t\t0x%02x - ", d->type);
if (d->type == 0 || d->type == 0xff) {
@@ -4007,7 +4071,7 @@ ipmi_ek_display_clock_config_record(struct ipmi_ek_multi_header *record)
*
* Restriction: None
*
-* Input/Ouput: filename1: name of the file that contain FRU binary data
+* Input/Output: filename1: name of the file that contain FRU binary data
* record: a pointer to current record
* list_head: a pointer to header of the list
* list_last: a pointer to tale of the list
@@ -4031,7 +4095,7 @@ ipmi_ekanalyzer_fru_file2structure(char *filename,
int ret = 0;
input_file = fopen(filename, "r");
- if (input_file == NULL) {
+ if (!input_file) {
lprintf(LOG_ERR, "File: '%s' is not found", filename);
return ERROR_STATUS;
}
@@ -4058,7 +4122,7 @@ ipmi_ekanalyzer_fru_file2structure(char *filename,
fseek(input_file, multi_offset, SEEK_SET);
while (!feof(input_file)) {
*list_record = malloc(sizeof(struct ipmi_ek_multi_header));
- if (*list_record == NULL) {
+ if (!(*list_record)) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return ERROR_STATUS;
}
@@ -4076,7 +4140,7 @@ ipmi_ekanalyzer_fru_file2structure(char *filename,
continue;
}
(*list_record)->data = malloc((*list_record)->header.len);
- if ((*list_record)->data == NULL) {
+ if (!(*list_record)->data) {
lprintf(LOG_ERR, "Failed to allocation memory size %d\n",
(*list_record)->header.len);
record_count++;
@@ -4121,7 +4185,7 @@ ipmi_ekanalyzer_fru_file2structure(char *filename,
*
* Function name: ipmi_ek_add_record2list
*
-* Description: this function adds a sigle FRU multi record to a linked list of
+* Description: this function adds a single FRU multi record to a linked list of
* FRU multi record.
*
* Restriction: None
@@ -4140,18 +4204,18 @@ ipmi_ek_add_record2list(struct ipmi_ek_multi_header **record,
struct ipmi_ek_multi_header **list_head,
struct ipmi_ek_multi_header **list_last)
{
- if (*list_head == NULL) {
- *list_head = *record;
- (*record)->prev = NULL;
- if (verbose > 2) {
- printf("Adding first record to list\n");
- }
- } else {
+ if (*list_head) {
(*list_last)->next = *record;
(*record)->prev = *list_last;
if (verbose > 2) {
printf("Add 1 record to list\n");
}
+ } else {
+ *list_head = *record;
+ (*record)->prev = NULL;
+ if (verbose > 2) {
+ printf("Adding first record to list\n");
+ }
}
*list_last = *record;
(*record)->next = NULL;
@@ -4161,7 +4225,7 @@ ipmi_ek_add_record2list(struct ipmi_ek_multi_header **record,
*
* Function name: ipmi_ek_remove_record_from_list
*
-* Description: this function removes a sigle FRU multi record from a linked
+* Description: this function removes a single FRU multi record from a linked
* list of FRU multi record.
*
* Restriction: None
@@ -4180,12 +4244,12 @@ ipmi_ek_remove_record_from_list(struct ipmi_ek_multi_header *record,
struct ipmi_ek_multi_header **list_head,
struct ipmi_ek_multi_header **list_last)
{
- if (record->prev == NULL) {
+ if (!record->prev) {
*list_head = record->next;
} else {
record->prev->next = record->next;
}
- if (record->next == NULL) {
+ if (!record->next) {
(*list_last) = record->prev;
} else {
record->next->prev = record->prev;
diff --git a/lib/ipmi_event.c b/lib/ipmi_event.c
index bc32ae8..df6aa51 100644
--- a/lib/ipmi_event.c
+++ b/lib/ipmi_event.c
@@ -29,7 +29,6 @@
* 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 _BSD_SOURCE
#include <stdlib.h>
#include <stdio.h>
@@ -53,6 +52,14 @@
#include <ipmitool/ipmi_event.h>
#include <ipmitool/ipmi_sdr.h>
+static
+inline
+bool
+is_system(const struct channel_info_t *chinfo)
+{
+ return (IPMI_CHANNEL_MEDIUM_SYSTEM == chinfo->medium
+ || CH_SYSTEM == chinfo->channel);
+}
static void
ipmi_event_msg_print(struct ipmi_intf * intf, struct platform_event_msg * pmsg)
@@ -62,7 +69,8 @@ ipmi_event_msg_print(struct ipmi_intf * intf, struct platform_event_msg * pmsg)
memset(&sel_event, 0, sizeof(struct sel_event_record));
sel_event.record_id = 0;
- sel_event.sel_type.standard_type.gen_id = 2;
+ htoipmi16(EVENT_GENERATOR(SMS, 0),
+ (void *)&sel_event.sel_type.standard_type.gen_id);
sel_event.sel_type.standard_type.evm_rev = pmsg->evm_rev;
sel_event.sel_type.standard_type.sensor_type = pmsg->sensor_type;
@@ -84,36 +92,42 @@ ipmi_send_platform_event(struct ipmi_intf * intf, struct platform_event_msg * em
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
- uint8_t rqdata[8];
- uint8_t chmed;
+ uint8_t rqdata[PLATFORM_EVENT_DATA_LEN_MAX];
+ uint8_t *rqdata_start = rqdata;
+ struct channel_info_t chinfo;
memset(&req, 0, sizeof(req));
- memset(rqdata, 0, 8);
+ memset(rqdata, 0, sizeof(rqdata));
req.msg.netfn = IPMI_NETFN_SE;
- req.msg.cmd = 0x02;
+ req.msg.cmd = IPMI_CMD_PLATFORM_EVENT;
req.msg.data = rqdata;
+ req.msg.data_len = PLATFORM_EVENT_DATA_LEN_NON_SI;
- chmed = ipmi_current_channel_medium(intf);
- if (chmed == IPMI_CHANNEL_MEDIUM_SYSTEM) {
- /* system interface, need extra generator ID */
- req.msg.data_len = 8;
- rqdata[0] = 0x41; // As per Fig. 29-2 and Table 5-4
- memcpy(rqdata+1, emsg, sizeof(struct platform_event_msg));
+ ipmi_current_channel_info(intf, &chinfo);
+ if (chinfo.channel == CH_UNKNOWN) {
+ lprintf(LOG_ERR, "Failed to send the platform event "
+ "via an unknown channel");
+ return -3;
}
- else {
- req.msg.data_len = 7;
- memcpy(rqdata, emsg, sizeof(struct platform_event_msg));
+
+ if (is_system(&chinfo)) {
+ /* system interface, need extra generator ID, see Fig. 29-2 */
+ req.msg.data_len = PLATFORM_EVENT_DATA_LEN_SI;
+ rqdata[0] = EVENT_GENERATOR(SMS, 0);
+ rqdata_start++;
}
+ memcpy(rqdata_start, emsg, sizeof(struct platform_event_msg));
+
ipmi_event_msg_print(intf, emsg);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Platform Event Message command failed");
return -1;
}
- else if (rsp->ccode > 0) {
+ else if (rsp->ccode) {
lprintf(LOG_ERR, "Platform Event Message command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -211,14 +225,14 @@ ipmi_event_find_offset(struct ipmi_intf *intf, uint8_t sensor_type, uint8_t even
{
const struct ipmi_event_sensor_types *evt;
- if (desc == NULL || sensor_type == 0 || event_type == 0) {
+ if (!desc || sensor_type == 0 || event_type == 0) {
return 0x00;
}
for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type);
- evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) {
- if (evt->desc != NULL &&
- strncasecmp(desc, evt->desc, __maxlen(desc, evt->desc)) == 0) {
+ evt; evt = ipmi_get_next_event_sensor_type(evt)) {
+ if (evt->desc &&
+ strcasecmp(desc, evt->desc) == 0) {
return evt->offset;
}
}
@@ -246,7 +260,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
int off;
uint8_t target, lun, channel;
- if (id == NULL) {
+ if (!id) {
lprintf(LOG_ERR, "No sensor ID supplied");
return -1;
}
@@ -254,11 +268,11 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
memset(&emsg, 0, sizeof(struct platform_event_msg));
emsg.evm_rev = 0x04;
- if (evdir == NULL)
+ if (!evdir)
emsg.event_dir = EVENT_DIR_ASSERT;
- else if (strncasecmp(evdir, "assert", 6) == 0)
+ else if (!strcmp(evdir, "assert"))
emsg.event_dir = EVENT_DIR_ASSERT;
- else if (strncasecmp(evdir, "deassert", 8) == 0)
+ else if (!strcmp(evdir, "deassert"))
emsg.event_dir = EVENT_DIR_DEASSERT;
else {
lprintf(LOG_ERR, "Invalid event direction %s. Must be 'assert' or 'deassert'", evdir);
@@ -267,7 +281,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
printf("Finding sensor %s... ", id);
sdr = ipmi_sdr_find_sdr_byid(intf, id);
- if (sdr == NULL) {
+ if (!sdr) {
printf("not found!\n");
return -1;
}
@@ -304,7 +318,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
int hilo = 0;
off = 1;
- if (state == NULL || strncasecmp(state, "list", 4) == 0) {
+ if (!state || !strcmp(state, "list")) {
printf("Sensor States:\n");
printf(" lnr : Lower Non-Recoverable \n");
printf(" lcr : Lower Critical\n");
@@ -315,12 +329,12 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
return -1;
}
- if (0 != strncasecmp(state, "lnr", 3) &&
- 0 != strncasecmp(state, "lcr", 3) &&
- 0 != strncasecmp(state, "lnc", 3) &&
- 0 != strncasecmp(state, "unc", 3) &&
- 0 != strncasecmp(state, "ucr", 3) &&
- 0 != strncasecmp(state, "unr", 3))
+ if (0 != strcmp(state, "lnr") &&
+ 0 != strcmp(state, "lcr") &&
+ 0 != strcmp(state, "lnc") &&
+ 0 != strcmp(state, "unc") &&
+ 0 != strcmp(state, "ucr") &&
+ 0 != strcmp(state, "unr"))
{
lprintf(LOG_ERR, "Invalid threshold identifier %s", state);
return -1;
@@ -349,11 +363,11 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
rsp = ipmi_sdr_get_sensor_thresholds(intf, emsg.sensor_num,
target, lun, channel);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Command Get Sensor Thresholds failed: invalid response.");
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Command Get Sensor Thresholds failed: %s",
val2str(rsp->ccode, completion_code_vals));
return (-1);
@@ -364,7 +378,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
rsp = ipmi_sdr_get_sensor_hysteresis(intf, emsg.sensor_num,
target, lun, channel);
- if (rsp != NULL && rsp->ccode == 0)
+ if (rsp && !rsp->ccode)
off = dir ? rsp->data[0] : rsp->data[1];
if (off <= 0)
off = 1;
@@ -401,7 +415,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
/*
* print list of available states for this sensor
*/
- if (state == NULL || strncasecmp(state, "list", 4) == 0) {
+ if (!state || strcasecmp(state, "list") == 0) {
print_sensor_states(intf, emsg.sensor_type, emsg.event_type);
printf("Sensor State Shortcuts:\n");
for (x = 0; x < sizeof(digi_on)/sizeof(*digi_on); x++) {
@@ -412,12 +426,12 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
off = 0;
for (x = 0; x < sizeof(digi_on)/sizeof(*digi_on); x++) {
- if (strncasecmp(state, digi_on[x], strlen(digi_on[x])) == 0) {
+ if (strcasecmp(state, digi_on[x]) == 0) {
emsg.event_data[0] = 1;
off = 1;
break;
}
- else if (strncasecmp(state, digi_off[x], strlen(digi_off[x])) == 0) {
+ else if (strcasecmp(state, digi_off[x]) == 0) {
emsg.event_data[0] = 0;
off = 1;
break;
@@ -441,7 +455,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
/*
* print list of available states for this sensor
*/
- if (state == NULL || strncasecmp(state, "list", 4) == 0) {
+ if (!state || strcasecmp(state, "list") == 0) {
print_sensor_states(intf, emsg.sensor_type, emsg.event_type);
return 0;
}
@@ -461,7 +475,7 @@ ipmi_event_fromsensor(struct ipmi_intf * intf, char * id, char * state, char * e
/*
* print list of available states for this sensor
*/
- if (state == NULL || strncasecmp(state, "list", 4) == 0) {
+ if (!state || strcasecmp(state, "list") == 0) {
print_sensor_states(intf, emsg.sensor_type, emsg.event_type);
return 0;
}
@@ -485,43 +499,30 @@ static int
ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
{
FILE * fp;
- struct ipmi_rs * rsp;
- struct ipmi_rq req;
- struct sel_event_record sel_event;
- uint8_t rqdata[8];
+ /* For ease of filling in from file data */
+ union {
+ struct platform_event_msg emsg;
+ uint8_t bytes[sizeof(struct platform_event_msg)];
+ } __attribute__ ((packed)) rqdata;
char buf[1024];
char * ptr, * tok;
- int i, j;
- uint8_t chmed;
int rc = 0;
- if (file == NULL)
+ if (!file)
return -1;
- memset(rqdata, 0, 8);
-
- /* setup Platform Event Message command */
- memset(&req, 0, sizeof(req));
- req.msg.netfn = IPMI_NETFN_SE;
- req.msg.cmd = 0x02;
- req.msg.data = rqdata;
- req.msg.data_len = 7;
-
- chmed = ipmi_current_channel_medium(intf);
- if (chmed == IPMI_CHANNEL_MEDIUM_SYSTEM) {
- /* system interface, need extra generator ID */
- rqdata[0] = 0x41; // As per Fig. 29-2 and Table 5-4
- req.msg.data_len = 8;
- }
-
fp = ipmi_open_file_read(file);
- if (fp == NULL)
+ if (!fp)
return -1;
while (feof(fp) == 0) {
- if (fgets(buf, 1024, fp) == NULL)
+ size_t count = 0;
+ if (!fgets(buf, 1024, fp))
continue;
+ /* Each line is a new event */
+ memset(&rqdata, 0, sizeof(rqdata));
+
/* clip off optional comment tail indicated by # */
ptr = strchr(buf, '#');
if (ptr)
@@ -541,49 +542,28 @@ ipmi_event_fromfile(struct ipmi_intf * intf, char * file)
/* parse the event, 7 bytes with optional comment */
/* 0x00 0x00 0x00 0x00 0x00 0x00 0x00 # event */
- i = 0;
tok = strtok(ptr, " ");
while (tok) {
- if (i == 7)
+ if (count == sizeof(struct platform_event_msg))
break;
- j = i++;
- if (chmed == IPMI_CHANNEL_MEDIUM_SYSTEM)
- j++;
- rqdata[j] = (uint8_t)strtol(tok, NULL, 0);
+ if (0 > str2uchar(tok, &rqdata.bytes[count])) {
+ lprintf(LOG_ERR, "Invalid token in file: [%s]", tok);
+ rc = -1;
+ break;
+ }
tok = strtok(NULL, " ");
+ ++count;
}
- if (i < 7) {
+ if (count < sizeof(struct platform_event_msg)) {
lprintf(LOG_ERR, "Invalid Event: %s",
- buf2str(rqdata, sizeof(rqdata)));
+ buf2str(rqdata.bytes, sizeof(rqdata.bytes)));
continue;
}
- memset(&sel_event, 0, sizeof(struct sel_event_record));
- sel_event.record_id = 0;
- sel_event.sel_type.standard_type.gen_id = 2;
-
- j = (chmed == IPMI_CHANNEL_MEDIUM_SYSTEM) ? 1 : 0;
- sel_event.sel_type.standard_type.evm_rev = rqdata[j++];
- sel_event.sel_type.standard_type.sensor_type = rqdata[j++];
- sel_event.sel_type.standard_type.sensor_num = rqdata[j++];
- sel_event.sel_type.standard_type.event_type = rqdata[j] & 0x7f;
- sel_event.sel_type.standard_type.event_dir = (rqdata[j++] & 0x80) >> 7;
- sel_event.sel_type.standard_type.event_data[0] = rqdata[j++];
- sel_event.sel_type.standard_type.event_data[1] = rqdata[j++];
- sel_event.sel_type.standard_type.event_data[2] = rqdata[j++];
-
- ipmi_sel_print_std_entry(intf, &sel_event);
-
- rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- lprintf(LOG_ERR, "Platform Event Message command failed");
- rc = -1;
- }
- else if (rsp->ccode > 0) {
- lprintf(LOG_ERR, "Platform Event Message command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
- rc = -1;
- }
+ /* Now actually send it, failures will be logged by the sender */
+ rc = ipmi_send_platform_event(intf, &rqdata.emsg);
+ if (IPMI_CC_OK != rc)
+ break;
}
fclose(fp);
@@ -616,11 +596,11 @@ ipmi_event_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int rc = 0;
- if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc == 0 || !strcmp(argv[0], "help")) {
ipmi_event_usage();
return 0;
}
- if (strncmp(argv[0], "file", 4) == 0) {
+ if (!strcmp(argv[0], "file")) {
if (argc < 2) {
ipmi_event_usage();
return 0;
diff --git a/lib/ipmi_firewall.c b/lib/ipmi_firewall.c
index 26bfd30..640a4ad 100644
--- a/lib/ipmi_firewall.c
+++ b/lib/ipmi_firewall.c
@@ -128,7 +128,7 @@ ipmi_firewall_parse_args(int argc, char ** argv, struct ipmi_function_params * p
return -1;
}
for (i=0; i<argc; i++) {
- if (strncmp(argv[i], "channel", 7) == 0 && (++i < argc)) {
+ if (!strcmp(argv[i], "channel") && (++i < argc)) {
uint8_t channel_tmp = 0;
if (is_ipmi_channel_num(argv[i], &channel_tmp) != 0) {
conv_err = 1;
@@ -137,31 +137,31 @@ ipmi_firewall_parse_args(int argc, char ** argv, struct ipmi_function_params * p
p->channel = channel_tmp;
}
}
- else if (strncmp(argv[i], "lun", 3) == 0 && (++i < argc)) {
+ else if (!strcmp(argv[i], "lun") && (++i < argc)) {
if (str2int(argv[i], &(p->lun)) != 0) {
lprintf(LOG_ERR, "Given lun '%s' is invalid.", argv[i]);
conv_err = 1;
break;
}
}
- else if (strncmp(argv[i], "force", 5) == 0) {
+ else if (!strcmp(argv[i], "force")) {
p->force = 1;
}
- else if (strncmp(argv[i], "netfn", 5) == 0 && (++i < argc)) {
+ else if (!strcmp(argv[i], "netfn") && (++i < argc)) {
if (str2int(argv[i], &(p->netfn)) != 0) {
lprintf(LOG_ERR, "Given netfn '%s' is invalid.", argv[i]);
conv_err = 1;
break;
}
}
- else if (strncmp(argv[i], "command", 7) == 0 && (++i < argc)) {
+ else if (!strcmp(argv[i], "command") && (++i < argc)) {
if (str2int(argv[i], &(p->command)) != 0) {
lprintf(LOG_ERR, "Given command '%s' is invalid.", argv[i]);
conv_err = 1;
break;
}
}
- else if (strncmp(argv[i], "subfn", 5) == 0 && (++i < argc)) {
+ else if (!strcmp(argv[i], "subfn") && (++i < argc)) {
if (str2int(argv[i], &(p->subfn)) != 0) {
lprintf(LOG_ERR, "Given subfn '%s' is invalid.", argv[i]);
conv_err = 1;
@@ -235,11 +235,11 @@ _get_netfn_support(struct ipmi_intf * intf, int channel, unsigned char * lun, un
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get NetFn Support command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get NetFn Support command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -289,11 +289,11 @@ _get_command_support(struct ipmi_intf * intf,
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Command Support (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Command Support (LUN=%d, NetFn=%d, op=0) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -316,11 +316,11 @@ _get_command_support(struct ipmi_intf * intf,
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Command Support (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Command Support (LUN=%d, NetFn=%d, op=1) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -368,11 +368,11 @@ _get_command_configurable(struct ipmi_intf * intf,
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Configurable Command (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Configurable Command (LUN=%d, NetFn=%d, op=0) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -395,11 +395,11 @@ _get_command_configurable(struct ipmi_intf * intf,
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Configurable Command (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Configurable Command (LUN=%d, NetFn=%d, op=1) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -447,11 +447,11 @@ _get_command_enables(struct ipmi_intf * intf,
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Command Enables (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Command Enables (LUN=%d, NetFn=%d, op=0) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -474,11 +474,11 @@ _get_command_enables(struct ipmi_intf * intf,
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Command Enables (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Command Enables (LUN=%d, NetFn=%d, op=1) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -558,11 +558,11 @@ _set_command_enables(struct ipmi_intf * intf,
req.msg.data_len = 19;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Set Command Enables (LUN=%d, NetFn=%d, op=0) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Set Command Enables (LUN=%d, NetFn=%d, op=0) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -579,11 +579,11 @@ _set_command_enables(struct ipmi_intf * intf,
req.msg.data_len = 19;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Set Command Enables (LUN=%d, NetFn=%d, op=1) command failed", p->lun, p->netfn);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Set Command Enables (LUN=%d, NetFn=%d, op=1) command failed: %s",
p->lun, p->netfn, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -625,11 +625,11 @@ _get_subfn_support(struct ipmi_intf * intf,
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Command Sub-function Support (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Command Sub-function Support (LUN=%d, NetFn=%d, command=%d) command failed: %s",
p->lun, p->netfn, p->command, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -672,11 +672,11 @@ _get_subfn_configurable(struct ipmi_intf * intf,
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Configurable Command Sub-function (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Configurable Command Sub-function (LUN=%d, NetFn=%d, command=%d) command failed: %s",
p->lun, p->netfn, p->command, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -719,11 +719,11 @@ _get_subfn_enables(struct ipmi_intf * intf,
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Command Sub-function Enables (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Command Sub-function Enables (LUN=%d, NetFn=%d, command=%d) command failed: %s",
p->lun, p->netfn, p->command, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -787,11 +787,11 @@ _set_subfn_enables(struct ipmi_intf * intf,
req.msg.data_len = 8;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Set Command Sub-function Enables (LUN=%d, NetFn=%d, command=%d) command failed", p->lun, p->netfn, p->command);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Set Command Sub-function Enables (LUN=%d, NetFn=%d, command=%d) command failed: %s",
p->lun, p->netfn, p->command, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -888,7 +888,7 @@ static int _gather_info(struct ipmi_intf * intf, struct ipmi_function_params * p
/* ipmi_firewall_info - print out info for firewall functions
*
- * @intf: ipmi inteface
+ * @intf: ipmi interface
* @argc: argument count
* @argv: argument list
*
@@ -903,7 +903,7 @@ ipmi_firewall_info(struct ipmi_intf * intf, int argc, char ** argv)
struct bmc_fn_support * bmc_fn_support;
unsigned int l, n, c;
- if ((argc > 0 && strncmp(argv[0], "help", 4) == 0) || ipmi_firewall_parse_args(argc, argv, &p) < 0)
+ if ((argc > 0 && !strcmp(argv[0], "help")) || ipmi_firewall_parse_args(argc, argv, &p) < 0)
{
printf_firewall_info_usage();
return 0;
@@ -1001,7 +1001,7 @@ ipmi_firewall_info(struct ipmi_intf * intf, int argc, char ** argv)
/* ipmi_firewall_enable_disable - enable/disable BMC functions
*
- * @intf: ipmi inteface
+ * @intf: ipmi interface
* @enable: whether to enable or disable
* @argc: argument count
* @argv: argument list
@@ -1018,7 +1018,7 @@ ipmi_firewall_enable_disable(struct ipmi_intf * intf, int enable, int argc, char
unsigned int l, n, c;
unsigned char enables[MAX_COMMAND_BYTES];
- if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc < 1 || !strcmp(argv[0], "help")) {
char * s1 = enable?"en":"dis";
char * s2 = enable?"":" [force]";
printf("%sable [channel H] lun L netfn N%s\n", s1, s2);
@@ -1055,7 +1055,7 @@ ipmi_firewall_enable_disable(struct ipmi_intf * intf, int enable, int argc, char
c = p.command;
if (p.subfn >= 0) {
// firewall (en|dis)able [channel c] lun l netfn n command m subfn s
- // (en|dis)able this sub-function for this commnad on this lun/netfn pair
+ // (en|dis)able this sub-function for this command on this lun/netfn pair
memcpy(enables,
bmc_fn_support->lun[l].netfn[n].command[c].subfn_enable,
MAX_SUBFN_BYTES);
@@ -1065,7 +1065,7 @@ ipmi_firewall_enable_disable(struct ipmi_intf * intf, int enable, int argc, char
} else if (p.command >= 0) {
// firewall (en|dis)able [channel c] lun l netfn n command m
- // (en|dis)able all subfn and command for this commnad on this lun/netfn pair
+ // (en|dis)able all subfn and command for this command on this lun/netfn pair
memset(enables, enable?0xff:0, MAX_SUBFN_BYTES);
ret = _set_subfn_enables(intf, &p,
&bmc_fn_support->lun[l].netfn[n].command[c], enables);
@@ -1076,14 +1076,14 @@ ipmi_firewall_enable_disable(struct ipmi_intf * intf, int enable, int argc, char
&bmc_fn_support->lun[l].netfn[n], enables, p.force);
} else if (p.netfn >= 0) {
// firewall (en|dis)able [channel c] lun l netfn n
- // (en|dis)able all commnads on this lun/netfn pair
+ // (en|dis)able all command on this lun/netfn pair
memset(enables, enable?0xff:0, sizeof(enables));
ret = _set_command_enables(intf, &p,
&bmc_fn_support->lun[l].netfn[n], enables, p.force);
/*
} else if (p.lun >= 0) {
// firewall (en|dis)able [channel c] lun l
- // (en|dis)able all commnads on all netfn pairs for this lun
+ // (en|dis)able all command on all netfn pairs for this lun
*/
}
free(bmc_fn_support);
@@ -1093,7 +1093,7 @@ ipmi_firewall_enable_disable(struct ipmi_intf * intf, int enable, int argc, char
/* ipmi_firewall_reset - reset firmware firewall to enable everything
*
- * @intf: ipmi inteface
+ * @intf: ipmi interface
* @argc: argument count
* @argv: argument list
*
@@ -1113,7 +1113,7 @@ ipmi_firewall_reset(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_ERR, "Not enough parameters given.");
printf_firewall_usage();
return (-1);
- } else if (argc > 0 && strncmp(argv[0], "help", 4) == 0) {
+ } else if (argc > 0 && !strcmp(argv[0], "help")) {
printf_firewall_usage();
return 0;
}
@@ -1171,19 +1171,19 @@ ipmi_firewall_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int rc = 0;
- if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc < 1 || !strcmp(argv[0], "help")) {
printf_firewall_usage();
}
- else if (strncmp(argv[0], "info", 4) == 0) {
+ else if (!strcmp(argv[0], "info")) {
rc = ipmi_firewall_info(intf, argc-1, &(argv[1]));
}
- else if (strncmp(argv[0], "enable", 6) == 0) {
+ else if (!strcmp(argv[0], "enable")) {
rc = ipmi_firewall_enable_disable(intf, 1, argc-1, &(argv[1]));
}
- else if (strncmp(argv[0], "disable", 7) == 0) {
+ else if (!strcmp(argv[0], "disable")) {
rc = ipmi_firewall_enable_disable(intf, 0, argc-1, &(argv[1]));
}
- else if (strncmp(argv[0], "reset", 5) == 0) {
+ else if (!strcmp(argv[0], "reset")) {
rc = ipmi_firewall_reset(intf, argc-1, &(argv[1]));
}
else {
diff --git a/lib/ipmi_fru.c b/lib/ipmi_fru.c
index cf00eff..3d1d8a1 100644
--- a/lib/ipmi_fru.c
+++ b/lib/ipmi_fru.c
@@ -33,12 +33,15 @@
#include <ipmitool/ipmi.h>
#include <ipmitool/log.h>
#include <ipmitool/helper.h>
+#include <ipmitool/ipmi_cc.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi_fru.h>
#include <ipmitool/ipmi_mc.h>
#include <ipmitool/ipmi_sdr.h>
#include <ipmitool/ipmi_strings.h> /* IANA id strings */
+#include <ipmitool/ipmi_time.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -49,6 +52,7 @@
#endif
#define FRU_MULTIREC_CHUNK_SIZE (255 + sizeof(struct fru_multirec_header))
+#define FRU_FIELD_VALID(a) (a && a[0])
static const char *section_id[4] = {
"Internal Use Section",
@@ -57,16 +61,56 @@ static const char *section_id[4] = {
"Product Section"
};
+static const char * combined_voltage_desc[] = {
+ "12 V",
+ "-12 V",
+ "5 V",
+ "3.3 V"
+};
+
+static const char * chassis_type_desc[] = {
+ "Unspecified",
+ "Other",
+ "Unknown",
+ "Desktop",
+ "Low Profile Desktop",
+ "Pizza Box",
+ "Mini Tower",
+ "Tower",
+ "Portable",
+ "LapTop",
+ "Notebook",
+ "Hand Held",
+ "Docking Station",
+ "All in One",
+ "Sub Notebook",
+ "Space-saving",
+ "Lunch Box",
+ "Main Server Chassis",
+ "Expansion Chassis",
+ "SubChassis",
+ "Bus Expansion Chassis",
+ "Peripheral Chassis",
+ "RAID Chassis",
+ "Rack Mount Chassis",
+ "Sealed-case PC",
+ "Multi-system Chassis",
+ "CompactPCI",
+ "AdvancedTCA",
+ "Blade",
+ "Blade Enclosure"
+};
+
+static inline bool fru_cc_rq2big(int code) {
+ return (code == IPMI_CC_REQ_DATA_INV_LENGTH
+ || code == IPMI_CC_REQ_DATA_FIELD_EXCEED
+ || code == IPMI_CC_CANT_RET_NUM_REQ_BYTES);
+}
+
/* From lib/dimm_spd.c: */
int
ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id);
-/* From src/plugins/ipmi_intf.c: */
-void
-ipmi_intf_set_max_request_data_size(struct ipmi_intf * intf, uint16_t size);
-void
-ipmi_intf_set_max_response_data_size(struct ipmi_intf * intf, uint16_t size);
-
extern int verbose;
static void ipmi_fru_read_to_bin(struct ipmi_intf * intf, char * pFileName, uint8_t fruId);
@@ -107,7 +151,7 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset)
{
static const char bcd_plus[] = "0123456789 -.:,_";
char * str;
- int len, off, size, i, j, k, typecode;
+ int len, off, size, i, j, k, typecode, char_idx;
union {
uint32_t bits;
char chars[4];
@@ -126,15 +170,15 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset)
switch (typecode) {
case 0: /* 00b: binary/unspecified */
- /* hex dump -> 2x length */
- size = (len*2);
+ case 1: /* 01b: BCD plus */
+ /* hex dump or BCD -> 2x length */
+ size = (len * 2);
break;
case 2: /* 10b: 6-bit ASCII */
- /* 4 chars per group of 1-3 bytes */
- size = ((((len+2)*4)/3) & ~3);
+ /* 4 chars per group of 1-3 bytes, round up to 4 bytes boundary */
+ size = (len / 3 + 1) * 4;
break;
case 3: /* 11b: 8-bit ASCII */
- case 1: /* 01b: BCD plus */
/* no length adjustment */
size = len;
break;
@@ -145,11 +189,11 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset)
return NULL;
}
str = malloc(size+1);
- if (str == NULL)
+ if (!str)
return NULL;
memset(str, 0, size+1);
- if (len == 0) {
+ if (size == 0) {
str[0] = '\0';
*offset = off;
return str;
@@ -157,30 +201,30 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset)
switch (typecode) {
case 0: /* Binary */
- strncpy(str, buf2str(&data[off], len), len*2);
+ strncpy(str, buf2str(&data[off], len), size);
break;
case 1: /* BCD plus */
- for (k=0; k<len; k++)
- str[k] = bcd_plus[(data[off+k] & 0x0f)];
+ for (k = 0; k < size; k++)
+ str[k] = bcd_plus[((data[off + k / 2] >> ((k % 2) ? 0 : 4)) & 0x0f)];
str[k] = '\0';
break;
case 2: /* 6-bit ASCII */
- for (i=j=0; i<len; i+=3) {
+ for (i = j = 0; i < len; i += 3) {
u.bits = 0;
- k = ((len-i) < 3 ? (len-i) : 3);
+ k = ((len - i) < 3 ? (len - i) : 3);
#if WORDS_BIGENDIAN
u.chars[3] = data[off+i];
u.chars[2] = (k > 1 ? data[off+i+1] : 0);
u.chars[1] = (k > 2 ? data[off+i+2] : 0);
-#define CHAR_IDX 3
+ char_idx = 3;
#else
memcpy((void *)&u.bits, &data[off+i], k);
-#define CHAR_IDX 0
+ char_idx = 0;
#endif
for (k=0; k<4; k++) {
- str[j++] = ((u.chars[CHAR_IDX] & 0x3f) + 0x20);
+ str[j++] = ((u.chars[char_idx] & 0x3f) + 0x20);
u.bits >>= 6;
}
}
@@ -188,8 +232,8 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset)
break;
case 3:
- memcpy(str, &data[off], len);
- str[len] = '\0';
+ memcpy(str, &data[off], size);
+ str[size] = '\0';
break;
}
@@ -204,26 +248,26 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset)
* input_filename - user input string
*
* returns 0 if path is ok
- * returns (-1) if path is NULL
- * returns (-2) if path is too short
- * returns (-3) if path is too long
+ * returns -1 if path is NULL
+ * returns -2 if path is too short
+ * returns -3 if path is too long
*/
int
is_valid_filename(const char *input_filename)
{
- if (input_filename == NULL) {
+ if (!input_filename) {
lprintf(LOG_ERR, "ERROR: NULL pointer passed.");
- return (-1);
+ return -1;
}
if (strlen(input_filename) < 1) {
lprintf(LOG_ERR, "File/path is invalid.");
- return (-2);
+ return -2;
}
if (strlen(input_filename) >= 512) {
lprintf(LOG_ERR, "File/path must be shorter than 512 bytes.");
- return (-3);
+ return -3;
}
return 0;
@@ -271,12 +315,12 @@ build_fru_bloc(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, " Device not present (No Response)");
return NULL;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR," Device not present (%s)",
val2str(rsp->ccode, completion_code_vals));
return NULL;
@@ -428,11 +472,15 @@ free_fru_bloc(t_ipmi_fru_bloc *bloc)
while (bloc) {
del = bloc;
bloc = bloc->next;
- free(del);
- del = NULL;
+ free_n(&del);
}
}
+/* By how many bytes to reduce a write command on a size failure. */
+#define FRU_BLOCK_SZ 8
+/* Baseline for a large enough piece to reduce via steps instead of bytes. */
+#define FRU_AREA_MAXIMUM_BLOCK_SZ 32
+
/*
* write FRU[doffset:length] from the pFrubuf[soffset:length]
* rc=1 on success
@@ -458,7 +506,7 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
if (fru->access && ((doffset & 1) || (length & 1))) {
lprintf(LOG_ERROR, "Odd offset or length specified");
- return (-1);
+ return -1;
}
t_ipmi_fru_bloc * fru_bloc = build_fru_bloc(intf, fru, id);
@@ -554,20 +602,20 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
break;
}
- if (rsp->ccode == 0xc7 || rsp->ccode == 0xc8 || rsp->ccode == 0xca) {
- if (fru->max_write_size > 8) {
- fru->max_write_size -= 8;
+ if (fru_cc_rq2big(rsp->ccode)) {
+ if (fru->max_write_size > FRU_AREA_MAXIMUM_BLOCK_SZ) {
+ fru->max_write_size -= FRU_BLOCK_SZ;
lprintf(LOG_INFO, "Retrying FRU write with request size %d",
fru->max_write_size);
continue;
}
- } else if(rsp->ccode == 0x80) {
- rsp->ccode = 0;
+ } else if (rsp->ccode == IPMI_CC_FRU_WRITE_PROTECTED_OFFSET) {
+ rsp->ccode = IPMI_CC_OK;
// Write protected section
protected_bloc = 1;
}
- if (rsp->ccode > 0)
+ if (rsp->ccode)
break;
if (protected_bloc == 0) {
@@ -615,7 +663,10 @@ int
read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
uint32_t offset, uint32_t length, uint8_t *frubuf)
{
- uint32_t off = offset, tmp, finish;
+ uint32_t off = offset;
+ uint32_t tmp;
+ uint32_t finish;
+ uint32_t size_left_in_buffer;
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[4];
@@ -628,10 +679,12 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
finish = offset + length;
if (finish > fru->size) {
+ memset(frubuf + fru->size, 0, length - fru->size);
finish = fru->size;
lprintf(LOG_NOTICE, "Read FRU Area length %d too large, "
"Adjusting to %d",
offset + length, finish - offset);
+ length = finish - offset;
}
memset(&req, 0, sizeof(req));
@@ -667,6 +720,7 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
}
}
+ size_left_in_buffer = length;
do {
tmp = fru->access ? off >> 1 : off;
msg_data[0] = id;
@@ -679,18 +733,19 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
msg_data[3] = (uint8_t)tmp;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_NOTICE, "FRU Read failed");
break;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
/* if we get C7h or C8h or CAh return code then we requested too
* many bytes at once so try again with smaller size */
- if ((rsp->ccode == 0xc7 || rsp->ccode == 0xc8 || rsp->ccode == 0xca)
- && fru->max_read_size > 8) {
- if (fru->max_read_size > 32) {
+ if (fru_cc_rq2big(rsp->ccode)
+ && fru->max_read_size > FRU_BLOCK_SZ)
+ {
+ if (fru->max_read_size > FRU_AREA_MAXIMUM_BLOCK_SZ) {
/* subtract read length more aggressively */
- fru->max_read_size -= 8;
+ fru->max_read_size -= FRU_BLOCK_SZ;
} else {
/* subtract length less aggressively */
fru->max_read_size--;
@@ -707,9 +762,18 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
}
tmp = fru->access ? rsp->data[0] << 1 : rsp->data[0];
+ if(rsp->data_len < 1
+ || tmp > rsp->data_len - 1
+ || tmp > size_left_in_buffer)
+ {
+ printf(" Not enough buffer size");
+ return -1;
+ }
+
memcpy(frubuf, rsp->data + 1, tmp);
off += tmp;
frubuf += tmp;
+ size_left_in_buffer -= tmp;
/* sometimes the size returned in the Info command
* is too large. return 0 so higher level function
* still attempts to parse what was returned */
@@ -742,7 +806,9 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
uint32_t offset, uint32_t length, uint8_t *frubuf)
{
static uint32_t fru_data_rqst_size = 20;
- uint32_t off = offset, tmp, finish;
+ uint32_t off = offset;
+ uint32_t tmp, finish;
+ uint32_t size_left_in_buffer;
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[4];
@@ -755,10 +821,12 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
finish = offset + length;
if (finish > fru->size) {
+ memset(frubuf + fru->size, 0, length - fru->size);
finish = fru->size;
lprintf(LOG_NOTICE, "Read FRU Area length %d too large, "
"Adjusting to %d",
offset + length, finish - offset);
+ length = finish - offset;
}
memset(&req, 0, sizeof(req));
@@ -773,6 +841,8 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
if (fru->access && fru_data_rqst_size > 16)
#endif
fru_data_rqst_size = 16;
+
+ size_left_in_buffer = length;
do {
tmp = fru->access ? off >> 1 : off;
msg_data[0] = id;
@@ -785,16 +855,16 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
msg_data[3] = (uint8_t)tmp;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_NOTICE, "FRU Read failed");
break;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
/* if we get C7 or C8 or CA return code then we requested too
* many bytes at once so try again with smaller size */
- if ((rsp->ccode == 0xc7 || rsp->ccode == 0xc8 || rsp->ccode == 0xca) &&
- (--fru_data_rqst_size > 8)) {
- lprintf(LOG_INFO, "Retrying FRU read with request size %d",
+ if (fru_cc_rq2big(rsp->ccode) && (--fru_data_rqst_size > FRU_BLOCK_SZ)) {
+ lprintf(LOG_INFO,
+ "Retrying FRU read with request size %d",
fru_data_rqst_size);
continue;
}
@@ -804,8 +874,16 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id,
}
tmp = fru->access ? rsp->data[0] << 1 : rsp->data[0];
+ if(rsp->data_len < 1
+ || tmp > rsp->data_len - 1
+ || tmp > size_left_in_buffer)
+ {
+ printf(" Not enough buffer size");
+ return -1;
+ }
memcpy((frubuf + off)-offset, rsp->data + 1, tmp);
off += tmp;
+ size_left_in_buffer -= tmp;
/* sometimes the size returned in the Info command
* is too large. return 0 so higher level function
@@ -834,7 +912,7 @@ fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru,
i = last_off = offset;
fru_data = malloc(fru->size + 1);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, " Out of memory!");
return;
}
@@ -878,8 +956,7 @@ fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru,
lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i);
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
}
@@ -898,6 +975,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
uint8_t * fru_data;
uint32_t fru_len, i;
uint8_t tmp[2];
+ size_t chassis_type;
fru_len = 0;
@@ -911,7 +989,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
}
fru_data = malloc(fru_len);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return;
}
@@ -920,8 +998,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
/* read in the full fru */
if (read_fru_area(intf, fru, id, offset, fru_len, fru_data) < 0) {
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
return;
}
@@ -931,42 +1008,38 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
*/
i = 2;
- printf(" Chassis Type : %s\n",
- chassis_type_desc[fru_data[i] >
- (sizeof(chassis_type_desc)/sizeof(chassis_type_desc[0])) - 1 ?
- 2 : fru_data[i]]);
+ chassis_type = (fru_data[i] > ARRAY_SIZE(chassis_type_desc) - 1)
+ ? 2
+ : fru_data[i];
+ printf(" Chassis Type : %s\n", chassis_type_desc[chassis_type]);
i++;
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Chassis Part Number : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Chassis Serial : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
/* read any extra fields */
- while ((fru_data[i] != 0xc1) && (i < fru_len))
- {
+ while ((i < fru_len) && (fru_data[i] != FRU_END_OF_FIELDS)) {
int j = i;
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Chassis Extra : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
if (i == j) {
@@ -974,10 +1047,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
}
}
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
+ free_n(&fru_data);
}
/* fru_area_print_board - Print FRU Board Area
@@ -995,7 +1065,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
uint8_t * fru_data;
uint32_t fru_len;
uint32_t i;
- time_t tval;
+ time_t ts;
uint8_t tmp[2];
fru_len = 0;
@@ -1010,7 +1080,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
}
fru_data = malloc(fru_len);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return;
}
@@ -1019,8 +1089,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
/* read in the full fru */
if (read_fru_area(intf, fru, id, offset, fru_len, fru_data) < 0) {
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
return;
}
@@ -1031,77 +1100,65 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru,
*/
i = 3;
- tval=((fru_data[i+2] << 16) + (fru_data[i+1] << 8) + (fru_data[i]));
- tval=tval * 60;
- tval=tval + secs_from_1970_1996;
- printf(" Board Mfg Date : %s", asctime(localtime(&tval)));
+ ts = ipmi_fru2time_t(&fru_data[i]);
+ printf(" Board Mfg Date : %s\n", ipmi_timestamp_string(ts));
i += 3; /* skip mfg. date time */
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Board Mfg : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Board Product : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Board Serial : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Board Part Number : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0 && verbose > 0) {
printf(" Board FRU ID : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
/* read any extra fields */
- while ((fru_data[i] != 0xc1) && (i < fru_len))
- {
+ while ((i < fru_len) && (fru_data[i] != FRU_END_OF_FIELDS)) {
int j = i;
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Board Extra : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
if (i == j)
break;
}
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
+ free_n(&fru_data);
}
/* fru_area_print_product - Print FRU Product Area
@@ -1132,7 +1189,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
}
fru_data = malloc(fru_len);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return;
}
@@ -1142,8 +1199,7 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
/* read in the full fru */
if (read_fru_area(intf, fru, id, offset, fru_len, fru_data) < 0) {
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
return;
}
@@ -1155,88 +1211,76 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru,
i = 3;
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Product Manufacturer : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Product Name : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Product Part Number : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Product Version : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Product Serial : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Product Asset Tag : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0 && verbose > 0) {
printf(" Product FRU ID : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
/* read any extra fields */
- while ((fru_data[i] != 0xc1) && (i < fru_len))
- {
+ while ((i < fru_len) && (fru_data[i] != FRU_END_OF_FIELDS)) {
int j = i;
fru_area = get_fru_area_str(fru_data, &i);
- if (fru_area != NULL) {
+ if (fru_area) {
if (strlen(fru_area) > 0) {
printf(" Product Extra : %s\n", fru_area);
}
- free(fru_area);
- fru_area = NULL;
+ free_n(&fru_area);
}
if (i == j)
break;
}
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
+ free_n(&fru_data);
}
/* fru_area_print_multirec - Print FRU Multi Record Area
@@ -1262,7 +1306,7 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru,
last_off = offset;
fru_data = malloc(FRU_MULTIREC_CHUNK_SIZE);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return;
}
@@ -1428,7 +1472,7 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru,
lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)", last_off, last_off);
- free(fru_data);
+ free_n(&fru_data);
}
/* ipmi_fru_query_new_value - Query new values to replace original FRU content
@@ -1440,16 +1484,18 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru,
* returns : TRUE if data changed
* returns : FALSE if data not changed
*/
-int ipmi_fru_query_new_value(uint8_t *data,int offset, size_t len)
+static
+bool
+ipmi_fru_query_new_value(uint8_t *data,int offset, size_t len)
{
- int status=FALSE;
+ bool status = false;
int ret;
char answer;
printf("Would you like to change this value <y/n> ? ");
ret = scanf("%c", &answer);
if (ret != 1) {
- return FALSE;
+ return false;
}
if( answer == 'y' || answer == 'Y' ){
@@ -1465,17 +1511,16 @@ int ipmi_fru_query_new_value(uint8_t *data,int offset, size_t len)
for( i=0;i<len;i++ ){
ret = scanf("%x", holder+i);
if (ret != 1) {
- free(holder);
- return FALSE;
+ free_n(&holder);
+ return false;
}
}
for( i=0;i<len;i++ ){
data[offset++] = (unsigned char) *(holder+i);
}
/* &data[offset++] */
- free(holder);
- holder = NULL;
- status = TRUE;
+ free_n(&holder);
+ status = true;
}
else{
printf("Entered %c\n",answer);
@@ -1572,12 +1617,13 @@ typedef struct OemKontronInformationRecordV1{
*/
-static void ipmi_fru_oemkontron_get( int argc, char ** argv,uint8_t * fru_data,
- int off,int len,
- struct fru_multirec_header *h,
- struct fru_multirec_oem_header *oh)
+static void ipmi_fru_oemkontron_get(int argc,
+ char ** argv,
+ uint8_t * fru_data,
+ int off,
+ struct fru_multirec_oem_header *oh)
{
- static int badParams=FALSE;
+ static bool badParams = false;
int start = off;
int offset = start;
offset += sizeof(struct fru_multirec_oem_header);
@@ -1585,117 +1631,114 @@ static void ipmi_fru_oemkontron_get( int argc, char ** argv,uint8_t * fru_data,
if(!badParams){
/* the 'OEM' field is already checked in caller */
if( argc > OEM_KONTRON_SUBCOMMAND_ARG_POS ){
- if(strncmp("oem", argv[OEM_KONTRON_SUBCOMMAND_ARG_POS],3)){
+ if(strcmp("oem", argv[OEM_KONTRON_SUBCOMMAND_ARG_POS])){
printf("usage: fru get <id> <oem>\n");
- badParams = TRUE;
+ badParams = true;
return;
}
}
if( argc<GET_OEM_KONTRON_COMPLETE_ARG_COUNT ){
printf("usage: oem <iana> <recordid>\n");
printf("usage: oem 15000 3\n");
- badParams = TRUE;
+ badParams = true;
return;
}
}
- if(!badParams){
-
- if(oh->record_id == OEM_KONTRON_INFORMATION_RECORD ) {
-
- uint8_t version;
-
- printf("Kontron OEM Information Record\n");
- version = oh->record_version;
-
- uint8_t blockCount;
- uint8_t blockIndex=0;
+ if (badParams) {
+ return;
+ }
- unsigned int matchInstance = 0;
- uint8_t instance = 0;
-
- if (str2uchar(argv[OEM_KONTRON_INSTANCE_ARG_POS], &instance) != 0) {
- lprintf(LOG_ERR,
- "Instance argument '%s' is either invalid or out of range.",
- argv[OEM_KONTRON_INSTANCE_ARG_POS]);
- badParams = TRUE;
- return;
- }
+ if (oh->record_id != OEM_KONTRON_INFORMATION_RECORD) {
+ return;
+ }
- blockCount = fru_data[offset++];
+ uint8_t version;
- for(blockIndex=0;blockIndex<blockCount;blockIndex++){
- void * pRecordData;
- uint8_t nameLen;
+ printf("Kontron OEM Information Record\n");
+ version = oh->record_version;
- nameLen = ( fru_data[offset++] &= 0x3F );
- printf(" Name: %*.*s\n",nameLen, nameLen, (const char *)(fru_data+offset));
+ uint8_t blockCount;
+ uint8_t blockIndex = 0;
- offset+=nameLen;
+ uint8_t instance = 0;
- pRecordData = &fru_data[offset];
+ if (str2uchar(argv[OEM_KONTRON_INSTANCE_ARG_POS], &instance) != 0) {
+ lprintf(LOG_ERR,
+ "Instance argument '%s' is either invalid or out of range.",
+ argv[OEM_KONTRON_INSTANCE_ARG_POS]);
+ badParams = true;
+ return;
+ }
- printf(" Record Version: %d\n", version);
- if( version == 0 )
- {
- printf(" Version: %*.*s\n",
- OEM_KONTRON_FIELD_SIZE,
- OEM_KONTRON_FIELD_SIZE,
- ((tOemKontronInformationRecordV0 *) pRecordData)->field1);
- printf(" Build Date: %*.*s\n",
- OEM_KONTRON_FIELD_SIZE,
- OEM_KONTRON_FIELD_SIZE,
- ((tOemKontronInformationRecordV0 *) pRecordData)->field2);
- printf(" Update Date: %*.*s\n",
- OEM_KONTRON_FIELD_SIZE,
- OEM_KONTRON_FIELD_SIZE,
- ((tOemKontronInformationRecordV0 *) pRecordData)->field3);
- printf(" Checksum: %*.*s\n\n",
- OEM_KONTRON_FIELD_SIZE,
- OEM_KONTRON_FIELD_SIZE,
- ((tOemKontronInformationRecordV0 *) pRecordData)->crc32);
- matchInstance++;
- offset+= sizeof(tOemKontronInformationRecordV0);
- offset++;
- }
- else if ( version == 1 )
- {
- printf(" Version: %*.*s\n",
- OEM_KONTRON_VERSION_FIELD_SIZE,
- OEM_KONTRON_VERSION_FIELD_SIZE,
- ((tOemKontronInformationRecordV1 *) pRecordData)->field1);
- printf(" Build Date: %*.*s\n",
- OEM_KONTRON_FIELD_SIZE,
- OEM_KONTRON_FIELD_SIZE,
- ((tOemKontronInformationRecordV1 *) pRecordData)->field2);
- printf(" Update Date: %*.*s\n",
- OEM_KONTRON_FIELD_SIZE,
- OEM_KONTRON_FIELD_SIZE,
- ((tOemKontronInformationRecordV1 *) pRecordData)->field3);
- printf(" Checksum: %*.*s\n\n",
- OEM_KONTRON_FIELD_SIZE,
- OEM_KONTRON_FIELD_SIZE,
- ((tOemKontronInformationRecordV1 *) pRecordData)->crc32);
- matchInstance++;
- offset+= sizeof(tOemKontronInformationRecordV1);
- offset++;
- }
- else
- {
- printf (" Unsupported version %d\n",version);
- }
- }
+ blockCount = fru_data[offset++];
+
+ for (blockIndex = 0; blockIndex < blockCount; blockIndex++) {
+ void *pRecordData;
+ uint8_t nameLen;
+
+ nameLen = (fru_data[offset++] &= 0x3F);
+ printf(" Name: %*.*s\n", nameLen, nameLen,
+ (const char *)(fru_data + offset));
+
+ offset += nameLen;
+
+ pRecordData = &fru_data[offset];
+
+ printf(" Record Version: %d\n", version);
+ if (version == 0) {
+ printf(" Version: %*.*s\n",
+ OEM_KONTRON_FIELD_SIZE,
+ OEM_KONTRON_FIELD_SIZE,
+ ((tOemKontronInformationRecordV0 *)pRecordData)->field1);
+ printf(" Build Date: %*.*s\n",
+ OEM_KONTRON_FIELD_SIZE,
+ OEM_KONTRON_FIELD_SIZE,
+ ((tOemKontronInformationRecordV0 *)pRecordData)->field2);
+ printf(" Update Date: %*.*s\n",
+ OEM_KONTRON_FIELD_SIZE,
+ OEM_KONTRON_FIELD_SIZE,
+ ((tOemKontronInformationRecordV0 *)pRecordData)->field3);
+ printf(" Checksum: %*.*s\n\n",
+ OEM_KONTRON_FIELD_SIZE,
+ OEM_KONTRON_FIELD_SIZE,
+ ((tOemKontronInformationRecordV0 *)pRecordData)->crc32);
+ offset += sizeof(tOemKontronInformationRecordV0);
+ offset++;
+ } else if (version == 1) {
+ printf(" Version: %*.*s\n",
+ OEM_KONTRON_VERSION_FIELD_SIZE,
+ OEM_KONTRON_VERSION_FIELD_SIZE,
+ ((tOemKontronInformationRecordV1 *)pRecordData)->field1);
+ printf(" Build Date: %*.*s\n",
+ OEM_KONTRON_FIELD_SIZE,
+ OEM_KONTRON_FIELD_SIZE,
+ ((tOemKontronInformationRecordV1 *)pRecordData)->field2);
+ printf(" Update Date: %*.*s\n",
+ OEM_KONTRON_FIELD_SIZE,
+ OEM_KONTRON_FIELD_SIZE,
+ ((tOemKontronInformationRecordV1 *)pRecordData)->field3);
+ printf(" Checksum: %*.*s\n\n",
+ OEM_KONTRON_FIELD_SIZE,
+ OEM_KONTRON_FIELD_SIZE,
+ ((tOemKontronInformationRecordV1 *)pRecordData)->crc32);
+ offset += sizeof(tOemKontronInformationRecordV1);
+ offset++;
+ } else {
+ printf(" Unsupported version %d\n", version);
}
}
}
-static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
+static
+bool
+ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
int off,int len,
struct fru_multirec_header *h,
struct fru_multirec_oem_header *oh)
{
- static int badParams=FALSE;
- int hasChanged = FALSE;
+ static bool badParams=false;
+ bool hasChanged = false;
int start = off;
int offset = start;
int length = len;
@@ -1706,9 +1749,9 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
if(!badParams){
/* the 'OEM' field is already checked in caller */
if( argc > OEM_KONTRON_SUBCOMMAND_ARG_POS ){
- if(strncmp("oem", argv[OEM_KONTRON_SUBCOMMAND_ARG_POS],3)){
+ if(strcmp("oem", argv[OEM_KONTRON_SUBCOMMAND_ARG_POS])){
printf("usage: fru edit <id> <oem> <args...>\n");
- badParams = TRUE;
+ badParams = true;
return hasChanged;
}
}
@@ -1716,14 +1759,14 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
printf("usage: oem <iana> <recordid> <format> <args...>\n");
printf("usage: oem 15000 3 0 <name> <instance> <field1>"\
" <field2> <field3> <crc32>\n");
- badParams = TRUE;
+ badParams = true;
return hasChanged;
}
if (str2uchar(argv[OEM_KONTRON_RECORDID_ARG_POS], &record_id) != 0) {
lprintf(LOG_ERR,
"Record ID argument '%s' is either invalid or out of range.",
argv[OEM_KONTRON_RECORDID_ARG_POS]);
- badParams = TRUE;
+ badParams = true;
return hasChanged;
}
if (record_id == OEM_KONTRON_INFORMATION_RECORD) {
@@ -1732,7 +1775,7 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
(strlen(argv[i]) != OEM_KONTRON_VERSION_FIELD_SIZE)) {
printf("error: version fields must have %d characters\n",
OEM_KONTRON_FIELD_SIZE);
- badParams = TRUE;
+ badParams = true;
return hasChanged;
}
}
@@ -1749,7 +1792,7 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
lprintf(LOG_ERR,
"Format argument '%s' is either invalid or out of range.",
argv[OEM_KONTRON_FORMAT_ARG_POS]);
- badParams = TRUE;
+ badParams = true;
return hasChanged;
}
@@ -1767,7 +1810,7 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
lprintf(LOG_ERR,
"Instance argument '%s' is either invalid or out of range.",
argv[OEM_KONTRON_INSTANCE_ARG_POS]);
- badParams = TRUE;
+ badParams = true;
return hasChanged;
}
@@ -1830,7 +1873,7 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
}
matchInstance++;
- hasChanged = TRUE;
+ hasChanged = true;
}
else if(!strncmp((char *)argv[OEM_KONTRON_NAME_ARG_POS],
(const char *)(fru_data+offset), nameLen)){
@@ -1906,12 +1949,14 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data,
* returns: TRUE if data changed
* returns: FALSE if data not changed
*/
-static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data,
+static
+bool
+ipmi_fru_picmg_ext_edit(uint8_t * fru_data,
int off,int len,
struct fru_multirec_header *h,
struct fru_multirec_oem_header *oh)
{
- int hasChanged = FALSE;
+ bool hasChanged = false;
int start = off;
int offset = start;
int length = len;
@@ -1936,7 +1981,7 @@ static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data,
max_current |= fru_data[++index]<<8;
printf(" New Maximum Internal Current(@12V): %.2f A (0x%02x)\n",
(float)max_current / 10.0f, max_current);
- hasChanged = TRUE;
+ hasChanged = true;
}
@@ -1974,7 +2019,7 @@ static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data,
printf(" New Current draw(@12V): %.2f A (0x%02x)\n",
(float)current / 10.0f, current);
- hasChanged = TRUE;
+ hasChanged = true;
}
}
break;
@@ -2885,11 +2930,11 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2922,11 +2967,11 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id)
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return 1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return 1;
@@ -3003,7 +3048,7 @@ ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru)
uint32_t save_channel;
int rc = 0;
- if (fru == NULL)
+ if (!fru)
return __ipmi_fru_print(intf, 0);
/* Logical FRU Device
@@ -3033,7 +3078,7 @@ ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru)
return 0;
memset(desc, 0, sizeof(desc));
- memcpy(desc, fru->id_string, fru->id_code & 0x01f);
+ memcpy(desc, fru->id_string, __min(fru->id_code & 0x01f, sizeof(desc)));
desc[fru->id_code & 0x01f] = 0;
printf("FRU Device Description : %s (ID %d)\n", desc, fru->device_id);
@@ -3101,11 +3146,11 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Device ID command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Device ID command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -3121,14 +3166,15 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
printf("\n");
}
- if ((itr = ipmi_sdr_start(intf, 0)) == NULL)
+ itr = ipmi_sdr_start(intf, 0);
+ if (!itr)
return -1;
/* Walk the SDRs looking for FRU Devices and Management Controller Devices. */
/* For FRU devices, print the FRU from the SDR locator record. */
/* For MC devices, issue FRU commands to the satellite controller to print */
/* FRU data. */
- while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL)
+ while ((header = ipmi_sdr_get_next_header(intf, itr)))
{
if (header->type == SDR_RECORD_TYPE_MC_DEVICE_LOCATOR ) {
/* Check the capabilities of the Management Controller Device */
@@ -3158,11 +3204,7 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
intf->target_addr = save_addr;
}
- if (mc) {
- free(mc);
- mc = NULL;
- }
-
+ free_n(&mc);
continue;
}
@@ -3172,19 +3214,15 @@ ipmi_fru_print_all(struct ipmi_intf * intf)
/* Print the FRU from the SDR locator record. */
fru = (struct sdr_record_fru_locator *)
ipmi_sdr_get_record(intf, header, itr);
- if (fru == NULL || !fru->logical) {
- if (fru) {
- free(fru);
- fru = NULL;
- }
+ if (!fru || !fru->logical) {
+ free_n(&fru);
continue;
}
rc = ipmi_fru_print(intf, fru);
- free(fru);
- fru = NULL;
+ free_n(&fru);
}
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
return rc;
}
@@ -3224,8 +3262,8 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf,
if (!rsp)
return;
- if (rsp->ccode > 0) {
- if (rsp->ccode == 0xc3)
+ if (rsp->ccode) {
+ if (rsp->ccode == IPMI_CC_TIMEOUT)
printf (" Timeout accessing FRU info. (Device not present?)\n");
return;
}
@@ -3240,7 +3278,7 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf,
}
pFruBuf = malloc(fru.size);
- if (pFruBuf != NULL) {
+ if (pFruBuf) {
printf("Fru Size : %d bytes\n",fru.size);
read_fru_area(intf, &fru, fruId, 0, fru.size, pFruBuf);
} else {
@@ -3248,7 +3286,7 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf,
return;
}
- if(pFruBuf != NULL)
+ if(pFruBuf)
{
FILE * pFile;
pFile = fopen(pFileName,"wb");
@@ -3257,14 +3295,12 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf,
printf("Done\n");
} else {
lprintf(LOG_ERR, "Error opening file %s\n", pFileName);
- free(pFruBuf);
- pFruBuf = NULL;
+ free_n(&pFruBuf);
return;
}
fclose(pFile);
}
- free(pFruBuf);
- pFruBuf = NULL;
+ free_n(&pFruBuf);
}
static void
@@ -3293,7 +3329,7 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf,
return;
if (rsp->ccode) {
- if (rsp->ccode == 0xc3)
+ if (rsp->ccode == IPMI_CC_TIMEOUT)
printf(" Timeout accessing FRU info. (Device not present?)\n");
return;
}
@@ -3308,13 +3344,13 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf,
}
pFruBuf = malloc(fru.size);
- if (pFruBuf == NULL) {
+ if (!pFruBuf) {
lprintf(LOG_ERR, "Cannot allocate %d bytes\n", fru.size);
return;
}
pFile = fopen(pFileName, "rb");
- if (pFile != NULL) {
+ if (pFile) {
len = fread(pFruBuf, 1, fru.size, pFile);
printf("Fru Size : %d bytes\n", fru.size);
printf("Size to Write : %d bytes\n", len);
@@ -3328,13 +3364,12 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf,
lprintf(LOG_INFO,"Done");
}
- free(pFruBuf);
- pFruBuf = NULL;
+ free_n(&pFruBuf);
}
/* ipmi_fru_write_help() - print help text for 'write'
*
- * retruns void
+ * returns void
*/
void
ipmi_fru_write_help()
@@ -3411,11 +3446,11 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id ,
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -3446,7 +3481,7 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id ,
memset(&fru, 0, sizeof(fru));
fru_data = malloc(fru.size + 1);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, " Out of memory!");
return -1;
}
@@ -3480,7 +3515,7 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id ,
if( argc <=2 ) {
suppliedIana = IPMI_OEM_PICMG;
} else {
- if( !strncmp( argv[2] , "oem" , 3 )) {
+ if( !strcmp( argv[2] , "oem")) {
/* Expect IANA number next */
if( argc <= 3 ) {
lprintf(LOG_ERR, "oem iana <record> <format> [<args>]");
@@ -3532,8 +3567,7 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id ,
i += h->len + sizeof (struct fru_multirec_header);
} while (!(h->format & 0x80) && (error != 1));
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
}
return 0;
}
@@ -3616,11 +3650,11 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id ,
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -3650,7 +3684,7 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id ,
i = last_off = offset;
fru_data = malloc(fru.size + 1);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, " Out of memory!");
return -1;
}
@@ -3679,7 +3713,7 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id ,
uint32_t suppliedIana = 0 ;
/* Now makes sure this is really PICMG record */
- if( !strncmp( argv[2] , "oem" , 3 )) {
+ if( !strcmp( argv[2] , "oem")) {
/* Expect IANA number next */
if( argc <= 3 ) {
lprintf(LOG_ERR, "oem iana <record> <format>");
@@ -3701,15 +3735,15 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id ,
if( suppliedIana == iana ) {
lprintf(LOG_DEBUG, "Matching record found" );
- if( iana == IPMI_OEM_KONTRON ) {
- ipmi_fru_oemkontron_get( argc,argv,fru_data,
- i + sizeof(struct fru_multirec_header),
- h->len, h, oh );
+ if( iana == IPMI_OEM_KONTRON ) {
+ ipmi_fru_oemkontron_get(argc, argv, fru_data,
+ i + sizeof(struct fru_multirec_header),
+ oh);
}
/* FIXME: Add OEM record support here */
else{
printf(" OEM IANA (%s) Record not supported in this mode\n",
- val2str( iana, ipmi_oem_info));
+ val2str( iana, ipmi_oem_info));
error = 1;
}
}
@@ -3717,16 +3751,16 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id ,
i += h->len + sizeof (struct fru_multirec_header);
} while (!(h->format & 0x80) && (error != 1));
- free(fru_data);
- fru_data = NULL;
+ free_n(&fru_data);
}
return 0;
}
-static int
-ipmi_fru_upg_ekeying(struct ipmi_intf * intf,
- char * pFileName,
- uint8_t fruId)
+#define ERR_EXIT do { rc = -1; goto exit; } while(0)
+
+static
+int
+ipmi_fru_upg_ekeying(struct ipmi_intf *intf, char *pFileName, uint8_t fruId)
{
struct fru_info fruInfo = {0};
uint8_t *buf = NULL;
@@ -3734,59 +3768,50 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf,
uint32_t fruMultiRecSize = 0;
uint32_t offFileMultiRec = 0;
uint32_t fileMultiRecSize = 0;
- if (pFileName == NULL) {
+ int rc = 0;
+
+ if (!pFileName) {
lprintf(LOG_ERR, "File expected, but none given.");
- return (-1);
+ ERR_EXIT;
}
if (ipmi_fru_get_multirec_location_from_fru(intf, fruId, &fruInfo,
&offFruMultiRec, &fruMultiRecSize) != 0) {
lprintf(LOG_ERR, "Failed to get multirec location from FRU.");
- return (-1);
+ ERR_EXIT;
}
lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize);
lprintf(LOG_DEBUG, "Multi Rec offset: %lu\n", offFruMultiRec);
if (ipmi_fru_get_multirec_size_from_file(pFileName, &fileMultiRecSize,
&offFileMultiRec) != 0) {
lprintf(LOG_ERR, "Failed to get multirec size from file '%s'.", pFileName);
- return (-1);
+ ERR_EXIT;
}
buf = malloc(fileMultiRecSize);
- if (buf == NULL) {
+ if (!buf) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
- return (-1);
+ ERR_EXIT;
}
if (ipmi_fru_get_multirec_from_file(pFileName, buf, fileMultiRecSize,
offFileMultiRec) != 0) {
lprintf(LOG_ERR, "Failed to get multirec from file '%s'.", pFileName);
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
- return (-1);
+ ERR_EXIT;
}
if (ipmi_fru_get_adjust_size_from_buffer(buf, &fileMultiRecSize) != 0) {
lprintf(LOG_ERR, "Failed to adjust size from buffer.");
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
- return (-1);
+ ERR_EXIT;
}
if (write_fru_area(intf, &fruInfo, fruId, 0, offFruMultiRec,
fileMultiRecSize, buf) != 0) {
lprintf(LOG_ERR, "Failed to write FRU area.");
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
- return (-1);
- }
- if (buf != NULL) {
- free(buf);
- buf = NULL;
+ ERR_EXIT;
}
+
lprintf(LOG_INFO, "Done upgrading Ekey.");
- return 0;
+
+exit:
+ free_n(&buf);
+
+ return rc;
}
/* ipmi_fru_upgekey_help - print help text for 'upgEkey'
@@ -3834,7 +3859,7 @@ ipmi_fru_get_multirec_size_from_file(char * pFileName,
return -1;
}
- /* Retreive length */
+ /* Retrieve length */
if (((header.offset.internal * 8) > (header.offset.internal * 8)) &&
((header.offset.internal * 8) < end))
end = (header.offset.internal * 8);
@@ -3882,7 +3907,7 @@ ipmi_fru_get_adjust_size_from_buffer(uint8_t * fru_data, uint32_t *pSize)
}
if (checksum != 0) {
lprintf(LOG_ERR, "Bad checksum in Multi Records");
- status = (-1);
+ status = -1;
if (verbose) {
printf("--> FAIL");
}
@@ -3912,9 +3937,9 @@ ipmi_fru_get_multirec_from_file(char * pFileName, uint8_t * pBufArea,
{
FILE * pFile;
uint32_t len = 0;
- if (pFileName == NULL) {
+ if (!pFileName) {
lprintf(LOG_ERR, "Invalid file name given.");
- return (-1);
+ return -1;
}
errno = 0;
@@ -3922,21 +3947,21 @@ ipmi_fru_get_multirec_from_file(char * pFileName, uint8_t * pBufArea,
if (!pFile) {
lprintf(LOG_ERR, "Error opening file '%s': %i -> %s.", pFileName, errno,
strerror(errno));
- return (-1);
+ return -1;
}
errno = 0;
if (fseek(pFile, offset, SEEK_SET) != 0) {
lprintf(LOG_ERR, "Failed to seek in file '%s': %i -> %s.", pFileName, errno,
strerror(errno));
fclose(pFile);
- return (-1);
+ return -1;
}
len = fread(pBufArea, size, 1, pFile);
fclose(pFile);
if (len != 1) {
lprintf(LOG_ERR, "Error in file '%s'.", pFileName);
- return (-1);
+ return -1;
}
return 0;
}
@@ -3971,8 +3996,8 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
return -1;
}
- if (rsp->ccode > 0) {
- if (rsp->ccode == 0xc3)
+ if (rsp->ccode) {
+ if (rsp->ccode == IPMI_CC_TIMEOUT)
printf (" Timeout accessing FRU info. (Device not present?)\n");
else
printf (" CCODE = 0x%02x\n", rsp->ccode);
@@ -4003,8 +4028,8 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
if (!rsp)
return -1;
- if (rsp->ccode > 0) {
- if (rsp->ccode == 0xc3)
+ if (rsp->ccode) {
+ if (rsp->ccode == IPMI_CC_TIMEOUT)
printf (" Timeout while reading FRU data. (Device not present?)\n");
return -1;
}
@@ -4021,7 +4046,7 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
end = pFruInfo->size;
- /* Retreive length */
+ /* Retrieve length */
if (((header.offset.internal * 8) > (header.offset.internal * 8)) &&
((header.offset.internal * 8) < end))
end = (header.offset.internal * 8);
@@ -4044,7 +4069,7 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf,
return 0;
}
-/* ipmi_fru_get_internal_use_offset - Retreive internal use offset
+/* ipmi_fru_get_internal_use_offset - Retrieve internal use offset
*
* @intf: ipmi interface
* @id: fru id
@@ -4085,17 +4110,16 @@ ipmi_fru_get_internal_use_info( struct ipmi_intf * intf,
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return -1;
}
- memset(&fru, 0, sizeof(fru));
fru->size = (rsp->data[1] << 8) | rsp->data[0];
fru->access = rsp->data[2] & 0x1;
@@ -4122,11 +4146,11 @@ ipmi_fru_get_internal_use_info( struct ipmi_intf * intf,
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return 1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return 1;
@@ -4265,7 +4289,7 @@ ipmi_fru_read_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName
if(rc == 0)
{
- if(pFileName == NULL)
+ if(!pFileName)
{
uint16_t counter;
for(counter = 0; counter < size; counter ++)
@@ -4287,8 +4311,7 @@ ipmi_fru_read_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName
else
{
lprintf(LOG_ERR, "Error opening file %s\n", pFileName);
- free(frubuf);
- frubuf = NULL;
+ free_n(&frubuf);
return -1;
}
fclose(pFile);
@@ -4296,8 +4319,7 @@ ipmi_fru_read_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName
}
printf("\n");
- free(frubuf);
- frubuf = NULL;
+ free_n(&frubuf);
}
}
@@ -4340,7 +4362,7 @@ ipmi_fru_write_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileNam
if(fp)
{
- /* Retreive file length, check if it's fits the Eeprom Size */
+ /* Retrieve file length, check if it's fits the Eeprom Size */
fseek(fp, 0 ,SEEK_END);
fileLength = ftell(fp);
@@ -4380,8 +4402,7 @@ ipmi_fru_write_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileNam
lprintf(LOG_ERR, "Unable to read file: %i\n", fru_read_size);
}
- free(frubuf);
- frubuf = NULL;
+ free_n(&frubuf);
}
fclose(fp);
fp = NULL;
@@ -4403,42 +4424,43 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
if (argc < 1) {
rc = ipmi_fru_print_all(intf);
}
- else if (strncmp(argv[0], "help", 4) == 0) {
+ else if (!strcmp(argv[0], "help")) {
ipmi_fru_help();
return 0;
}
- else if (strncmp(argv[0], "print", 5) == 0 ||
- strncmp(argv[0], "list", 4) == 0) {
+ else if (!strcmp(argv[0], "print")
+ || !strcmp(argv[0], "list"))
+ {
if (argc > 1) {
- if (strcmp(argv[1], "help") == 0) {
+ if (!strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE, "fru print [fru id] - print information about FRU(s)");
return 0;
}
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
rc = __ipmi_fru_print(intf, fru_id);
} else {
rc = ipmi_fru_print_all(intf);
}
}
- else if (!strncmp(argv[0], "read", 5)) {
- if (argc > 1 && strcmp(argv[1], "help") == 0) {
+ else if (!strcmp(argv[0], "read")) {
+ if (argc > 1 && !strcmp(argv[1], "help")) {
ipmi_fru_read_help();
return 0;
} else if (argc < 3) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_fru_read_help();
- return (-1);
+ return -1;
}
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
/* There is a file name in the parameters */
if (is_valid_filename(argv[2]) != 0)
- return (-1);
+ return -1;
if (verbose) {
printf("FRU ID : %d\n", fru_id);
@@ -4447,22 +4469,22 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
/* TODO - rc is missing */
ipmi_fru_read_to_bin(intf, argv[2], fru_id);
}
- else if (!strncmp(argv[0], "write", 5)) {
- if (argc > 1 && strcmp(argv[1], "help") == 0) {
+ else if (!strcmp(argv[0], "write")) {
+ if (argc > 1 && !strcmp(argv[1], "help")) {
ipmi_fru_write_help();
return 0;
} else if (argc < 3) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_fru_write_help();
- return (-1);
+ return -1;
}
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
/* There is a file name in the parameters */
if (is_valid_filename(argv[2]) != 0)
- return (-1);
+ return -1;
if (verbose) {
printf("FRU ID : %d\n", fru_id);
@@ -4471,67 +4493,67 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
/* TODO - rc is missing */
ipmi_fru_write_from_bin(intf, argv[2], fru_id);
}
- else if (!strncmp(argv[0], "upgEkey", 7)) {
- if (argc > 1 && strcmp(argv[1], "help") == 0) {
+ else if (!strcmp(argv[0], "upgEkey")) {
+ if (argc > 1 && !strcmp(argv[1], "help")) {
ipmi_fru_upgekey_help();
return 0;
} else if (argc < 3) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_fru_upgekey_help();
- return (-1);
+ return -1;
}
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
/* There is a file name in the parameters */
if (is_valid_filename(argv[2]) != 0)
- return (-1);
+ return -1;
rc = ipmi_fru_upg_ekeying(intf, argv[2], fru_id);
}
- else if (!strncmp(argv[0], "internaluse", 11)) {
- if (argc > 1 && strcmp(argv[1], "help") == 0) {
+ else if (!strcmp(argv[0], "internaluse")) {
+ if (argc > 1 && !strcmp(argv[1], "help")) {
ipmi_fru_internaluse_help();
return 0;
}
- if ( (argc >= 3) && (!strncmp(argv[2], "info", 4)) ) {
+ if ( (argc >= 3) && (!strcmp(argv[2], "info")) ) {
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
rc = ipmi_fru_info_internal_use(intf, fru_id);
}
- else if ( (argc >= 3) && (!strncmp(argv[2], "print", 5)) ) {
+ else if ( (argc >= 3) && (!strcmp(argv[2], "print")) ) {
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
rc = ipmi_fru_read_internal_use(intf, fru_id, NULL);
}
- else if ( (argc >= 4) && (!strncmp(argv[2], "read", 4)) ) {
+ else if ( (argc >= 4) && (!strcmp(argv[2], "read")) ) {
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
/* There is a file name in the parameters */
if (is_valid_filename(argv[3]) != 0)
- return (-1);
+ return -1;
lprintf(LOG_DEBUG, "FRU ID : %d", fru_id);
lprintf(LOG_DEBUG, "FRU File : %s", argv[3]);
rc = ipmi_fru_read_internal_use(intf, fru_id, argv[3]);
}
- else if ( (argc >= 4) && (!strncmp(argv[2], "write", 5)) ) {
+ else if ( (argc >= 4) && (!strcmp(argv[2], "write")) ) {
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
/* There is a file name in the parameters */
if (is_valid_filename(argv[3]) != 0)
- return (-1);
+ return -1;
lprintf(LOG_DEBUG, "FRU ID : %d", fru_id);
lprintf(LOG_DEBUG, "FRU File : %s", argv[3]);
@@ -4541,22 +4563,22 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_ERR,
"Either unknown command or not enough parameters given.");
ipmi_fru_internaluse_help();
- return (-1);
+ return -1;
}
}
- else if (!strncmp(argv[0], "edit", 4)) {
- if (argc > 1 && strcmp(argv[1], "help") == 0) {
+ else if (!strcmp(argv[0], "edit")) {
+ if (argc > 1 && !strcmp(argv[1], "help")) {
ipmi_fru_edit_help();
return 0;
} else if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_fru_edit_help();
- return (-1);
+ return -1;
}
if (argc >= 2) {
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
if (verbose) {
printf("FRU ID : %d\n", fru_id);
@@ -4566,38 +4588,38 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
}
if (argc >= 3) {
- if (!strncmp(argv[2], "field", 5)) {
+ if (!strcmp(argv[2], "field")) {
if (argc != 6) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_fru_edit_help();
- return (-1);
+ return -1;
}
rc = ipmi_fru_set_field_string(intf, fru_id, *argv[3], *argv[4],
(char *) argv[5]);
- } else if (!strncmp(argv[2], "oem", 3)) {
+ } else if (!strcmp(argv[2], "oem")) {
rc = ipmi_fru_edit_multirec(intf, fru_id, argc, argv);
} else {
lprintf(LOG_ERR, "Invalid command: %s", argv[2]);
ipmi_fru_edit_help();
- return (-1);
+ return -1;
}
} else {
rc = ipmi_fru_edit_multirec(intf, fru_id, argc, argv);
}
}
- else if (!strncmp(argv[0], "get", 4)) {
- if (argc > 1 && (strncmp(argv[1], "help", 4) == 0)) {
+ else if (!strcmp(argv[0], "get")) {
+ if (argc > 1 && (!strcmp(argv[1], "help"))) {
ipmi_fru_get_help();
return 0;
} else if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_fru_get_help();
- return (-1);
+ return -1;
}
if (argc >= 2) {
if (is_fru_id(argv[1], &fru_id) != 0)
- return (-1);
+ return -1;
if (verbose) {
printf("FRU ID : %d\n", fru_id);
@@ -4607,12 +4629,12 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
}
if (argc >= 3) {
- if (!strncmp(argv[2], "oem", 3)) {
+ if (!strcmp(argv[2], "oem")) {
rc = ipmi_fru_get_multirec(intf, fru_id, argc, argv);
} else {
lprintf(LOG_ERR, "Invalid command: %s", argv[2]);
ipmi_fru_get_help();
- return (-1);
+ return -1;
}
} else {
rc = ipmi_fru_get_multirec(intf, fru_id, argc, argv);
@@ -4621,7 +4643,7 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
else {
lprintf(LOG_ERR, "Invalid FRU command: %s", argv[0]);
ipmi_fru_help();
- return (-1);
+ return -1;
}
return rc;
@@ -4668,15 +4690,15 @@ f_type, uint8_t f_index, char *f_string)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
@@ -4686,7 +4708,7 @@ f_type, uint8_t f_index, char *f_string)
if (fru.size < 1) {
printf(" Invalid FRU size %d", fru.size);
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
/*
@@ -4704,17 +4726,17 @@ f_type, uint8_t f_index, char *f_string)
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL)
+ if (!rsp)
{
printf(" Device not present (No Response)\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
- if (rsp->ccode > 0)
+ if (rsp->ccode)
{
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
@@ -4723,20 +4745,17 @@ f_type, uint8_t f_index, char *f_string)
memcpy(&header, rsp->data + 1, 8);
- if (header.version != 1)
- {
+ if (header.version != 1) {
printf(" Unknown FRU header version 0x%02x",
header.version);
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
fru_data = malloc( fru.size );
-
- if( fru_data == NULL )
- {
+ if (!fru_data) {
printf("Out of memory!\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
@@ -4766,14 +4785,14 @@ f_type, uint8_t f_index, char *f_string)
else
{
printf("Wrong field type.");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
memset(fru_data, 0, fru.size);
if( read_fru_area(intf ,&fru, fruId, header_offset ,
fru_section_len , fru_data) < 0 )
{
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
/* Convert index from character to decimal */
@@ -4782,16 +4801,15 @@ f_type, uint8_t f_index, char *f_string)
/*Seek to field index */
for (i=0; i <= f_index; i++) {
fru_field_offset_tmp = fru_field_offset;
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
+ if (fru_area) {
+ free_n(&fru_area);
}
fru_area = (uint8_t *) get_fru_area_str(fru_data, &fru_field_offset);
}
- if( (fru_area == NULL ) || strlen((const char *)fru_area) == 0 ) {
+ if (!FRU_FIELD_VALID(fru_area)) {
printf("Field not found !\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
@@ -4815,7 +4833,7 @@ f_type, uint8_t f_index, char *f_string)
header_offset, fru_section_len, fru_data) < 0 )
{
printf("Write to FRU data failed.\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
}
@@ -4825,20 +4843,14 @@ f_type, uint8_t f_index, char *f_string)
ipmi_fru_set_field_string_rebuild(intf,fruId,fru,header,f_type,f_index,f_string)
)
{
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_out;
}
}
- ipmi_fru_set_field_string_out:
- if (fru_data != NULL) {
- free(fru_data);
- fru_data = NULL;
- }
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
- }
+ipmi_fru_set_field_string_out:
+ free_n(&fru_data);
+ free_n(&fru_area);
return rc;
}
@@ -4894,10 +4906,9 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
fru_data_new = malloc( fru.size );
- if( fru_data_old == NULL || fru_data_new == NULL )
- {
+ if (!fru_data_old || !fru_data_new) {
printf("Out of memory!\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_rebuild_out;
}
@@ -4952,7 +4963,7 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
else
{
printf("Wrong field type.");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_rebuild_out;
}
@@ -4960,16 +4971,13 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
3) Seek to field index */
for (i = 0;i <= f_index; i++) {
fru_field_offset_tmp = fru_field_offset;
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
- }
+ free_n(&fru_area);
fru_area = (uint8_t *) get_fru_area_str(fru_data_old, &fru_field_offset);
}
- if( (fru_area == NULL ) || strlen((const char *)fru_area) == 0 ) {
+ if (!FRU_FIELD_VALID(fru_area)) {
printf("Field not found (1)!\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_rebuild_out;
}
@@ -5142,7 +5150,7 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
*(fru_data_new + fru_field_offset_tmp) = (0xc0 + strlen(f_string));
memcpy(fru_data_new + fru_field_offset_tmp + 1, f_string, strlen(f_string));
- /* Copy remaing bytes in section */
+ /* Copy remaining bytes in section */
#ifdef DBG_RESIZE_FRU
printf("Copying remaining of sections: %d \n",
(int)((fru_data_old + header_offset + fru_section_len - 1) -
@@ -5178,7 +5186,7 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
else
{
printf( "Internal error, padding length %i (must be from 0 to 7) ", padding_len );
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_rebuild_out;
}
@@ -5188,25 +5196,16 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId,
if( write_fru_area( intf, &fru, fruId, 0, 0, fru.size, fru_data_new ) < 0 )
{
printf("Write to FRU data failed.\n");
- rc = (-1);
+ rc = -1;
goto ipmi_fru_set_field_string_rebuild_out;
}
printf("Done.\n");
- ipmi_fru_set_field_string_rebuild_out:
- if (fru_area != NULL) {
- free(fru_area);
- fru_area = NULL;
- }
- if (fru_data_new != NULL) {
- free(fru_data_new);
- fru_data_new = NULL;
- }
- if (fru_data_old != NULL) {
- free(fru_data_old);
- fru_data_old = NULL;
- }
+ipmi_fru_set_field_string_rebuild_out:
+ free_n(&fru_area);
+ free_n(&fru_data_new);
+ free_n(&fru_data_old);
return rc;
}
diff --git a/lib/ipmi_fwum.c b/lib/ipmi_fwum.c
index d1e3f4f..b01c545 100644
--- a/lib/ipmi_fwum.c
+++ b/lib/ipmi_fwum.c
@@ -151,16 +151,16 @@ ipmi_fwum_main(struct ipmi_intf *intf, int argc, char **argv)
printf_kfwum_help();
return (-1);
}
- if (strncmp(argv[0], "help", 4) == 0) {
+ if (!strcmp(argv[0], "help")) {
printf_kfwum_help();
rc = 0;
- } else if (strncmp(argv[0], "info", 4) == 0) {
+ } else if (!strcmp(argv[0], "info")) {
rc = ipmi_fwum_info(intf);
- } else if (strncmp(argv[0], "status", 6) == 0) {
+ } else if (!strcmp(argv[0], "status")) {
rc = ipmi_fwum_status(intf);
- } else if (strncmp(argv[0], "rollback", 8) == 0) {
+ } else if (!strcmp(argv[0], "rollback")) {
rc = KfwumManualRollback(intf);
- } else if (strncmp(argv[0], "download", 8) == 0) {
+ } else if (!strcmp(argv[0], "download")) {
if ((argc < 2) || (strlen(argv[1]) < 1)) {
lprintf(LOG_ERR,
"Path and file name must be specified.");
@@ -168,14 +168,14 @@ ipmi_fwum_main(struct ipmi_intf *intf, int argc, char **argv)
}
printf("Firmware File Name : %s\n", argv[1]);
rc = ipmi_fwum_fwupgrade(intf, argv[1], 0);
- } else if (strncmp(argv[0], "upgrade", 7) == 0) {
+ } else if (!strcmp(argv[0], "upgrade")) {
if ((argc >= 2) && (strlen(argv[1]) > 0)) {
printf("Upgrading using file name %s\n", argv[1]);
rc = ipmi_fwum_fwupgrade(intf, argv[1], 1);
} else {
rc = KfwumStartFirmwareUpgrade(intf);
}
- } else if (strncmp(argv[0], "tracelog", 8) == 0) {
+ } else if (!strcmp(argv[0], "tracelog")) {
rc = KfwumGetTraceLog(intf);
} else {
lprintf(LOG_ERR, "Invalid KFWUM command: %s", argv[0]);
@@ -258,7 +258,7 @@ ipmi_fwum_fwupgrade(struct ipmi_intf *intf, char *file, int action)
unsigned short padding;
unsigned long fsize = 0;
unsigned char not_used;
- if (file == NULL) {
+ if (!file) {
lprintf(LOG_ERR, "No file given.");
return (-1);
}
@@ -312,7 +312,7 @@ KfwumGetFileSize(const char *pFileName, unsigned long *pFileSize)
{
FILE *pFileHandle = NULL;
pFileHandle = fopen(pFileName, "rb");
- if (pFileHandle == NULL) {
+ if (!pFileHandle) {
return (-1);
}
if (fseek(pFileHandle, 0L , SEEK_END) == 0) {
@@ -342,7 +342,7 @@ KfwumSetupBuffersFromFile(const char *pFileName, unsigned long fileSize)
int qty = 0;
pFileHandle = fopen(pFileName, "rb");
- if (pFileHandle == NULL) {
+ if (!pFileHandle) {
lprintf(LOG_ERR, "Failed to open '%s' for reading.",
pFileName);
return (-1);
@@ -454,7 +454,7 @@ KfwumGetInfo(struct ipmi_intf *intf, unsigned char output,
if (!rsp) {
lprintf(LOG_ERR, "Error in FWUM Firmware Get Info Command.");
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "FWUM Firmware Get Info returned %x",
rsp->ccode);
return (-1);
@@ -479,7 +479,7 @@ KfwumGetInfo(struct ipmi_intf *intf, unsigned char output,
printf("Number Of Memory Bank : %u\n", pGetInfo->numBank);
}
*pNumBank = pGetInfo->numBank;
- /* Determine wich type of download to use: */
+ /* Determine which type of download to use: */
/* Old FWUM or Old IPMC fw (data_len < 7)
* --> Address with small buffer size
*/
@@ -501,14 +501,14 @@ KfwumGetInfo(struct ipmi_intf *intf, unsigned char output,
printf("Protocol Revision :");
printf(" > 5 optimizing buffers\n");
}
- if (strstr(intf->name,"lan") != NULL) {
+ if (strstr(intf->name,"lan")) {
/* also covers lanplus */
save_fw_nfo.bufferSize = KFWUM_SMALL_BUFFER;
if (verbose) {
printf("IOL payload size : %d\n",
save_fw_nfo.bufferSize);
}
- } else if ((strstr(intf->name,"open")!= NULL)
+ } else if (strstr(intf->name,"open")
&& intf->target_addr != IPMI_BMC_SLAVE_ADDR
&& (intf->target_addr != intf->my_addr)) {
save_fw_nfo.bufferSize = KFWUM_SMALL_BUFFER;
@@ -549,10 +549,10 @@ KfwumGetDeviceInfo(struct ipmi_intf *intf, unsigned char output,
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in Get Device Id Command");
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Get Device Id returned %x",
rsp->ccode);
return (-1);
@@ -598,19 +598,19 @@ KfwumGetStatus(struct ipmi_intf * intf)
if (verbose) {
printf(" Getting Status!\n");
}
- /* Retreive the number of bank */
+ /* Retrieve the number of bank */
rc = KfwumGetInfo(intf, 0, &numBank);
for(counter = 0;
(counter < numBank) && (rc == 0);
counter ++) {
- /* Retreive the status of each bank */
+ /* Retrieve the status of each bank */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_FIRMWARE;
req.msg.cmd = KFWUM_CMD_ID_GET_FIRMWARE_STATUS;
req.msg.data = &counter;
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Error in FWUM Firmware Get Status Command.");
rc = (-1);
@@ -668,10 +668,10 @@ KfwumManualRollback(struct ipmi_intf *intf)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in FWUM Manual Rollback Command.");
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR,
"Error in FWUM Manual Rollback Command returned %x",
rsp->ccode);
@@ -707,7 +707,7 @@ KfwumStartFirmwareImage(struct ipmi_intf *intf, unsigned long length,
req.msg.data_len = 6;
}
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Error in FWUM Firmware Start Firmware Image Download Command.");
return (-1);
@@ -755,13 +755,13 @@ KfwumSaveFirmwareImage(struct ipmi_intf *intf, unsigned char sequenceNumber,
/* + 1 => sequenceNumber*/
}
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Error in FWUM Firmware Save Firmware Image Download Command.");
/* We don't receive "C7" on errors with IOL,
* instead we receive nothing
*/
- if (strstr(intf->name, "lan") != NULL) {
+ if (strstr(intf->name, "lan")) {
no_rsp++;
if (no_rsp < FWUM_SAVE_FIRMWARE_NO_RESPONSE_LIMIT) {
*pInBufLength -= 1;
@@ -772,7 +772,7 @@ KfwumSaveFirmwareImage(struct ipmi_intf *intf, unsigned char sequenceNumber,
*pInBufLength = 0;
break;
} /* For other interface keep trying */
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
if (rsp->ccode == 0xc0) {
sleep(1);
} else if ((rsp->ccode == 0xc7)
@@ -836,9 +836,9 @@ KfwumFinishFirmwareImage(struct ipmi_intf *intf, tKFWUM_InFirmwareInfo firmInfo)
/* Infinite loop if BMC doesn't reply or replies 0xc0 every time. */
do {
rsp = intf->sendrecv(intf, &req);
- } while (rsp == NULL || rsp->ccode == 0xc0);
+ } while (!rsp || rsp->ccode == 0xc0);
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR,
"FWUM Firmware Finish Firmware Image Download returned %x",
rsp->ccode);
@@ -917,7 +917,7 @@ KfwumStartFirmwareUpgrade(struct ipmi_intf *intf)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Error in FWUM Firmware Start Firmware Upgrade Command");
rc = (-1);
@@ -950,7 +950,7 @@ KfwumGetTraceLog(struct ipmi_intf *intf)
(chunkIdx < TRACE_LOG_CHUNK_COUNT)
&& (rc == 0);
chunkIdx++) {
- /* Retreive each log chunk and print it */
+ /* Retrieve each log chunk and print it */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_FIRMWARE;
req.msg.cmd = KFWUM_CMD_ID_GET_TRACE_LOG;
@@ -958,7 +958,7 @@ KfwumGetTraceLog(struct ipmi_intf *intf)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Error in FWUM Firmware Get Trace Log Command");
rc = (-1);
@@ -971,7 +971,7 @@ KfwumGetTraceLog(struct ipmi_intf *intf)
break;
}
for (cmdIdx=0; cmdIdx < TRACE_LOG_CHUNK_SIZE; cmdIdx++) {
- /* Don't diplay commands with an invalid state */
+ /* Don't display commands with an invalid state */
if ((rsp->data[TRACE_LOG_ATT_COUNT * cmdIdx + 1] != 0)
&& (rsp->data[TRACE_LOG_ATT_COUNT * cmdIdx] < KFWUM_CMD_ID_STD_MAX_CMD)) {
printf(" Cmd ID: %17s -- CmdState: %10s -- CompCode: %2x\n",
@@ -1001,7 +1001,7 @@ KfwumGetInfoFromFirmware(unsigned char *pBuf, unsigned long bufSize,
}
offset = IN_FIRMWARE_INFO_OFFSET_LOCATION;
- /* Now, fill the structure with read informations */
+ /* Now, fill the structure with read information */
pInfo->checksum = (unsigned short)KWUM_GET_BYTE_AT_OFFSET(pBuf,
offset + 0 + IN_FIRMWARE_INFO_OFFSET_CHECKSUM ) << 8;
diff --git a/lib/ipmi_gendev.c b/lib/ipmi_gendev.c
index 7a4cf08..215a717 100644
--- a/lib/ipmi_gendev.c
+++ b/lib/ipmi_gendev.c
@@ -71,7 +71,6 @@ typedef struct gendev_eeprom_info
static int
ipmi_gendev_get_eeprom_size(
- struct ipmi_intf *intf,
struct sdr_record_generic_locator *dev,
t_gendev_eeprom_info *info
)
@@ -88,8 +87,7 @@ ipmi_gendev_get_eeprom_size(
lprintf(LOG_ERR, "DevType : %x", dev->dev_type);
lprintf(LOG_ERR, "DevType Mod: %x", dev->dev_type_modifier);
*/
- if( info != NULL)
- {
+ if (info) {
switch(dev->dev_type)
{
case 0x08: // 24C01
@@ -192,7 +190,7 @@ ipmi_gendev_read_file(
int eeprom_size;
t_gendev_eeprom_info eeprom_info;
- eeprom_size = ipmi_gendev_get_eeprom_size(intf, dev, &eeprom_info);
+ eeprom_size = ipmi_gendev_get_eeprom_size(dev, &eeprom_info);
if(eeprom_size > 0)
{
@@ -280,8 +278,7 @@ ipmi_gendev_read_file(
msize
);
- if (rsp != NULL)
- {
+ if (rsp) {
retryCounter = GENDEV_RETRY_COUNT;
rc = 0;
}
@@ -364,7 +361,7 @@ ipmi_gendev_write_file(
int eeprom_size;
t_gendev_eeprom_info eeprom_info;
- eeprom_size = ipmi_gendev_get_eeprom_size(intf, dev, &eeprom_info);
+ eeprom_size = ipmi_gendev_get_eeprom_size(dev, &eeprom_info);
if(eeprom_size > 0)
{
@@ -376,7 +373,7 @@ ipmi_gendev_write_file(
if(fp)
{
- /* Retreive file length, check if it's fits the Eeprom Size */
+ /* Retrieve file length, check if it's fits the Eeprom Size */
fseek(fp, 0 ,SEEK_END);
fileLength = ftell(fp);
@@ -457,8 +454,6 @@ ipmi_gendev_write_file(
break;
}
-
-
for(
retryCounter = 0;
retryCounter<GENDEV_RETRY_COUNT;
@@ -476,8 +471,7 @@ ipmi_gendev_write_file(
i2caddr+= (((eeprom_info.size) % address_span_size) * 2);
rsp = ipmi_master_write_read(intf, i2cbus, i2caddr, (uint8_t *) wrByte, eeprom_info.address_length+msize, 0);
- if (rsp != NULL)
- {
+ if (rsp) {
retryCounter = GENDEV_RETRY_COUNT;
rc = 0;
}
@@ -495,8 +489,7 @@ ipmi_gendev_write_file(
}
}
- if( rc == 0 )
- {
+ if (!rc) {
static uint8_t previousCompleted = 101;
percentCompleted = ((counter * 100) / eeprom_info.size );
@@ -548,11 +541,7 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv)
lprintf(LOG_ERR, "Rx gendev command: %s", argv[0]);
- if (
- (argc == 0)
- ||
- (strncmp(argv[0], "help", 4) == 0)
- )
+ if (!argc || !strcmp(argv[0], "help"))
{
lprintf(LOG_ERR,
"SDR Commands: list read write");
@@ -562,18 +551,12 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv)
" read <sdr name> <file> Read to file eeprom specify by Generic Device Locators");
lprintf(LOG_ERR,
" write <sdr name> <file> Write from file eeprom specify by Generic Device Locators");
- }
- else if ( strncmp(argv[0], "list", 4) == 0)
- {
- rc = ipmi_sdr_print_sdr(intf,
- SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR);
- }
- else if (strncmp(argv[0], "read", 4) == 0)
- {
+ } else if (!strcmp(argv[0], "list")) {
+ rc = ipmi_sdr_print_sdr(intf, SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR);
+ } else if (!strcmp(argv[0], "read")) {
if (argc < 3)
lprintf(LOG_ERR, "usage: gendev read <gendev> <filename>");
- else
- {
+ else {
struct sdr_record_list *sdr;
lprintf(LOG_ERR, "Gendev read sdr name : %s", argv[1]);
@@ -582,14 +565,12 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv)
/* lookup by sensor name */
sdr = ipmi_sdr_find_sdr_byid(intf, argv[1]);
- if (sdr == NULL)
- {
+ if (!sdr) {
lprintf(LOG_ERR, "Sensor data record not found!");
return -1;
}
- if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR)
- {
+ if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) {
lprintf(LOG_ERR, "Target SDR is not a generic device locator");
return -1;
}
@@ -598,13 +579,10 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv)
ipmi_gendev_read_file(intf, sdr->record.genloc, argv[2]);
}
- }
- else if (strncmp(argv[0], "write", 5) == 0)
- {
+ } else if (!strcmp(argv[0], "write")) {
if (argc < 3)
lprintf(LOG_ERR, "usage: gendev write <gendev> <filename>");
- else
- {
+ else {
struct sdr_record_list *sdr;
lprintf(LOG_ERR, "Gendev write sdr name : %s", argv[1]);
@@ -613,25 +591,20 @@ ipmi_gendev_main(struct ipmi_intf *intf, int argc, char **argv)
/* lookup by sensor name */
sdr = ipmi_sdr_find_sdr_byid(intf, argv[1]);
- if (sdr == NULL)
- {
+ if (!sdr) {
lprintf(LOG_ERR, "Sensor data record not found!");
return -1;
}
- if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR)
- {
+ if (sdr->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR) {
lprintf(LOG_ERR, "Target SDR is not a generic device locator");
return -1;
}
lprintf(LOG_ERR, "Gendev write file name: %s", argv[2]);
ipmi_gendev_write_file(intf, sdr->record.genloc, argv[2]);
-
}
- }
- else
- {
+ } else {
lprintf(LOG_ERR, "Invalid gendev command: %s", argv[0]);
rc = -1;
}
diff --git a/lib/ipmi_hpmfwupg.c b/lib/ipmi_hpmfwupg.c
index bbcffc0..ea9072e 100644
--- a/lib/ipmi_hpmfwupg.c
+++ b/lib/ipmi_hpmfwupg.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2006 Kontron Canada, Inc. All Rights Reserved.
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 2020 Joyent, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,10 +31,6 @@
* 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 _BSD_SOURCE || \
- (_XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
- !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi_mc.h>
@@ -52,12 +49,27 @@
# include <config.h>
#endif
-/* From src/plugins/ipmi_intf.c: */
-uint16_t
-ipmi_intf_get_max_request_data_size(struct ipmi_intf * intf);
+/*
+ * This error code is used as a temporary PATCH to
+ * the latest Open ipmi driver. This PATCH
+ * will be removed once a new Open IPMI driver is released.
+ * (Buggy version = 39)
+ */
+#define ENABLE_OPENIPMI_V39_PATCH
+
+#ifdef ENABLE_OPENIPMI_V39_PATCH
+# define RETRY_COUNT_MAX 3
+static int errorCount;
+# define HPMFWUPG_IS_RETRYABLE(error) \
+ ((((error==0x83)||(error==0x82)||(error==0x80)) && (errorCount++<RETRY_COUNT_MAX))?TRUE:FALSE)
+#else
+# define HPMFWUPG_IS_RETRYABLE(error) FALSE
+#endif
extern int verbose;
+VERSIONINFO gVersionInfo[HPMFWUPG_COMPONENT_ID_MAX];
+
int HpmfwupgUpgrade(struct ipmi_intf *intf, char *imageFilename,
int activate, int, int);
int HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx *pFwupgCtx);
@@ -117,7 +129,7 @@ int HpmFwupgActionUploadFirmware(struct HpmfwupgComponentBitMask components,
int option,
int *pFlagColdReset);
int
-HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf,
+HpmfwupgPreUpgradeCheck(
struct HpmfwupgUpgradeCtx *pFwupgCtx,
int componentMask, int option);
@@ -507,10 +519,9 @@ HpmfwupgUpgrade(struct ipmi_intf *intf, char *imageFilename, int activate,
lprintf(LOG_NOTICE, "\nPerforming upgrade stage:");
}
if (option & VIEW_MODE) {
- rc = HpmfwupgPreUpgradeCheck(intf,
- &fwupgCtx,componentMask, VIEW_MODE);
+ rc = HpmfwupgPreUpgradeCheck(&fwupgCtx,componentMask, VIEW_MODE);
} else {
- rc = HpmfwupgPreUpgradeCheck(intf, &fwupgCtx,
+ rc = HpmfwupgPreUpgradeCheck(&fwupgCtx,
componentMask, option);
if (rc == HPMFWUPG_SUCCESS) {
if (verbose) {
@@ -534,7 +545,7 @@ HpmfwupgUpgrade(struct ipmi_intf *intf, char *imageFilename, int activate,
}
if (rc == HPMFWUPG_SUCCESS) {
if (option & VIEW_MODE) {
- /* Dont display anything here in case we are just viewing it */
+ /* Don't display anything here in case we are just viewing it */
lprintf(LOG_NOTICE," ");
} else if (option & COMPARE_MODE) {
lprintf(LOG_NOTICE,
@@ -544,7 +555,7 @@ HpmfwupgUpgrade(struct ipmi_intf *intf, char *imageFilename, int activate,
"\nFirmware upgrade procedure successful\n");
}
} else if (option & VIEW_MODE) {
- /* Dont display anything here in case we are just viewing it */
+ /* Don't display anything here in case we are just viewing it */
lprintf(LOG_NOTICE," ");
} else if (option & COMPARE_MODE) {
lprintf(LOG_NOTICE,
@@ -653,7 +664,7 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
if (rc != HPMFWUPG_SUCCESS) {
/* Giving one more chance to user to check whether its OK to continue even if the
* product ID does not match. This is helpful as sometimes we just want to update
- * and dont care whether we have a different product Id. If the user says NO then
+ * and don't care whether we have a different product Id. If the user says NO then
* we need to just bail out from here
*/
if (!((option & FORCE_MODE) || (option & VIEW_MODE))) {
@@ -725,7 +736,7 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
"\n Some components present in the image file are not supported by the IPMC");
return HPMFWUPG_ERROR;
}
- /* Make sure the upgrade is desirable rigth now */
+ /* Make sure the upgrade is desirable right now */
if (pFwupgCtx->targetCap.GlobalCapabilities.bitField.fwUpgUndesirable == 1) {
lprintf(LOG_NOTICE, "\n Upgrade undesirable at this moment");
return HPMFWUPG_ERROR;
@@ -834,7 +845,7 @@ HpmfwupgValidateActionRecordChecksum(struct HpmfwupgActionRecord *pActionRecord)
* is same as target version.
*/
int
-HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf,
+HpmfwupgPreUpgradeCheck(
struct HpmfwupgUpgradeCtx *pFwupgCtx,
int componentMask, int option)
{
@@ -1213,7 +1224,7 @@ HpmFwupgActionUploadFirmware(struct HpmfwupgComponentBitMask components,
if (rc == HPMFWUPG_UPLOAD_BLOCK_LENGTH && !bufLengthIsSet) {
rc = HPMFWUPG_SUCCESS;
/* Retry with a smaller buffer length */
- if (strstr(intf->name,"lan") != NULL && bufLength > 8) {
+ if (strstr(intf->name,"lan") && bufLength > 8) {
bufLength-= 8;
lprintf(LOG_INFO,
"Trying reduced buffer length: %d",
@@ -1304,7 +1315,7 @@ HpmFwupgActionUploadFirmware(struct HpmfwupgComponentBitMask components,
HpmDisplayUpgrade(1,0,0,0);
if ((option & COMPARE_MODE)
&& !pFwupgCtx->genCompProp[pFwupgCtx->componentId].GeneralCompProperties.bitfield.comparisonSupport) {
- printf("| |Comparison isn't supported for given compenent. |\n");
+ printf("| |Comparison isn't supported for given component. |\n");
}
*pImagePtr = pDataInitial + firmwareLength;
}
@@ -1390,27 +1401,26 @@ int
HpmfwupgGetBufferFromFile(char *imageFilename,
struct HpmfwupgUpgradeCtx *pFwupgCtx)
{
- int rc = HPMFWUPG_SUCCESS;
+ int rc = HPMFWUPG_ERROR;
int ret = 0;
FILE *pImageFile = fopen(imageFilename, "rb");
- if (pImageFile == NULL) {
+ if (!pImageFile) {
lprintf(LOG_ERR, "Cannot open image file '%s'",
imageFilename);
- return HPMFWUPG_ERROR;
+ goto ret_no_close;
}
/* Get the raw data in file */
ret = fseek(pImageFile, 0, SEEK_END);
if (ret != 0) {
lprintf(LOG_ERR, "Failed to seek in the image file '%s'",
imageFilename);
- return HPMFWUPG_ERROR;
+ goto ret_close;
}
pFwupgCtx->imageSize = ftell(pImageFile);
pFwupgCtx->pImageData = malloc(sizeof(unsigned char)*pFwupgCtx->imageSize);
- if (pFwupgCtx->pImageData == NULL) {
+ if (!pFwupgCtx->pImageData) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
- fclose(pImageFile);
- return HPMFWUPG_ERROR;
+ goto ret_close;
}
rewind(pImageFile);
ret = fread(pFwupgCtx->pImageData,
@@ -1422,9 +1432,14 @@ HpmfwupgGetBufferFromFile(char *imageFilename,
"Failed to read file %s size %d",
imageFilename,
pFwupgCtx->imageSize);
- rc = HPMFWUPG_ERROR;
+ goto ret_close;
}
+
+ rc = HPMFWUPG_SUCCESS;
+
+ret_close:
fclose(pImageFile);
+ret_no_close:
return rc;
}
@@ -1438,11 +1453,11 @@ HpmfwupgGetDeviceId(struct ipmi_intf *intf, struct ipm_devid_rsp *pGetDevId)
req.msg.cmd = BMC_GET_DEVICE_ID;
req.msg.data_len = 0;
rsp = HpmfwupgSendCmd(intf, req, NULL);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error getting device ID.");
return HPMFWUPG_ERROR;
}
- if (rsp->ccode != 0x00) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error getting device ID.");
lprintf(LOG_ERR, "compcode=0x%x: %s",
rsp->ccode,
@@ -1466,12 +1481,12 @@ HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf,
req.msg.data = (unsigned char*)&pCtx->req;
req.msg.data_len = sizeof(struct HpmfwupgGetTargetUpgCapabilitiesReq);
rsp = HpmfwupgSendCmd(intf, req, NULL);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Error getting target upgrade capabilities.");
return HPMFWUPG_ERROR;
}
- if (rsp->ccode != 0x00) {
+ if (rsp->ccode) {
lprintf(LOG_ERR,
"Error getting target upgrade capabilities, ccode: 0x%x: %s",
rsp->ccode,
@@ -1507,7 +1522,7 @@ HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf,
pCtx->resp.GlobalCapabilities.bitField.autRollbackOverride ? 'y' : 'n');
lprintf(LOG_NOTICE, "IPMC degraded...........[%c] ",
pCtx->resp.GlobalCapabilities.bitField.ipmcDegradedDurinUpg ? 'y' : 'n');
- lprintf(LOG_NOTICE, "Defered activation......[%c] ",
+ lprintf(LOG_NOTICE, "Deferred activation.....[%c] ",
pCtx->resp.GlobalCapabilities.bitField.deferActivation ? 'y' : 'n');
lprintf(LOG_NOTICE, "Service affected........[%c] ",
pCtx->resp.GlobalCapabilities.bitField.servAffectDuringUpg ? 'y' : 'n');
@@ -1543,12 +1558,12 @@ HpmfwupgGetComponentProperties(struct ipmi_intf *intf,
req.msg.data = (unsigned char*)&pCtx->req;
req.msg.data_len = sizeof(struct HpmfwupgGetComponentPropertiesReq);
rsp = HpmfwupgSendCmd(intf, req, NULL);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_NOTICE,
"Error getting component properties\n");
return HPMFWUPG_ERROR;
}
- if (rsp->ccode != 0x00) {
+ if (rsp->ccode) {
lprintf(LOG_NOTICE,
"Error getting component properties");
lprintf(LOG_NOTICE,
@@ -1669,11 +1684,11 @@ HpmfwupgAbortUpgrade(struct ipmi_intf *intf,
req.msg.data = (unsigned char*)&pCtx->req;
req.msg.data_len = sizeof(struct HpmfwupgAbortUpgradeReq);
rsp = HpmfwupgSendCmd(intf, req, NULL);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error - aborting upgrade.");
return HPMFWUPG_ERROR;
}
- if (rsp->ccode != 0x00) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error aborting upgrade");
lprintf(LOG_ERR, "compcode=0x%x: %s",
rsp->ccode,
@@ -1698,14 +1713,14 @@ HpmfwupgInitiateUpgradeAction(struct ipmi_intf *intf,
req.msg.data = (unsigned char*)&pCtx->req;
req.msg.data_len = sizeof(struct HpmfwupgInitiateUpgradeActionReq);
rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error initiating upgrade action.");
return HPMFWUPG_ERROR;
}
/* Long duration command handling */
if (rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS) {
rc = HpmfwupgWaitLongDurationCmd(intf, pFwupgCtx);
- } else if (rsp->ccode != 0x00) {
+ } else if (rsp->ccode) {
lprintf(LOG_NOTICE,"Error initiating upgrade action");
lprintf(LOG_NOTICE, "compcode=0x%x: %s",
rsp->ccode,
@@ -1732,7 +1747,7 @@ HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf,
/* 2 is the size of the upload struct - data */
req.msg.data_len = 2 + count;
rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_NOTICE, "Error uploading firmware block.");
return HPMFWUPG_ERROR;
}
@@ -1768,7 +1783,7 @@ HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf,
/* Long duration command handling */
if (rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS) {
rc = HpmfwupgWaitLongDurationCmd(intf, pFwupgCtx);
- } else if (rsp->ccode != 0x00) {
+ } else if (rsp->ccode) {
/* PATCH --> This validation is to handle retryables errors codes on IPMB bus.
* This will be fixed in the next release of open ipmi and this
* check will have to be removed. (Buggy version = 39)
@@ -1809,7 +1824,7 @@ HpmfwupgFinishFirmwareUpload(struct ipmi_intf *intf,
req.msg.data = (unsigned char*)&pCtx->req;
req.msg.data_len = sizeof(struct HpmfwupgFinishFirmwareUploadReq);
rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error fininshing firmware upload.");
return HPMFWUPG_ERROR;
}
@@ -1846,7 +1861,7 @@ HpmfwupgActivateFirmware(struct ipmi_intf *intf,
req.msg.data_len = sizeof(struct HpmfwupgActivateFirmwareReq)
- (!pCtx->req.rollback_override ? 1 : 0);
rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error activating firmware.");
return HPMFWUPG_ERROR;
}
@@ -1947,7 +1962,7 @@ HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf,
req.msg.data = (unsigned char*)&pCtx->req;
req.msg.data_len = sizeof(struct HpmfwupgManualFirmwareRollbackReq);
rsp = HpmfwupgSendCmd(intf, req, &fwupgCtx);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error sending manual rollback.");
return HPMFWUPG_ERROR;
}
@@ -1958,7 +1973,7 @@ HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf,
printf("Waiting firmware rollback...");
fflush(stdout);
rc = HpmfwupgQueryRollbackStatus(intf, &resCmd, &fwupgCtx);
- } else if ( rsp->ccode != 0x00 ) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error sending manual rollback");
lprintf(LOG_ERR, "compcode=0x%x: %s",
rsp->ccode,
@@ -1985,7 +2000,7 @@ HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf,
req.msg.data = (unsigned char*)&pCtx->req;
req.msg.data_len = sizeof(struct HpmfwupgQueryRollbackStatusReq);
/* If we are not in upgrade context, we use default timeout values */
- if (pFwupgCtx != NULL) {
+ if (pFwupgCtx) {
struct HpmfwupgImageHeader *pImageHeader;
if (pFwupgCtx->pImageData) {
pImageHeader = (struct HpmfwupgImageHeader*)pFwupgCtx->pImageData;
@@ -1994,7 +2009,7 @@ HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf,
rollbackTimeout = 0;
}
/* Use the greater of the two timeouts (header and target caps) */
- rollbackTimeout = MAX(rollbackTimeout,
+ rollbackTimeout = __max(rollbackTimeout,
pFwupgCtx->targetCap.rollbackTimeout) * 5;
} else {
rollbackTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT;
@@ -2021,7 +2036,7 @@ HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf,
&& ((rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS)
|| (rsp->ccode == IPMI_CC_TIMEOUT))
&& (timeoutSec2 - timeoutSec1 < rollbackTimeout));
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error getting upgrade status.");
return HPMFWUPG_ERROR;
}
@@ -2065,11 +2080,11 @@ HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelftest
unsigned int timeoutSec1, timeoutSec2;
pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER;
/* If we are not in upgrade context, we use default timeout values */
- if (pFwupgCtx != NULL) {
+ if (pFwupgCtx) {
/* Getting selftest timeout from new image */
struct HpmfwupgImageHeader *pImageHeader = (struct HpmfwupgImageHeader*)
pFwupgCtx->pImageData;
- selfTestTimeout = MAX(pImageHeader->selfTestTimeout,
+ selfTestTimeout = __max(pImageHeader->selfTestTimeout,
pFwupgCtx->targetCap.selftestTimeout) * 5;
} else {
selfTestTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT;
@@ -2101,7 +2116,7 @@ HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelftest
} while (rsp
&& (rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS)
&& (timeoutSec2 - timeoutSec1 < selfTestTimeout));
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_NOTICE, "Error getting upgrade status\n");
return HPMFWUPG_ERROR;
}
@@ -2135,14 +2150,14 @@ HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req,
unsigned int timeoutSec1, timeoutSec2;
unsigned char retry = 0;
/* If we are not in upgrade context, we use default timeout values */
- if (pFwupgCtx != NULL) {
+ if (pFwupgCtx) {
inaccessTimeout = pFwupgCtx->targetCap.inaccessTimeout*5;
upgradeTimeout = pFwupgCtx->targetCap.upgradeTimeout*5;
} else {
/* keeping the inaccessTimeout to 60 seconds results in almost 2900 retries
* So if the target is not available it will be retrying the command for 2900
- * times which is not effecient -So reducing the Timout to 5 seconds which is
- * almost 200 retries if it continuously recieves 0xC3 as completion code.
+ * times which is not efficient -So reducing the Timeout to 5 seconds which is
+ * almost 200 retries if it continuously receives 0xC3 as completion code.
*/
inaccessTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT;
upgradeTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT;
@@ -2151,10 +2166,10 @@ HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req,
do {
static unsigned char isValidSize = FALSE;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
#define HPM_LAN_PACKET_RESIZE_LIMIT 6
/* also covers lanplus */
- if (strstr(intf->name, "lan") != NULL) {
+ if (strstr(intf->name, "lan")) {
static int errorCount=0;
static struct ipmi_rs fakeRsp;
lprintf(LOG_DEBUG,
@@ -2219,7 +2234,7 @@ HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req,
}
}
/* Handle inaccessibility timeout (rsp = NULL if IOL) */
- if (rsp == NULL || rsp->ccode == 0xff || rsp->ccode == 0xc3 || rsp->ccode == 0xd3) {
+ if (!rsp || rsp->ccode == 0xff || rsp->ccode == 0xc3 || rsp->ccode == 0xd3) {
if (inaccessTimeoutCounter < inaccessTimeout) {
timeoutSec2 = time(NULL);
if (timeoutSec2 > timeoutSec1) {
@@ -2272,14 +2287,14 @@ HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf,
unsigned int timeoutSec1, timeoutSec2;
struct HpmfwupgGetUpgradeStatusCtx upgStatusCmd;
/* If we are not in upgrade context, we use default timeout values */
- if (pFwupgCtx != NULL) {
+ if (pFwupgCtx) {
upgradeTimeout = (unsigned int)(pFwupgCtx->targetCap.upgradeTimeout*5);
if (verbose) {
printf("Use File Upgrade Capabilities: %i seconds\n",
upgradeTimeout);
}
} else {
- /* Try to retreive from Caps */
+ /* Try to retrieve from Caps */
struct HpmfwupgGetTargetUpgCapabilitiesCtx targetCapCmd;
if(HpmfwupgGetTargetUpgCapabilities(intf, &targetCapCmd) != HPMFWUPG_SUCCESS) {
upgradeTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT;
@@ -2295,13 +2310,9 @@ HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf,
}
}
}
- if (rc == HPMFWUPG_SUCCESS) {
- /* Poll upgrade status until completion or timeout*/
- timeoutSec1 = time(NULL);
- timeoutSec2 = time(NULL);
- rc = HpmfwupgGetUpgradeStatus(intf, &upgStatusCmd,
- pFwupgCtx, 1);
- }
+ /* Poll upgrade status until completion or timeout*/
+ timeoutSec2 = timeoutSec1 = time(NULL);
+ rc = HpmfwupgGetUpgradeStatus(intf, &upgStatusCmd, pFwupgCtx, 1);
while (
/* With KCS: Cover the case where we sometime
* receive d5 (on the first get status) from
@@ -2464,12 +2475,12 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv)
HpmfwupgPrintUsage();
return HPMFWUPG_ERROR;
}
- if (strcmp(argv[0], "help") == 0) {
+ if (!strcmp(argv[0], "help")) {
HpmfwupgPrintUsage();
return HPMFWUPG_SUCCESS;
- } else if ((strcmp(argv[0], "check") == 0)) {
+ } else if (!strcmp(argv[0], "check")) {
/* hpm check */
- if (argv[1] == NULL) {
+ if (!argv[1]) {
rc = HpmfwupgTargetCheck(intf,VIEW_MODE);
} else {
/* hpm check <filename> */
@@ -2479,18 +2490,18 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv)
0, VIEW_MODE);
}
}
- } else if (strcmp(argv[0], "upgrade") == 0) {
+ } else if (!strcmp(argv[0], "upgrade")) {
int i =0;
for (i=1; i< argc ; i++) {
- if (strcmp(argv[i],"activate") == 0) {
+ if (!strcmp(argv[i],"activate")) {
activateFlag = 1;
}
/* hpm upgrade <filename> force */
- if (strcmp(argv[i],"force") == 0) {
+ if (!strcmp(argv[i],"force")) {
option |= FORCE_MODE;
}
/* hpm upgrade <filename> component <comp Id> */
- if (strcmp(argv[i],"component") == 0) {
+ if (!strcmp(argv[i],"component")) {
if (i+1 < argc) {
/* Error Checking */
if (str2int(argv[i+1], &componentId) != 0
@@ -2519,7 +2530,7 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv)
return HPMFWUPG_ERROR;
}
}
- if (strcmp(argv[i],"debug") == 0) {
+ if (!strcmp(argv[i],"debug")) {
option |= DEBUG_MODE;
}
}
@@ -2529,11 +2540,11 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv)
rc = HpmfwupgUpgrade(intf, argv[1], activateFlag,
componentMask, option);
}
- } else if (strcmp(argv[0], "compare") == 0) {
+ } else if (!strcmp(argv[0], "compare")) {
int i = 0;
for (i=1; i< argc; i++) {
/* hpm compare <file> [component x...] */
- if (strcmp(argv[i],"component") == 0) {
+ if (!strcmp(argv[i],"component")) {
if (i+1 < argc) {
/* Error Checking */
if (str2int(argv[i+1], &componentId) != 0
@@ -2562,7 +2573,7 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv)
"No component Id provided\n");
return HPMFWUPG_ERROR;
}
- } else if (strcmp(argv[i],"debug") == 0) {
+ } else if (!strcmp(argv[i],"debug")) {
option|= DEBUG_MODE;
}
}
@@ -2572,19 +2583,19 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv)
rc = HpmfwupgUpgrade(intf, argv[1], 0,
componentMask, option);
}
- } else if ((argc >= 1) && (strcmp(argv[0], "activate") == 0)) {
+ } else if (argc >= 1 && !strcmp(argv[0], "activate")) {
struct HpmfwupgActivateFirmwareCtx cmdCtx;
- if ((argc == 2) && (strcmp(argv[1], "norollback") == 0)) {
+ if (argc == 2 && !strcmp(argv[1], "norollback")) {
cmdCtx.req.rollback_override = 1;
} else {
cmdCtx.req.rollback_override = 0;
}
rc = HpmfwupgActivateFirmware(intf, &cmdCtx, NULL);
- } else if ((argc == 1) && (strcmp(argv[0], "targetcap") == 0)) {
+ } else if (argc == 1 && !strcmp(argv[0], "targetcap")) {
struct HpmfwupgGetTargetUpgCapabilitiesCtx cmdCtx;
verbose++;
rc = HpmfwupgGetTargetUpgCapabilities(intf, &cmdCtx);
- } else if ((argc == 3) && (strcmp(argv[0], "compprop") == 0)) {
+ } else if (argc == 3 && !strcmp(argv[0], "compprop")) {
struct HpmfwupgGetComponentPropertiesCtx cmdCtx;
if (str2uchar(argv[1], &(cmdCtx.req.componentId)) != 0
|| cmdCtx.req.componentId > 7) {
@@ -2606,23 +2617,23 @@ ipmi_hpmfwupg_main(struct ipmi_intf *intf, int argc, char **argv)
}
verbose++;
rc = HpmfwupgGetComponentProperties(intf, &cmdCtx);
- } else if ((argc == 1) && (strcmp(argv[0], "abort") == 0)) {
+ } else if (argc == 1 && !strcmp(argv[0], "abort")) {
struct HpmfwupgAbortUpgradeCtx cmdCtx;
verbose++;
rc = HpmfwupgAbortUpgrade(intf, &cmdCtx);
- } else if ((argc == 1) && (strcmp(argv[0], "upgstatus") == 0)) {
+ } else if (argc == 1 && !strcmp(argv[0], "upgstatus")) {
struct HpmfwupgGetUpgradeStatusCtx cmdCtx;
verbose++;
rc = HpmfwupgGetUpgradeStatus(intf, &cmdCtx, NULL, 0);
- } else if ((argc == 1) && (strcmp(argv[0], "rollback") == 0)) {
+ } else if (argc == 1 && !strcmp(argv[0], "rollback")) {
struct HpmfwupgManualFirmwareRollbackCtx cmdCtx;
verbose++;
rc = HpmfwupgManualFirmwareRollback(intf, &cmdCtx);
- } else if ((argc == 1) && (strcmp(argv[0], "rollbackstatus") == 0)) {
+ } else if (argc == 1 && !strcmp(argv[0], "rollbackstatus")) {
struct HpmfwupgQueryRollbackStatusCtx cmdCtx;
verbose++;
rc = HpmfwupgQueryRollbackStatus(intf, &cmdCtx, NULL);
- } else if ((argc == 1) && (strcmp(argv[0], "selftestresult") == 0)) {
+ } else if (argc == 1 && !strcmp(argv[0], "selftestresult")) {
struct HpmfwupgQuerySelftestResultCtx cmdCtx;
verbose++;
rc = HpmfwupgQuerySelftestResult(intf, &cmdCtx, NULL);
diff --git a/lib/ipmi_ime.c b/lib/ipmi_ime.c
index 6bdca3b..5499eba 100755..100644
--- a/lib/ipmi_ime.c
+++ b/lib/ipmi_ime.c
@@ -202,11 +202,11 @@ static int ImeGetInfo(struct ipmi_intf *intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Device ID command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Device ID command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -240,8 +240,7 @@ static int ImeGetInfo(struct ipmi_intf *intf)
{
rc = IME_SUCCESS;
printf("Manufacturer Name : %s\n",
- val2str( (long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
- ipmi_oem_info) );
+ OEM_MFG_STRING(devid->manufacturer_id));
printf("Product ID : %u (0x%02x%02x)\n",
buf2short((uint8_t *)(devid->product_id)),
@@ -251,7 +250,7 @@ static int ImeGetInfo(struct ipmi_intf *intf)
(devid->product_id[1]<<8)+devid->product_id[0],
ipmi_oem_product_info);
- if (product!=NULL)
+ if (product)
{
printf("Product Name : %s\n", product);
}
@@ -357,12 +356,7 @@ static int ImeUpgrade(struct ipmi_intf *intf, char* imageFilename)
rc = ImeImageCtxFromFile(imageFilename, &imgCtx);
- if(
- (rc == IME_ERROR) ||
- (imgCtx.pData == NULL) ||
- (imgCtx.size == 0)
- )
- {
+ if (rc == IME_ERROR || !imgCtx.pData || !imgCtx.size) {
return IME_ERROR;
}
@@ -510,11 +504,11 @@ static int ImeUpdatePrepare(struct ipmi_intf *intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "UpdatePrepare command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "UpdatePrepare command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -545,11 +539,11 @@ static int ImeUpdateOpenArea(struct ipmi_intf *intf)
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "UpdateOpenArea command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "UpdateOpenArea command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -585,11 +579,11 @@ static int ImeUpdateWriteArea(
req.msg.data_len = length + 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "UpdateWriteArea command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "UpdateWriteArea command failed: %s",
val2str(rsp->ccode, completion_code_vals));
if( rsp->ccode == 0x80) // restart operation
@@ -632,11 +626,11 @@ static int ImeUpdateCloseArea(
req.msg.data_len = length;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "UpdateCloseArea command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "UpdateCloseArea command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -666,11 +660,11 @@ static int ImeUpdateGetStatus(struct ipmi_intf *intf, tImeStatus *pStatus )
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "UpdatePrepare command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "UpdatePrepare command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -739,11 +733,11 @@ static int ImeUpdateGetCapabilities(struct ipmi_intf *intf, tImeCaps *pCaps )
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "UpdatePrepare command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "UpdatePrepare command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -779,11 +773,11 @@ static int ImeUpdateRegisterUpdate(struct ipmi_intf *intf, tImeUpdateType type)
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "ImeUpdateRegisterUpdate command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "ImeUpdateRegisterUpdate command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -810,11 +804,11 @@ static int ImeUpdateShowStatus(struct ipmi_intf *intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "UpdatePrepare command failed");
return IME_ERROR;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "UpdatePrepare command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return IME_ERROR;
@@ -879,15 +873,13 @@ static int ImeImageCtxFromFile(
{
int rc = IME_SUCCESS;
FILE* pImageFile = fopen(imageFilename, "rb");
-
- if ( pImageFile == NULL )
- {
+
+ if (!pImageFile) {
lprintf(LOG_NOTICE,"Cannot open image file %s", imageFilename);
rc = IME_ERROR;
}
-
- if ( rc == IME_SUCCESS )
- {
+
+ if (rc == IME_SUCCESS) {
/* Get the raw data in file */
fseek(pImageFile, 0, SEEK_END);
pImageCtx->size = ftell(pImageFile);
@@ -901,32 +893,26 @@ static int ImeImageCtxFromFile(
pImageCtx->pData = malloc(sizeof(unsigned char)*pImageCtx->size);
rewind(pImageFile);
- if ( pImageCtx->pData != NULL )
- {
- if (pImageCtx->size < fread(pImageCtx->pData, sizeof(unsigned char),
- pImageCtx->size, pImageFile))
- rc = IME_ERROR;
- }
- else
+ if (!pImageCtx->pData
+ || pImageCtx->size < fread(pImageCtx->pData, sizeof(unsigned char),
+ pImageCtx->size, pImageFile))
{
rc = IME_ERROR;
}
}
-
+
// Calculate checksum CRC8
if ( rc == IME_SUCCESS )
{
pImageCtx->crc8 = ImeCrc8(pImageCtx->size, pImageCtx->pData);
}
-
- if( pImageFile != NULL)
- {
+ if (pImageFile) {
fclose(pImageFile);
}
-
+
return rc;
-}
+}
static uint8_t ImeCrc8( uint32_t length, uint8_t * pBuf )
{
@@ -1002,16 +988,13 @@ int ipmi_ime_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_DEBUG,"ipmi_ime_main()");
- if ( (argc == 0) || (strcmp(argv[0], "help") == 0) )
- {
+ if (!argc || !strcmp(argv[0], "help")) {
ImePrintUsage();
}
- else if ( (argc == 0) || (strcmp(argv[0], "info") == 0) )
- {
+ else if (!strcmp(argv[0], "info")) {
rc = ImeGetInfo(intf);
}
- else if ( strcmp(argv[0], "update") == 0)
- {
+ else if (!strcmp(argv[0], "update")) {
if(argc == 2)
{
lprintf(LOG_NOTICE,"Update using file: %s", argv[1]);
@@ -1023,8 +1006,7 @@ int ipmi_ime_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = IME_ERROR;
}
}
- else if ( (argc == 0) || (strcmp(argv[0], "rollback") == 0) )
- {
+ else if (!strcmp(argv[0], "rollback")) {
rc = ImeManualRollback(intf);
}
else
diff --git a/lib/ipmi_isol.c b/lib/ipmi_isol.c
index bc0b08b..1c2708f 100644
--- a/lib/ipmi_isol.c
+++ b/lib/ipmi_isol.c
@@ -29,7 +29,6 @@
* 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 _XOPEN_SOURCE
#include <stdlib.h>
#include <string.h>
@@ -84,7 +83,7 @@ static int ipmi_get_isol_info(struct ipmi_intf * intf,
data[3] = 0x00; /* selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in Get ISOL Config Command");
return -1;
}
@@ -92,7 +91,7 @@ static int ipmi_get_isol_info(struct ipmi_intf * intf,
lprintf(LOG_ERR, "IPMI v1.5 Serial Over Lan (ISOL) not supported!");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error in Get ISOL Config Command: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -108,11 +107,11 @@ static int ipmi_get_isol_info(struct ipmi_intf * intf,
data[3] = 0x00; /* selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in Get ISOL Config Command");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error in Get ISOL Config Command: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -128,11 +127,11 @@ static int ipmi_get_isol_info(struct ipmi_intf * intf,
data[3] = 0x00; /* selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error in Get ISOL Config Command");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error in Get ISOL Config Command: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -193,12 +192,12 @@ static int ipmi_isol_set_param(struct ipmi_intf * intf,
/*
* enabled
*/
- if (strcmp(param, "enabled") == 0)
+ if (!strcmp(param, "enabled"))
{
data[1] = ISOL_ENABLE_PARAM;
- if (strcmp(value, "true") == 0)
+ if (!strcmp(value, "true"))
data[2] = 0x01;
- else if (strcmp(value, "false") == 0)
+ else if (!strcmp(value, "false"))
data[2] = 0x00;
else {
lprintf(LOG_ERR, "Invalid value %s for parameter %s",
@@ -211,7 +210,7 @@ static int ipmi_isol_set_param(struct ipmi_intf * intf,
/*
* privilege-level
*/
- else if (strcmp(param, "privilege-level") == 0)
+ else if (!strcmp(param, "privilege-level"))
{
data[1] = ISOL_AUTHENTICATION_PARAM;
if (! strcmp(value, "user"))
@@ -236,22 +235,22 @@ static int ipmi_isol_set_param(struct ipmi_intf * intf,
/*
* bit-rate
*/
- else if (strcmp(param, "bit-rate") == 0)
+ else if (!strcmp(param, "bit-rate"))
{
data[1] = ISOL_BAUD_RATE_PARAM;
- if (strncmp(value, "9.6", 3) == 0) {
+ if (!strcmp(value, "9.6")) {
data[2] = 0x06;
}
- else if (strncmp(value, "19.2", 4) == 0) {
+ else if (!strcmp(value, "19.2")) {
data[2] = 0x07;
}
- else if (strncmp(value, "38.4", 4) == 0) {
+ else if (!strcmp(value, "38.4")) {
data[2] = 0x08;
}
- else if (strncmp(value, "57.6", 4) == 0) {
+ else if (!strcmp(value, "57.6")) {
data[2] = 0x09;
}
- else if (strncmp(value, "115.2", 5) == 0) {
+ else if (!strcmp(value, "115.2")) {
data[2] = 0x0A;
}
else {
@@ -272,11 +271,11 @@ static int ipmi_isol_set_param(struct ipmi_intf * intf,
*/
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting ISOL parameter '%s'", param);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error setting ISOL parameter '%s': %s",
param, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -429,11 +428,11 @@ ipmi_isol_deactivate(struct ipmi_intf * intf)
data[5] = 0x00;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error deactivating ISOL");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error deactivating ISOL: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -573,7 +572,7 @@ ipmi_isol_red_pill(struct ipmi_intf * intf)
int timedout = 0;
buffer = (char*)malloc(buffer_size);
- if (buffer == NULL) {
+ if (!buffer) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -791,20 +790,20 @@ int ipmi_isol_main(struct ipmi_intf * intf, int argc, char ** argv)
/*
* Help
*/
- if (!argc || !strncmp(argv[0], "help", 4))
+ if (!argc || !strcmp(argv[0], "help"))
print_isol_usage();
/*
* Info
*/
- else if (!strncmp(argv[0], "info", 4)) {
+ else if (!strcmp(argv[0], "info")) {
ret = ipmi_print_isol_info(intf);
}
/*
* Set a parameter value
*/
- else if (!strncmp(argv[0], "set", 3)) {
+ else if (!strcmp(argv[0], "set")) {
if (argc < 3) {
print_isol_set_usage();
return -1;
@@ -815,7 +814,7 @@ int ipmi_isol_main(struct ipmi_intf * intf, int argc, char ** argv)
/*
* Activate
*/
- else if (!strncmp(argv[0], "activate", 8)) {
+ else if (!strcmp(argv[0], "activate")) {
ret = ipmi_isol_activate(intf);
}
diff --git a/lib/ipmi_kontronoem.c b/lib/ipmi_kontronoem.c
index 64860be..16e6014 100644
--- a/lib/ipmi_kontronoem.c
+++ b/lib/ipmi_kontronoem.c
@@ -60,8 +60,7 @@ static void ipmi_kontron_help(void);
static int ipmi_kontron_set_serial_number(struct ipmi_intf *intf);
static int ipmi_kontron_set_mfg_date (struct ipmi_intf *intf);
static void ipmi_kontron_nextboot_help(void);
-static int ipmi_kontron_nextboot_set(struct ipmi_intf *intf, int argc,
- char **argv);
+static int ipmi_kontron_nextboot_set(struct ipmi_intf *intf, char **argv);
static int ipmi_kontronoem_send_set_large_buffer(struct ipmi_intf *intf,
unsigned char channel, unsigned char size);
@@ -76,38 +75,38 @@ ipmi_kontronoem_main(struct ipmi_intf *intf, int argc, char **argv)
ipmi_kontron_help();
return (-1);
}
- if (strncmp(argv[0], "help", 4) == 0) {
+ if (!strcmp(argv[0], "help")) {
ipmi_kontron_help();
rc = 0;
- } else if (!strncmp(argv[0], "setsn", 5)) {
+ } else if (!strcmp(argv[0], "setsn")) {
if (argc < 1) {
printf("fru setsn\n");
return (-1);
}
if (ipmi_kontron_set_serial_number(intf) > 0) {
- printf("FRU serial number setted successfully\n");
+ printf("FRU serial number set successfully\n");
} else {
printf("FRU serial number set failed\n");
rc = (-1);
}
- } else if (!strncmp(argv[0], "setmfgdate", 10)) {
+ } else if (!strcmp(argv[0], "setmfgdate")) {
if (argc < 1) {
printf("fru setmfgdate\n");
return (-1);
}
if (ipmi_kontron_set_mfg_date(intf) > 0) {
- printf("FRU manufacturing date setted successfully\n");
+ printf("FRU manufacturing date set successfully\n");
} else {
printf("FRU manufacturing date set failed\n");
rc = (-1);
}
- } else if (!strncmp(argv[0], "nextboot", 8)) {
+ } else if (!strcmp(argv[0], "nextboot")) {
if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_kontron_nextboot_help();
return (-1);
}
- rc = ipmi_kontron_nextboot_set(intf, (argc - 1), (argv + 1));
+ rc = ipmi_kontron_nextboot_set(intf, (argv + 1));
if (rc == 0) {
printf("Nextboot set successfully\n");
} else {
@@ -188,10 +187,10 @@ ipmi_kontronoem_send_set_large_buffer(struct ipmi_intf *intf,
req.msg.data_len = 2;
req.msg.lun = 0x00;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf("Cannot send large buffer command\n");
return(-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf("Invalid length for the selected interface (%s) %d\n",
val2str(rsp->ccode, completion_code_vals), rsp->ccode);
return(-1);
@@ -243,16 +242,16 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf)
/* Set Lun, necessary for this oem command */
req.msg.lun = 0x03;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf(" This option is not implemented for this board\n");
return (-1);
}
sn_size = rsp->data_len;
sn = malloc(sn_size + 1);
- if (sn == NULL) {
+ if (!sn) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (-1);
}
@@ -269,12 +268,12 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf)
req.msg.data = msg_data;
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
free(sn);
sn = NULL;
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
free(sn);
@@ -302,12 +301,12 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf)
req.msg.data = msg_data;
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
free(sn);
sn = NULL;
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
free(sn);
@@ -328,7 +327,7 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf)
/* Set the Board Section */
board_sec_len = (header.offset.product * 8) - (header.offset.board * 8);
fru_data = malloc(fru.size);
- if (fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
free(sn);
sn = NULL;
@@ -346,20 +345,20 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf)
/* Position at Board Manufacturer */
fru_data_offset = (header.offset.board * 8) + 6;
fru_area = get_fru_area_str(fru_data, &fru_data_offset);
- if (fru_area != NULL) {
+ if (fru_area) {
free(fru_area);
fru_area = NULL;
}
/* Position at Board Product Name */
fru_area = get_fru_area_str(fru_data, &fru_data_offset);
- if (fru_area != NULL) {
+ if (fru_area) {
free(fru_area);
fru_area = NULL;
}
fru_data_offset_tmp = fru_data_offset;
/* Position at Serial Number */
fru_area = get_fru_area_str(fru_data, &fru_data_offset_tmp);
- if (fru_area == NULL) {
+ if (!fru_area) {
lprintf(LOG_ERR, "Failed to read FRU Area string.");
free(fru_data);
fru_data = NULL;
@@ -420,32 +419,32 @@ ipmi_kontron_set_serial_number(struct ipmi_intf *intf)
/* Position at Product Manufacturer */
fru_data_offset = (header.offset.product * 8) + 3;
fru_area = get_fru_area_str(fru_data, &fru_data_offset);
- if (fru_area != NULL) {
+ if (fru_area) {
free(fru_area);
fru_area = NULL;
}
/* Position at Product Name */
fru_area = get_fru_area_str(fru_data, &fru_data_offset);
- if (fru_area != NULL) {
+ if (fru_area) {
free(fru_area);
fru_area = NULL;
}
/* Position at Product Part */
fru_area = get_fru_area_str(fru_data, &fru_data_offset);
- if (fru_area != NULL) {
+ if (fru_area) {
free(fru_area);
fru_area = NULL;
}
/* Position at Product Version */
fru_area = get_fru_area_str(fru_data, &fru_data_offset);
- if (fru_area != NULL) {
+ if (fru_area) {
free(fru_area);
fru_area = NULL;
}
fru_data_offset_tmp = fru_data_offset;
/* Position at Serial Number */
fru_area = get_fru_area_str(fru_data, &fru_data_offset_tmp);
- if (fru_area == NULL) {
+ if (!fru_area) {
lprintf(LOG_ERR, "Failed to read FRU Area string.");
free(sn);
sn = NULL;
@@ -532,10 +531,10 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf)
/* Set Lun temporary, necessary for this oem command */
req.msg.lun = 0x03;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf("Device not present (No Response)\n");
return(-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf("This option is not implemented for this board\n");
return(-1);
}
@@ -554,10 +553,10 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf)
req.msg.data = msg_data;
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return(-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return(-1);
@@ -582,10 +581,10 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf)
req.msg.data = msg_data;
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return (-1);
@@ -601,7 +600,7 @@ ipmi_kontron_set_mfg_date (struct ipmi_intf *intf)
}
board_sec_len = (header.offset.product * 8) - (header.offset.board * 8);
fru_data = malloc(fru.size);
- if(fru_data == NULL) {
+ if (!fru_data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return(-1);
}
@@ -656,7 +655,7 @@ ipmi_kontron_nextboot_help(void)
* returns 1 if successful
*/
static int
-ipmi_kontron_nextboot_set(struct ipmi_intf *intf, int argc, char **argv)
+ipmi_kontron_nextboot_set(struct ipmi_intf *intf, char **argv)
{
struct ipmi_rs *rsp;
struct ipmi_rq req;
@@ -672,7 +671,7 @@ ipmi_kontron_nextboot_set(struct ipmi_intf *intf, int argc, char **argv)
msg_data[5] = 0xFF;
msg_data[6] = 0xFF; /* any */
for (i = 0; bootdev[i] != 0; i++) {
- if (strcmp(argv[0], bootdev[i]) == 0) {
+ if (!strcmp(argv[0], bootdev[i])) {
msg_data[5] = i;
break;
}
@@ -690,10 +689,10 @@ ipmi_kontron_nextboot_set(struct ipmi_intf *intf, int argc, char **argv)
/* Set Lun temporary, necessary for this oem command */
req.msg.lun = 0x03;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf("Device not present (No Response)\n");
return(-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
printf("Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
return (-1);
diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c
index 65d881b..16c0d9a 100644
--- a/lib/ipmi_lanp.c
+++ b/lib/ipmi_lanp.c
@@ -57,6 +57,62 @@
extern int verbose;
+static struct lan_param {
+ int cmd;
+ int size;
+ char desc[24];
+ uint8_t *data;
+ int data_len;
+} ipmi_lan_params[] = {
+ { IPMI_LANP_SET_IN_PROGRESS, 1, "Set in Progress", NULL, 0 },
+ { IPMI_LANP_AUTH_TYPE, 1, "Auth Type Support", NULL, 0 },
+ { IPMI_LANP_AUTH_TYPE_ENABLE, 5, "Auth Type Enable", NULL, 0 },
+ { IPMI_LANP_IP_ADDR, 4, "IP Address", NULL, 0 },
+ { IPMI_LANP_IP_ADDR_SRC, 1, "IP Address Source", NULL, 0 },
+ { IPMI_LANP_MAC_ADDR, 6, "MAC Address", NULL, 0 }, /* 5 */
+ { IPMI_LANP_SUBNET_MASK, 4, "Subnet Mask", NULL, 0 },
+ { IPMI_LANP_IP_HEADER, 3, "IP Header", NULL, 0 },
+ { IPMI_LANP_PRI_RMCP_PORT, 2, "Primary RMCP Port", NULL, 0 },
+ { IPMI_LANP_SEC_RMCP_PORT, 2, "Secondary RMCP Port", NULL, 0 },
+ { IPMI_LANP_BMC_ARP, 1, "BMC ARP Control", NULL, 0}, /* 10 */
+ { IPMI_LANP_GRAT_ARP, 1, "Gratituous ARP Intrvl", NULL, 0 },
+ { IPMI_LANP_DEF_GATEWAY_IP, 4, "Default Gateway IP", NULL, 0 },
+ { IPMI_LANP_DEF_GATEWAY_MAC, 6, "Default Gateway MAC", NULL, 0 },
+ { IPMI_LANP_BAK_GATEWAY_IP, 4, "Backup Gateway IP", NULL, 0 },
+ { IPMI_LANP_BAK_GATEWAY_MAC, 6, "Backup Gateway MAC", NULL, 0 }, /* 15 */
+ { IPMI_LANP_SNMP_STRING, 18, "SNMP Community String", NULL, 0 },
+ { IPMI_LANP_NUM_DEST, 1, "Number of Destinations", NULL, 0 },
+ { IPMI_LANP_DEST_TYPE, 4, "Destination Type", NULL, 0 },
+ { IPMI_LANP_DEST_ADDR, 13, "Destination Addresses", NULL, 0 },
+ { IPMI_LANP_VLAN_ID, 2, "802.1q VLAN ID", NULL, 0 }, /* 20 */
+ { IPMI_LANP_VLAN_PRIORITY, 1, "802.1q VLAN Priority", NULL, 0 },
+ { IPMI_LANP_RMCP_CIPHER_SUPPORT,1, "RMCP+ Cipher Suite Count", NULL, 0 },
+ { IPMI_LANP_RMCP_CIPHERS, 16, "RMCP+ Cipher Suites", NULL, 0 },
+ { IPMI_LANP_RMCP_PRIV_LEVELS, 9, "Cipher Suite Priv Max", NULL, 0 },
+ { IPMI_LANP_BAD_PASS_THRESH, 6, "Bad Password Threshold", NULL, 0 },
+ { IPMI_LANP_OEM_ALERT_STRING, 28, "OEM Alert String", NULL, 0 }, /* 25 */
+ { IPMI_LANP_ALERT_RETRY, 1, "Alert Retry Algorithm", NULL, 0 },
+ { IPMI_LANP_UTC_OFFSET, 3, "UTC Offset", NULL, 0 },
+ { IPMI_LANP_DHCP_SERVER_IP, 4, "DHCP Server IP", NULL, 0 },
+ { IPMI_LANP_DHCP_SERVER_MAC, 6, "DHDP Server MAC", NULL, 0},
+ { IPMI_LANP_DHCP_ENABLE, 1, "DHCP Enable", NULL, 0 }, /* 30 */
+ { IPMI_LANP_CHAN_ACCESS_MODE, 2, "Channel Access Mode", NULL, 0 },
+ { -1, -1, "", NULL, -1 }
+};
+
+static const struct valstr set_lan_cc_vals[] = {
+ { 0x80, "Unsupported parameter" },
+ { 0x81, "Attempt to set 'in progress' while not in 'complete' state" },
+ { 0x82, "Parameter is read-only" },
+ { 0x83, "Parameter is wrote-only" },
+ { 0x00, NULL }
+};
+
+static const struct valstr get_lan_cc_vals[] = {
+ { 0x80, "Unsupported parameter" },
+ { 0x00, NULL }
+};
+
static void print_lan_alert_print_usage(void);
static void print_lan_alert_set_usage(void);
static void print_lan_set_usage(void);
@@ -80,7 +136,7 @@ static void print_lan_usage(void);
* @chan: channel number to check
*/
static int
-is_lan_channel(struct ipmi_intf * intf, uint8_t chan)
+is_lan_channel(struct ipmi_intf *intf, uint8_t chan)
{
uint8_t medium;
@@ -105,7 +161,7 @@ is_lan_channel(struct ipmi_intf * intf, uint8_t chan)
* @start: channel number to start searching from
*/
uint8_t
-find_lan_channel(struct ipmi_intf * intf, uint8_t start)
+find_lan_channel(struct ipmi_intf *intf, uint8_t start)
{
uint8_t chan = 0;
@@ -131,10 +187,11 @@ find_lan_channel(struct ipmi_intf * intf, uint8_t start)
* @select: lan parameter set selector
*/
static struct lan_param *
-get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int select)
+get_lan_param_select(struct ipmi_intf *intf, uint8_t chan, int param, int select)
{
- struct lan_param * p = NULL;
- struct ipmi_rs * rsp;
+ struct lan_param *p = NULL;
+ struct lan_param *rc = NULL;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
int i = 0;
uint8_t msg_data[4];
@@ -146,9 +203,9 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
}
}
- if (p == NULL) {
+ if (!p) {
lprintf(LOG_INFO, "Get LAN Parameter failed: Unknown parameter.");
- return NULL;
+ return rc;
}
msg_data[0] = chan;
@@ -163,9 +220,9 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed", p->desc);
- return NULL;
+ return rc;
}
switch (rsp->ccode)
@@ -176,19 +233,18 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
case 0x80: /* parameter not supported */
case 0xc9: /* parameter out of range */
case 0xcc: /* invalid data field in request */
-
- /* these completion codes usually mean parameter not supported */
- lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
- p->desc, val2str(rsp->ccode, completion_code_vals));
+ /* We treat them as valid but empty response */
p->data = NULL;
p->data_len = 0;
- return p;
-
+ rc = p;
+ /* fall through */
default:
-
/* other completion codes are treated as error */
lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
- p->desc, val2str(rsp->ccode, completion_code_vals));
+ p->desc,
+ specific_val2str(rsp->ccode,
+ get_lan_cc_vals,
+ completion_code_vals));
return NULL;
}
@@ -211,7 +267,7 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
* @param: lan parameter id
*/
static struct lan_param *
-get_lan_param(struct ipmi_intf * intf, uint8_t chan, int param)
+get_lan_param(struct ipmi_intf *intf, uint8_t chan, int param)
{
return get_lan_param_select(intf, chan, param, 0);
}
@@ -232,10 +288,10 @@ get_lan_param(struct ipmi_intf * intf, uint8_t chan, int param)
* @len: length of lan parameter data
*/
static int
-set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len)
+set_lan_param_wait(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len)
{
- struct lan_param * p;
+ struct lan_param *p;
int retry = 10; /* 10 retries */
lprintf(LOG_DEBUG, "Waiting for Set LAN Parameter to complete...");
@@ -244,7 +300,7 @@ set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
for (;;) {
p = get_lan_param(intf, chan, param);
- if (p == NULL) {
+ if (!p) {
sleep(IPMI_LANP_TIMEOUT);
if (retry-- == 0)
return -1;
@@ -291,10 +347,10 @@ set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
* @wait: whether to wait for write completion
*/
static int
-__set_lan_param(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len, int wait)
+__set_lan_param(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len, int wait)
{
- struct ipmi_rs * rsp;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
uint8_t msg_data[32];
@@ -312,13 +368,15 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
req.msg.data_len = len+2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Set LAN Parameter failed");
return -1;
}
- if ((rsp->ccode > 0) && (wait != 0)) {
+ if (rsp->ccode && wait) {
lprintf(LOG_DEBUG, "Warning: Set LAN Parameter failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ specific_val2str(rsp->ccode,
+ set_lan_cc_vals,
+ completion_code_vals));
if (rsp->ccode == 0xcc) {
/* retry hack for invalid data field ccode */
int retry = 10; /* 10 retries */
@@ -328,9 +386,7 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
break;
sleep(IPMI_LANP_TIMEOUT);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL)
- continue;
- if (rsp->ccode > 0)
+ if (!rsp || rsp->ccode)
continue;
return set_lan_param_wait(intf, chan, param, data, len);
}
@@ -341,7 +397,7 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
}
}
- if (wait == 0)
+ if (!wait)
return 0;
return set_lan_param_wait(intf, chan, param, data, len);
}
@@ -358,13 +414,13 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
* @chan: ipmi channel
*/
static int
-ipmi_lanp_lock_state(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lanp_lock_state(struct ipmi_intf *intf, uint8_t chan)
{
- struct lan_param * p;
+ struct lan_param *p;
p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data == NULL)
+ if (!p->data)
return -1;
return (p->data[0] & 3);
}
@@ -381,7 +437,7 @@ ipmi_lanp_lock_state(struct ipmi_intf * intf, uint8_t chan)
* @chan: ipmi channel
*/
static void
-ipmi_lanp_lock(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lanp_lock(struct ipmi_intf *intf, uint8_t chan)
{
uint8_t val = IPMI_LANP_WRITE_LOCK;
int retry = 3;
@@ -411,7 +467,7 @@ ipmi_lanp_lock(struct ipmi_intf * intf, uint8_t chan)
* @chan: ipmi channel
*/
static void
-ipmi_lanp_unlock(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lanp_unlock(struct ipmi_intf *intf, uint8_t chan)
{
uint8_t val = IPMI_LANP_WRITE_COMMIT;
int rc;
@@ -436,8 +492,8 @@ ipmi_lanp_unlock(struct ipmi_intf * intf, uint8_t chan)
* @len: length of lan parameter data
*/
static int
-set_lan_param(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len)
+set_lan_param(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len)
{
int rc;
ipmi_lanp_lock(intf, chan);
@@ -457,8 +513,8 @@ set_lan_param(struct ipmi_intf * intf, uint8_t chan,
* @len: length of lan parameter data
*/
static int
-set_lan_param_nowait(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len)
+set_lan_param_nowait(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len)
{
int rc;
ipmi_lanp_lock(intf, chan);
@@ -468,16 +524,16 @@ set_lan_param_nowait(struct ipmi_intf * intf, uint8_t chan,
}
static int
-lan_set_arp_interval(struct ipmi_intf * intf, uint8_t chan, uint8_t ival)
+lan_set_arp_interval(struct ipmi_intf *intf, uint8_t chan, uint8_t ival)
{
struct lan_param *lp;
uint8_t interval = 0;
int rc = 0;
lp = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
if (ival != 0) {
@@ -498,16 +554,16 @@ lan_set_arp_interval(struct ipmi_intf * intf, uint8_t chan, uint8_t ival)
}
static int
-lan_set_arp_generate(struct ipmi_intf * intf,
+lan_set_arp_generate(struct ipmi_intf *intf,
uint8_t chan, uint8_t ctl)
{
struct lan_param *lp;
uint8_t data;
lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
data = lp->data[0];
@@ -522,16 +578,16 @@ lan_set_arp_generate(struct ipmi_intf * intf,
}
static int
-lan_set_arp_respond(struct ipmi_intf * intf,
+lan_set_arp_respond(struct ipmi_intf *intf,
uint8_t chan, uint8_t ctl)
{
struct lan_param *lp;
uint8_t data;
lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
data = lp->data[0];
@@ -574,9 +630,9 @@ static char priv_level_to_char(unsigned char priv_level)
static int
-ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lan_print(struct ipmi_intf *intf, uint8_t chan)
{
- struct lan_param * p;
+ struct lan_param *p;
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX) {
lprintf(LOG_ERR, "Invalid Channel %d", chan);
@@ -590,9 +646,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: ", p->desc);
p->data[0] &= 3;
switch (p->data[0]) {
@@ -614,9 +670,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: %s%s%s%s%s\n", p->desc,
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
@@ -626,9 +682,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: Callback : %s%s%s%s%s\n", p->desc,
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
@@ -662,9 +718,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR_SRC);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: ", p->desc);
p->data[0] &= 0xf;
switch (p->data[0]) {
@@ -687,79 +743,79 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_SUBNET_MASK);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_MAC_ADDR);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, mac2str(p->data));
p = get_lan_param(intf, chan, IPMI_LANP_SNMP_STRING);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, p->data);
p = get_lan_param(intf, chan, IPMI_LANP_IP_HEADER);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: TTL=0x%02x Flags=0x%02x Precedence=0x%02x TOS=0x%02x\n",
p->desc, p->data[0], p->data[1] & 0xe0, p->data[2] & 0xe0, p->data[2] & 0x1e);
p = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: ARP Responses %sabled, Gratuitous ARP %sabled\n", p->desc,
(p->data[0] & 2) ? "En" : "Dis", (p->data[0] & 1) ? "En" : "Dis");
p = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %.1f seconds\n", p->desc, (float)((p->data[0] + 1) / 2));
p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, mac2str(p->data));
p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, mac2str(p->data));
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID);
- if (p != NULL && p->data != NULL) {
+ if (p && p->data) {
int id = ((p->data[1] & 0x0f) << 8) + p->data[0];
if (p->data[1] & 0x80)
printf("%-24s: %d\n", p->desc, id);
@@ -768,25 +824,25 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_PRIORITY);
- if (p != NULL && p->data != NULL)
+ if (p && p->data)
printf("%-24s: %d\n", p->desc, p->data[0] & 0x07);
/* Determine supported Cipher Suites -- Requires two calls */
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHER_SUPPORT);
- if (p == NULL)
+ if (!p)
return -1;
- else if (p->data != NULL)
+ else if (p->data)
{
unsigned char cipher_suite_count = p->data[0];
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHERS);
- if (p == NULL)
+ if (!p)
return -1;
printf("%-24s: ", p->desc);
/* Now we're dangerous. There are only 15 fixed cipher
suite IDs, but the spec allows for 16 in the return data.*/
- if ((p->data != NULL) && (p->data_len <= 17))
+ if (p->data && p->data_len <= 17)
{
unsigned int i;
for (i = 0; (i < 16) && (i < cipher_suite_count); ++i)
@@ -806,9 +862,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
/* RMCP+ Messaging Cipher Suite Privilege Levels */
/* These are the privilege levels for the 15 fixed cipher suites */
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS);
- if (p == NULL)
+ if (!p)
return -1;
- if ((p->data != NULL) && (p->data_len == 9))
+ if (p->data && 9 == p->data_len)
{
printf("%-24s: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", p->desc,
priv_level_to_char(p->data[1] & 0x0F),
@@ -840,9 +896,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
/* Bad Password Threshold */
p = get_lan_param(intf, chan, IPMI_LANP_BAD_PASS_THRESH);
- if (p == NULL)
+ if (!p)
return -1;
- if ((p->data != NULL) && (p->data_len == 6)) {
+ if (p->data && 6 == p->data_len) {
int tmp;
printf("%-24s: %d\n", p->desc, p->data[1]);
@@ -862,20 +918,20 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
/* Configure Authentication Types */
/* TODO - probably some code duplication going on ??? */
static int
-ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * types)
+ipmi_lan_set_auth(struct ipmi_intf *intf, uint8_t chan, char *level, char *types)
{
uint8_t data[5];
uint8_t authtype = 0;
- char * p;
- struct lan_param * lp;
+ char *p;
+ struct lan_param *lp;
- if (level == NULL || types == NULL)
+ if (!level || !types)
return -1;
lp = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
lprintf(LOG_DEBUG, "%-24s: callback=0x%02x user=0x%02x operator=0x%02x admin=0x%02x oem=0x%02x",
@@ -886,16 +942,16 @@ ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * ty
p = types;
while (p) {
- if (strncasecmp(p, "none", 4) == 0)
+ if (strcasecmp(p, "none") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_NONE;
- else if (strncasecmp(p, "md2", 3) == 0)
+ else if (strcasecmp(p, "md2") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD2;
- else if (strncasecmp(p, "md5", 3) == 0)
+ else if (strcasecmp(p, "md5") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD5;
- else if ((strncasecmp(p, "password", 8) == 0) ||
- (strncasecmp(p, "key", 3) == 0))
+ else if ((strcasecmp(p, "password") == 0) ||
+ (strcasecmp(p, "key") == 0))
authtype |= 1 << IPMI_SESSION_AUTHTYPE_KEY;
- else if (strncasecmp(p, "oem", 3) == 0)
+ else if (strcasecmp(p, "oem") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_OEM;
else
lprintf(LOG_WARNING, "Invalid authentication type: %s", p);
@@ -906,13 +962,13 @@ ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * ty
p = level;
while (p) {
- if (strncasecmp(p, "callback", 8) == 0)
+ if (strcasecmp(p, "callback") == 0)
data[0] = authtype;
- else if (strncasecmp(p, "user", 4) == 0)
+ else if (strcasecmp(p, "user") == 0)
data[1] = authtype;
- else if (strncasecmp(p, "operator", 8) == 0)
+ else if (strcasecmp(p, "operator") == 0)
data[2] = authtype;
- else if (strncasecmp(p, "admin", 5) == 0)
+ else if (strcasecmp(p, "admin") == 0)
data[3] = authtype;
else
lprintf(LOG_WARNING, "Invalid authentication level: %s", p);
@@ -944,7 +1000,7 @@ ipmi_lan_set_password(struct ipmi_intf *intf,
*/
ipmi_intf_session_set_password(intf, (char *)password);
printf("Password %s for user %d\n",
- (password == NULL) ? "cleared" : "set", user_id);
+ password ? "set" : "cleared", user_id);
return 0;
}
@@ -1103,7 +1159,7 @@ ipmi_set_user_access(struct ipmi_intf *intf, uint8_t channel, uint8_t user_id)
static int
-get_cmdline_cipher_suite_priv_data(char * arg, uint8_t * buf)
+get_cmdline_cipher_suite_priv_data(char *arg, uint8_t *buf)
{
int i, ret = 0;
@@ -1180,7 +1236,7 @@ get_cmdline_cipher_suite_priv_data(char * arg, uint8_t * buf)
static int
-get_cmdline_ipaddr(char * arg, uint8_t * buf)
+get_cmdline_ipaddr(char *arg, uint8_t *buf)
{
uint32_t ip1, ip2, ip3, ip4;
if (sscanf(arg,
@@ -1206,18 +1262,27 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string)
{
struct lan_param *p;
uint8_t data[2];
- int rc;
+ int rc = -1;
- if (string == NULL) {
+ if (!string) { /* request to disable VLAN */
lprintf(LOG_DEBUG, "Get current VLAN ID from BMC.");
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID);
- if (p != NULL && p->data != NULL && p->data_len > 1) {
+ if (p && p->data && p->data_len > 1) {
int id = ((p->data[1] & 0x0f) << 8) + p->data[0];
- if (id < 1 || id > 4094) {
+ if (IPMI_LANP_VLAN_DISABLE == id) {
+ printf("VLAN is already disabled for channel %"
+ PRIu8 "\n", chan);
+ rc = 0;
+ goto out;
+ }
+ if (!IPMI_LANP_IS_VLAN_VALID(id)) {
lprintf(LOG_ERR,
- "Retrieved VLAN ID %i is out of range <1..4094>.",
- id);
- return (-1);
+ "Retrieved VLAN ID %i is out of "
+ "range <%d..%d>.",
+ id,
+ IPMI_LANP_VLAN_ID_MIN,
+ IPMI_LANP_VLAN_ID_MAX);
+ goto out;
}
data[0] = p->data[0];
data[1] = p->data[1] & 0x0F;
@@ -1229,13 +1294,18 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string)
else {
int id = 0;
if (str2int(string, &id) != 0) {
- lprintf(LOG_ERR, "Given VLAN ID '%s' is invalid.", string);
- return (-1);
+ lprintf(LOG_ERR,
+ "Given VLAN ID '%s' is invalid.",
+ string);
+ goto out;
}
- if (id < 1 || id > 4094) {
- lprintf(LOG_NOTICE, "VLAN ID must be between 1 and 4094.");
- return (-1);
+ if (!IPMI_LANP_IS_VLAN_VALID(id)) {
+ lprintf(LOG_NOTICE,
+ "VLAN ID must be between %d and %d.",
+ IPMI_LANP_VLAN_ID_MIN,
+ IPMI_LANP_VLAN_ID_MAX);
+ goto out;
}
else {
data[0] = (uint8_t)id;
@@ -1243,6 +1313,8 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string)
}
}
rc = set_lan_param(intf, chan, IPMI_LANP_VLAN_ID, data, 2);
+
+out:
return rc;
}
@@ -1270,8 +1342,8 @@ static void
print_lan_set_bad_pass_thresh_usage(void)
{
lprintf(LOG_NOTICE,
-"lan set <chanel> bad_pass_thresh <thresh_num> <1|0> <reset_interval> <lockout_interval>\n"
-" <thresh_num> Bad Pasword Threshold number.\n"
+"lan set <channel> bad_pass_thresh <thresh_num> <1|0> <reset_interval> <lockout_interval>\n"
+" <thresh_num> Bad Password Threshold number.\n"
" <1|0> 1 = generate a Session Audit sensor event.\n"
" 0 = do not generate an event.\n"
" <reset_interval> Attempt Count Reset Interval. In tens of seconds.\n"
@@ -1316,7 +1388,7 @@ get_cmdline_bad_pass_thresh(char *argv[], uint8_t *buf)
}
static int
-ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_lan_set(struct ipmi_intf *intf, int argc, char **argv)
{
uint8_t data[32];
uint8_t chan;
@@ -1327,8 +1399,9 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
- if (strncmp(argv[0], "help", 4) == 0 ||
- strncmp(argv[1], "help", 4) == 0) {
+ if (!strcmp(argv[0], "help")
+ || !strcmp(argv[1], "help"))
+ {
print_lan_set_usage();
return 0;
}
@@ -1348,23 +1421,23 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
memset(&data, 0, sizeof(data));
/* set user access */
- if (strncmp(argv[1], "user", 4) == 0) {
+ if (!strcmp(argv[1], "user")) {
rc = ipmi_set_user_access(intf, chan, 1);
}
/* set channel access mode */
- else if (strncmp(argv[1], "access", 6) == 0) {
+ else if (!strcmp(argv[1], "access")) {
if (argc < 3) {
print_lan_set_access_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_access_usage();
return 0;
}
- else if (strncmp(argv[2], "on", 2) == 0) {
+ else if (!strcmp(argv[2], "on")) {
rc = ipmi_set_channel_access(intf, chan, 1);
}
- else if (strncmp(argv[2], "off", 3) == 0) {
+ else if (!strcmp(argv[2], "off")) {
rc = ipmi_set_channel_access(intf, chan, 0);
}
else {
@@ -1373,15 +1446,15 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* set ARP control */
- else if (strncmp(argv[1], "arp", 3) == 0) {
+ else if (!strcmp(argv[1], "arp")) {
if (argc < 3) {
print_lan_set_arp_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_arp_usage();
}
- else if (strncmp(argv[2], "interval", 8) == 0) {
+ else if (!strcmp(argv[2], "interval")) {
uint8_t interval = 0;
if (str2uchar(argv[3], &interval) != 0) {
lprintf(LOG_ERR, "Given ARP interval '%s' is invalid.", argv[3]);
@@ -1389,28 +1462,28 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
rc = lan_set_arp_interval(intf, chan, interval);
}
- else if (strncmp(argv[2], "generate", 8) == 0) {
+ else if (!strcmp(argv[2], "generate")) {
if (argc < 4) {
print_lan_set_arp_usage();
return (-1);
}
- else if (strncmp(argv[3], "on", 2) == 0)
+ else if (!strcmp(argv[3], "on"))
rc = lan_set_arp_generate(intf, chan, 1);
- else if (strncmp(argv[3], "off", 3) == 0)
+ else if (!strcmp(argv[3], "off"))
rc = lan_set_arp_generate(intf, chan, 0);
else {
print_lan_set_arp_usage();
return (-1);
}
}
- else if (strncmp(argv[2], "respond", 7) == 0) {
+ else if (!strcmp(argv[2], "respond")) {
if (argc < 4) {
print_lan_set_arp_usage();
return (-1);
}
- else if (strncmp(argv[3], "on", 2) == 0)
+ else if (!strcmp(argv[3], "on"))
rc = lan_set_arp_respond(intf, chan, 1);
- else if (strncmp(argv[3], "off", 3) == 0)
+ else if (!strcmp(argv[3], "off"))
rc = lan_set_arp_respond(intf, chan, 0);
else {
print_lan_set_arp_usage();
@@ -1422,12 +1495,12 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* set authentication types */
- else if (strncmp(argv[1], "auth", 4) == 0) {
+ else if (!strcmp(argv[1], "auth")) {
if (argc < 3) {
print_lan_set_auth_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_auth_usage();
return 0;
} else {
@@ -1435,22 +1508,22 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* ip address source */
- else if (strncmp(argv[1], "ipsrc", 5) == 0) {
+ else if (!strcmp(argv[1], "ipsrc")) {
if (argc < 3) {
print_lan_set_ipsrc_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_ipsrc_usage();
return 0;
}
- else if (strncmp(argv[2], "none", 4) == 0)
+ else if (!strcmp(argv[2], "none"))
data[0] = 0;
- else if (strncmp(argv[2], "static", 5) == 0)
+ else if (!strcmp(argv[2], "static"))
data[0] = 1;
- else if (strncmp(argv[2], "dhcp", 4) == 0)
+ else if (!strcmp(argv[2], "dhcp"))
data[0] = 2;
- else if (strncmp(argv[2], "bios", 4) == 0)
+ else if (!strcmp(argv[2], "bios"))
data[0] = 3;
else {
print_lan_set_ipsrc_usage();
@@ -1460,16 +1533,16 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
/* session password
* not strictly a lan setting, but its used for lan connections */
- else if (strncmp(argv[1], "password", 8) == 0) {
+ else if (!strcmp(argv[1], "password")) {
rc = ipmi_lan_set_password(intf, 1, argv[2]);
}
/* snmp community string */
- else if (strncmp(argv[1], "snmp", 4) == 0) {
+ else if (!strcmp(argv[1], "snmp")) {
if (argc < 3) {
print_lan_set_snmp_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_snmp_usage();
return 0;
} else {
@@ -1480,7 +1553,7 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* ip address */
- else if (strncmp(argv[1], "ipaddr", 6) == 0) {
+ else if (!strcmp(argv[1], "ipaddr")) {
if(argc != 3)
{
print_lan_set_usage();
@@ -1495,7 +1568,7 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* network mask */
- else if (strncmp(argv[1], "netmask", 7) == 0) {
+ else if (!strcmp(argv[1], "netmask")) {
if(argc != 3)
{
print_lan_set_usage();
@@ -1510,7 +1583,7 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* mac address */
- else if (strncmp(argv[1], "macaddr", 7) == 0) {
+ else if (!strcmp(argv[1], "macaddr")) {
if(argc != 3)
{
print_lan_set_usage();
@@ -1525,24 +1598,26 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* default gateway settings */
- else if (strncmp(argv[1], "defgw", 5) == 0) {
+ else if (!strcmp(argv[1], "defgw")) {
if (argc < 4) {
print_lan_set_defgw_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_defgw_usage();
return 0;
}
- else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
- (get_cmdline_ipaddr(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "ipaddr")
+ && !get_cmdline_ipaddr(argv[3], data))
+ {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_IP].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP, data, 4);
}
- else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
- (str2mac(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "macaddr")
+ && !str2mac(argv[3], data))
+ {
printf("Setting LAN %s to %s\n",
ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_MAC].desc,
mac2str(data));
@@ -1554,24 +1629,25 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* backup gateway settings */
- else if (strncmp(argv[1], "bakgw", 5) == 0) {
+ else if (!strcmp(argv[1], "bakgw")) {
if (argc < 4) {
print_lan_set_bakgw_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_bakgw_usage();
return 0;
}
- else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
- (get_cmdline_ipaddr(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "ipaddr")
+ && !get_cmdline_ipaddr(argv[3], data))
+ {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_IP].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP, data, 4);
}
- else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
- (str2mac(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "macaddr")
+ && !str2mac(argv[3], data)) {
printf("Setting LAN %s to %s\n",
ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_MAC].desc,
mac2str(data));
@@ -1582,24 +1658,24 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
}
- else if (strncasecmp(argv[1], "vlan", 4) == 0) {
+ else if (!strcmp(argv[1], "vlan")) {
if (argc < 4) {
print_lan_set_vlan_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_vlan_usage();
return 0;
}
- else if (strncasecmp(argv[2], "id", 2) == 0) {
- if (strncasecmp(argv[3], "off", 3) == 0) {
+ else if (!strcmp(argv[2], "id")) {
+ if (!strcmp(argv[3], "off")) {
ipmi_lan_set_vlan_id(intf, chan, NULL);
}
else {
ipmi_lan_set_vlan_id(intf, chan, argv[3]);
}
}
- else if (strncasecmp(argv[2], "priority", 8) == 0) {
+ else if (!strcmp(argv[2], "priority")) {
ipmi_lan_set_vlan_priority(intf, chan, argv[3]);
}
else {
@@ -1608,18 +1684,18 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* set PEF alerting on or off */
- else if (strncasecmp(argv[1], "alert", 5) == 0) {
+ else if (!strcmp(argv[1], "alert")) {
if (argc < 3) {
lprintf(LOG_NOTICE, "LAN set alert must be 'on' or 'off'");
return (-1);
}
- else if (strncasecmp(argv[2], "on", 2) == 0 ||
- strncasecmp(argv[2], "enable", 6) == 0) {
+ else if (!strcmp(argv[2], "on") ||
+ !strcmp(argv[2], "enable")) {
printf("Enabling PEF alerts for LAN channel %d\n", chan);
rc = ipmi_set_alert_enable(intf, chan, 1);
}
- else if (strncasecmp(argv[2], "off", 3) == 0 ||
- strncasecmp(argv[2], "disable", 7) == 0) {
+ else if (!strcmp(argv[2], "off") ||
+ !strcmp(argv[2], "disable")) {
printf("Disabling PEF alerts for LAN channel %d\n", chan);
rc = ipmi_set_alert_enable(intf, chan, 0);
}
@@ -1629,14 +1705,14 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* RMCP+ cipher suite privilege levels */
- else if (strncmp(argv[1], "cipher_privs", 12) == 0)
+ else if (!strcmp(argv[1], "cipher_privs"))
{
if (argc != 3) {
print_lan_set_cipher_privs_usage();
return (-1);
}
- else if ((strncmp(argv[2], "help", 4) == 0) ||
- get_cmdline_cipher_suite_priv_data(argv[2], data))
+ else if (!strcmp(argv[2], "help")
+ || get_cmdline_cipher_suite_priv_data(argv[2], data))
{
print_lan_set_cipher_privs_usage();
return 0;
@@ -1646,9 +1722,9 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
rc = set_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS, data, 9);
}
}
- else if (strncmp(argv[1], "bad_pass_thresh", 15) == 0)
+ else if (!strcmp(argv[1], "bad_pass_thresh"))
{
- if (argc == 3 && strncmp(argv[2], "help", 4) == 0) {
+ if (argc == 3 && !strcmp(argv[2], "help")) {
print_lan_set_bad_pass_thresh_usage();
return 0;
}
@@ -1668,14 +1744,14 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
static int
-is_alert_destination(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
+is_alert_destination(struct ipmi_intf *intf, uint8_t channel, uint8_t alert)
{
- struct lan_param * p;
+ struct lan_param *p;
p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
- if (p == NULL)
+ if (!p)
return 0;
- if (p->data == NULL)
+ if (!p->data)
return 0;
if (alert <= (p->data[0] & 0xf))
@@ -1685,7 +1761,7 @@ is_alert_destination(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
}
static int
-ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
+ipmi_lan_alert_print(struct ipmi_intf *intf, uint8_t channel, uint8_t alert)
{
# define PTYPE_LEN 4
# define PADDR_LEN 13
@@ -1695,15 +1771,14 @@ ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
uint8_t paddr[PADDR_LEN];
lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_TYPE, alert);
- if (lp_ptr == NULL || lp_ptr->data == NULL
+ if (!lp_ptr || !lp_ptr->data
|| lp_ptr->data_len < PTYPE_LEN) {
return (-1);
}
memcpy(ptype, lp_ptr->data, PTYPE_LEN);
lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_ADDR, alert);
- if (lp_ptr == NULL || lp_ptr->data == NULL
- || lp_ptr->data_len < PADDR_LEN) {
+ if (!lp_ptr || !lp_ptr->data || lp_ptr->data_len < PADDR_LEN) {
return (-1);
}
memcpy(paddr, lp_ptr->data, PADDR_LEN);
@@ -1760,15 +1835,15 @@ ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
}
static int
-ipmi_lan_alert_print_all(struct ipmi_intf * intf, uint8_t channel)
+ipmi_lan_alert_print_all(struct ipmi_intf *intf, uint8_t channel)
{
int j, ndest;
- struct lan_param * p;
+ struct lan_param *p;
p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data == NULL)
+ if (!p->data)
return -1;
ndest = p->data[0] & 0xf;
@@ -1780,10 +1855,10 @@ ipmi_lan_alert_print_all(struct ipmi_intf * intf, uint8_t channel)
}
static int
-ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
- int argc, char ** argv)
+ipmi_lan_alert_set(struct ipmi_intf *intf, uint8_t chan, uint8_t alert,
+ int argc, char **argv)
{
- struct lan_param * p;
+ struct lan_param *p;
uint8_t data[32], temp[32];
int rc = 0;
@@ -1792,8 +1867,9 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
return (-1);
}
- if (strncmp(argv[0], "help", 4) == 0 ||
- strncmp(argv[1], "help", 4) == 0) {
+ if (!strcmp(argv[0], "help")
+ || !strcmp(argv[1], "help"))
+ {
print_lan_alert_set_usage();
return 0;
}
@@ -1802,14 +1878,14 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
memset(temp, 0, sizeof(temp));
/* alert destination ip address */
- if (strncasecmp(argv[0], "ipaddr", 6) == 0 &&
+ if (strcasecmp(argv[0], "ipaddr") == 0 &&
(get_cmdline_ipaddr(argv[1], temp) == 0)) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
- memcpy(data, p->data, p->data_len);
+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
/* set new ipaddr */
memcpy(data+3, temp, 4);
printf("Setting LAN Alert %d IP Address to %d.%d.%d.%d\n", alert,
@@ -1817,14 +1893,14 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert destination mac address */
- else if (strncasecmp(argv[0], "macaddr", 7) == 0 &&
+ else if (strcasecmp(argv[0], "macaddr") == 0 &&
(str2mac(argv[1], temp) == 0)) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
- memcpy(data, p->data, p->data_len);
+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
/* set new macaddr */
memcpy(data+7, temp, 6);
printf("Setting LAN Alert %d MAC Address to "
@@ -1832,21 +1908,21 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert destination gateway selector */
- else if (strncasecmp(argv[0], "gateway", 7) == 0) {
+ else if (strcasecmp(argv[0], "gateway") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
- memcpy(data, p->data, p->data_len);
+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
- if (strncasecmp(argv[1], "def", 3) == 0 ||
- strncasecmp(argv[1], "default", 7) == 0) {
+ if (strcasecmp(argv[1], "def") == 0 ||
+ strcasecmp(argv[1], "default") == 0) {
printf("Setting LAN Alert %d to use Default Gateway\n", alert);
data[2] = 0;
}
- else if (strncasecmp(argv[1], "bak", 3) == 0 ||
- strncasecmp(argv[1], "backup", 6) == 0) {
+ else if (strcasecmp(argv[1], "bak") == 0 ||
+ strcasecmp(argv[1], "backup") == 0) {
printf("Setting LAN Alert %d to use Backup Gateway\n", alert);
data[2] = 1;
}
@@ -1858,21 +1934,21 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert acknowledgement */
- else if (strncasecmp(argv[0], "ack", 3) == 0) {
+ else if (strcasecmp(argv[0], "ack") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
- memcpy(data, p->data, p->data_len);
+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
- if (strncasecmp(argv[1], "on", 2) == 0 ||
- strncasecmp(argv[1], "yes", 3) == 0) {
+ if (strcasecmp(argv[1], "on") == 0 ||
+ strcasecmp(argv[1], "yes") == 0) {
printf("Setting LAN Alert %d to Acknowledged\n", alert);
data[1] |= 0x80;
}
- else if (strncasecmp(argv[1], "off", 3) == 0 ||
- strncasecmp(argv[1], "no", 2) == 0) {
+ else if (strcasecmp(argv[1], "off") == 0 ||
+ strcasecmp(argv[1], "no") == 0) {
printf("Setting LAN Alert %d to Unacknowledged\n", alert);
data[1] &= ~0x80;
}
@@ -1883,24 +1959,24 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* alert destination type */
- else if (strncasecmp(argv[0], "type", 4) == 0) {
+ else if (strcasecmp(argv[0], "type") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
- memcpy(data, p->data, p->data_len);
+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
- if (strncasecmp(argv[1], "pet", 3) == 0) {
+ if (strcasecmp(argv[1], "pet") == 0) {
printf("Setting LAN Alert %d destination to PET Trap\n", alert);
data[1] &= ~0x07;
}
- else if (strncasecmp(argv[1], "oem1", 4) == 0) {
+ else if (strcasecmp(argv[1], "oem1") == 0) {
printf("Setting LAN Alert %d destination to OEM 1\n", alert);
data[1] &= ~0x07;
data[1] |= 0x06;
}
- else if (strncasecmp(argv[1], "oem2", 4) == 0) {
+ else if (strcasecmp(argv[1], "oem2") == 0) {
printf("Setting LAN Alert %d destination to OEM 2\n", alert);
data[1] |= 0x07;
}
@@ -1911,13 +1987,13 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* alert acknowledge timeout or retry interval */
- else if (strncasecmp(argv[0], "time", 4) == 0) {
+ else if (strcasecmp(argv[0], "time") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
- memcpy(data, p->data, p->data_len);
+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
if (str2uchar(argv[1], &data[2]) != 0) {
lprintf(LOG_ERR, "Invalid time: %s", argv[1]);
@@ -1927,13 +2003,13 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* number of retries */
- else if (strncasecmp(argv[0], "retry", 5) == 0) {
+ else if (strcasecmp(argv[0], "retry") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
- memcpy(data, p->data, p->data_len);
+ memcpy(data, p->data, __min(p->data_len, sizeof(data)));
if (str2uchar(argv[1], &data[3]) != 0) {
lprintf(LOG_ERR, "Invalid retry: %s", argv[1]);
@@ -1952,7 +2028,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
}
static int
-ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_lan_alert(struct ipmi_intf *intf, int argc, char **argv)
{
uint8_t alert;
uint8_t channel = 1;
@@ -1962,14 +2038,14 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
print_lan_alert_set_usage();
return (-1);
}
- else if (strncasecmp(argv[0], "help", 4) == 0) {
+ else if (strcasecmp(argv[0], "help") == 0) {
print_lan_alert_print_usage();
print_lan_alert_set_usage();
return 0;
}
/* alert print [channel] [alert] */
- if (strncasecmp(argv[0], "print", 5) == 0) {
+ if (strcasecmp(argv[0], "print") == 0) {
if (argc < 2) {
channel = find_lan_channel(intf, 1);
if (!is_lan_channel(intf, channel)) {
@@ -1979,7 +2055,7 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
return ipmi_lan_alert_print_all(intf, channel);
}
- if (strncasecmp(argv[1], "help", 4) == 0) {
+ if (strcasecmp(argv[1], "help") == 0) {
print_lan_alert_print_usage();
return 0;
}
@@ -2008,12 +2084,12 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
}
/* alert set <channel> <alert> [option] */
- if (strncasecmp(argv[0], "set", 3) == 0) {
+ if (strcasecmp(argv[0], "set") == 0) {
if (argc < 5) {
print_lan_alert_set_usage();
return (-1);
}
- else if (strncasecmp(argv[1], "help", 4) == 0) {
+ else if (strcasecmp(argv[1], "help") == 0) {
print_lan_alert_set_usage();
return 0;
}
@@ -2044,10 +2120,10 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
static int
-ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lan_stats_get(struct ipmi_intf *intf, uint8_t chan)
{
int rc = 0;
- struct ipmi_rs * rsp;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
uint8_t msg_data[2];
uint16_t statsTemp;
@@ -2069,14 +2145,16 @@ ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get LAN Stats command failed");
return (-1);
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get LAN Stats command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ specific_val2str(rsp->ccode,
+ get_lan_cc_vals,
+ completion_code_vals));
return (-1);
}
@@ -2122,10 +2200,10 @@ ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
static int
-ipmi_lan_stats_clear(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lan_stats_clear(struct ipmi_intf *intf, uint8_t chan)
{
int rc = 0;
- struct ipmi_rs * rsp;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
uint8_t msg_data[2];
@@ -2145,14 +2223,16 @@ ipmi_lan_stats_clear(struct ipmi_intf * intf, uint8_t chan)
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_INFO, "Get LAN Stats command failed");
return (-1);
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_INFO, "Get LAN Stats command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ specific_val2str(rsp->ccode,
+ get_lan_cc_vals,
+ completion_code_vals));
return (-1);
}
@@ -2412,7 +2492,7 @@ print_lan_usage(void)
int
-ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_lanp_main(struct ipmi_intf *intf, int argc, char **argv)
{
int rc = 0;
uint8_t chan = 0;
@@ -2420,13 +2500,13 @@ ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
if (argc == 0) {
print_lan_usage();
return (-1);
- } else if (strncmp(argv[0], "help", 4) == 0) {
+ } else if (!strcmp(argv[0], "help")) {
print_lan_usage();
return 0;
}
- if (strncmp(argv[0], "printconf", 9) == 0 ||
- strncmp(argv[0], "print", 5) == 0)
+ if (!strcmp(argv[0], "printconf")
+ || !strcmp(argv[0], "print"))
{
if (argc > 2) {
print_lan_usage();
@@ -2444,11 +2524,11 @@ ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
rc = ipmi_lan_print(intf, chan);
- } else if (strncmp(argv[0], "set", 3) == 0) {
+ } else if (!strcmp(argv[0], "set")) {
rc = ipmi_lan_set(intf, argc-1, &(argv[1]));
- } else if (strncmp(argv[0], "alert", 5) == 0) {
+ } else if (!strcmp(argv[0], "alert")) {
rc = ipmi_lan_alert(intf, argc-1, &(argv[1]));
- } else if (strncmp(argv[0], "stats", 5) == 0) {
+ } else if (!strcmp(argv[0], "stats")) {
if (argc < 2) {
print_lan_usage();
return (-1);
@@ -2464,9 +2544,9 @@ ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_ERR, "Invalid channel: %d", chan);
return (-1);
}
- if (strncmp(argv[1], "get", 3) == 0) {
+ if (!strcmp(argv[1], "get")) {
rc = ipmi_lan_stats_get(intf, chan);
- } else if (strncmp(argv[1], "clear", 5) == 0) {
+ } else if (!strcmp(argv[1], "clear")) {
rc = ipmi_lan_stats_clear(intf, chan);
} else {
print_lan_usage();
diff --git a/lib/ipmi_lanp6.c b/lib/ipmi_lanp6.c
index bbffb89..4af6d8b 100644
--- a/lib/ipmi_lanp6.c
+++ b/lib/ipmi_lanp6.c
@@ -333,7 +333,7 @@ ipmi_lanp_err(const struct ipmi_rs *rsp, const struct ipmi_lanp *p,
int log_level = LOG_ERR;
int err;
- if (rsp == NULL) {
+ if (!rsp) {
reason = "No response";
err = -1;
} else {
@@ -354,7 +354,7 @@ ipmi_lanp_err(const struct ipmi_rs *rsp, const struct ipmi_lanp *p,
reason = val2str(rsp->ccode, lanp_cc_vals);
}
- if (reason == NULL) {
+ if (!reason) {
/* print completion code value */
snprintf(cc_msg, sizeof(cc_msg), "CC=%02x", rsp->ccode);
reason = cc_msg;
@@ -403,7 +403,7 @@ ipmi_get_dynamic_oem_lanp(void *priv, const struct ipmi_lanp *param,
param->name, set_selector, block_selector);
rsp = lp->intf->sendrecv(lp->intf, &req);
- if (rsp == NULL || rsp->ccode) {
+ if (!rsp || rsp->ccode) {
return ipmi_lanp_err(rsp, param, "get", quiet);
}
@@ -467,7 +467,7 @@ ipmi_set_dynamic_oem_lanp(void *priv, const struct ipmi_lanp *param,
lprintf(LOG_INFO, "Setting parameter '%s'", param->name);
rsp = lp->intf->sendrecv(lp->intf, &req);
- if (rsp == NULL || rsp->ccode) {
+ if (!rsp || rsp->ccode) {
return ipmi_lanp_err(rsp, param, "set", 0);
}
@@ -1027,9 +1027,7 @@ static void lanp_print_usage(int cmd)
printf("\n available parameters:\n");
/* 'save' shall use 'write' filter, since it outputs a block
* of 'set's */
- ipmi_cfgp_usage(lan_cfgp,
- sizeof(lan_cfgp)/sizeof(lan_cfgp[0]),
- cmd != LANP_CMD_PRINT);
+ ipmi_cfgp_usage(lan_cfgp, ARRAY_SIZE(lan_cfgp), cmd != LANP_CMD_PRINT);
}
}
@@ -1161,8 +1159,8 @@ ipmi_lan6_main(struct ipmi_intf *intf, int argc, char **argv)
*/
ipmi_cfgp_init(&ctx, lan_cfgp,
- sizeof(lan_cfgp)/sizeof(lan_cfgp[0]), "lan6 set nolock",
- lanp_ip6_cfgp, &lp);
+ ARRAY_SIZE(lan_cfgp), "lan6 set nolock",
+ lanp_ip6_cfgp, &lp);
ret = ipmi_cfgp_parse_sel(&ctx, argc, (const char **)argv, &sel);
if (ret == -1) {
diff --git a/lib/ipmi_main.c b/lib/ipmi_main.c
index 811c80b..a673a30 100644
--- a/lib/ipmi_main.c
+++ b/lib/ipmi_main.c
@@ -29,11 +29,6 @@
* 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 _XOPEN_SOURCE 700
-#define _BSD_SOURCE || \
- (_XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
- !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
#include <stdlib.h>
#include <stdio.h>
@@ -47,6 +42,7 @@
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
+#include <locale.h>
#include <ipmitool/helper.h>
#include <ipmitool/log.h>
@@ -70,18 +66,20 @@
#include <ipmitool/ipmi_user.h>
#include <ipmitool/ipmi_raw.h>
#include <ipmitool/ipmi_pef.h>
+#include <ipmitool/ipmi_time.h>
#include <ipmitool/ipmi_oem.h>
#include <ipmitool/ipmi_ekanalyzer.h>
#include <ipmitool/ipmi_picmg.h>
#include <ipmitool/ipmi_kontronoem.h>
#include <ipmitool/ipmi_vita.h>
+#include <ipmitool/ipmi_quantaoem.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef ENABLE_ALL_OPTIONS
-# define OPTION_STRING "I:46hVvcgsEKYao:H:d:P:f:U:p:C:L:A:t:T:m:z:S:l:b:B:e:k:y:O:R:N:D:"
+# define OPTION_STRING "I:46hVvcgsEKYao:H:d:P:f:U:p:C:L:A:t:T:m:z:S:l:b:B:e:k:y:O:R:N:D:Z"
#else
# define OPTION_STRING "I:46hVvcH:f:U:p:d:S:D:"
#endif
@@ -90,8 +88,6 @@
void
ipmi_intf_set_max_request_data_size(struct ipmi_intf * intf, uint16_t size);
-extern int verbose;
-extern int csv_output;
extern const struct valstr ipmi_privlvl_vals[];
extern const struct valstr ipmi_authtype_session_vals[];
@@ -113,14 +109,14 @@ ipmi_password_file_read(char * filename)
int l;
pass = malloc(21);
- if (pass == NULL) {
+ if (!pass) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(pass, 0, 21);
fp = ipmi_open_file_read((const char *)filename);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Unable to open password file %s",
filename);
free(pass);
@@ -128,7 +124,7 @@ ipmi_password_file_read(char * filename)
}
/* read in id */
- if (fgets(pass, 21, fp) == NULL) {
+ if (!fgets(pass, 21, fp)) {
lprintf(LOG_ERR, "Unable to read password from file %s",
filename);
free(pass);
@@ -157,10 +153,10 @@ ipmi_cmd_print(struct ipmi_cmd * cmdlist)
struct ipmi_cmd * cmd;
int hdr = 0;
- if (cmdlist == NULL)
+ if (!cmdlist)
return;
- for (cmd=cmdlist; cmd->func != NULL; cmd++) {
- if (cmd->desc == NULL)
+ for (cmd=cmdlist; cmd->func; cmd++) {
+ if (!cmd->desc)
continue;
if (hdr == 0) {
lprintf(LOG_NOTICE, "Commands:");
@@ -182,7 +178,7 @@ ipmi_cmd_print(struct ipmi_cmd * cmdlist)
* @argc: command argument count
* @argv: command argument list
*
- * returns value from func() of that commnad if found
+ * returns value from func() of that command if found
* returns -1 if command is not found
*/
int
@@ -191,25 +187,25 @@ ipmi_cmd_run(struct ipmi_intf * intf, char * name, int argc, char ** argv)
struct ipmi_cmd * cmd = intf->cmdlist;
/* hook to run a default command if nothing specified */
- if (name == NULL) {
- if (cmd->func == NULL || cmd->name == NULL)
+ if (!name) {
+ if (!cmd->func || !cmd->name)
return -1;
- else if (strncmp(cmd->name, "default", 7) == 0)
+
+ if (!strcmp(cmd->name, "default"))
return cmd->func(intf, 0, NULL);
- else {
- lprintf(LOG_ERR, "No command provided!");
- ipmi_cmd_print(intf->cmdlist);
- return -1;
- }
+
+ lprintf(LOG_ERR, "No command provided!");
+ ipmi_cmd_print(intf->cmdlist);
+ return -1;
}
- for (cmd=intf->cmdlist; cmd->func != NULL; cmd++) {
- if (strncmp(name, cmd->name, __maxlen(cmd->name, name)) == 0)
+ for (cmd=intf->cmdlist; cmd->func; cmd++) {
+ if (!strcmp(name, cmd->name))
break;
}
- if (cmd->func == NULL) {
+ if (!cmd->func) {
cmd = intf->cmdlist;
- if (strncmp(cmd->name, "default", 7) == 0)
+ if (!strcmp(cmd->name, "default"))
return cmd->func(intf, argc+1, argv-1);
lprintf(LOG_ERR, "Invalid command: %s", name);
@@ -263,12 +259,13 @@ ipmi_option_usage(const char * progname, struct ipmi_cmd * cmdlist, struct ipmi_
lprintf(LOG_NOTICE, " -O seloem Use file for OEM SEL event descriptions");
lprintf(LOG_NOTICE, " -N seconds Specify timeout for lan [default=2] / lanplus [default=1] interface");
lprintf(LOG_NOTICE, " -R retry Set the number of retries for lan/lanplus interface [default=4]");
+ lprintf(LOG_NOTICE, " -Z Display all dates in UTC");
#endif
lprintf(LOG_NOTICE, "");
ipmi_intf_print(intflist);
- if (cmdlist != NULL)
+ if (cmdlist)
ipmi_cmd_print(cmdlist);
}
/* ipmi_catch_sigint - Handle the interrupt signal (Ctrl-C), close the
@@ -281,7 +278,7 @@ ipmi_option_usage(const char * progname, struct ipmi_cmd * cmdlist, struct ipmi_
*/
void ipmi_catch_sigint()
{
- if (ipmi_main_intf != NULL) {
+ if (ipmi_main_intf) {
printf("\nSIGN INT: Close Interface %s\n",ipmi_main_intf->desc);
/* reduce retry count to a single retry */
ipmi_main_intf->ssn_params.retry = 1;
@@ -323,6 +320,7 @@ ipmi_main(int argc, char ** argv,
uint8_t target_addr = 0;
uint8_t target_channel = 0;
+ uint8_t u8tmp = 0;
uint8_t transit_addr = 0;
uint8_t transit_channel = 0;
uint8_t target_lun = 0;
@@ -347,19 +345,29 @@ ipmi_main(int argc, char ** argv,
char * seloem = NULL;
int port = 0;
int devnum = 0;
- int cipher_suite_id = 3; /* See table 22-19 of the IPMIv2 spec */
+#ifdef IPMI_INTF_LANPLUS
+ /* lookup best cipher suite available */
+ enum cipher_suite_ids cipher_suite_id = IPMI_LANPLUS_CIPHER_SUITE_RESERVED;
+#endif /* IPMI_INTF_LANPLUS */
int argflag, i, found;
int rc = -1;
int ai_family = AF_UNSPEC;
char sol_escape_char = SOL_ESCAPE_CHARACTER_DEFAULT;
char * devfile = NULL;
+ /* Set program locale according to system settings */
+ setlocale(LC_ALL, "");
+
+
/* save program name */
progname = strrchr(argv[0], '/');
- progname = ((progname == NULL) ? argv[0] : progname+1);
+ progname = ((!progname) ? argv[0] : progname+1);
signal(SIGINT, ipmi_catch_sigint);
memset(kgkey, 0, sizeof(kgkey));
+ /* setup log */
+ log_init(progname, 0, 0);
+
while ((argflag = getopt(argc, (char **)argv, OPTION_STRING)) != -1)
{
switch (argflag) {
@@ -369,17 +377,18 @@ ipmi_main(int argc, char ** argv,
intfname = NULL;
}
intfname = strdup(optarg);
- if (intfname == NULL) {
+ if (!intfname) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
- if (intflist != NULL) {
+ if (intflist) {
found = 0;
- for (sup=intflist; sup->name != NULL; sup++) {
- if (strncmp(sup->name, intfname, strlen(intfname)) == 0 &&
- strncmp(sup->name, intfname, strlen(sup->name)) == 0 &&
- sup->supported == 1)
+ for (sup=intflist; sup->name; sup++) {
+ if (!strcmp(sup->name, intfname)
+ && sup->supported)
+ {
found = 1;
+ }
}
if (!found) {
lprintf(LOG_ERR, "Interface %s not supported", intfname);
@@ -425,21 +434,24 @@ ipmi_main(int argc, char ** argv,
goto out_free;
}
break;
+#ifdef IPMI_INTF_LANPLUS
case 'C':
- if (str2int(optarg, &cipher_suite_id) != 0) {
- lprintf(LOG_ERR, "Invalid parameter given or out of range for '-C'.");
- rc = -1;
- goto out_free;
- }
- /* add check Cipher is -gt 0 */
- if (cipher_suite_id < 0) {
- lprintf(LOG_ERR, "Cipher suite ID %i is invalid.", cipher_suite_id);
+ /* Cipher Suite ID is a byte as per IPMI specification */
+ if (str2uchar(optarg, &u8tmp) != 0) {
+ lprintf(LOG_ERR, "Invalid parameter given or out of "
+ "range [0-255] for '-C'.");
rc = -1;
goto out_free;
}
+ cipher_suite_id = u8tmp;
break;
+#endif /* IPMI_INTF_LANPLUS */
case 'v':
- verbose++;
+ log_level_set(++verbose);
+ if (verbose == 2) {
+ /* add version info to debug output */
+ lprintf(LOG_DEBUG, "%s version %s\n", progname, VERSION);
+ }
break;
case 'c':
csv_output = 1;
@@ -450,7 +462,7 @@ ipmi_main(int argc, char ** argv,
hostname = NULL;
}
hostname = strdup(optarg);
- if (hostname == NULL) {
+ if (!hostname) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -461,7 +473,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = ipmi_password_file_read(optarg);
- if (password == NULL)
+ if (!password)
lprintf(LOG_ERR, "Unable to read password "
"from file %s", optarg);
break;
@@ -471,14 +483,14 @@ ipmi_main(int argc, char ** argv,
#else
tmp_pass = getpass("Password: ");
#endif
- if (tmp_pass != NULL) {
+ if (tmp_pass) {
if (password) {
free(password);
password = NULL;
}
password = strdup(tmp_pass);
tmp_pass = NULL;
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -518,7 +530,7 @@ ipmi_main(int argc, char ** argv,
#else
tmp_pass = getpass("Key: ");
#endif
- if (tmp_pass != NULL) {
+ if (tmp_pass) {
memset(kgkey, 0, sizeof(kgkey));
strncpy((char *)kgkey, tmp_pass,
sizeof(kgkey) - 1);
@@ -535,7 +547,7 @@ ipmi_main(int argc, char ** argv,
goto out_free;
}
username = strdup(optarg);
- if (username == NULL) {
+ if (!username) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -546,7 +558,7 @@ ipmi_main(int argc, char ** argv,
sdrcache = NULL;
}
sdrcache = strdup(optarg);
- if (sdrcache == NULL) {
+ if (!sdrcache) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -558,7 +570,7 @@ ipmi_main(int argc, char ** argv,
free(devfile);
}
devfile = strdup(optarg);
- if (devfile == NULL) {
+ if (!devfile) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -602,12 +614,13 @@ ipmi_main(int argc, char ** argv,
oemtype = NULL;
}
oemtype = strdup(optarg);
- if (oemtype == NULL) {
+ if (!oemtype) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
- if (strncmp(oemtype, "list", 4) == 0 ||
- strncmp(oemtype, "help", 4) == 0) {
+ if (!strcmp(oemtype, "list")
+ || !strcmp(oemtype, "help"))
+ {
ipmi_oem_print();
rc = 0;
goto out_free;
@@ -635,7 +648,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = strdup(optarg);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -651,7 +664,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = strdup(tmp_env);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -662,7 +675,7 @@ ipmi_main(int argc, char ** argv,
password = NULL;
}
password = strdup(tmp_env);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -736,7 +749,7 @@ ipmi_main(int argc, char ** argv,
seloem = NULL;
}
seloem = strdup(optarg);
- if (seloem == NULL) {
+ if (!seloem) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -763,6 +776,9 @@ ipmi_main(int argc, char ** argv,
goto out_free;
}
break;
+ case 'Z':
+ time_in_utc = 1;
+ break;
#endif
default:
ipmi_option_usage(progname, cmdlist, intflist);
@@ -771,8 +787,9 @@ ipmi_main(int argc, char ** argv,
}
/* check for command before doing anything */
- if (argc-optind > 0 &&
- strncmp(argv[optind], "help", 4) == 0) {
+ if (argc-optind > 0
+ && !strcmp(argv[optind], "help"))
+ {
ipmi_cmd_print(cmdlist);
rc = 0;
goto out_free;
@@ -786,17 +803,17 @@ ipmi_main(int argc, char ** argv,
* and the authtype was not explicitly set to NONE
* then prompt the user.
*/
- if (hostname != NULL && password == NULL &&
+ if (hostname && !password &&
(authtype != IPMI_SESSION_AUTHTYPE_NONE || authtype < 0)) {
#ifdef HAVE_GETPASSPHRASE
tmp_pass = getpassphrase("Password: ");
#else
tmp_pass = getpass("Password: ");
#endif
- if (tmp_pass != NULL) {
+ if (tmp_pass) {
password = strdup(tmp_pass);
tmp_pass = NULL;
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
@@ -808,49 +825,52 @@ ipmi_main(int argc, char ** argv,
* otherwise the default is hardcoded
* to use the first entry in the list
*/
- if (intfname == NULL && hostname != NULL) {
+ if (!intfname && hostname) {
intfname = strdup("lan");
- if (intfname == NULL) {
+ if (!intfname) {
lprintf(LOG_ERR, "%s: malloc failure", progname);
goto out_free;
}
}
- if (password != NULL && intfname != NULL) {
- if (strcmp(intfname, "lan") == 0 && strlen(password) > 16) {
+ if (password && intfname) {
+ if (!strcmp(intfname, "lan") && strlen(password) > 16) {
lprintf(LOG_ERR, "%s: password is longer than 16 bytes.", intfname);
rc = -1;
goto out_free;
- } else if (strcmp(intfname, "lanplus") == 0 && strlen(password) > 20) {
+ } else if (!strcmp(intfname, "lanplus") && strlen(password) > 20) {
lprintf(LOG_ERR, "%s: password is longer than 20 bytes.", intfname);
rc = -1;
goto out_free;
}
- } /* if (password != NULL && intfname != NULL) */
+ }
/* load interface */
ipmi_main_intf = ipmi_intf_load(intfname);
- if (ipmi_main_intf == NULL) {
+ if (!ipmi_main_intf) {
lprintf(LOG_ERR, "Error loading interface %s", intfname);
goto out_free;
}
- /* setup log */
- log_init(progname, 0, verbose);
+ /* load the IANA PEN registry */
+ if (ipmi_oem_info_init()) {
+ lprintf(LOG_ERR, "Failed to initialize the OEM info dictionary");
+ goto out_free;
+ }
/* run OEM setup if found */
- if (oemtype != NULL &&
+ if (oemtype &&
ipmi_oem_setup(ipmi_main_intf, oemtype) < 0) {
lprintf(LOG_ERR, "OEM setup for \"%s\" failed", oemtype);
goto out_free;
}
/* set session variables */
- if (hostname != NULL)
+ if (hostname)
ipmi_intf_session_set_hostname(ipmi_main_intf, hostname);
- if (username != NULL)
+ if (username)
ipmi_intf_session_set_username(ipmi_main_intf, username);
- if (password != NULL)
+ if (password)
ipmi_intf_session_set_password(ipmi_main_intf, password);
ipmi_intf_session_set_kgkey(ipmi_main_intf, kgkey);
if (port > 0)
@@ -870,7 +890,9 @@ ipmi_main(int argc, char ** argv,
ipmi_intf_session_set_lookupbit(ipmi_main_intf, lookupbit);
ipmi_intf_session_set_sol_escape_char(ipmi_main_intf, sol_escape_char);
+#ifdef IPMI_INTF_LANPLUS
ipmi_intf_session_set_cipher_suite_id(ipmi_main_intf, cipher_suite_id);
+#endif /* IPMI_INTF_LANPLUS */
ipmi_main_intf->devnum = devnum;
@@ -880,7 +902,7 @@ ipmi_main(int argc, char ** argv,
ipmi_main_intf->ai_family = ai_family;
/* Open the interface with the specified or default IPMB address */
ipmi_main_intf->my_addr = arg_addr ? arg_addr : IPMI_BMC_SLAVE_ADDR;
- if (ipmi_main_intf->open != NULL) {
+ if (ipmi_main_intf->open) {
if (ipmi_main_intf->open(ipmi_main_intf) < 0) {
goto out_free;
}
@@ -975,11 +997,11 @@ ipmi_main(int argc, char ** argv,
ipmi_main_intf->target_ipmb_addr);
/* parse local SDR cache if given */
- if (sdrcache != NULL) {
- ipmi_sdr_list_cache_fromfile(ipmi_main_intf, sdrcache);
+ if (sdrcache) {
+ ipmi_sdr_list_cache_fromfile(sdrcache);
}
/* Parse SEL OEM file if given */
- if (seloem != NULL) {
+ if (seloem) {
ipmi_sel_oem_init(seloem);
}
@@ -1016,37 +1038,37 @@ ipmi_main(int argc, char ** argv,
ipmi_cleanup(ipmi_main_intf);
/* call interface close function if available */
- if (ipmi_main_intf->opened > 0 && ipmi_main_intf->close != NULL)
+ if (ipmi_main_intf->opened && ipmi_main_intf->close)
ipmi_main_intf->close(ipmi_main_intf);
out_free:
log_halt();
- if (intfname != NULL) {
+ if (intfname) {
free(intfname);
intfname = NULL;
}
- if (hostname != NULL) {
+ if (hostname) {
free(hostname);
hostname = NULL;
}
- if (username != NULL) {
+ if (username) {
free(username);
username = NULL;
}
- if (password != NULL) {
+ if (password) {
free(password);
password = NULL;
}
- if (oemtype != NULL) {
+ if (oemtype) {
free(oemtype);
oemtype = NULL;
}
- if (seloem != NULL) {
+ if (seloem) {
free(seloem);
seloem = NULL;
}
- if (sdrcache != NULL) {
+ if (sdrcache) {
free(sdrcache);
sdrcache = NULL;
}
@@ -1055,6 +1077,8 @@ ipmi_main(int argc, char ** argv,
devfile = NULL;
}
+ ipmi_oem_info_free();
+
return rc;
}
diff --git a/lib/ipmi_mc.c b/lib/ipmi_mc.c
index 4580bfb..a594347 100644
--- a/lib/ipmi_mc.c
+++ b/lib/ipmi_mc.c
@@ -34,6 +34,10 @@
#include <string.h>
#include <stdio.h>
#include <time.h>
+#include <limits.h>
+#include <stdbool.h>
+
+#include <arpa/inet.h>
#include <ipmitool/helper.h>
#include <ipmitool/log.h>
@@ -42,6 +46,7 @@
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi_mc.h>
#include <ipmitool/ipmi_strings.h>
+#include <ipmitool/ipmi_time.h>
extern int verbose;
@@ -81,14 +86,14 @@ ipmi_mc_reset(struct ipmi_intf * intf, int cmd)
if (cmd == BMC_COLD_RESET)
intf->abort = 1;
- if (cmd == BMC_COLD_RESET && rsp == NULL) {
+ if (cmd == BMC_COLD_RESET && !rsp) {
/* This is expected. See 20.2 Cold Reset Command, p.243, IPMIv2.0 rev1.0 */
- } else if (rsp == NULL) {
+ } else if (!rsp) {
lprintf(LOG_ERR, "MC reset command failed.");
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "MC reset command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return (-1);
}
@@ -181,13 +186,13 @@ printf_mc_usage(void)
struct bitfield_data * bf;
lprintf(LOG_NOTICE, "MC Commands:");
lprintf(LOG_NOTICE, " reset <warm|cold>");
- lprintf(LOG_NOTICE, " guid");
+ lprintf(LOG_NOTICE, " guid [auto|smbios|ipmi|rfc4122|dump]");
lprintf(LOG_NOTICE, " info");
lprintf(LOG_NOTICE, " watchdog <get|reset|off>");
lprintf(LOG_NOTICE, " selftest");
lprintf(LOG_NOTICE, " getenables");
lprintf(LOG_NOTICE, " setenables <option=on|off> ...");
- for (bf = mc_enables_bf; bf->name != NULL; bf++) {
+ for (bf = mc_enables_bf; bf->name; bf++) {
lprintf(LOG_NOTICE, " %-20s %s", bf->name, bf->desc);
}
printf_sysinfo_usage(0);
@@ -230,15 +235,38 @@ printf_sysinfo_usage(int full_help)
static void
print_watchdog_usage(void)
{
- lprintf(LOG_NOTICE, "usage: watchdog <command>:");
- lprintf(LOG_NOTICE, " get : Get Current Watchdog settings");
- lprintf(LOG_NOTICE, " reset : Restart Watchdog timer based on most recent settings");
- lprintf(LOG_NOTICE, " off : Shut off a running Watchdog timer");
+ lprintf(LOG_NOTICE,
+"usage: watchdog <command>:\n"
+"\n"
+" set <option[=value]> [<option[=value]> ...]\n"
+" Set Watchdog settings\n"
+" Options: (* = mandatory)\n"
+" timeout=<1-6553> - [0] Initial countdown value, sec\n"
+" pretimeout=<1-255> - [0] Pre-timeout interval, sec\n"
+" int=<smi|nmi|msg> - [-] Pre-timeout interrupt type\n"
+" use=<frb2|post|osload|sms|oem> - [-] Timer use\n"
+" clear=<frb2|post|osload|sms|oem> - [-] Clear timer use expiration\n"
+" flag, can be specified\n"
+" multiple times\n"
+" action=<reset|poweroff|cycle|none> - [none] Timer action\n"
+" nolog - [-] Don't log the timer use\n"
+" dontstop - [-] Don't stop the timer\n"
+" while applying settings\n"
+"\n"
+" get\n"
+" Get Current settings\n"
+"\n"
+" reset\n"
+" Restart Watchdog timer based on the most recent settings\n"
+"\n"
+" off\n"
+" Shut off a running Watchdog timer"
+ );
}
/* ipmi_mc_get_enables - print out MC enables
*
- * @intf: ipmi inteface
+ * @intf: ipmi interface
*
* returns 0 on success
* returns -1 on error
@@ -255,17 +283,17 @@ ipmi_mc_get_enables(struct ipmi_intf * intf)
req.msg.cmd = BMC_GET_GLOBAL_ENABLES;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Global Enables command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Global Enables command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return -1;
}
- for (bf = mc_enables_bf; bf->name != NULL; bf++) {
+ for (bf = mc_enables_bf; bf->name; bf++) {
printf("%-40s : %sabled\n", bf->desc,
rsp->data[0] & bf->mask ? "en" : "dis");
}
@@ -275,7 +303,7 @@ ipmi_mc_get_enables(struct ipmi_intf * intf)
/* ipmi_mc_set_enables - set MC enable flags
*
- * @intf: ipmi inteface
+ * @intf: ipmi interface
* @argc: argument count
* @argv: argument list
*
@@ -295,7 +323,7 @@ ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
printf_mc_usage();
return (-1);
}
- else if (strncmp(argv[0], "help", 4) == 0) {
+ else if (!strcmp(argv[0], "help")) {
printf_mc_usage();
return 0;
}
@@ -305,28 +333,28 @@ ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
req.msg.cmd = BMC_GET_GLOBAL_ENABLES;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Global Enables command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Global Enables command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return -1;
}
en = rsp->data[0];
for (i = 0; i < argc; i++) {
- for (bf = mc_enables_bf; bf->name != NULL; bf++) {
+ for (bf = mc_enables_bf; bf->name; bf++) {
int nl = strlen(bf->name);
- if (strncmp(argv[i], bf->name, nl) != 0)
+ if (strcmp(argv[i], bf->name))
continue;
- if (strncmp(argv[i]+nl+1, "off", 3) == 0) {
+ if (!strcmp(argv[i]+nl+1, "off")) {
printf("Disabling %s\n", bf->desc);
en &= ~bf->mask;
}
- else if (strncmp(argv[i]+nl+1, "on", 2) == 0) {
+ else if (!strcmp(argv[i]+nl+1, "on")) {
printf("Enabling %s\n", bf->desc);
en |= bf->mask;
}
@@ -347,13 +375,13 @@ ipmi_mc_set_enables(struct ipmi_intf * intf, int argc, char ** argv)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Set Global Enables command failed");
return -1;
}
- else if (rsp->ccode > 0) {
+ else if (rsp->ccode) {
lprintf(LOG_ERR, "Set Global Enables command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return -1;
}
@@ -397,13 +425,13 @@ ipmi_mc_get_deviceid(struct ipmi_intf * intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Device ID command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Device ID command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return -1;
}
@@ -421,18 +449,15 @@ ipmi_mc_get_deviceid(struct ipmi_intf * intf)
printf("Manufacturer ID : %lu\n",
(long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id));
printf("Manufacturer Name : %s\n",
- val2str( (long)IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
- ipmi_oem_info) );
+ OEM_MFG_STRING(devid->manufacturer_id));
printf("Product ID : %u (0x%02x%02x)\n",
buf2short((uint8_t *)(devid->product_id)),
devid->product_id[1], devid->product_id[0]);
- product=oemval2str(IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id),
- (devid->product_id[1]<<8)+devid->product_id[0],
- ipmi_oem_product_info);
+ product = OEM_PROD_STRING(devid->manufacturer_id, devid->product_id);
- if (product!=NULL) {
+ if (product) {
printf("Product Name : %s\n", product);
}
@@ -470,69 +495,292 @@ ipmi_mc_get_deviceid(struct ipmi_intf * intf)
* returns - negative number means error, positive is a ccode.
*/
int
-_ipmi_mc_get_guid(struct ipmi_intf *intf, struct ipmi_guid_t *guid)
+_ipmi_mc_get_guid(struct ipmi_intf *intf, ipmi_guid_t *guid)
{
struct ipmi_rs *rsp;
struct ipmi_rq req;
- if (guid == NULL) {
+ if (!guid) {
return (-3);
}
- memset(guid, 0, sizeof(struct ipmi_guid_t));
+ memset(guid, 0, sizeof(ipmi_guid_t));
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = BMC_GET_GUID;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 16
- || rsp->data_len != sizeof(struct ipmi_guid_t)) {
+ || rsp->data_len != sizeof(ipmi_guid_t)) {
return (-2);
}
- memcpy(guid, &rsp->data[0], sizeof(struct ipmi_guid_t));
+ memcpy(guid, &rsp->data[0], sizeof(ipmi_guid_t));
return 0;
}
-/* ipmi_mc_print_guid - print-out given BMC GUID
+/* A helper function to convert GUID time to time_t */
+static time_t _guid_time(uint64_t t_low, uint64_t t_mid, uint64_t t_hi)
+{
+ /* GUID time-stamp is a 60-bit value representing the
+ * count of 100ns intervals since 00:00:00.00, 15 Oct 1582 */
+
+ const uint64_t t100ns_in_sec = 10000000LL;
+
+ /* Seconds from 15 Oct 1582 to 1 Jan 1970 00:00:00 */
+ uint64_t epoch_since_gregorian = 12219292800;
+
+ /* 100ns intervals since 15 Oct 1582 00:00:00 */
+ uint64_t gregorian = (GUID_TIME_HI(t_hi) << 48)
+ | (t_mid << 32)
+ | t_low;
+ time_t unixtime; /* We need timestamp in seconds since UNIX epoch */
+
+ gregorian /= t100ns_in_sec; /* Convert to seconds */
+ unixtime = gregorian - epoch_since_gregorian;
+
+ return unixtime;
+}
+
+#define TM_YEAR_BASE 1900
+#define EPOCH_YEAR 1970
+static bool _is_time_valid(time_t t)
+{
+ time_t t_now = time(NULL);
+ struct tm tm;
+ struct tm now;
+
+ gmtime_r(&t, &tm);
+ gmtime_r(&t_now, &now);
+
+ /* It's enought to check that the year fits in [Epoch .. now] interval */
+
+ if (tm.tm_year + TM_YEAR_BASE < EPOCH_YEAR)
+ return false;
+
+ if (tm.tm_year > now.tm_year) {
+ /* GUID timestamp can't be in future */
+ return false;
+ }
+
+ return true;
+}
+
+/** ipmi_mc_parse_guid - print-out given BMC GUID
+ *
+ * The function parses the raw guid data according to the requested encoding
+ * mode. If GUID_AUTO mode is requested, then automatic detection of encoding
+ * is attempted using the version nibble of the time_hi_and_version field of
+ * each of the supported encodings.
*
- * @guid - struct with GUID.
+ * Considering the rather random nature of GUIDs, it may happen that the
+ * version nibble is valid for multiple encodings at the same time. That's why
+ * if the version is 1 (time-based), the function will also check validity of
+ * the time stamp. If a valid time stamp is found for a given mode, the mode is
+ * considered detected and no further checks are performed. Otherwise other
+ * encodings are probed the same way. If in neither encoding the valid version
+ * nibble happened to indicate time-based version or no valid time-stamp has
+ * been found, then the last probed encoding with valid version nibble is
+ * considered detected. If none of the probed encodings indicated a valid
+ * version nibble, then fall back to GUID_DUMP
*
- * returns 0
+ * @param[in] guid - The original GUID data as received from BMC
+ * @param[in] mode - The requested mode/encoding
+ *
+ * @returns parsed GUID
*/
-static int
-ipmi_mc_print_guid(struct ipmi_guid_t guid)
+parsed_guid_t ipmi_parse_guid(void *guid, ipmi_guid_mode_t guid_mode)
{
- char tbuf[40];
- time_t s;
- memset(tbuf, 0, 40);
- /* Kipp - changed order of last field (node) to follow specification */
- printf("System GUID : %08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x\n",
- guid.time_low, guid.time_mid, guid.time_hi_and_version,
- guid.clock_seq_hi_variant << 8 | guid.clock_seq_low,
- guid.node[0], guid.node[1], guid.node[2],
- guid.node[3], guid.node[4], guid.node[5]);
+ ipmi_guid_mode_t i;
+ ipmi_guid_t *ipmi_guid = guid;
+ rfc_guid_t *rfc_guid = guid;
+ parsed_guid_t parsed_guid = { 0 };
+ uint32_t t_low[GUID_REAL_MODES];
+ uint16_t t_mid[GUID_REAL_MODES];
+ uint16_t t_hi[GUID_REAL_MODES];
+ uint16_t clk[GUID_REAL_MODES];
+ time_t seconds[GUID_REAL_MODES];
+ bool detect = false;
+
+ /* Unless another mode is detected, default to dumping */
+ if (GUID_AUTO == guid_mode) {
+ detect = true;
+ guid_mode = GUID_DUMP;
+ }
- s = (time_t)guid.time_low; /* Kipp - removed the BSWAP_32, it was not needed here */
- strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", localtime(&s));
- printf("Timestamp : %s\n", tbuf);
- return 0;
+ /* Try to convert time using all possible methods to use
+ * the result later if GUID_AUTO is requested */
+
+ /* For IPMI all fields are little-endian (LSB first) */
+ t_hi[GUID_IPMI] = ipmi16toh(&ipmi_guid->time_hi_and_version);
+ t_mid[GUID_IPMI] = ipmi16toh(&ipmi_guid->time_mid);
+ t_low[GUID_IPMI] = ipmi32toh(&ipmi_guid->time_low);
+ clk[GUID_IPMI] = ipmi16toh(&ipmi_guid->clock_seq_and_rsvd);
+
+ /* For RFC4122 all fields are in network byte order (MSB first) */
+ t_hi[GUID_RFC4122] = ntohs(rfc_guid->time_hi_and_version);
+ t_mid[GUID_RFC4122] = ntohs(rfc_guid->time_mid);
+ t_low[GUID_RFC4122] = ntohl(rfc_guid->time_low);
+ clk[GUID_RFC4122] = ntohs(rfc_guid->clock_seq_and_rsvd);
+
+ /* For SMBIOS time fields are little-endian (as in IPMI), the rest is
+ * in network order (as in RFC4122) */
+ t_hi[GUID_SMBIOS] = ipmi16toh(&rfc_guid->time_hi_and_version);
+ t_mid[GUID_SMBIOS] = ipmi16toh(&rfc_guid->time_mid);
+ t_low[GUID_SMBIOS] = ipmi32toh(&rfc_guid->time_low);
+ clk[GUID_SMBIOS] = ntohs(rfc_guid->clock_seq_and_rsvd);
+
+ /* Using 0 here to allow for reordering of modes in ipmi_guid_mode_t */
+ for (i = 0; i < GUID_REAL_MODES; ++i) {
+ seconds[i] = _guid_time(t_low[i], t_mid[i], t_hi[i]);
+
+ /* If autodetection was initially requested and mode
+ * hasn't been detected yet */
+ if (detect) {
+ guid_version_t ver = GUID_VERSION(t_hi[i]);
+ if (is_guid_version_valid(ver)) {
+ guid_mode = i;
+ if (GUID_VERSION_TIME == ver && _is_time_valid(seconds[i])) {
+ break;
+ }
+ }
+ }
+ }
+
+ if (guid_mode >= GUID_REAL_MODES) {
+ guid_mode = GUID_DUMP;
+ /* The endianness and field order are irrelevant for dump mode */
+ memcpy(&parsed_guid, guid, sizeof(ipmi_guid_t));
+ goto out;
+ }
+
+ /*
+ * Return only a valid version in the parsed version field.
+ * If one needs the raw value, they still may use
+ * GUID_VERSION(parsed_guid.time_hi_and_version)
+ */
+ parsed_guid.ver = GUID_VERSION(t_hi[guid_mode]);
+ if (parsed_guid.ver > GUID_VERSION_MAX) {
+ parsed_guid.ver = GUID_VERSION_UNKNOWN;
+ }
+
+ if (GUID_VERSION_TIME == parsed_guid.ver) {
+ parsed_guid.time = seconds[guid_mode];
+ }
+
+ if (GUID_IPMI == guid_mode) {
+ /*
+ * In IPMI all fields are little-endian (LSB first)
+ * That is, first byte last. Hence, swap before copying.
+ */
+ memcpy(parsed_guid.node,
+ array_byteswap(ipmi_guid->node, GUID_NODE_SZ),
+ GUID_NODE_SZ);
+ } else {
+ /*
+ * For RFC4122 and SMBIOS the node field is in network byte order.
+ * That is first byte first. Hence, copy as is.
+ */
+ memcpy(parsed_guid.node, rfc_guid->node, GUID_NODE_SZ);
+ }
+
+ parsed_guid.time_low = t_low[guid_mode];
+ parsed_guid.time_mid = t_mid[guid_mode];
+ parsed_guid.time_hi_and_version = t_hi[guid_mode];
+ parsed_guid.clock_seq_and_rsvd = clk[guid_mode];
+
+out:
+ parsed_guid.mode = guid_mode;
+ return parsed_guid;
}
-/* ipmi_mc_get_guid - Gets and prints-out System GUID */
-int
-ipmi_mc_get_guid(struct ipmi_intf *intf)
+/* ipmi_mc_print_guid - print-out given BMC GUID
+ *
+ * @param[in] intf - The IPMI interface to request GUID from
+ * @param[in] guid_mode - GUID decoding mode
+ *
+ * @returns status code
+ * @retval 0 - Success
+ * @retval -1 - Error
+ */
+static int
+ipmi_mc_print_guid(struct ipmi_intf *intf, ipmi_guid_mode_t guid_mode)
{
- struct ipmi_guid_t guid;
+ /* Allocate a byte array for ease of use in dump mode */
+ uint8_t guid_data[sizeof(ipmi_guid_t)];
+
+ /* These are host architecture specific */
+ parsed_guid_t guid;
+
+ const char *guid_ver_str[GUID_VERSION_COUNT] = {
+ [GUID_VERSION_UNKNOWN] = "Unknown/unsupported",
+ [GUID_VERSION_TIME] = "Time-based",
+ [GUID_VERSION_DCE] = "DCE Security with POSIX UIDs (not for IPMI)",
+ [GUID_VERSION_MD5] = "Name-based using MD5",
+ [GUID_VERSION_RND] = "Random or pseudo-random",
+ [GUID_VERSION_SHA1] = "Name-based using SHA-1"
+ };
+
+ const char *guid_mode_str[GUID_TOTAL_MODES] = {
+ [GUID_IPMI] = "IPMI",
+ [GUID_RFC4122] = "RFC4122",
+ [GUID_SMBIOS] = "SMBIOS",
+ [GUID_AUTO] = "Automatic (if you see this, report a bug)",
+ [GUID_DUMP] = "Unknown (data dumped)"
+ };
+
int rc;
- rc = _ipmi_mc_get_guid(intf, &guid);
+
+ rc = _ipmi_mc_get_guid(intf, (ipmi_guid_t *)guid_data);
if (eval_ccode(rc) != 0) {
return (-1);
}
- rc = ipmi_mc_print_guid(guid);
- return rc;
+
+ printf("System GUID : ");
+
+ guid = ipmi_parse_guid(guid_data, guid_mode);
+ if (GUID_DUMP == guid.mode) {
+ size_t i;
+ for (i = 0; i < sizeof(guid_data); ++i) {
+ printf("%02X", guid_data[i]);
+ }
+ printf("\n");
+ return 0;
+ }
+
+ printf("%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x\n",
+ (int)guid.time_low,
+ (int)guid.time_mid,
+ (int)guid.time_hi_and_version,
+ guid.clock_seq_and_rsvd,
+ guid.node[0], guid.node[1], guid.node[2],
+ guid.node[3], guid.node[4], guid.node[5]);
+
+ if (GUID_AUTO == guid_mode) {
+ /* ipmi_parse_guid() returns only valid modes in guid.ver */
+ printf("GUID Encoding : %s", guid_mode_str[guid.mode]);
+ if (GUID_IPMI != guid.mode) {
+ printf(" (WARNING: IPMI Specification violation!)");
+ }
+ printf("\n");
+ }
+
+ printf("GUID Version : %s", guid_ver_str[guid.ver]);
+
+ switch (guid.ver) {
+ case GUID_VERSION_UNKNOWN:
+ printf(" (%d)\n", GUID_VERSION((int)guid.time_hi_and_version));
+ break;
+ case GUID_VERSION_TIME:
+ printf("\nTimestamp : %s\n", ipmi_timestamp_numeric(guid.time));
+ break;
+ default:
+ printf("\n");
+ }
+
+ return 0;
}
/* ipmi_mc_get_selftest - returns and print selftest results
@@ -559,7 +807,7 @@ static int ipmi_mc_get_selftest(struct ipmi_intf * intf)
if (rsp->ccode) {
lprintf(LOG_ERR, "Bad response: (%s)",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return -1;
}
@@ -583,7 +831,7 @@ static int ipmi_mc_get_selftest(struct ipmi_intf * intf)
printf(" -> SEL device not accessible\n");
}
if (sft_res->test & IPM_SELFTEST_SDR_ERROR) {
- printf(" -> SDR repository not accesible\n");
+ printf(" -> SDR repository not accessible\n");
}
if (sft_res->test & IPM_SELFTEST_FRU_ERROR) {
printf("FRU device not accessible\n");
@@ -625,6 +873,63 @@ static int ipmi_mc_get_selftest(struct ipmi_intf * intf)
return rv;
}
+struct wdt_string_s {
+ const char *get; /* The name of 'timer use' for `watchdog get` command */
+ const char *set; /* The name of 'timer use' for `watchdog set` command */
+};
+
+
+#define WDTS(g,s) &(const struct wdt_string_s){ (g), (s) }
+
+const struct wdt_string_s *wdt_use[] = {
+ WDTS("Reserved", "none"),
+ WDTS("BIOS FRB2", "frb2"),
+ WDTS("BIOS/POST", "post"),
+ WDTS("OS Load", "osload"),
+ WDTS("SMS/OS", "sms"),
+ WDTS("OEM", "oem"),
+ WDTS("Reserved", NULL),
+ WDTS("Reserved", NULL),
+ NULL
+};
+
+const struct wdt_string_s *wdt_int[] = {
+ WDTS("None", "none"),
+ WDTS("SMI", "smi"),
+ WDTS("NMI/Diagnostic", "nmi"),
+ WDTS("Messaging", "msg"),
+ WDTS("Reserved", NULL),
+ WDTS("Reserved", NULL),
+ WDTS("Reserved", NULL),
+ WDTS("Reserved", NULL),
+ NULL
+};
+
+const struct wdt_string_s *wdt_action[] = {
+ WDTS("No action", "none"),
+ WDTS("Hard Reset", "reset"),
+ WDTS("Power Down", "poweroff"),
+ WDTS("Power Cycle", "cycle"),
+ WDTS("Reserved", NULL),
+ WDTS("Reserved", NULL),
+ WDTS("Reserved", NULL),
+ WDTS("Reserved", NULL),
+ NULL
+};
+
+int find_set_wdt_string(const struct wdt_string_s *w[], const char *s)
+{
+ int val = 0;
+ while (w[val]) {
+ if (!strcmp(s, w[val]->set)) break;
+ ++val;
+ }
+ if (!w[val]) {
+ return -1;
+ }
+ return val;
+}
+
/* ipmi_mc_get_watchdog
*
* @intf: ipmi interface
@@ -632,35 +937,15 @@ static int ipmi_mc_get_selftest(struct ipmi_intf * intf)
* returns 0 on success
* returns -1 on error
*/
-
-const char *wdt_use_string[8] = {
- "Reserved",
- "BIOS FRB2",
- "BIOS/POST",
- "OS Load",
- "SMS/OS",
- "OEM",
- "Reserved",
- "Reserved"
-};
-
-const char *wdt_action_string[8] = {
- "No action",
- "Hard Reset",
- "Power Down",
- "Power Cycle",
- "Reserved",
- "Reserved",
- "Reserved",
- "Reserved"
-};
-
static int
ipmi_mc_get_watchdog(struct ipmi_intf * intf)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
struct ipm_get_watchdog_rsp * wdt_res;
+ double init_cnt;
+ double pres_cnt;
+ size_t i;
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
@@ -668,35 +953,226 @@ ipmi_mc_get_watchdog(struct ipmi_intf * intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Watchdog Timer command failed");
return -1;
}
if (rsp->ccode) {
lprintf(LOG_ERR, "Get Watchdog Timer command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return -1;
}
wdt_res = (struct ipm_get_watchdog_rsp *) rsp->data;
+ /* Convert 100ms intervals to seconds */
+ init_cnt = (double)ipmi16toh(&wdt_res->init_cnt_le) / 10.0;
+ pres_cnt = (double)ipmi16toh(&wdt_res->pres_cnt_le) / 10.0;
+
printf("Watchdog Timer Use: %s (0x%02x)\n",
- wdt_use_string[(wdt_res->timer_use & 0x07 )], wdt_res->timer_use);
+ wdt_use[IPMI_WDT_GET(wdt_res->use, USE)]->get, wdt_res->use);
printf("Watchdog Timer Is: %s\n",
- wdt_res->timer_use & 0x40 ? "Started/Running" : "Stopped");
- printf("Watchdog Timer Actions: %s (0x%02x)\n",
- wdt_action_string[(wdt_res->timer_actions&0x07)], wdt_res->timer_actions);
+ IS_WDT_BIT(wdt_res->use, USE_RUNNING)
+ ? "Started/Running"
+ : "Stopped");
+ printf("Watchdog Timer Logging: %s\n",
+ IS_WDT_BIT(wdt_res->use, USE_NOLOG)
+ ? "Off"
+ : "On");
+ printf("Watchdog Timer Action: %s (0x%02x)\n",
+ wdt_action[IPMI_WDT_GET(wdt_res->intr_action, ACTION)]->get,
+ wdt_res->intr_action);
+ printf("Pre-timeout interrupt: %s\n",
+ wdt_int[IPMI_WDT_GET(wdt_res->intr_action, INTR)]->get);
printf("Pre-timeout interval: %d seconds\n", wdt_res->pre_timeout);
- printf("Timer Expiration Flags: 0x%02x\n", wdt_res->timer_use_exp);
- printf("Initial Countdown: %i sec\n",
- ((wdt_res->initial_countdown_msb << 8) | wdt_res->initial_countdown_lsb)/10);
- printf("Present Countdown: %i sec\n",
- (((wdt_res->present_countdown_msb << 8) | wdt_res->present_countdown_lsb)) / 10);
+ printf("Timer Expiration Flags: %s(0x%02x)\n",
+ wdt_res->exp_flags ? "" : "None ",
+ wdt_res->exp_flags);
+ for (i = 0; i < sizeof(wdt_res->exp_flags) * CHAR_BIT; ++i) {
+ if (IS_SET(wdt_res->exp_flags, i)) {
+ printf(" * %s\n", wdt_use[i]->get);
+ }
+ }
+ printf("Initial Countdown: %0.1f sec\n", init_cnt);
+ printf("Present Countdown: %0.1f sec\n", pres_cnt);
return 0;
}
+/* Configuration to set with ipmi_mc_set_watchdog() */
+typedef struct ipmi_mc_set_wdt_conf_s {
+ uint16_t timeout;
+ uint8_t pretimeout;
+ uint8_t intr;
+ uint8_t use;
+ uint8_t clear;
+ uint8_t action;
+ bool nolog;
+ bool dontstop;
+} wdt_conf_t;
+
+/* Options parser for ipmi_mc_set_watchdog() */
+static bool
+parse_set_wdt_options(wdt_conf_t *conf, int argc, char *argv[])
+{
+ const int MAX_TIMEOUT = 6553; /* Seconds, makes almost USHRT_MAX when
+ converted to 100ms intervals */
+ const int MAX_PRETIMEOUT = 255; /* Seconds */
+ bool error = true;
+ int i;
+
+ if (!argc || !strcmp(argv[0], "help")) {
+ goto out;
+ }
+
+ for (i = 0; i < argc; ++i) {
+ long val;
+ char *vstr = strchr(argv[i], '=');
+ if (vstr)
+ vstr++; /* Point to the value */
+
+ switch (argv[i][0]) { /* only check the first letter to allow for
+ shortcuts */
+ case 't': /* timeout */
+ val = strtol(vstr, NULL, 10);
+ if (val < 1 || val > MAX_TIMEOUT) {
+ lprintf(LOG_ERR, "Timeout value %lu is out of range (1-%d)\n",
+ val, MAX_TIMEOUT);
+ goto out;
+ }
+ conf->timeout = val * 10; /* Convert seconds to 100ms intervals */
+ break;
+ case 'p': /* pretimeout */
+ val = strtol(vstr, NULL, 10);
+ if (val < 1 || val > MAX_PRETIMEOUT) {
+ lprintf(LOG_ERR,
+ "Pretimeout value %lu is out of range (1-%d)\n",
+ val, MAX_PRETIMEOUT);
+ goto out;
+ }
+ conf->pretimeout = val; /* Convert seconds to 100ms intervals */
+ break;
+ case 'i': /* int */
+ if (0 > (val = find_set_wdt_string(wdt_int, vstr))) {
+ lprintf(LOG_ERR, "Interrupt type '%s' is not valid\n", vstr);
+ goto out;
+ }
+ conf->intr = val;
+ break;
+ case 'u': /* use */
+ if (0 > (val = find_set_wdt_string(wdt_use, vstr))) {
+ lprintf(LOG_ERR, "Use '%s' is not valid\n", vstr);
+ goto out;
+ }
+ conf->use = val;
+ break;
+ case 'a': /* action */
+ if (0 > (val = find_set_wdt_string(wdt_action, vstr))) {
+ lprintf(LOG_ERR, "Use '%s' is not valid\n", vstr);
+ goto out;
+ }
+ conf->action = val;
+ break;
+ case 'c': /* clear */
+ if (0 > (val = find_set_wdt_string(wdt_use, vstr))) {
+ lprintf(LOG_ERR, "Use '%s' is not valid\n", vstr);
+ goto out;
+ }
+ conf->clear |= 1 << val;
+ break;
+ case 'n': /* nolog */
+ conf->nolog = true;
+ break;
+ case 'd': /* dontstop */
+ conf->dontstop = true;
+ break;
+
+ default:
+ lprintf(LOG_ERR, "Invalid option '%s'", argv[i]);
+ break;
+ }
+ }
+
+ error = false;
+
+out:
+ return error;
+}
+
+/* ipmi_mc_set_watchdog
+ *
+ * @intf: ipmi interface
+ * @argc: argument count
+ * @argv: arguments
+ *
+ * returns 0 on success
+ * returns non-zero (-1 or IPMI completion code) on error
+ */
+static int
+ipmi_mc_set_watchdog(struct ipmi_intf * intf, int argc, char *argv[])
+{
+ struct ipmi_rs * rsp;
+ struct ipmi_rq req = {0};
+ unsigned char msg_data[6] = {0};
+ int rc = -1;
+ wdt_conf_t conf = {0};
+ bool options_error = parse_set_wdt_options(&conf, argc, argv);
+
+ /* Fill data bytes according to IPMI 2.0 Spec section 27.6 */
+ msg_data[0] = conf.nolog << IPMI_WDT_USE_NOLOG_SHIFT;
+ msg_data[0] |= conf.dontstop << IPMI_WDT_USE_DONTSTOP_SHIFT;
+ msg_data[0] |= conf.use & IPMI_WDT_USE_MASK;
+
+ msg_data[1] = (conf.intr & IPMI_WDT_INTR_MASK) << IPMI_WDT_INTR_SHIFT;
+ msg_data[1] |= conf.action & IPMI_WDT_ACTION_MASK;
+
+ msg_data[2] = conf.pretimeout;
+
+ msg_data[3] = conf.clear;
+
+ htoipmi16(conf.timeout, &msg_data[4]);
+
+ req.msg.netfn = IPMI_NETFN_APP;
+ req.msg.cmd = BMC_SET_WATCHDOG_TIMER;
+ req.msg.data_len = 6;
+ req.msg.data = msg_data;
+
+ lprintf(LOG_INFO,
+ "Sending Set Watchdog command [%02X %02X %02X %02X %02X %02X]:"
+ , msg_data[0], msg_data[1], msg_data[2]
+ , msg_data[3], msg_data[4], msg_data[5]
+ );
+ lprintf(LOG_INFO, " - nolog = %d", conf.nolog);
+ lprintf(LOG_INFO, " - dontstop = %d", conf.dontstop);
+ lprintf(LOG_INFO, " - use = 0x%02hhX", conf.use);
+ lprintf(LOG_INFO, " - intr = 0x%02hhX", conf.intr);
+ lprintf(LOG_INFO, " - action = 0x%02hhX", conf.action);
+ lprintf(LOG_INFO, " - pretimeout = %hhu", conf.pretimeout);
+ lprintf(LOG_INFO, " - clear = 0x%02hhX", conf.clear);
+ lprintf(LOG_INFO, " - timeout = %hu", conf.timeout);
+
+ rsp = intf->sendrecv(intf, &req);
+ if (!rsp) {
+ lprintf(LOG_ERR, "Set Watchdog Timer command failed");
+ goto out;
+ }
+
+ rc = rsp->ccode;
+ if (rc) {
+ lprintf(LOG_ERR, "Set Watchdog Timer command failed: %s",
+ CC_STRING(rsp->ccode));
+ goto out;
+ }
+
+ lprintf(LOG_NOTICE, "Watchdog Timer was successfully configured");
+
+out:
+ if (options_error) print_watchdog_usage();
+
+ return rc;
+}
+
/* ipmi_mc_shutoff_watchdog
*
* @intf: ipmi interface
@@ -737,14 +1213,14 @@ ipmi_mc_shutoff_watchdog(struct ipmi_intf * intf)
msg_data[5] = 0x0b; /* countdown msb - 5 mins */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Watchdog Timer Shutoff command failed!");
return -1;
}
if (rsp->ccode) {
lprintf(LOG_ERR, "Watchdog Timer Shutoff command failed! %s",
- val2str(rsp->ccode, completion_code_vals));
+ CC_STRING(rsp->ccode));
return -1;
}
@@ -772,16 +1248,16 @@ ipmi_mc_rst_watchdog(struct ipmi_intf * intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Reset Watchdog Timer command failed!");
return -1;
}
if (rsp->ccode) {
lprintf(LOG_ERR, "Reset Watchdog Timer command failed: %s",
- (rsp->ccode == IPM_WATCHDOG_RESET_ERROR) ?
- "Attempt to reset uninitialized watchdog" :
- val2str(rsp->ccode, completion_code_vals));
+ (rsp->ccode == IPM_WATCHDOG_RESET_ERROR)
+ ? "Attempt to reset uninitialized watchdog"
+ : CC_STRING(rsp->ccode));
return -1;
}
@@ -808,24 +1284,24 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
printf_mc_usage();
rc = (-1);
}
- else if (strncmp(argv[0], "help", 4) == 0) {
+ else if (!strcmp(argv[0], "help")) {
printf_mc_usage();
rc = 0;
}
- else if (strncmp(argv[0], "reset", 5) == 0) {
+ else if (!strcmp(argv[0], "reset")) {
if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
printf_mc_reset_usage();
rc = (-1);
}
- else if (strncmp(argv[1], "help", 4) == 0) {
+ else if (!strcmp(argv[1], "help")) {
printf_mc_reset_usage();
rc = 0;
}
- else if (strncmp(argv[1], "cold", 4) == 0) {
+ else if (!strcmp(argv[1], "cold")) {
rc = ipmi_mc_reset(intf, BMC_COLD_RESET);
}
- else if (strncmp(argv[1], "warm", 4) == 0) {
+ else if (!strcmp(argv[1], "warm")) {
rc = ipmi_mc_reset(intf, BMC_WARM_RESET);
}
else {
@@ -834,38 +1310,68 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = (-1);
}
}
- else if (strncmp(argv[0], "info", 4) == 0) {
+ else if (!strcmp(argv[0], "info")) {
rc = ipmi_mc_get_deviceid(intf);
}
- else if (strncmp(argv[0], "guid", 4) == 0) {
- rc = ipmi_mc_get_guid(intf);
+ else if (!strcmp(argv[0], "guid")) {
+ ipmi_guid_mode_t guid_mode = GUID_AUTO;
+
+ /* Allow for 'rfc' and 'rfc4122' */
+ if (argc > 1) {
+ if (!strcmp(argv[1], "rfc")) {
+ guid_mode = GUID_RFC4122;
+ }
+ else if (!strcmp(argv[1], "smbios")) {
+ guid_mode = GUID_SMBIOS;
+ }
+ else if (!strcmp(argv[1], "ipmi")) {
+ guid_mode = GUID_IPMI;
+ }
+ else if (!strcmp(argv[1], "auto")) {
+ guid_mode = GUID_AUTO;
+ }
+ else if (!strcmp(argv[1], "dump")) {
+ guid_mode = GUID_DUMP;
+ }
+ }
+ rc = ipmi_mc_print_guid(intf, guid_mode);
}
- else if (strncmp(argv[0], "getenables", 10) == 0) {
+ else if (!strcmp(argv[0], "getenables")) {
rc = ipmi_mc_get_enables(intf);
}
- else if (strncmp(argv[0], "setenables", 10) == 0) {
+ else if (!strcmp(argv[0], "setenables")) {
rc = ipmi_mc_set_enables(intf, argc-1, &(argv[1]));
}
- else if (!strncmp(argv[0], "selftest", 8)) {
+ else if (!strcmp(argv[0], "selftest")) {
rc = ipmi_mc_get_selftest(intf);
}
- else if (!strncmp(argv[0], "watchdog", 8)) {
+ else if (!strcmp(argv[0], "watchdog")) {
if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
print_watchdog_usage();
rc = (-1);
}
- else if (strncmp(argv[1], "help", 4) == 0) {
+ else if (!strcmp(argv[1], "help")) {
print_watchdog_usage();
rc = 0;
}
- else if (strncmp(argv[1], "get", 3) == 0) {
+ else if (!strcmp(argv[1], "set")) {
+ if (argc < 3) { /* Requires options */
+ lprintf(LOG_ERR, "Not enough parameters given.");
+ print_watchdog_usage();
+ rc = (-1);
+ }
+ else {
+ rc = ipmi_mc_set_watchdog(intf, argc - 2, &(argv[2]));
+ }
+ }
+ else if (!strcmp(argv[1], "get")) {
rc = ipmi_mc_get_watchdog(intf);
}
- else if(strncmp(argv[1], "off", 3) == 0) {
+ else if (!strcmp(argv[1], "off")) {
rc = ipmi_mc_shutoff_watchdog(intf);
}
- else if(strncmp(argv[1], "reset", 5) == 0) {
+ else if (!strcmp(argv[1], "reset")) {
rc = ipmi_mc_rst_watchdog(intf);
}
else {
@@ -874,10 +1380,10 @@ ipmi_mc_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = (-1);
}
}
- else if (strncmp(argv[0], "getsysinfo", 10) == 0) {
+ else if (!strcmp(argv[0], "getsysinfo")) {
rc = ipmi_sysinfo_main(intf, argc, argv, 0);
}
- else if (strncmp(argv[0], "setsysinfo", 10) == 0) {
+ else if (!strcmp(argv[0], "setsysinfo")) {
rc = ipmi_sysinfo_main(intf, argc, argv, 1);
}
else {
@@ -969,10 +1475,10 @@ ipmi_mc_getsysinfo(struct ipmi_intf * intf, int param, int block, int set,
* u8 data0[14]
*/
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL)
+ if (!rsp)
return (-1);
- if (rsp->ccode == 0) {
+ if (!rsp->ccode) {
if (len > rsp->data_len)
len = rsp->data_len;
if (len && buffer)
@@ -1011,7 +1517,7 @@ ipmi_mc_setsysinfo(struct ipmi_intf * intf, int len, void *buffer)
* u8 data1[16]
*/
rsp = intf->sendrecv(intf, &req);
- if (rsp != NULL) {
+ if (rsp) {
return rsp->ccode;
}
return -1;
@@ -1022,10 +1528,10 @@ ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv, int is_set)
{
char *str;
unsigned char infostr[256];
- unsigned char paramdata[18];
+ char paramdata[18];
int len, maxset, param, pos, rc, set;
- if (argc == 2 && strcmp(argv[1], "help") == 0) {
+ if (argc == 2 && !strcmp(argv[1], "help")) {
printf_sysinfo_usage(1);
return 0;
}
@@ -1109,7 +1615,7 @@ ipmi_sysinfo_main(struct ipmi_intf *intf, int argc, char ** argv, int is_set)
}
else if (rc > 0) {
lprintf(LOG_ERR, "%s command failed: %s", argv[0],
- val2str(rc, completion_code_vals));
+ CC_STRING(rc));
}
return rc;
}
diff --git a/lib/ipmi_oem.c b/lib/ipmi_oem.c
index 96db2ea..d7cf9aa 100644
--- a/lib/ipmi_oem.c
+++ b/lib/ipmi_oem.c
@@ -37,8 +37,9 @@
#include <ipmitool/helper.h>
#include <ipmitool/ipmi_sel.h>
-static int ipmi_oem_supermicro(struct ipmi_intf * intf);
-static int ipmi_oem_ibm(struct ipmi_intf * intf);
+static int ipmi_oem_supermicro(struct ipmi_intf *intf);
+static int ipmi_oem_ibm(struct ipmi_intf *intf);
+static int ipmi_oem_quanta(struct ipmi_intf *intf);
static struct ipmi_oem_handle ipmi_oem_list[] = {
{
@@ -71,36 +72,49 @@ static struct ipmi_oem_handle ipmi_oem_list[] = {
.name = "kontron",
.desc = "Kontron OEM big buffer support"
},
+ {
+ .name = "quanta",
+ .desc = "Quanta IPMIv1.5 BMC with OEM LAN authentication support",
+ .setup = ipmi_oem_quanta,
+ },
{ 0 }
};
/* Supermicro IPMIv2 BMCs use OEM authtype */
static int
-ipmi_oem_supermicro(struct ipmi_intf * intf)
+ipmi_oem_supermicro(struct ipmi_intf *intf)
{
ipmi_intf_session_set_authtype(intf, IPMI_SESSION_AUTHTYPE_OEM);
return 0;
}
static int
-ipmi_oem_ibm(struct ipmi_intf * intf)
+ipmi_oem_ibm(struct ipmi_intf *__UNUSED__(intf))
{
- char * filename;
- if ((filename = getenv("IPMI_OEM_IBM_DATAFILE")) == NULL) {
+ char *filename = getenv("IPMI_OEM_IBM_DATAFILE");
+ if (!filename) {
lprintf(LOG_ERR, "Unable to read IPMI_OEM_IBM_DATAFILE from environment");
return -1;
}
return ipmi_sel_oem_init((const char *)filename);
}
+/* Quanta IPMIv2 BMCs use OEM authtype */
+static int
+ipmi_oem_quanta(struct ipmi_intf *intf)
+{
+ ipmi_intf_session_set_authtype(intf, IPMI_SESSION_AUTHTYPE_OEM);
+ return 0;
+}
+
/* ipmi_oem_print - print list of OEM handles
*/
void
ipmi_oem_print(void)
{
- struct ipmi_oem_handle * oem;
+ struct ipmi_oem_handle *oem;
lprintf(LOG_NOTICE, "\nOEM Support:");
- for (oem=ipmi_oem_list; oem->name != NULL && oem->desc != NULL; oem++) {
+ for (oem=ipmi_oem_list; oem->name && oem->desc; oem++) {
lprintf(LOG_NOTICE, "\t%-12s %s", oem->name, oem->desc);
}
lprintf(LOG_NOTICE, "");
@@ -120,26 +134,27 @@ ipmi_oem_setup(struct ipmi_intf * intf, char * oemtype)
struct ipmi_oem_handle * oem;
int rc = 0;
- if (oemtype == NULL ||
- strncmp(oemtype, "help", 4) == 0 ||
- strncmp(oemtype, "list", 4) == 0) {
+ if (!oemtype
+ || !strcmp(oemtype, "help")
+ || !strcmp(oemtype, "list"))
+ {
ipmi_oem_print();
return -1;
}
- for (oem=ipmi_oem_list; oem->name != NULL; oem++) {
- if (strncmp(oemtype, oem->name, strlen(oem->name)) == 0)
+ for (oem=ipmi_oem_list; oem->name; oem++) {
+ if (!strcmp(oemtype, oem->name))
break;
}
- if (oem->name == NULL)
+ if (!oem->name)
return -1;
/* save pointer for later use */
intf->oem = oem;
/* run optional setup function if it is defined */
- if (oem->setup != NULL) {
+ if (oem->setup) {
lprintf(LOG_DEBUG, "Running OEM setup for \"%s\"", oem->desc);
rc = oem->setup(intf);
}
@@ -158,10 +173,10 @@ ipmi_oem_setup(struct ipmi_intf * intf, char * oemtype)
int
ipmi_oem_active(struct ipmi_intf * intf, const char * oemtype)
{
- if (intf->oem == NULL)
+ if (!intf->oem)
return 0;
- if (strncmp(intf->oem->name, oemtype, strlen(oemtype)) == 0)
+ if (!strcmp(intf->oem->name, oemtype))
return 1;
return 0;
diff --git a/lib/ipmi_pef.c b/lib/ipmi_pef.c
index bbf25f2..ef8c5d4 100644
--- a/lib/ipmi_pef.c
+++ b/lib/ipmi_pef.c
@@ -42,6 +42,7 @@
#include <ipmitool/ipmi_mc.h>
#include <ipmitool/ipmi_pef.h>
#include <ipmitool/ipmi_sel.h>
+#include <ipmitool/ipmi_time.h>
#include <ipmitool/log.h>
extern int verbose;
@@ -78,6 +79,307 @@ static const char * pef_flag_fmts[][3] = {
};
static const char * listitem[] = {" | %s", ",%s", "%s"};
+static struct bit_desc_map
+pef_b2s_actions = {
+BIT_DESC_MAP_ALL,
+{ {"Alert", PEF_ACTION_ALERT},
+ {"Power-off", PEF_ACTION_POWER_DOWN},
+ {"Reset", PEF_ACTION_RESET},
+ {"Power-cycle", PEF_ACTION_POWER_CYCLE},
+ {"OEM-defined", PEF_ACTION_OEM},
+ {"Diagnostic-interrupt", PEF_ACTION_DIAGNOSTIC_INTERRUPT},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_severities = {
+BIT_DESC_MAP_ANY,
+{ {"Non-recoverable", PEF_SEVERITY_NON_RECOVERABLE},
+ {"Critical", PEF_SEVERITY_CRITICAL},
+ {"Warning", PEF_SEVERITY_WARNING},
+ {"OK", PEF_SEVERITY_OK},
+ {"Information", PEF_SEVERITY_INFORMATION},
+ {"Monitor", PEF_SEVERITY_MONITOR},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_sensortypes = {
+BIT_DESC_MAP_LIST,
+{ {"Any", 255},
+ {"Temperature", 1},
+ {"Voltage", 2},
+ {"Current", 3},
+ {"Fan", 4},
+ {"Chassis Intrusion", 5},
+ {"Platform security breach", 6},
+ {"Processor", 7},
+ {"Power supply", 8},
+ {"Power Unit", 9},
+ {"Cooling device", 10},
+ {"Other (units-based)", 11},
+ {"Memory", 12},
+ {"Drive Slot", 13},
+ {"POST memory resize", 14},
+ {"POST error", 15},
+ {"Logging disabled", 16},
+ {"Watchdog 1", 17},
+ {"System event", 18},
+ {"Critical Interrupt", 19},
+ {"Button", 20},
+ {"Module/board", 21},
+ {"uController/coprocessor", 22},
+ {"Add-in card", 23},
+ {"Chassis", 24},
+ {"Chipset", 25},
+ {"Other (FRU)", 26},
+ {"Cable/interconnect", 27},
+ {"Terminator", 28},
+ {"System boot", 29},
+ {"Boot error", 30},
+ {"OS boot", 31},
+ {"OS critical stop", 32},
+ {"Slot/connector", 33},
+ {"ACPI power state", 34},
+ {"Watchdog 2", 35},
+ {"Platform alert", 36},
+ {"Entity presence", 37},
+ {"Monitor ASIC/IC", 38},
+ {"LAN", 39},
+ {"Management subsystem health", 40},
+ {"Battery", 41},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_1 = {
+BIT_DESC_MAP_LIST,
+{ {"<LNC", 0}, /* '<' : getting worse */
+ {">LNC", 1}, /* '>' : getting better */
+ {"<LC", 2},
+ {">LC", 3},
+ {"<LNR", 4},
+ {">LNR", 5},
+ {">UNC", 6},
+ {"<UNC", 7},
+ {">UC", 8},
+ {"<UC", 9},
+ {">UNR", 10},
+ {"<UNR", 11},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_2 = {
+BIT_DESC_MAP_LIST,
+{ {"transition to idle", 0},
+ {"transition to active", 1},
+ {"transition to busy", 2},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_3 = {
+BIT_DESC_MAP_LIST,
+{ {"state deasserted", 0},
+ {"state asserted", 1},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_4 = {
+BIT_DESC_MAP_LIST,
+{ {"predictive failure deasserted", 0},
+ {"predictive failure asserted", 1},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_5 = {
+BIT_DESC_MAP_LIST,
+{ {"limit not exceeded", 0},
+ {"limit exceeded", 1},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_6 = {
+BIT_DESC_MAP_LIST,
+{ {"performance met", 0},
+ {"performance lags", 1},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_7 = {
+BIT_DESC_MAP_LIST,
+{ {"ok", 0},
+ {"<warn", 1}, /* '<' : getting worse */
+ {"<fail", 2},
+ {"<dead", 3},
+ {">warn", 4}, /* '>' : getting better */
+ {">fail", 5},
+ {"dead", 6},
+ {"monitor", 7},
+ {"informational", 8},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_8 = {
+BIT_DESC_MAP_LIST,
+{ {"device removed/absent", 0},
+ {"device inserted/present", 1},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_9 = {
+BIT_DESC_MAP_LIST,
+{ {"device disabled", 0},
+ {"device enabled", 1},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_10 = {
+BIT_DESC_MAP_LIST,
+{ {"transition to running", 0},
+ {"transition to in test", 1},
+ {"transition to power off", 2},
+ {"transition to online", 3},
+ {"transition to offline", 4},
+ {"transition to off duty", 5},
+ {"transition to degraded", 6},
+ {"transition to power save", 7},
+ {"install error", 8},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_11 = {
+BIT_DESC_MAP_LIST,
+{ {"fully redundant", 0},
+ {"redundancy lost", 1},
+ {"redundancy degraded", 2},
+ {"<non-redundant/sufficient", 3}, /* '<' : getting worse */
+ {">non-redundant/sufficient", 4}, /* '>' : getting better */
+ {"non-redundant/insufficient", 5},
+ {"<redundancy degraded", 6},
+ {">redundancy degraded", 7},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_gentype_12 = {
+BIT_DESC_MAP_LIST,
+{ {"D0 power state", 0},
+ {"D1 power state", 1},
+ {"D2 power state", 2},
+ {"D3 power state", 3},
+ {NULL}
+} };
+
+static struct bit_desc_map *
+pef_b2s_generic_ER[] = {
+ &pef_b2s_gentype_1,
+ &pef_b2s_gentype_2,
+ &pef_b2s_gentype_3,
+ &pef_b2s_gentype_4,
+ &pef_b2s_gentype_5,
+ &pef_b2s_gentype_6,
+ &pef_b2s_gentype_7,
+ &pef_b2s_gentype_8,
+ &pef_b2s_gentype_9,
+ &pef_b2s_gentype_10,
+ &pef_b2s_gentype_11,
+ &pef_b2s_gentype_12,
+};
+#define PEF_B2S_GENERIC_ER_ENTRIES ARRAY_SIZE(pef_b2s_generic_ER)
+
+static struct bit_desc_map
+pef_b2s_policies = {
+BIT_DESC_MAP_LIST,
+{ {"Match-always", PEF_POLICY_FLAGS_MATCH_ALWAYS},
+ {"Try-next-entry", PEF_POLICY_FLAGS_PREV_OK_SKIP},
+ {"Try-next-set", PEF_POLICY_FLAGS_PREV_OK_NEXT_POLICY_SET},
+ {"Try-next-channel", PEF_POLICY_FLAGS_PREV_OK_NEXT_CHANNEL_IN_SET},
+ {"Try-next-destination", PEF_POLICY_FLAGS_PREV_OK_NEXT_DESTINATION_IN_SET},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_ch_medium = {
+#define PEF_CH_MEDIUM_TYPE_IPMB 1
+#define PEF_CH_MEDIUM_TYPE_ICMB_10 2
+#define PEF_CH_MEDIUM_TYPE_ICMB_09 3
+#define PEF_CH_MEDIUM_TYPE_LAN 4
+#define PEF_CH_MEDIUM_TYPE_SERIAL 5
+#define PEF_CH_MEDIUM_TYPE_XLAN 6
+#define PEF_CH_MEDIUM_TYPE_PCI_SMBUS 7
+#define PEF_CH_MEDIUM_TYPE_SMBUS_V1X 8
+#define PEF_CH_MEDIUM_TYPE_SMBUS_V2X 9
+#define PEF_CH_MEDIUM_TYPE_USB_V1X 10
+#define PEF_CH_MEDIUM_TYPE_USB_V2X 11
+#define PEF_CH_MEDIUM_TYPE_SYSTEM 12
+BIT_DESC_MAP_LIST,
+{ {"IPMB (I2C)", PEF_CH_MEDIUM_TYPE_IPMB},
+ {"ICMB v1.0", PEF_CH_MEDIUM_TYPE_ICMB_10},
+ {"ICMB v0.9", PEF_CH_MEDIUM_TYPE_ICMB_09},
+ {"802.3 LAN", PEF_CH_MEDIUM_TYPE_LAN},
+ {"Serial/Modem (RS-232)", PEF_CH_MEDIUM_TYPE_SERIAL},
+ {"Other LAN", PEF_CH_MEDIUM_TYPE_XLAN},
+ {"PCI SMBus", PEF_CH_MEDIUM_TYPE_PCI_SMBUS},
+ {"SMBus v1.0/1.1", PEF_CH_MEDIUM_TYPE_SMBUS_V1X},
+ {"SMBus v2.0", PEF_CH_MEDIUM_TYPE_SMBUS_V2X},
+ {"USB 1.x", PEF_CH_MEDIUM_TYPE_USB_V1X},
+ {"USB 2.x", PEF_CH_MEDIUM_TYPE_USB_V2X},
+ {"System I/F (KCS,SMIC,BT)", PEF_CH_MEDIUM_TYPE_SYSTEM},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_control = {
+BIT_DESC_MAP_ALL,
+{ {"PEF", PEF_CONTROL_ENABLE},
+ {"PEF event messages", PEF_CONTROL_ENABLE_EVENT_MESSAGES},
+ {"PEF startup delay", PEF_CONTROL_ENABLE_STARTUP_DELAY},
+ {"Alert startup delay", PEF_CONTROL_ENABLE_ALERT_STARTUP_DELAY},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_lan_desttype = {
+BIT_DESC_MAP_LIST,
+{ {"Acknowledged", PEF_LAN_DEST_TYPE_ACK},
+ {"PET", PEF_LAN_DEST_TYPE_PET},
+ {"OEM 1", PEF_LAN_DEST_TYPE_OEM_1},
+ {"OEM 2", PEF_LAN_DEST_TYPE_OEM_2},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_serial_desttype = {
+BIT_DESC_MAP_LIST,
+{ {"Acknowledged", PEF_SERIAL_DEST_TYPE_ACK},
+ {"TAP page", PEF_SERIAL_DEST_TYPE_TAP},
+ {"PPP PET", PEF_SERIAL_DEST_TYPE_PPP},
+ {"Basic callback", PEF_SERIAL_DEST_TYPE_BASIC_CALLBACK},
+ {"PPP callback", PEF_SERIAL_DEST_TYPE_PPP_CALLBACK},
+ {"OEM 1", PEF_SERIAL_DEST_TYPE_OEM_1},
+ {"OEM 2", PEF_SERIAL_DEST_TYPE_OEM_2},
+ {NULL}
+} };
+
+static struct bit_desc_map
+pef_b2s_tap_svc_confirm = {
+BIT_DESC_MAP_LIST,
+{ {"ACK", PEF_SERIAL_TAP_CONFIRMATION_ACK_AFTER_ETX},
+ {"211+ACK", PEF_SERIAL_TAP_CONFIRMATION_211_ACK_AFTER_ETX},
+ {"{211|213}+ACK", PEF_SERIAL_TAP_CONFIRMATION_21X_ACK_AFTER_ETX},
+ {NULL}
+} };
+
static int ipmi_pef2_list_filters(struct ipmi_intf *);
const char *
@@ -193,7 +495,7 @@ ipmi_pef_print_1xd(const char * text, uint32_t val)
static int
ipmi_pef_print_guid(uint8_t *guid)
{
- if (guid == NULL) {
+ if (!guid) {
return (-1);
}
@@ -247,7 +549,7 @@ _ipmi_get_pef_capabilities(struct ipmi_intf *intf,
{
struct ipmi_rs *rsp;
struct ipmi_rq req;
- if (pcap == NULL) {
+ if (!pcap) {
return (-3);
}
@@ -257,9 +559,9 @@ _ipmi_get_pef_capabilities(struct ipmi_intf *intf,
req.msg.cmd = IPMI_CMD_GET_PEF_CAPABILITIES;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 3) {
return (-2);
@@ -287,7 +589,7 @@ _ipmi_get_pef_filter_entry(struct ipmi_intf *intf, uint8_t filter_id,
uint8_t data[3];
uint8_t data_len = 3 * sizeof(uint8_t);
int dest_size;
- if (filter_entry == NULL) {
+ if (!filter_entry) {
return (-3);
}
@@ -303,9 +605,9 @@ _ipmi_get_pef_filter_entry(struct ipmi_intf *intf, uint8_t filter_id,
req.msg.data = (uint8_t *)&data;
req.msg.data_len = data_len;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 22 || (rsp->data_len - 1) != dest_size) {
return (-2);
@@ -331,7 +633,7 @@ _ipmi_get_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id,
uint8_t data[3];
uint8_t data_len = 3 * sizeof(uint8_t);
int dest_size;
- if (filter_cfg == NULL) {
+ if (!filter_cfg) {
return (-3);
}
@@ -347,9 +649,9 @@ _ipmi_get_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id,
req.msg.data = (uint8_t *)&data;
req.msg.data_len = data_len;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 3 || (rsp->data_len - 1) != dest_size) {
return (-2);
@@ -375,7 +677,7 @@ _ipmi_get_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id,
uint8_t data[3];
uint8_t data_len = 3 * sizeof(uint8_t);
int dest_size;
- if (policy_entry == NULL) {
+ if (!policy_entry) {
return (-3);
}
@@ -391,9 +693,9 @@ _ipmi_get_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id,
req.msg.data = (uint8_t *)&data;
req.msg.data_len = data_len;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 5 || (rsp->data_len - 1) != dest_size) {
return (-2);
@@ -416,7 +718,7 @@ _ipmi_get_pef_filter_table_size(struct ipmi_intf *intf, uint8_t *table_size)
struct ipmi_rq req;
struct pef_cfgparm_selector psel;
- if (table_size == NULL) {
+ if (!table_size) {
return (-3);
}
@@ -430,9 +732,9 @@ _ipmi_get_pef_filter_table_size(struct ipmi_intf *intf, uint8_t *table_size)
req.msg.data = (uint8_t *)&psel;
req.msg.data_len = sizeof(psel);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 2) {
return (-2);
@@ -455,7 +757,7 @@ _ipmi_get_pef_policy_table_size(struct ipmi_intf *intf, uint8_t *table_size)
struct ipmi_rq req;
struct pef_cfgparm_selector psel;
- if (table_size == NULL) {
+ if (!table_size) {
return (-3);
}
@@ -469,9 +771,9 @@ _ipmi_get_pef_policy_table_size(struct ipmi_intf *intf, uint8_t *table_size)
req.msg.data = (uint8_t *)&psel;
req.msg.data_len = sizeof(psel);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 2) {
return (-2);
@@ -494,7 +796,7 @@ _ipmi_get_pef_system_guid(struct ipmi_intf *intf,
struct ipmi_rs *rsp;
struct ipmi_rq req;
struct pef_cfgparm_selector psel;
- if (system_guid == NULL) {
+ if (!system_guid) {
return (-3);
}
@@ -508,9 +810,9 @@ _ipmi_get_pef_system_guid(struct ipmi_intf *intf,
req.msg.data_len = sizeof(psel);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 18
|| (rsp->data_len - 2) != sizeof(system_guid->guid)) {
@@ -537,7 +839,7 @@ _ipmi_set_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id,
struct ipmi_rq req;
uint8_t data[3];
uint8_t data_len = 3 * sizeof(uint8_t);
- if (filter_cfg == NULL) {
+ if (!filter_cfg) {
return (-3);
}
@@ -553,9 +855,9 @@ _ipmi_set_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id,
data[2] = filter_cfg->cfg;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
}
return 0;
@@ -576,7 +878,7 @@ _ipmi_set_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id,
struct ipmi_rs *rsp;
struct ipmi_rq req;
struct pef_cfgparm_set_policy_table_entry payload;
- if (policy_entry == NULL) {
+ if (!policy_entry) {
return (-3);
}
@@ -593,16 +895,17 @@ _ipmi_set_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id,
sizeof(policy_entry->entry));
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
}
return 0;
}
static void
-ipmi_pef_print_oem_lan_dest(struct ipmi_intf *intf, uint8_t ch, uint8_t dest)
+ipmi_pef_print_oem_lan_dest(struct ipmi_intf *intf,
+ uint8_t dest)
{
char address[128];
int len;
@@ -865,7 +1168,7 @@ ipmi_pef_print_serial_dest(struct ipmi_intf *intf, uint8_t ch, uint8_t dest)
if (!dest || tbl_size == 0) /* Page alerting not supported */
return;
if (dest > tbl_size) {
- ipmi_pef_print_oem_lan_dest(intf, ch, dest - tbl_size);
+ ipmi_pef_print_oem_lan_dest(intf, dest - tbl_size);
return;
}
@@ -903,7 +1206,7 @@ ipmi_pef_print_serial_dest(struct ipmi_intf *intf, uint8_t ch, uint8_t dest)
}
static void
-ipmi_pef_print_dest(struct ipmi_intf * intf, uint8_t ch, uint8_t dest)
+ipmi_pef_print_dest(uint8_t dest)
{ /*
// print generic alert destination info
*/
@@ -1095,13 +1398,13 @@ ipmi_pef2_filter(struct ipmi_intf *intf, int argc, char **argv)
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_pef2_filter_help();
rc = (-1);
- } else if (!strncmp(argv[0], "help\0", 5)) {
+ } else if (!strcmp(argv[0], "help")) {
ipmi_pef2_filter_help();
rc = 0;
- } else if (!strncmp(argv[0], "list\0", 5)) {
+ } else if (!strcmp(argv[0], "list")) {
rc = ipmi_pef2_list_filters(intf);
- } else if (!strncmp(argv[0], "enable\0", 7)
- ||(!strncmp(argv[0], "disable\0", 8))) {
+ } else if (!strcmp(argv[0], "enable")
+ ||(!strcmp(argv[0], "disable"))) {
uint8_t enable;
uint8_t filter_id;
if (argc != 2) {
@@ -1117,16 +1420,16 @@ ipmi_pef2_filter(struct ipmi_intf *intf, int argc, char **argv)
"Valid range is <1..255>.");
return (-1);
}
- if (!strncmp(argv[0], "enable\0", 7)) {
+ if (!strcmp(argv[0], "enable")) {
enable = 1;
} else {
enable = 0;
}
rc = ipmi_pef2_filter_enable(intf, enable, filter_id);
- } else if (!strncmp(argv[0], "create\0", 7)) {
+ } else if (!strcmp(argv[0], "create")) {
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
- } else if (!strncmp(argv[0], "delete\0", 7)) {
+ } else if (!strcmp(argv[0], "delete")) {
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
} else {
@@ -1143,7 +1446,7 @@ ipmi_pef2_get_info(struct ipmi_intf *intf)
{
struct pef_capabilities pcap;
struct pef_cfgparm_system_guid psys_guid;
- struct ipmi_guid_t guid;
+ ipmi_guid_t guid;
int rc;
uint8_t *guid_ptr = NULL;
uint8_t policy_table_size;
@@ -1183,6 +1486,7 @@ ipmi_pef2_get_info(struct ipmi_intf *intf)
ipmi_pef_print_guid(guid_ptr);
}
ipmi_pef_print_flags(&pef_b2s_actions, P_SUPP, pcap.actions);
+ putchar('\n');
return 0;
}
@@ -1193,8 +1497,6 @@ ipmi_pef2_get_status(struct ipmi_intf *intf)
struct ipmi_rs *rsp;
struct ipmi_rq req;
struct pef_cfgparm_selector psel;
- char tbuf[40];
- uint32_t timei;
time_t ts;
memset(&req, 0, sizeof(req));
@@ -1206,15 +1508,9 @@ ipmi_pef2_get_status(struct ipmi_intf *intf)
"Last S/W processed ID");
return (-1);
}
- memcpy(&timei, rsp->data, sizeof(timei));
-#if WORDS_BIGENDIAN
- timei = BSWAP_32(timei);
-#endif
- ts = (time_t)timei;
-
- strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&ts));
- ipmi_pef_print_str("Last SEL addition", tbuf);
+ ts = ipmi32toh(rsp->data);
+ ipmi_pef_print_str("Last SEL addition", ipmi_timestamp_numeric(ts));
ipmi_pef_print_2xd("Last SEL record ID", rsp->data[5], rsp->data[4]);
ipmi_pef_print_2xd("Last S/W processed ID", rsp->data[7], rsp->data[6]);
ipmi_pef_print_2xd("Last BMC processed ID", rsp->data[9], rsp->data[8]);
@@ -1242,6 +1538,7 @@ ipmi_pef2_get_status(struct ipmi_intf *intf)
return (-1);
}
ipmi_pef_print_flags(&pef_b2s_actions, P_ACTV, rsp->data[1]);
+ putchar('\n');
return 0;
}
@@ -1337,7 +1634,7 @@ ipmi_pef2_list_policies(struct ipmi_intf *intf)
dest);
break;
default:
- ipmi_pef_print_dest(intf, channel_info.channel, dest);
+ ipmi_pef_print_dest(dest);
break;
}
printf("\n");
@@ -1424,13 +1721,13 @@ ipmi_pef2_policy(struct ipmi_intf *intf, int argc, char **argv)
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_pef2_policy_help();
rc = (-1);
- } else if (!strncmp(argv[0], "help\0", 5)) {
+ } else if (!strcmp(argv[0], "help")) {
ipmi_pef2_policy_help();
rc = 0;
- } else if (!strncmp(argv[0], "list\0", 5)) {
+ } else if (!strcmp(argv[0], "list")) {
rc = ipmi_pef2_list_policies(intf);
- } else if (!strncmp(argv[0], "enable\0", 7)
- || !strncmp(argv[0], "disable\0", 8)) {
+ } else if (!strcmp(argv[0], "enable")
+ || !strcmp(argv[0], "disable")) {
uint8_t enable;
uint8_t policy_id;
if (argc != 2) {
@@ -1445,16 +1742,16 @@ ipmi_pef2_policy(struct ipmi_intf *intf, int argc, char **argv)
lprintf(LOG_ERR, "PEF Policy ID out of range. Valid range is <1..127>.");
return (-1);
}
- if (!strncmp(argv[0], "enable\0", 7)) {
+ if (!strcmp(argv[0], "enable")) {
enable = 1;
} else {
enable = 0;
}
rc = ipmi_pef2_policy_enable(intf, enable, policy_id);
- } else if (!strncmp(argv[0], "create\0", 7)) {
+ } else if (!strcmp(argv[0], "create")) {
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
- } else if (!strncmp(argv[0], "delete\0", 7)) {
+ } else if (!strcmp(argv[0], "delete")) {
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
} else {
@@ -1515,30 +1812,30 @@ int ipmi_pef_main(struct ipmi_intf *intf, int argc, char **argv)
lprintf(LOG_ERR, "Not enough parameters given.");
ipmi_pef2_help();
rc = (-1);
- } else if (!strncmp(argv[0], "help\0", 5)) {
+ } else if (!strcmp(argv[0], "help")) {
ipmi_pef2_help();
rc = 0;
- } else if (!strncmp(argv[0], "capabilities\0", 13)) {
+ } else if (!strcmp(argv[0], "capabilities")) {
/* rc = ipmi_pef2_get_capabilities(intf); */
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
- } else if (!strncmp(argv[0], "event\0", 6)) {
+ } else if (!strcmp(argv[0], "event")) {
/* rc = ipmi_pef2_event(intf, (argc - 1), ++argv); */
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
- } else if (!strncmp(argv[0], "filter\0", 7)) {
+ } else if (!strcmp(argv[0], "filter")) {
rc = ipmi_pef2_filter(intf, (argc - 1), ++argv);
- } else if (!strncmp(argv[0], "info\0", 5)) {
+ } else if (!strcmp(argv[0], "info")) {
rc = ipmi_pef2_get_info(intf);
- } else if (!strncmp(argv[0], "pet\0", 4)) {
+ } else if (!strcmp(argv[0], "pet")) {
/* rc = ipmi_pef2_pet(intf, (argc - 1), ++argv); */
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
- } else if (!strncmp(argv[0], "policy\0", 7)) {
+ } else if (!strcmp(argv[0], "policy")) {
rc = ipmi_pef2_policy(intf, (argc - 1), ++argv);
- } else if (!strncmp(argv[0], "status\0", 7)) {
+ } else if (!strcmp(argv[0], "status")) {
rc = ipmi_pef2_get_status(intf);
- } else if (!strncmp(argv[0], "timer\0", 6)) {
+ } else if (!strcmp(argv[0], "timer")) {
/* rc = ipmi_pef2_timer(intf, (argc - 1), ++argv); */
lprintf(LOG_ERR, "Not implemented.");
rc = 1;
diff --git a/lib/ipmi_picmg.c b/lib/ipmi_picmg.c
index c7d9c8e..8becc78 100644
--- a/lib/ipmi_picmg.c
+++ b/lib/ipmi_picmg.c
@@ -37,11 +37,6 @@
#include <ipmitool/ipmi_strings.h>
#include <ipmitool/log.h>
-#define PICMG_EXTENSION_ATCA_MAJOR_VERSION 2
-#define PICMG_EXTENSION_AMC0_MAJOR_VERSION 4
-#define PICMG_EXTENSION_UTCA_MAJOR_VERSION 5
-
-
#define PICMG_EKEY_MODE_QUERY 0
#define PICMG_EKEY_MODE_PRINT_ALL 1
#define PICMG_EKEY_MODE_PRINT_ENABLED 2
@@ -67,7 +62,84 @@ typedef enum picmg_card_type {
PICMG_CARD_TYPE_RESERVED
} t_picmg_card_type ;
-/* This is the version of the PICMG Extenstion */
+static const char* amc_link_type_str[] = {
+ "RESERVED",
+ "RESERVED1",
+ "PCI EXPRESS",
+ "ADVANCED SWITCHING1",
+ "ADVANCED SWITCHING2",
+ "ETHERNET",
+ "RAPIDIO",
+ "STORAGE",
+};
+
+static const char* amc_link_type_ext_str[][16] = {
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_RESERVED */
+ {
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
+ },
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_RESERVED1 */
+ {
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
+ },
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_PCI_EXPRESS */
+ {
+ "Gen 1 - NSSC",
+ "Gen 1 - SSC",
+ "Gen 2 - NSSC",
+ "Gen 2 - SSC",
+ "", "", "", "",
+ "", "", "", "",
+ "", "", "", ""
+ },
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_ADVANCED_SWITCHING1 */
+ {
+ "Gen 1 - NSSC",
+ "Gen 1 - SSC",
+ "Gen 2 - NSSC",
+ "Gen 2 - SSC",
+ "", "", "", "",
+ "", "", "", "",
+ "", "", "", ""
+ },
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_ADVANCED_SWITCHING2 */
+ {
+ "Gen 1 - NSSC",
+ "Gen 1 - SSC",
+ "Gen 2 - NSSC",
+ "Gen 2 - SSC",
+ "", "", "", "",
+ "", "", "", "",
+ "", "", "", ""
+ },
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET */
+ {
+ "1000BASE-BX (SerDES Gigabit)",
+ "10GBASE-BX410 Gigabit XAUI",
+ "", "",
+ "", "", "", "",
+ "", "", "", "",
+ "", "", "", ""
+ },
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_RAPIDIO */
+ {
+ "1.25 Gbaud transmission rate",
+ "2.5 Gbaud transmission rate",
+ "3.125 Gbaud transmission rate",
+ "", "", "", "", "",
+ "", "", "", "", "", "", "", ""
+ },
+ /* FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE */
+ {
+ "Fibre Channel",
+ "Serial ATA",
+ "Serial Attached SCSI",
+ "", "", "", "", "",
+ "", "", "", "", "", "", "", ""
+ }
+};
+
+/* This is the version of the PICMG Extension */
static t_picmg_card_type PicmgCardType = PICMG_CARD_TYPE_RESERVED;
void
@@ -130,6 +202,28 @@ struct sAmcAddrMap {
{0x88, "reserved", 0},
};
+/* the LED color capabilities */
+static const char *led_color_str[] = {
+ "reserved",
+ "BLUE",
+ "RED",
+ "GREEN",
+ "AMBER",
+ "ORANGE",
+ "WHITE",
+ "reserved"
+};
+
+const char *
+picmg_led_color_str(int color)
+{
+ if (color < 0 || (size_t)color >= ARRAY_SIZE(led_color_str)) {
+ return "invalid";
+ }
+
+ return led_color_str[color];
+}
+
/* is_amc_channel - wrapper to convert user input into integer
* AMC Channel range seems to be <0..255>, bits [7:0]
*
@@ -151,7 +245,7 @@ is_amc_channel(const char *argv_ptr, uint8_t *amc_chan_ptr)
return (-1);
}
/* is_amc_dev - wrapper to convert user input into integer.
- * AMC Dev ID limits are uknown.
+ * AMC Dev ID limits are unknown.
*
* @argv_ptr: source string to convert from; usually argv
* @amc_dev_ptr: pointer where to store result
@@ -172,7 +266,7 @@ is_amc_dev(const char *argv_ptr, int32_t *amc_dev_ptr)
return (-1);
}
/* is_amc_intf - wrapper to convert user input into integer.
- * AMC Interface (ID) limits are uknown.
+ * AMC Interface (ID) limits are unknown.
*
* @argv_ptr: source string to convert from; usually argv
* @amc_intf_ptr: pointer where to store result
@@ -193,7 +287,7 @@ is_amc_intf(const char *argv_ptr, int32_t *amc_intf_ptr)
return (-1);
}
/* is_amc_port - wrapper to convert user input into integer.
- * AMC Port limits are uknown.
+ * AMC Port limits are unknown.
*
* @argv_ptr: source string to convert from; usually argv
* @amc_port_ptr: pointer where to store result
@@ -213,7 +307,7 @@ is_amc_port(const char *argv_ptr, int32_t *amc_port_ptr)
return (-1);
}
/* is_clk_acc - wrapper to convert user input into integer.
- * Clock Accuracy limits are uknown[1byte by spec].
+ * Clock Accuracy limits are unknown[1byte by spec].
*
* @argv_ptr: source string to convert from; usually argv
* @clk_acc_ptr: pointer where to store result
@@ -234,7 +328,7 @@ is_clk_acc(const char *argv_ptr, uint8_t *clk_acc_ptr)
return (-1);
}
/* is_clk_family - wrapper to convert user input into integer.
- * Clock Family limits are uknown[1byte by spec].
+ * Clock Family limits are unknown[1byte by spec].
*
* @argv_ptr: source string to convert from; usually argv
* @clk_family_ptr: pointer where to store result
@@ -255,7 +349,7 @@ is_clk_family(const char *argv_ptr, uint8_t *clk_family_ptr)
return (-1);
}
/* is_clk_freq - wrapper to convert user input into integer.
- * Clock Frequency limits are uknown, but specification says
+ * Clock Frequency limits are unknown, but specification says
* 3Bytes + 1B checksum
*
* @argv_ptr: source string to convert from; usually argv
@@ -277,7 +371,7 @@ is_clk_freq(const char *argv_ptr, uint32_t *clk_freq_ptr)
return (-1);
}
/* is_clk_id - wrapper to convert user input into integer.
- * Clock ID limits are uknown, however it's 1B by specification and I've
+ * Clock ID limits are unknown, however it's 1B by specification and I've
* found two ranges: <1..5> or <0..15>
*
* @argv_ptr: source string to convert from; usually argv
@@ -298,7 +392,7 @@ is_clk_id(const char *argv_ptr, uint8_t *clk_id_ptr)
return (-1);
}
/* is_clk_index - wrapper to convert user input into integer.
- * Clock Index limits are uknown[1B by spec]
+ * Clock Index limits are unknown[1B by spec]
*
* @argv_ptr: source string to convert from; usually argv
* @clk_index_ptr: pointer where to store result
@@ -318,7 +412,7 @@ is_clk_index(const char *argv_ptr, uint8_t *clk_index_ptr)
return (-1);
}
/* is_clk_resid - wrapper to convert user input into integer.
- * Clock Resource Index(?) limits are uknown, but maximum seems to be 15.
+ * Clock Resource Index(?) limits are unknown, but maximum seems to be 15.
*
* @argv_ptr: source string to convert from; usually argv
* @clk_resid_ptr: pointer where to store result
@@ -661,7 +755,7 @@ ipmi_picmg_properties(struct ipmi_intf * intf, int show )
#define PICMG_FRU_ACTIVATE (unsigned char) 0x01
int
-ipmi_picmg_fru_activation(struct ipmi_intf * intf, int argc, char ** argv, unsigned char state)
+ipmi_picmg_fru_activation(struct ipmi_intf * intf, char ** argv, unsigned char state)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -695,7 +789,7 @@ ipmi_picmg_fru_activation(struct ipmi_intf * intf, int argc, char ** argv, unsig
int
-ipmi_picmg_fru_activation_policy_get(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_fru_activation_policy_get(struct ipmi_intf * intf, char ** argv)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -734,7 +828,7 @@ ipmi_picmg_fru_activation_policy_get(struct ipmi_intf * intf, int argc, char **
}
int
-ipmi_picmg_fru_activation_policy_set(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_fru_activation_policy_set(struct ipmi_intf * intf, char ** argv)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -1029,7 +1123,7 @@ ipmi_picmg_amc_portstate_get(struct ipmi_intf * intf, int32_t device,
/* Removed endianness check here, probably not required
- as we dont use bitfields */
+ as we don't use bitfields */
port = d->linkInfo[0] & 0x0F;
type = ((d->linkInfo[0] & 0xF0) >> 4 )|(d->linkInfo[1] & 0x0F );
ext = ((d->linkInfo[1] & 0xF0) >> 4 );
@@ -1158,7 +1252,7 @@ ipmi_picmg_amc_portstate_set(struct ipmi_intf * intf, uint8_t channel,
int
-ipmi_picmg_get_led_properties(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_get_led_properties(struct ipmi_intf * intf, char ** argv)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -1197,7 +1291,7 @@ ipmi_picmg_get_led_properties(struct ipmi_intf * intf, int argc, char ** argv)
}
int
-ipmi_picmg_get_led_capabilities(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_get_led_capabilities(struct ipmi_intf * intf, char ** argv)
{
int i;
struct ipmi_rs * rsp;
@@ -1234,20 +1328,20 @@ ipmi_picmg_get_led_capabilities(struct ipmi_intf * intf, int argc, char ** argv)
printf("LED Color Capabilities: ");
for ( i=0 ; i<8 ; i++ ) {
if ( rsp->data[1] & (0x01 << i) ) {
- printf("%s, ", led_color_str[ i ]);
+ printf("%s, ", picmg_led_color_str(i));
}
}
printf("\n");
printf("Default LED Color in\n");
- printf(" LOCAL control: %s\n", led_color_str[ rsp->data[2] ] );
- printf(" OVERRIDE state: %s\n", led_color_str[ rsp->data[3] ] );
+ printf(" LOCAL control: %s\n", picmg_led_color_str(rsp->data[2]));
+ printf(" OVERRIDE state: %s\n", picmg_led_color_str(rsp->data[3]));
return 0;
}
int
-ipmi_picmg_get_led_state(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_get_led_state(struct ipmi_intf * intf, char ** argv)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -1308,7 +1402,9 @@ ipmi_picmg_get_led_state(struct ipmi_intf * intf, int argc, char ** argv)
}
printf(" Local Control On-Duration: %x\n", rsp->data[3] );
- printf(" Local Control Color: %x [%s]\n", rsp->data[4], led_color_str[ rsp->data[4] ]);
+ printf(" Local Control Color: %x [%s]\n",
+ rsp->data[4],
+ picmg_led_color_str(rsp->data[4]));
/* override state or lamp test */
if (rsp->data[1] & 0x02) {
@@ -1322,7 +1418,9 @@ ipmi_picmg_get_led_state(struct ipmi_intf * intf, int argc, char ** argv)
}
printf(" Override On-Duration: %x\n", rsp->data[6] );
- printf(" Override Color: %x [%s]\n", rsp->data[7], led_color_str[ rsp->data[7] ]);
+ printf(" Override Color: %x [%s]\n",
+ rsp->data[7],
+ picmg_led_color_str(rsp->data[7]));
}
@@ -1334,7 +1432,7 @@ ipmi_picmg_get_led_state(struct ipmi_intf * intf, int argc, char ** argv)
}
int
-ipmi_picmg_set_led_state(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_set_led_state(struct ipmi_intf * intf, char ** argv)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -1410,7 +1508,7 @@ ipmi_picmg_set_led_state(struct ipmi_intf * intf, int argc, char ** argv)
}
int
-ipmi_picmg_get_power_level(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_get_power_level(struct ipmi_intf * intf, char ** argv)
{
int i;
struct ipmi_rs * rsp;
@@ -1461,7 +1559,7 @@ ipmi_picmg_get_power_level(struct ipmi_intf * intf, int argc, char ** argv)
}
int
-ipmi_picmg_set_power_level(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_set_power_level(struct ipmi_intf * intf, char ** argv)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -1565,7 +1663,7 @@ ipmi_picmg_bused_resource(struct ipmi_intf * intf, t_picmg_bused_resource_mode m
}
int
-ipmi_picmg_fru_control(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_picmg_fru_control(struct ipmi_intf * intf, char ** argv)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
@@ -1654,7 +1752,7 @@ ipmi_picmg_clk_get(struct ipmi_intf * intf, uint8_t clk_id, int8_t clk_res,
return -1;
}
- if (rsp->ccode == 0 ) {
+ if (!rsp->ccode) {
enabled = (rsp->data[1]&0x8)!=0;
direction = (rsp->data[1]&0x4)!=0;
@@ -1785,24 +1883,24 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
int rc = 0;
int showProperties = 0;
- if (argc == 0 || (!strncmp(argv[0], "help", 4))) {
+ if (!argc || !strcmp(argv[0], "help")) {
ipmi_picmg_help();
return 0;
}
/* Get PICMG properties is called to obtain version information */
- if (argc !=0 && !strncmp(argv[0], "properties", 10)) {
+ if (!strcmp(argv[0], "properties")) {
showProperties =1;
}
rc = ipmi_picmg_properties(intf,showProperties);
/* address info command */
- if (!strncmp(argv[0], "addrinfo", 8)) {
+ if (!strcmp(argv[0], "addrinfo")) {
rc = ipmi_picmg_getaddr(intf, argc-1, &argv[1]);
}
- else if (!strncmp(argv[0], "busres", 6)) {
+ else if (!strcmp(argv[0], "busres")) {
if (argc > 1) {
- if (!strncmp(argv[1], "summary", 7)) {
+ if (!strcmp(argv[1], "summary")) {
ipmi_picmg_bused_resource(intf, PICMG_BUSED_RESOURCE_SUMMARY );
}
} else {
@@ -1810,9 +1908,9 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* fru control command */
- else if (!strncmp(argv[0], "frucontrol", 10)) {
+ else if (!strcmp(argv[0], "frucontrol")) {
if (argc > 2) {
- rc = ipmi_picmg_fru_control(intf, argc-1, &(argv[1]));
+ rc = ipmi_picmg_fru_control(intf, &(argv[1]));
}
else {
lprintf(LOG_NOTICE, "usage: frucontrol <FRU-ID> <OPTION>");
@@ -1830,9 +1928,9 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
/* fru activation command */
- else if (!strncmp(argv[0], "activate", 8)) {
+ else if (!strcmp(argv[0], "activate")) {
if (argc > 1) {
- rc = ipmi_picmg_fru_activation(intf, argc-1, &(argv[1]), PICMG_FRU_ACTIVATE);
+ rc = ipmi_picmg_fru_activation(intf, &(argv[1]), PICMG_FRU_ACTIVATE);
}
else {
lprintf(LOG_ERR, "Specify the FRU to activate.");
@@ -1841,9 +1939,9 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
/* fru deactivation command */
- else if (!strncmp(argv[0], "deactivate", 10)) {
+ else if (!strcmp(argv[0], "deactivate")) {
if (argc > 1) {
- rc = ipmi_picmg_fru_activation(intf, argc-1, &(argv[1]), PICMG_FRU_DEACTIVATE);
+ rc = ipmi_picmg_fru_activation(intf, &(argv[1]), PICMG_FRU_DEACTIVATE);
}else {
lprintf(LOG_ERR, "Specify the FRU to deactivate.");
return -1;
@@ -1851,17 +1949,17 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
/* activation policy command */
- else if (!strncmp(argv[0], "policy", 6)) {
+ else if (!strcmp(argv[0], "policy")) {
if (argc > 1) {
- if (!strncmp(argv[1], "get", 3)) {
+ if (!strcmp(argv[1], "get")) {
if (argc > 2) {
- rc = ipmi_picmg_fru_activation_policy_get(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_fru_activation_policy_get(intf, &(argv[2]));
} else {
lprintf(LOG_NOTICE, "usage: get <fruid>");
}
- } else if (!strncmp(argv[1], "set", 3)) {
+ } else if (!strcmp(argv[1], "set")) {
if (argc > 4) {
- rc = ipmi_picmg_fru_activation_policy_set(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_fru_activation_policy_set(intf, &(argv[2]));
} else {
lprintf(LOG_NOTICE, "usage: set <fruid> <lockmask> <lock>");
lprintf(LOG_NOTICE,
@@ -1884,18 +1982,18 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
/* portstate command */
- else if (!strncmp(argv[0], "portstate", 9)) {
+ else if (!strcmp(argv[0], "portstate")) {
lprintf(LOG_DEBUG,"PICMG: portstate API");
if (argc > 1) {
- if (!strncmp(argv[1], "get", 3)) {
+ if (!strcmp(argv[1], "get")) {
int32_t iface;
uint8_t channel = 0;
lprintf(LOG_DEBUG,"PICMG: get");
- if(!strncmp(argv[1], "getall", 6)) {
+ if(!strcmp(argv[1], "getall")) {
for(iface=0;iface<=PICMG_EKEY_MAX_INTERFACE;iface++) {
for(channel=1;channel<=PICMG_EKEY_MAX_CHANNEL;channel++) {
if(!(( iface == FRU_PICMGEXT_DESIGN_IF_FABRIC ) &&
@@ -1907,7 +2005,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
}
- else if(!strncmp(argv[1], "getgranted", 10)) {
+ else if(!strcmp(argv[1], "getgranted")) {
for(iface=0;iface<=PICMG_EKEY_MAX_INTERFACE;iface++) {
for(channel=1;channel<=PICMG_EKEY_MAX_CHANNEL;channel++) {
rc = ipmi_picmg_portstate_get(intf,iface,channel,
@@ -1915,7 +2013,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
}
- else if(!strncmp(argv[1], "getdenied", 9)){
+ else if(!strcmp(argv[1], "getdenied")){
for(iface=0;iface<=PICMG_EKEY_MAX_INTERFACE;iface++) {
for(channel=1;channel<=PICMG_EKEY_MAX_CHANNEL;channel++) {
rc = ipmi_picmg_portstate_get(intf,iface,channel,
@@ -1938,7 +2036,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_NOTICE, "<intf> <chn>|getall|getgranted|getdenied");
}
}
- else if (!strncmp(argv[1], "set", 3)) {
+ else if (!strcmp(argv[1], "set")) {
if (argc == 9) {
int32_t interface = 0;
int32_t port = 0;
@@ -1981,18 +2079,18 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* amc portstate command */
- else if (!strncmp(argv[0], "amcportstate", 12)) {
+ else if (!strcmp(argv[0], "amcportstate")) {
lprintf(LOG_DEBUG,"PICMG: amcportstate API");
if (argc > 1) {
- if (!strncmp(argv[1], "get", 3)){
+ if (!strcmp(argv[1], "get")){
int32_t device;
uint8_t channel;
lprintf(LOG_DEBUG,"PICMG: get");
- if(!strncmp(argv[1], "getall", 6)){
+ if(!strcmp(argv[1], "getall")){
int maxDevice = PICMG_EKEY_AMC_MAX_DEVICE;
if( PicmgCardType != PICMG_CARD_TYPE_ATCA ){
maxDevice = 0;
@@ -2004,7 +2102,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
}
- else if(!strncmp(argv[1], "getgranted", 10)){
+ else if(!strcmp(argv[1], "getgranted")){
int maxDevice = PICMG_EKEY_AMC_MAX_DEVICE;
if( PicmgCardType != PICMG_CARD_TYPE_ATCA ){
maxDevice = 0;
@@ -2016,7 +2114,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
}
- else if(!strncmp(argv[1], "getdenied", 9)){
+ else if(!strcmp(argv[1], "getdenied")){
int maxDevice = PICMG_EKEY_AMC_MAX_DEVICE;
if( PicmgCardType != PICMG_CARD_TYPE_ATCA ){
maxDevice = 0;
@@ -2049,7 +2147,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_NOTICE, "<chn> <device>|getall|getgranted|getdenied");
}
}
- else if (!strncmp(argv[1], "set", 3)) {
+ else if (!strcmp(argv[1], "set")) {
if (argc > 7) {
int32_t device = -1;
int32_t port = 0;
@@ -2096,35 +2194,35 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* ATCA led commands */
- else if (!strncmp(argv[0], "led", 3)) {
+ else if (!strcmp(argv[0], "led")) {
if (argc > 1) {
- if (!strncmp(argv[1], "prop", 4)) {
+ if (!strcmp(argv[1], "prop")) {
if (argc > 2) {
- rc = ipmi_picmg_get_led_properties(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_get_led_properties(intf, &(argv[2]));
}
else {
lprintf(LOG_NOTICE, "led prop <FRU-ID>");
}
}
- else if (!strncmp(argv[1], "cap", 3)) {
+ else if (!strcmp(argv[1], "cap")) {
if (argc > 3) {
- rc = ipmi_picmg_get_led_capabilities(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_get_led_capabilities(intf, &(argv[2]));
}
else {
lprintf(LOG_NOTICE, "led cap <FRU-ID> <LED-ID>");
}
}
- else if (!strncmp(argv[1], "get", 3)) {
+ else if (!strcmp(argv[1], "get")) {
if (argc > 3) {
- rc = ipmi_picmg_get_led_state(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_get_led_state(intf, &(argv[2]));
}
else {
lprintf(LOG_NOTICE, "led get <FRU-ID> <LED-ID>");
}
}
- else if (!strncmp(argv[1], "set", 3)) {
+ else if (!strcmp(argv[1], "set")) {
if (argc > 6) {
- rc = ipmi_picmg_set_led_state(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_set_led_state(intf, &(argv[2]));
}
else {
lprintf(LOG_NOTICE,
@@ -2164,11 +2262,11 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* power commands */
- else if (!strncmp(argv[0], "power", 5)) {
+ else if (!strcmp(argv[0], "power")) {
if (argc > 1) {
- if (!strncmp(argv[1], "get", 3)) {
+ if (!strcmp(argv[1], "get")) {
if (argc > 3) {
- rc = ipmi_picmg_get_power_level(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_get_power_level(intf, &(argv[2]));
}
else {
lprintf(LOG_NOTICE, "power get <FRU-ID> <type>");
@@ -2181,9 +2279,9 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
}
- else if (!strncmp(argv[1], "set", 3)) {
+ else if (!strcmp(argv[1], "set")) {
if (argc > 4) {
- rc = ipmi_picmg_set_power_level(intf, argc-1, &(argv[2]));
+ rc = ipmi_picmg_set_power_level(intf, &(argv[2]));
}
else {
lprintf(LOG_NOTICE, "power set <FRU-ID> <level> <present-desired>");
@@ -2208,9 +2306,9 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
}/* clk commands*/
- else if (!strncmp(argv[0], "clk", 3)) {
+ else if (!strcmp(argv[0], "clk")) {
if (argc > 1) {
- if (!strncmp(argv[1], "get", 3)) {
+ if (!strcmp(argv[1], "get")) {
int8_t clk_res = -1;
uint8_t clk_id;
uint8_t max_res = 15;
@@ -2219,7 +2317,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
max_res = 0;
}
- if(!strncmp(argv[1], "getall", 6)) {
+ if(!strcmp(argv[1], "getall")) {
if( verbose ) { printf("Getting all clock state\n") ;}
for(clk_res=0;clk_res<=max_res;clk_res++) {
for(clk_id=0;clk_id<=15;clk_id++) {
@@ -2228,7 +2326,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
}
- else if(!strncmp(argv[1], "getdenied", 6)) {
+ else if(!strcmp(argv[1], "getdenied")) {
if( verbose ) { printf("Getting disabled clocks\n") ;}
for(clk_res=0;clk_res<=max_res;clk_res++) {
for(clk_id=0;clk_id<=15;clk_id++) {
@@ -2237,7 +2335,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
}
}
}
- else if(!strncmp(argv[1], "getgranted", 6)) {
+ else if(!strcmp(argv[1], "getgranted")) {
if( verbose ) { printf("Getting enabled clocks\n") ;}
for(clk_res=0;clk_res<=max_res;clk_res++) {
for(clk_id=0;clk_id<=15;clk_id++) {
@@ -2266,7 +2364,7 @@ ipmi_picmg_main (struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
}
- else if (!strncmp(argv[1], "set", 3)) {
+ else if (!strcmp(argv[1], "set")) {
if (argc > 7) {
rc = ipmi_picmg_clk_set(intf, argc-1, &(argv[2]));
}
@@ -2330,7 +2428,7 @@ ipmi_picmg_ipmb_address(struct ipmi_intf *intf) {
uint8_t
picmg_discover(struct ipmi_intf *intf) {
/* Check if PICMG extension is available to use the function
- * GetDeviceLocator to retreive i2c address PICMG hack to set
+ * GetDeviceLocator to retrieve i2c address PICMG hack to set
* right IPMB address, If extension is not supported, should
* not give any problems
* PICMG Extension Version 2.0 (PICMG 3.0 Revision 1.0 ATCA) to
@@ -2353,13 +2451,13 @@ picmg_discover(struct ipmi_intf *intf) {
req.msg.data_len = 1;
msg_data = 0;
- lprintf(LOG_INFO, "Running Get PICMG Properties my_addr %#x, transit %#x, target %#x",
+ lprintf(LOG_DEBUG, "Running Get PICMG Properties my_addr %#x, transit %#x, target %#x",
intf->my_addr, intf->transit_addr, intf->target_addr);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- lprintf(LOG_INFO,"No response from Get PICMG Properties");
- } else if (rsp->ccode != 0) {
- lprintf(LOG_INFO,"Error response %#x from Get PICMG Properities",
+ if (!rsp) {
+ lprintf(LOG_DEBUG,"No response from Get PICMG Properties");
+ } else if (rsp->ccode) {
+ lprintf(LOG_DEBUG,"Error response %#x from Get PICMG Properties",
rsp->ccode);
} else if (rsp->data_len < 4) {
lprintf(LOG_INFO,"Invalid Get PICMG Properties response length %d",
@@ -2367,14 +2465,14 @@ picmg_discover(struct ipmi_intf *intf) {
} else if (rsp->data[0] != 0) {
lprintf(LOG_INFO,"Invalid Get PICMG Properties group extension %#x",
rsp->data[0]);
- } else if ((rsp->data[1] & 0x0F) != PICMG_EXTENSION_ATCA_MAJOR_VERSION
- && (rsp->data[1] & 0x0F) != PICMG_EXTENSION_AMC0_MAJOR_VERSION
- && (rsp->data[1] & 0x0F) != PICMG_EXTENSION_UTCA_MAJOR_VERSION) {
+ } else if ((rsp->data[1] & 0x0F) != PICMG_ATCA_MAJOR_VERSION
+ && (rsp->data[1] & 0x0F) != PICMG_AMC_MAJOR_VERSION
+ && (rsp->data[1] & 0x0F) != PICMG_UTCA_MAJOR_VERSION) {
lprintf(LOG_INFO,"Unknown PICMG Extension Version %d.%d",
(rsp->data[1] & 0x0F), (rsp->data[1] >> 4));
} else {
picmg_avail = 1;
- lprintf(LOG_INFO, "Discovered PICMG Extension Version %d.%d",
+ lprintf(LOG_DEBUG, "Discovered PICMG Extension Version %d.%d",
(rsp->data[1] & 0x0f), (rsp->data[1] >> 4));
}
diff --git a/lib/ipmi_quantaoem.c b/lib/ipmi_quantaoem.c
new file mode 100644
index 0000000..0ddcefd
--- /dev/null
+++ b/lib/ipmi_quantaoem.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2018 Quanta Computer Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Quanta Computer Inc. or the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
+ * Quanta Computer Inc. AND ITS LICENSORS SHALL NOT BE LIABLE
+ * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
+ * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
+ * Quanta Computer Inc. OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
+ * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
+ * 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 _XOPEN_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <signal.h>
+#include <ctype.h>
+#include <sys/time.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <sys/select.h>
+#include <termios.h>
+#include <ipmitool/ipmi.h>
+#include <ipmitool/ipmi_mc.h>
+#include <ipmitool/ipmi_intf.h>
+#include <ipmitool/helper.h>
+#include <ipmitool/log.h>
+#include <ipmitool/ipmi_sel.h>
+#include <ipmitool/ipmi_sdr.h>
+#include <ipmitool/ipmi_strings.h>
+#include <ipmitool/ipmi_channel.h>
+#include <ipmitool/ipmi_quantaoem.h>
+#include <ipmitool/ipmi_raw.h>
+
+/* Max Size of the description String to be displyed for the Each sel entry */
+#define SIZE_OF_DESC 128
+
+#define CPU_SHIFT 6
+#define CPU_MASK 0X03
+#define CPU_NUM(x) (((x) >> CPU_SHIFT) & CPU_MASK)
+
+#define CHANNEL_BASE 0x41
+#define CHANNEL_SHIFT 3
+#define CHANNEL_MASK 0x07
+#define CHANNEL_OFFSET(x) (((x) >> CHANNEL_SHIFT) & CHANNEL_MASK)
+#define CHANNEL_NUM(x) (CHANNEL_BASE + CHANNEL_OFFSET(x))
+
+#define DIMM_MASK 0x07
+#define DIMM_NUM(x) ((x) & DIMM_MASK)
+
+#define GET_PLATFORM_ID_DATA_SIZE 4
+
+// Magic code to check if it's valid command
+#define QCT_MAGIC_1 0x4C
+#define QCT_MAGIC_2 0x1C
+#define QCT_MAGIC_3 0x00
+#define QCT_MAGIC_4 0x02
+
+qct_platform_t
+oem_qct_get_platform_id(struct ipmi_intf *intf)
+{
+ /* Execute a Get platform ID command to determine the board */
+ struct ipmi_rs *rsp;
+ struct ipmi_rq req;
+ qct_platform_t platform_id;
+ uint8_t msg_data[GET_PLATFORM_ID_DATA_SIZE];
+
+ /* Ask for IPMI v2 data as well */
+ msg_data[0] = QCT_MAGIC_1;
+ msg_data[1] = QCT_MAGIC_2;
+ msg_data[2] = QCT_MAGIC_3;
+ msg_data[3] = QCT_MAGIC_4;
+
+ memset(&req, 0, sizeof(req));
+ req.msg.netfn = OEM_QCT_NETFN;
+ req.msg.cmd = OEM_QCT_GET_INFO;
+ req.msg.data = msg_data;
+ req.msg.data_len = sizeof(msg_data);
+
+ rsp = intf->sendrecv(intf, &req);
+ if (!rsp) {
+ lprintf(LOG_ERR, "Get Platform ID command failed");
+ return 0;
+ }
+ if (rsp->ccode) {
+ lprintf(LOG_ERR, "Get Platform ID command failed: %#x %s",
+ rsp->ccode, val2str(rsp->ccode, completion_code_vals));
+ return 0;
+ }
+ platform_id = rsp->data[0];
+ lprintf(LOG_DEBUG,"Platform ID: %hhx", rsp->data[0]);
+ return platform_id;
+}
+
+char *
+oem_qct_get_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
+{
+ struct ipmi_rs *rsp;
+ struct ipmi_rq req;
+ char *desc = NULL;
+ int data;
+ int sensor_type;
+ qct_platform_t platform_id;
+
+ /* Get the OEM event Bytes of the SEL Records byte 15 to data */
+ data = rec->sel_type.standard_type.event_data[2];
+ /* Check for the Standard Event type == 0x6F */
+ if (rec->sel_type.standard_type.event_type != 0x6F) {
+ goto out;
+ }
+ /* Allocate mem for the Description string */
+ desc = malloc(SIZE_OF_DESC);
+ if (!desc) {
+ lprintf(LOG_ERR, "ipmitool: malloc failure");
+ goto out;
+ }
+ memset(desc, 0, SIZE_OF_DESC);
+ sensor_type = rec->sel_type.standard_type.sensor_type;
+ switch (sensor_type) {
+ case SENSOR_TYPE_MEMORY:
+ memset(&req, 0, sizeof (req));
+ req.msg.netfn = IPMI_NETFN_APP;
+ req.msg.lun = 0;
+ req.msg.cmd = BMC_GET_DEVICE_ID;
+ req.msg.data = NULL;
+ req.msg.data_len = 0;
+
+ rsp = intf->sendrecv(intf, &req);
+ if (!rsp) {
+ lprintf(LOG_ERR, " Error getting system info");
+ goto out;
+ } else if (rsp->ccode) {
+ lprintf(LOG_ERR, " Error getting system info: %s",
+ val2str(rsp->ccode, completion_code_vals));
+ goto out;
+ }
+ /* check the platform type */
+ platform_id = oem_qct_get_platform_id(intf);
+ if (OEM_QCT_PLATFORM_PURLEY == platform_id) {
+ snprintf(desc, SIZE_OF_DESC, "CPU%d_%c%d",
+ CPU_NUM(data),
+ CHANNEL_NUM(data),
+ DIMM_NUM(data));
+ }
+ break;
+ default:
+ goto out;
+ }
+ return desc;
+out:
+ if (desc) {
+ free(desc);
+ desc = NULL;
+ }
+ return desc;
+}
diff --git a/lib/ipmi_raw.c b/lib/ipmi_raw.c
index 92c0177..a8a42a0 100644
--- a/lib/ipmi_raw.c
+++ b/lib/ipmi_raw.c
@@ -101,11 +101,11 @@ ipmi_master_write_read(struct ipmi_intf * intf, uint8_t bus, uint8_t addr,
}
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "I2C Master Write-Read command failed");
return NULL;
}
- else if (rsp->ccode > 0) {
+ else if (rsp->ccode) {
switch (rsp->ccode) {
case 0x81:
lprintf(LOG_ERR, "I2C Master Write-Read command failed: Lost Arbitration");
@@ -145,7 +145,7 @@ ipmi_rawspd_main(struct ipmi_intf * intf, int argc, char ** argv)
memset(spd_data, 0, RAW_SPD_SIZE);
- if (argc < 2 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc < 2 || !strcmp(argv[0], "help")) {
lprintf(LOG_NOTICE, "usage: spd <i2cbus> <i2caddr> [channel] [maxread]");
return 0;
}
@@ -171,7 +171,7 @@ ipmi_rawspd_main(struct ipmi_intf * intf, int argc, char ** argv)
for (i = 0; i < RAW_SPD_SIZE; i+= msize) {
rsp = ipmi_master_write_read(intf, i2cbus, i2caddr,
(uint8_t *)&i, 1, msize );
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to perform I2C Master Write-Read");
return -1;
}
@@ -190,6 +190,9 @@ static void rawi2c_usage(void)
lprintf(LOG_NOTICE, " chan=0 is default, bus= must be specified to use chan=");
}
+#define BUS_KW "bus="
+#define CHAN_KW "chan="
+
int
ipmi_rawi2c_main(struct ipmi_intf * intf, int argc, char ** argv)
{
@@ -203,25 +206,25 @@ ipmi_rawi2c_main(struct ipmi_intf * intf, int argc, char ** argv)
int i = 0;
/* handle bus= argument */
- if (argc > 2 && strncmp(argv[0], "bus=", 4) == 0) {
+ if (argc > 2 && !strncmp(argv[0], BUS_KW, strlen(BUS_KW))) {
i = 1;
- if (strncmp(argv[0], "bus=public", 10) == 0)
+ if (!strcmp(argv[0], BUS_KW "public"))
bus = 0;
- else if (sscanf(argv[0], "bus=%u", &rbus) == 1)
+ else if (sscanf(argv[0], BUS_KW "%u", &rbus) == 1)
bus = ((rbus & 7) << 1) | 1;
else
bus = 0;
/* handle channel= argument
* the bus= argument must be supplied first on command line */
- if (argc > 3 && strncmp(argv[1], "chan=", 5) == 0) {
+ if (argc > 3 && !strncmp(argv[1], CHAN_KW, strlen(CHAN_KW))) {
i = 2;
- if (sscanf(argv[1], "chan=%u", &rbus) == 1)
+ if (sscanf(argv[1], CHAN_KW "%u", &rbus) == 1)
bus |= rbus << 4;
}
}
- if ((argc-i) < 2 || strncmp(argv[0], "help", 4) == 0) {
+ if ((argc - i) < 2 || !strcmp(argv[0], "help")) {
rawi2c_usage();
return 0;
}
@@ -259,7 +262,7 @@ ipmi_rawi2c_main(struct ipmi_intf * intf, int argc, char ** argv)
printbuf(wdata, wsize, "WRITE DATA");
rsp = ipmi_master_write_read(intf, bus, i2caddr, wdata, wsize, rsize);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to perform I2C Master Write-Read");
return -1;
}
@@ -322,7 +325,7 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
int i;
uint8_t data[256];
- if (argc == 1 && strncmp(argv[0], "help", 4) == 0) {
+ if (argc == 1 && !strcmp(argv[0], "help")) {
ipmi_raw_help();
return 0;
}
@@ -379,13 +382,13 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to send RAW command "
"(channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x)",
intf->target_channel & 0x0f, req.msg.netfn, req.msg.lun, req.msg.cmd);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Unable to send RAW command "
"(channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x rsp=0x%x): %s",
intf->target_channel & 0x0f, req.msg.netfn, req.msg.lun, req.msg.cmd, rsp->ccode,
@@ -417,7 +420,7 @@ ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
*/
int
is_valid_param(const char *input_param, uint8_t *uchr_ptr, const char *label) {
- if (input_param == NULL || label == NULL) {
+ if (!input_param || !label) {
lprintf(LOG_ERROR, "ERROR: NULL pointer passed.");
return (-1);
}
diff --git a/lib/ipmi_sdr.c b/lib/ipmi_sdr.c
index 2a9cbe3..42ae9f9 100644
--- a/lib/ipmi_sdr.c
+++ b/lib/ipmi_sdr.c
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012 Hewlett-Packard Development Company, L.P.
+ * Copyright 2020 Joyent, Inc.
*
* Based on code from
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
@@ -32,7 +33,6 @@
* 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 _BSD_SOURCE
#include <string.h>
@@ -53,6 +53,7 @@
#include <ipmitool/ipmi_entity.h>
#include <ipmitool/ipmi_constants.h>
#include <ipmitool/ipmi_strings.h>
+#include <ipmitool/ipmi_time.h>
#if HAVE_CONFIG_H
# include <config.h>
@@ -68,41 +69,211 @@ static struct sdr_record_list *sdr_list_head = NULL;
static struct sdr_record_list *sdr_list_tail = NULL;
static struct ipmi_sdr_iterator *sdr_list_itr = NULL;
-void printf_sdr_usage();
+/* IPMI 2.0 Table 43-15, Sensor Unit Type Codes */
+#define UNIT_TYPE_MAX 92 /* This is the ID of "grams" */
+#define UNIT_TYPE_LONGEST_NAME 19 /* This is the length of "color temp deg K" */
+static const char *unit_desc[] = {
+ "unspecified",
+ "degrees C",
+ "degrees F",
+ "degrees K",
+ "Volts",
+ "Amps",
+ "Watts",
+ "Joules",
+ "Coulombs",
+ "VA",
+ "Nits",
+ "lumen",
+ "lux",
+ "Candela",
+ "kPa",
+ "PSI",
+ "Newton",
+ "CFM",
+ "RPM",
+ "Hz",
+ "microsecond",
+ "millisecond",
+ "second",
+ "minute",
+ "hour",
+ "day",
+ "week",
+ "mil",
+ "inches",
+ "feet",
+ "cu in",
+ "cu feet",
+ "mm",
+ "cm",
+ "m",
+ "cu cm",
+ "cu m",
+ "liters",
+ "fluid ounce",
+ "radians",
+ "steradians",
+ "revolutions",
+ "cycles",
+ "gravities",
+ "ounce",
+ "pound",
+ "ft-lb",
+ "oz-in",
+ "gauss",
+ "gilberts",
+ "henry",
+ "millihenry",
+ "farad",
+ "microfarad",
+ "ohms",
+ "siemens",
+ "mole",
+ "becquerel",
+ "PPM",
+ "reserved",
+ "Decibels",
+ "DbA",
+ "DbC",
+ "gray",
+ "sievert",
+ "color temp deg K",
+ "bit",
+ "kilobit",
+ "megabit",
+ "gigabit",
+ "byte",
+ "kilobyte",
+ "megabyte",
+ "gigabyte",
+ "word",
+ "dword",
+ "qword",
+ "line",
+ "hit",
+ "miss",
+ "retry",
+ "reset",
+ "overflow",
+ "underrun",
+ "collision",
+ "packets",
+ "messages",
+ "characters",
+ "error",
+ "correctable error",
+ "uncorrectable error",
+ "fatal error",
+ "grams"
+};
+
+/* sensor type codes (IPMI v1.5 table 36.3)
+ / Updated to v2.0 Table 42-3, Sensor Type Codes */
+static const char *sensor_type_desc[] = {
+ "reserved",
+ "Temperature",
+ "Voltage",
+ "Current",
+ "Fan",
+ "Physical Security",
+ "Platform Security",
+ "Processor",
+ "Power Supply",
+ "Power Unit",
+ "Cooling Device",
+ "Other",
+ "Memory",
+ "Drive Slot / Bay",
+ "POST Memory Resize",
+ "System Firmwares",
+ "Event Logging Disabled",
+ "Watchdog1",
+ "System Event",
+ "Critical Interrupt",
+ "Button",
+ "Module / Board",
+ "Microcontroller",
+ "Add-in Card",
+ "Chassis",
+ "Chip Set",
+ "Other FRU",
+ "Cable / Interconnect",
+ "Terminator",
+ "System Boot Initiated",
+ "Boot Error",
+ "OS Boot",
+ "OS Critical Stop",
+ "Slot / Connector",
+ "System ACPI Power State",
+ "Watchdog2",
+ "Platform Alert",
+ "Entity Presence",
+ "Monitor ASIC",
+ "LAN",
+ "Management Subsys Health",
+ "Battery",
+ "Session Audit",
+ "Version Change",
+ "FRU State"
+};
-/* From src/plugins/ipmi_intf.c: */
-uint16_t
-ipmi_intf_get_max_response_data_size(struct ipmi_intf * intf);
+void printf_sdr_usage();
-/* ipmi_sdr_get_unit_string - return units for base/modifier
+/** ipmi_sdr_get_unit_string - return units for base/modifier
*
- * @pct: units are a percentage
- * @type: unit type
- * @base: base
- * @modifier: modifier
+ * @param[in] pct Indicates that units are a percentage
+ * @param[in] relation Modifier unit to base unit relation
+ * (SDR_UNIT_MOD_NONE, SDR_UNIT_MOD_MUL,
+ * or SDR_UNIT_MOD_DIV)
+ * @param[in] base The base unit type id
+ * @param[in] modifier The modifier unit type id
*
- * returns pointer to static string
+ * @returns a pointer to static string
*/
const char *
-ipmi_sdr_get_unit_string(uint8_t pct, uint8_t type, uint8_t base, uint8_t modifier)
+ipmi_sdr_get_unit_string(bool pct, uint8_t relation,
+ uint8_t base, uint8_t modifier)
{
- static char unitstr[16];
+ /*
+ * Twice as long as the longest possible unit name, plus
+ * two characters for '%' and relation (either '*' or '/'),
+ * plus the terminating null-byte.
+ */
+ static char unitstr[2 * UNIT_TYPE_LONGEST_NAME + 2 + 1];
+
/*
* By default, if units are supposed to be percent, we will pre-pend
* the percent string to the textual representation of the units.
*/
- char *pctstr = pct ? "% " : "";
- memset(unitstr, 0, sizeof (unitstr));
- switch (type) {
- case 2:
- snprintf(unitstr, sizeof (unitstr), "%s%s * %s",
- pctstr, unit_desc[base], unit_desc[modifier]);
+ const char *pctstr = pct ? "% " : "";
+ const char *basestr;
+ const char *modstr;
+
+ if (base <= UNIT_TYPE_MAX) {
+ basestr = unit_desc[base];
+ }
+ else {
+ basestr = "invalid";
+ }
+
+ if (modifier <= UNIT_TYPE_MAX) {
+ modstr = unit_desc[modifier];
+ }
+ else {
+ modstr = "invalid";
+ }
+
+ switch (relation) {
+ case SDR_UNIT_MOD_MUL:
+ snprintf(unitstr, sizeof (unitstr), "%s%s*%s",
+ pctstr, basestr, modstr);
break;
- case 1:
+ case SDR_UNIT_MOD_DIV:
snprintf(unitstr, sizeof (unitstr), "%s%s/%s",
- pctstr, unit_desc[base], unit_desc[modifier]);
+ pctstr, basestr, modstr);
break;
- case 0:
+ case SDR_UNIT_MOD_NONE:
default:
/*
* Display the text "percent" only when the Base unit is
@@ -111,8 +282,8 @@ ipmi_sdr_get_unit_string(uint8_t pct, uint8_t type, uint8_t base, uint8_t modifi
if (base == 0 && pct) {
snprintf(unitstr, sizeof(unitstr), "percent");
} else {
- snprintf(unitstr, sizeof (unitstr), "%s%s",
- pctstr, unit_desc[base]);
+ snprintf(unitstr, sizeof (unitstr), "%s%s",
+ pctstr, basestr);
}
break;
}
@@ -138,8 +309,8 @@ sdr_sensor_has_analog_reading(struct ipmi_intf *intf,
* But... HP didn't interpret this as meaning that "Only Threshold
* Sensors" can provide analog readings. So, HP packed analog
* readings into some of their non-Threshold Sensor. There is
- * nothing that explictly prohibits this in the spec, so if
- * an Analog reading is available in a Non-Threshod sensor and
+ * nothing that explicitly prohibits this in the spec, so if
+ * an Analog reading is available in a Non-Threshold sensor and
* there are units specified for identifying the reading then
* we do an analog conversion even though the sensor is
* non-Threshold. To be safe, we provide this extension for
@@ -205,7 +376,7 @@ sdr_convert_sensor_reading(struct sdr_record_full_sensor *sensor, uint8_t val)
case 1:
if (val & 0x80)
val++;
- /* Deliberately fall through to case 2. */
+ /* fall through */
case 2:
result = (double) (((m * (int8_t) val) +
(b * pow(10, k1))) * pow(10, k2));
@@ -285,7 +456,7 @@ sdr_convert_sensor_hysterisis(struct sdr_record_full_sensor *sensor, uint8_t val
case 1:
if (val & 0x80)
val++;
- /* Deliberately fall through to case 2. */
+ /* fall through */
case 2:
result = (double) (((m * (int8_t) val) ) * pow(10, k2));
break;
@@ -360,7 +531,7 @@ sdr_convert_sensor_tolerance(struct sdr_record_full_sensor *sensor, uint8_t val)
case 1:
if (val & 0x80)
val++;
- /* Deliberately fall through to case 2. */
+ /* fall through */
case 2:
result = (double) (((m * ((double)((int8_t) val)/2))) * pow(10, k2));
break;
@@ -691,7 +862,7 @@ ipmi_sdr_get_sensor_event_enable(struct ipmi_intf *intf, uint8_t sensor,
/* ipmi_sdr_get_thresh_status - threshold status indicator
*
- * @rsp: response from Get Sensor Reading comand
+ * @rsp: response from Get Sensor Reading command
* @validread: validity of the status field argument
* @invalidstr: string to return if status field is not valid
*
@@ -756,7 +927,7 @@ ipmi_sdr_get_thresh_status(struct sensor_reading *sr, const char *invalidstr)
return "ok";
}
-/* ipmi_sdr_get_header - retreive SDR record header
+/* ipmi_sdr_get_header - retrieve SDR record header
*
* @intf: ipmi interface
* @itr: sdr iterator
@@ -793,7 +964,7 @@ ipmi_sdr_get_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
for (try = 0; try < 5; try++) {
sdr_rq.reserve_id = itr->reservation;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SDR %04x command failed",
itr->next);
continue;
@@ -811,7 +982,7 @@ ipmi_sdr_get_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
"Unable to renew SDR reservation");
return NULL;
}
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Get SDR %04x command failed: %s",
itr->next, val2str(rsp->ccode,
completion_code_vals));
@@ -859,7 +1030,7 @@ ipmi_sdr_get_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
return &sdr_rs;
}
-/* ipmi_sdr_get_next_header - retreive next SDR header
+/* ipmi_sdr_get_next_header - retrieve next SDR header
*
* @intf: ipmi interface
* @itr: sdr iterator
@@ -876,7 +1047,7 @@ ipmi_sdr_get_next_header(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
return NULL;
header = ipmi_sdr_get_header(intf, itr);
- if (header == NULL)
+ if (!header)
return NULL;
itr->next = header->next;
@@ -959,13 +1130,13 @@ ipmi_sdr_print_sensor_event_status(struct ipmi_intf *intf,
rsp = ipmi_sdr_get_sensor_event_status(intf, sensor_num,
target, lun, channel);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_DEBUG,
"Error reading event status for sensor #%02x",
sensor_num);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_DEBUG,
"Error reading event status for sensor #%02x: %s",
sensor_num, val2str(rsp->ccode, completion_code_vals));
@@ -1173,13 +1344,13 @@ ipmi_sdr_print_sensor_event_enable(struct ipmi_intf *intf,
rsp = ipmi_sdr_get_sensor_event_enable(intf, sensor_num,
target, lun, channel);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_DEBUG,
"Error reading event enable for sensor #%02x",
sensor_num);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_DEBUG,
"Error reading event enable for sensor #%02x: %s",
sensor_num, val2str(rsp->ccode, completion_code_vals));
@@ -1399,7 +1570,7 @@ ipmi_sdr_read_sensor_value(struct ipmi_intf *intf,
{
static struct sensor_reading sr;
- if (sensor == NULL)
+ if (!sensor)
return NULL;
/* Initialize to reading valid value of zero */
@@ -1439,7 +1610,7 @@ ipmi_sdr_read_sensor_value(struct ipmi_intf *intf,
sr.s_a_units = ""; /* no converted analog units units */
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_DEBUG, "Error reading sensor %s (#%02x)",
sr.s_id, sensor->keys.sensor_num);
return &sr;
@@ -1525,7 +1696,7 @@ ipmi_sdr_print_sensor_fc(struct ipmi_intf *intf,
sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 2);
- if (sr == NULL)
+ if (!sr)
return -1;
target = sensor->keys.owner_id;
@@ -1978,7 +2149,7 @@ ipmi_sdr_print_discrete_state_mini(struct ipmi_intf *intf,
printf("%s", header);
for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type);
- evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) {
+ evt; evt = ipmi_get_next_event_sensor_type(evt)) {
if (evt->data != 0xFF) {
continue;
}
@@ -2028,7 +2199,7 @@ ipmi_sdr_print_discrete_state(struct ipmi_intf *intf, const char *desc,
return;
for (evt = ipmi_get_first_event_sensor_type(intf, sensor_type, event_type);
- evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) {
+ evt; evt = ipmi_get_next_event_sensor_type(evt)) {
if (evt->data != 0xFF) {
continue;
}
@@ -2080,11 +2251,11 @@ ipmi_sdr_print_sensor_eventonly(struct ipmi_intf *intf,
{
char desc[17];
- if (sensor == NULL)
+ if (!sensor)
return -1;
memset(desc, 0, sizeof (desc));
- snprintf(desc, (sensor->id_code & 0x1f) + 1, "%s", sensor->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (sensor->id_code & 0x1f) + 1, sensor->id_string);
if (verbose) {
printf("Sensor ID : %s (0x%x)\n",
@@ -2119,23 +2290,21 @@ ipmi_sdr_print_sensor_eventonly(struct ipmi_intf *intf,
/* ipmi_sdr_print_sensor_mc_locator - print SDR MC locator record
*
- * @intf: ipmi interface
* @mc: mc locator sdr record
*
* returns 0 on success
* returns -1 on error
*/
int
-ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf *intf,
- struct sdr_record_mc_locator *mc)
+ipmi_sdr_print_sensor_mc_locator(struct sdr_record_mc_locator *mc)
{
char desc[17];
- if (mc == NULL)
+ if (!mc)
return -1;
memset(desc, 0, sizeof (desc));
- snprintf(desc, (mc->id_code & 0x1f) + 1, "%s", mc->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (mc->id_code & 0x1f) + 1, mc->id_string);
if (verbose == 0) {
if (csv_output)
@@ -2215,20 +2384,18 @@ ipmi_sdr_print_sensor_mc_locator(struct ipmi_intf *intf,
/* ipmi_sdr_print_sensor_generic_locator - print generic device locator record
*
- * @intf: ipmi interface
* @gen: generic device locator sdr record
*
* returns 0 on success
* returns -1 on error
*/
int
-ipmi_sdr_print_sensor_generic_locator(struct ipmi_intf *intf,
- struct sdr_record_generic_locator *dev)
+ipmi_sdr_print_sensor_generic_locator(struct sdr_record_generic_locator *dev)
{
char desc[17];
memset(desc, 0, sizeof (desc));
- snprintf(desc, (dev->id_code & 0x1f) + 1, "%s", dev->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (dev->id_code & 0x1f) + 1, dev->id_string);
if (!verbose) {
if (csv_output)
@@ -2272,20 +2439,18 @@ ipmi_sdr_print_sensor_generic_locator(struct ipmi_intf *intf,
/* ipmi_sdr_print_sensor_fru_locator - print FRU locator record
*
- * @intf: ipmi interface
* @fru: fru locator sdr record
*
* returns 0 on success
* returns -1 on error
*/
int
-ipmi_sdr_print_sensor_fru_locator(struct ipmi_intf *intf,
- struct sdr_record_fru_locator *fru)
+ipmi_sdr_print_sensor_fru_locator(struct sdr_record_fru_locator *fru)
{
char desc[17];
memset(desc, 0, sizeof (desc));
- snprintf(desc, (fru->id_code & 0x1f) + 1, "%s", fru->id_string);
+ snprintf(desc, sizeof(desc), "%.*s", (fru->id_code & 0x1f) + 1, fru->id_string);
if (!verbose) {
if (csv_output)
@@ -2329,32 +2494,15 @@ ipmi_sdr_print_sensor_fru_locator(struct ipmi_intf *intf,
return 0;
}
-/* ipmi_sdr_print_sensor_entity_assoc - print SDR entity association record
- *
- * @intf: ipmi interface
- * @mc: entity association sdr record
- *
- * returns 0 on success
- * returns -1 on error
- */
-int
-ipmi_sdr_print_sensor_entity_assoc(struct ipmi_intf *intf,
- struct sdr_record_entity_assoc *assoc)
-{
- return 0;
-}
-
/* ipmi_sdr_print_sensor_oem_intel - print Intel OEM sensors
*
- * @intf: ipmi interface
* @oem: oem sdr record
*
* returns 0 on success
* returns -1 on error
*/
static int
-ipmi_sdr_print_sensor_oem_intel(struct ipmi_intf *intf,
- struct sdr_record_oem *oem)
+ipmi_sdr_print_sensor_oem_intel(struct sdr_record_oem *oem)
{
switch (oem->data[3]) { /* record sub-type */
case 0x02: /* Power Unit Map */
@@ -2435,20 +2583,19 @@ ipmi_sdr_print_sensor_oem_intel(struct ipmi_intf *intf,
* a particular BMC might stuff into its OEM records. The
* records are keyed off manufacturer ID and record subtypes.
*
- * @intf: ipmi interface
* @oem: oem sdr record
*
* returns 0 on success
* returns -1 on error
*/
static int
-ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
+ipmi_sdr_print_sensor_oem(struct sdr_record_oem *oem)
{
int rc = 0;
- if (oem == NULL)
+ if (!oem)
return -1;
- if (oem->data_len == 0 || oem->data == NULL)
+ if (oem->data_len == 0 || !oem->data)
return -1;
if (verbose > 2)
@@ -2457,7 +2604,7 @@ ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
/* intel manufacturer id */
if (oem->data[0] == 0x57 &&
oem->data[1] == 0x01 && oem->data[2] == 0x00) {
- rc = ipmi_sdr_print_sensor_oem_intel(intf, oem);
+ rc = ipmi_sdr_print_sensor_oem_intel(oem);
}
return rc;
@@ -2465,7 +2612,6 @@ ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
/* ipmi_sdr_print_name_from_rawentry - Print SDR name from raw data
*
- * @intf: ipmi interface
* @type: sensor type
* @raw: raw sensor data
*
@@ -2473,7 +2619,7 @@ ipmi_sdr_print_sensor_oem(struct ipmi_intf *intf, struct sdr_record_oem *oem)
* returns -1 on error
*/
int
-ipmi_sdr_print_name_from_rawentry(struct ipmi_intf *intf, uint16_t id,
+ipmi_sdr_print_name_from_rawentry(uint16_t id,
uint8_t type, uint8_t *raw)
{
union {
@@ -2489,35 +2635,43 @@ ipmi_sdr_print_name_from_rawentry(struct ipmi_intf *intf, uint16_t id,
int rc =0;
char desc[17];
+ const char *id_string;
+ uint8_t id_code;
memset(desc, ' ', sizeof (desc));
switch ( type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
record.full = (struct sdr_record_full_sensor *) raw;
- snprintf(desc, (record.full->id_code & 0x1f) +1, "%s",
- (const char *)record.full->id_string);
+ id_code = record.full->id_code;
+ id_string = record.full->id_string;
break;
+
case SDR_RECORD_TYPE_COMPACT_SENSOR:
record.compact = (struct sdr_record_compact_sensor *) raw ;
- snprintf(desc, (record.compact->id_code & 0x1f) +1, "%s",
- (const char *)record.compact->id_string);
+ id_code = record.compact->id_code;
+ id_string = record.compact->id_string;
break;
+
case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
record.eventonly = (struct sdr_record_eventonly_sensor *) raw ;
- snprintf(desc, (record.eventonly->id_code & 0x1f) +1, "%s",
- (const char *)record.eventonly->id_string);
- break;
+ id_code = record.eventonly->id_code;
+ id_string = record.eventonly->id_string;
+ break;
+
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
record.mcloc = (struct sdr_record_mc_locator *) raw ;
- snprintf(desc, (record.mcloc->id_code & 0x1f) +1, "%s",
- (const char *)record.mcloc->id_string);
+ id_code = record.mcloc->id_code;
+ id_string = record.mcloc->id_string;
break;
+
default:
rc = -1;
- break;
- }
+ }
+ if (!rc) {
+ snprintf(desc, sizeof(desc), "%.*s", (id_code & 0x1f) + 1, id_string);
+ }
- lprintf(LOG_INFO, "ID: 0x%04x , NAME: %-16s", id, desc);
+ lprintf(LOG_INFO, "ID: 0x%04x , NAME: %-16s", id, desc);
return rc;
}
@@ -2551,35 +2705,27 @@ ipmi_sdr_print_rawentry(struct ipmi_intf *intf, uint8_t type,
*) raw);
break;
case SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_generic_locator(intf,
- (struct
+ rc = ipmi_sdr_print_sensor_generic_locator((struct
sdr_record_generic_locator
*) raw);
break;
case SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_fru_locator(intf,
- (struct
+ rc = ipmi_sdr_print_sensor_fru_locator((struct
sdr_record_fru_locator
*) raw);
break;
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_mc_locator(intf,
- (struct
+ rc = ipmi_sdr_print_sensor_mc_locator((struct
sdr_record_mc_locator *)
raw);
break;
case SDR_RECORD_TYPE_ENTITY_ASSOC:
- rc = ipmi_sdr_print_sensor_entity_assoc(intf,
- (struct
- sdr_record_entity_assoc
- *) raw);
break;
case SDR_RECORD_TYPE_OEM:{
struct sdr_record_oem oem;
oem.data = raw;
oem.data_len = len;
- rc = ipmi_sdr_print_sensor_oem(intf,
- (struct sdr_record_oem *)
+ rc = ipmi_sdr_print_sensor_oem((struct sdr_record_oem *)
&oem);
break;
}
@@ -2616,24 +2762,19 @@ ipmi_sdr_print_listentry(struct ipmi_intf *intf, struct sdr_record_list *entry)
entry->record.eventonly);
break;
case SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_generic_locator(intf,
- entry->record.
+ rc = ipmi_sdr_print_sensor_generic_locator(entry->record.
genloc);
break;
case SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_fru_locator(intf,
- entry->record.fruloc);
+ rc = ipmi_sdr_print_sensor_fru_locator(entry->record.fruloc);
break;
case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
- rc = ipmi_sdr_print_sensor_mc_locator(intf,
- entry->record.mcloc);
+ rc = ipmi_sdr_print_sensor_mc_locator(entry->record.mcloc);
break;
case SDR_RECORD_TYPE_ENTITY_ASSOC:
- rc = ipmi_sdr_print_sensor_entity_assoc(intf,
- entry->record.entassoc);
break;
case SDR_RECORD_TYPE_OEM:
- rc = ipmi_sdr_print_sensor_oem(intf, entry->record.oem);
+ rc = ipmi_sdr_print_sensor_oem(entry->record.oem);
break;
case SDR_RECORD_TYPE_DEVICE_ENTITY_ASSOC:
case SDR_RECORD_TYPE_MC_CONFIRMATION:
@@ -2662,15 +2803,15 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
lprintf(LOG_DEBUG, "Querying SDR for sensor list");
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1;
}
}
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
if (type != e->type && type != 0xff && type != 0xfe)
continue;
if (type == 0xfe &&
@@ -2681,21 +2822,21 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
rc = -1;
}
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
+ if (!rec) {
lprintf(LOG_ERR, "ipmitool: ipmi_sdr_get_record() failed");
rc = -1;
continue;
}
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
- if (rec != NULL) {
+ if (rec) {
free(rec);
rec = NULL;
}
@@ -2734,7 +2875,7 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -2753,7 +2894,7 @@ ipmi_sdr_print_sdr(struct ipmi_intf *intf, uint8_t type)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -2792,9 +2933,9 @@ ipmi_sdr_get_reservation(struct ipmi_intf *intf, int use_builtin,
rsp = intf->sendrecv(intf, &req);
/* be slient for errors, they are handled by calling function */
- if (rsp == NULL)
+ if (!rsp)
return -1;
- if (rsp->ccode > 0)
+ if (rsp->ccode)
return -1;
*reserve_id = ((struct sdr_reserve_repo_rs *) &(rsp->data))->reserve_id;
@@ -2820,7 +2961,7 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin)
struct ipm_devid_rsp *devid;
itr = malloc(sizeof (struct ipmi_sdr_iterator));
- if (itr == NULL) {
+ if (!itr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
@@ -2833,13 +2974,13 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Device ID command failed");
free(itr);
itr = NULL;
return NULL;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Device ID command failed: %#x %s",
rsp->ccode, val2str(rsp->ccode, completion_code_vals));
free(itr);
@@ -2875,13 +3016,13 @@ ipmi_sdr_start(struct ipmi_intf *intf, int use_builtin)
req.msg.cmd = GET_SDR_REPO_INFO;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error obtaining SDR info");
free(itr);
itr = NULL;
return NULL;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error obtaining SDR info: %s",
val2str(rsp->ccode, completion_code_vals));
free(itr);
@@ -2973,7 +3114,7 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
return NULL;
data = malloc(len + 1);
- if (data == NULL) {
+ if (!data) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
@@ -3019,7 +3160,8 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
sdr_rq.length, sdr_rq.offset);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+
+ if (!rsp || rsp->ccode == IPMI_CC_CANT_RET_NUM_REQ_BYTES) {
sdr_max_read_len = sdr_rq.length - 1;
if (sdr_max_read_len > 0) {
/* no response may happen if requests are bridged
@@ -3030,14 +3172,7 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
data = NULL;
return NULL;
}
- }
-
- switch (rsp->ccode) {
- case 0xca:
- /* read too many bytes at once */
- sdr_max_read_len = sdr_rq.length - 1;
- continue;
- case 0xc5:
+ } else if (rsp->ccode == IPMI_CC_RES_CANCELED) {
/* lost reservation */
lprintf(LOG_DEBUG, "SDR reservation cancelled. "
"Sleeping a bit and retrying...");
@@ -3055,14 +3190,14 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
}
/* special completion codes handled above */
- if (rsp->ccode > 0 || rsp->data_len == 0) {
+ if (rsp->ccode || rsp->data_len == 0) {
free(data);
data = NULL;
return NULL;
}
memcpy(data + i, rsp->data + 2, sdr_rq.length);
- i += sdr_max_read_len;
+ i += sdr_rq.length;
}
return data;
@@ -3070,13 +3205,12 @@ ipmi_sdr_get_record(struct ipmi_intf * intf, struct sdr_get_rs * header,
/* ipmi_sdr_end - cleanup SDR iterator
*
- * @intf: ipmi interface
* @itr: SDR iterator
*
* no meaningful return code
*/
void
-ipmi_sdr_end(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr)
+ipmi_sdr_end(struct ipmi_sdr_iterator *itr)
{
if (itr) {
free(itr);
@@ -3098,11 +3232,11 @@ __sdr_list_add(struct sdr_record_list *head, struct sdr_record_list *entry)
struct sdr_record_list *e;
struct sdr_record_list *new;
- if (head == NULL)
+ if (!head)
return -1;
new = malloc(sizeof (struct sdr_record_list));
- if (new == NULL) {
+ if (!new) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -3127,7 +3261,7 @@ static void
__sdr_list_empty(struct sdr_record_list *head)
{
struct sdr_record_list *e, *f;
- for (e = head; e != NULL; e = f) {
+ for (e = head; e; e = f) {
f = e->next;
free(e);
e = NULL;
@@ -3137,18 +3271,16 @@ __sdr_list_empty(struct sdr_record_list *head)
/* ipmi_sdr_list_empty - clean global SDR list
*
- * @intf: ipmi interface
- *
* no meaningful return code
*/
void
-ipmi_sdr_list_empty(struct ipmi_intf *intf)
+ipmi_sdr_list_empty(void)
{
struct sdr_record_list *list, *next;
- ipmi_sdr_end(intf, sdr_list_itr);
+ ipmi_sdr_end(sdr_list_itr);
- for (list = sdr_list_head; list != NULL; list = next) {
+ for (list = sdr_list_head; list; list = next) {
switch (list->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3215,16 +3347,16 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
struct sdr_record_list *e;
int found = 0;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3243,12 +3375,12 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3257,8 +3389,8 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3302,7 +3434,7 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3310,7 +3442,7 @@ ipmi_sdr_find_sdr_bynumtype(struct ipmi_intf *intf, uint16_t gen_id, uint8_t num
}
/* put in the global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3339,9 +3471,9 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
struct sdr_get_rs *header;
struct sdr_record_list *e;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
@@ -3349,13 +3481,13 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
/* check what we've already read */
head = malloc(sizeof (struct sdr_record_list));
- if (head == NULL) {
+ if (!head) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(head, 0, sizeof (struct sdr_record_list));
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3370,12 +3502,12 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3384,8 +3516,8 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3425,7 +3557,7 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3433,7 +3565,7 @@ ipmi_sdr_find_sdr_bysensortype(struct ipmi_intf *intf, uint8_t type)
}
/* put in the global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3459,23 +3591,23 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
struct sdr_record_list *e;
struct sdr_record_list *head;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
head = malloc(sizeof (struct sdr_record_list));
- if (head == NULL) {
+ if (!head) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(head, 0, sizeof (struct sdr_record_list));
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
case SDR_RECORD_TYPE_COMPACT_SENSOR:
@@ -3524,12 +3656,12 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3538,8 +3670,8 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3605,7 +3737,7 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3613,7 +3745,7 @@ ipmi_sdr_find_sdr_byentity(struct ipmi_intf *intf, struct entity_id *entity)
}
/* add to global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3639,33 +3771,33 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
struct sdr_record_list *e;
struct sdr_record_list *head;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
head = malloc(sizeof (struct sdr_record_list));
- if (head == NULL) {
+ if (!head) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
memset(head, 0, sizeof (struct sdr_record_list));
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next)
+ for (e = sdr_list_head; e; e = e->next)
if (e->type == type)
__sdr_list_add(head, e);
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3674,8 +3806,8 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3711,7 +3843,7 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3722,7 +3854,7 @@ ipmi_sdr_find_sdr_bytype(struct ipmi_intf *intf, uint8_t type)
__sdr_list_add(head, sdrr);
/* add to global record list */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3749,21 +3881,21 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
int found = 0;
int idlen;
- if (id == NULL)
+ if (!id)
return NULL;
idlen = strlen(id);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return NULL;
}
}
/* check what we've already read */
- for (e = sdr_list_head; e != NULL; e = e->next) {
+ for (e = sdr_list_head; e; e = e->next) {
switch (e->type) {
case SDR_RECORD_TYPE_FULL_SENSOR:
if (!strncmp((const char *)e->record.full->id_string,
@@ -3805,12 +3937,12 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
}
/* now keep looking */
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -3819,8 +3951,8 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3891,7 +4023,7 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -3899,7 +4031,7 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -3915,14 +4047,13 @@ ipmi_sdr_find_sdr_byid(struct ipmi_intf *intf, char *id)
/* ipmi_sdr_list_cache_fromfile - generate SDR cache for fast lookup from local file
*
- * @intf: ipmi interface
* @ifile: input filename
*
* returns pointer to SDR list
* returns NULL on error
*/
int
-ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
+ipmi_sdr_list_cache_fromfile(const char *ifile)
{
FILE *fp;
struct __sdr_header {
@@ -3935,13 +4066,13 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
uint8_t *rec;
int ret = 0, count = 0, bc = 0;
- if (ifile == NULL) {
+ if (!ifile) {
lprintf(LOG_ERR, "No SDR cache filename given");
return -1;
}
fp = ipmi_open_file_read(ifile);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Unable to open SDR cache %s for reading",
ifile);
return -1;
@@ -3973,7 +4104,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
}
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
ret = -1;
break;
@@ -3984,10 +4115,10 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
sdrr->type = header.type;
rec = malloc(header.length + 1);
- if (rec == NULL) {
+ if (!rec) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
ret = -1;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4001,11 +4132,11 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
"record %04x read %d bytes, expected %d",
header.id, bc, header.length);
ret = -1;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
- if (rec != NULL) {
+ if (rec) {
free(rec);
rec = NULL;
}
@@ -4041,7 +4172,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4049,7 +4180,7 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -4062,9 +4193,9 @@ ipmi_sdr_list_cache_fromfile(struct ipmi_intf *intf, const char *ifile)
sdrr->id);
}
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = malloc(sizeof (struct ipmi_sdr_iterator));
- if (sdr_list_itr != NULL) {
+ if (sdr_list_itr) {
sdr_list_itr->reservation = 0;
sdr_list_itr->total = count;
sdr_list_itr->next = 0xffff;
@@ -4087,20 +4218,20 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
{
struct sdr_get_rs *header;
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
sdr_list_itr = ipmi_sdr_start(intf, 0);
- if (sdr_list_itr == NULL) {
+ if (!sdr_list_itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1;
}
}
- while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, sdr_list_itr))) {
uint8_t *rec;
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
break;
}
@@ -4109,8 +4240,8 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
sdrr->type = header->type;
rec = ipmi_sdr_get_record(intf, header, sdr_list_itr);
- if (rec == NULL) {
- if (sdrr != NULL) {
+ if (!rec) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4146,7 +4277,7 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
default:
free(rec);
rec = NULL;
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
@@ -4154,7 +4285,7 @@ ipmi_sdr_list_cache(struct ipmi_intf *intf)
}
/* add to global record liset */
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -4192,11 +4323,11 @@ ipmi_sdr_get_info(struct ipmi_intf *intf,
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SDR Repository Info command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get SDR Repository Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -4210,24 +4341,6 @@ ipmi_sdr_get_info(struct ipmi_intf *intf,
return 0;
}
-/* ipmi_sdr_timestamp - return string from timestamp value
- *
- * @stamp: 32bit timestamp
- *
- * returns pointer to static buffer
- */
-static char *
-ipmi_sdr_timestamp(uint32_t stamp)
-{
- static char tbuf[40];
- time_t s = (time_t) stamp;
- memset(tbuf, 0, 40);
- if (stamp)
- strftime(tbuf, sizeof (tbuf), "%m/%d/%Y %H:%M:%S",
- gmtime(&s));
- return tbuf;
-}
-
/*
* ipmi_sdr_print_info
*
@@ -4240,7 +4353,7 @@ ipmi_sdr_timestamp(uint32_t stamp)
int
ipmi_sdr_print_info(struct ipmi_intf *intf)
{
- uint32_t timestamp;
+ time_t timestamp;
uint16_t free_space;
struct get_sdr_repository_info_rsp sdr_repository_info;
@@ -4274,21 +4387,26 @@ ipmi_sdr_print_info(struct ipmi_intf *intf)
break;
}
- timestamp =
- (sdr_repository_info.most_recent_addition_timestamp[3] << 24) |
- (sdr_repository_info.most_recent_addition_timestamp[2] << 16) |
- (sdr_repository_info.most_recent_addition_timestamp[1] << 8) |
- sdr_repository_info.most_recent_addition_timestamp[0];
- printf("Most recent Addition : %s\n",
- ipmi_sdr_timestamp(timestamp));
+ printf("Most recent Addition : ");
+ if (sdr_repository_info.partial_add_sdr_supported)
+ {
+ timestamp = ipmi32toh(sdr_repository_info
+ .most_recent_addition_timestamp);
+ printf("%s\n", ipmi_timestamp_numeric(timestamp));
+ }
+ else {
+ printf("NA\n");
+ }
- timestamp =
- (sdr_repository_info.most_recent_erase_timestamp[3] << 24) |
- (sdr_repository_info.most_recent_erase_timestamp[2] << 16) |
- (sdr_repository_info.most_recent_erase_timestamp[1] << 8) |
- sdr_repository_info.most_recent_erase_timestamp[0];
- printf("Most recent Erase : %s\n",
- ipmi_sdr_timestamp(timestamp));
+ printf("Most recent Erase : ");
+ if(sdr_repository_info.delete_sdr_supported) {
+ timestamp = ipmi32toh(sdr_repository_info
+ .most_recent_erase_timestamp);
+ printf("%s\n", ipmi_timestamp_numeric(timestamp));
+ }
+ else {
+ printf("NA\n");
+ }
printf("SDR overflow : %s\n",
(sdr_repository_info.overflow_flag ? "yes" : "no"));
@@ -4321,7 +4439,7 @@ ipmi_sdr_print_info(struct ipmi_intf *intf)
reserve_sdr_repository_supported ? "yes" : "no");
printf("SDR Repository Alloc info supported : %s\n",
sdr_repository_info.
- get_sdr_repository_allo_info_supported ? "yes" : "no");
+ get_sdr_repository_allo_info_supported ? "yes" : "no");
return 0;
}
@@ -4347,7 +4465,7 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
/* open connection to SDR */
itr = ipmi_sdr_start(intf, 0);
- if (itr == NULL) {
+ if (!itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1;
}
@@ -4355,9 +4473,9 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
printf("Dumping Sensor Data Repository to '%s'\n", ofile);
/* generate list of records */
- while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, itr))) {
sdrr = malloc(sizeof(struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -4372,16 +4490,16 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
sdrr->length = header->length;
sdrr->raw = ipmi_sdr_get_record(intf, header, itr);
- if (sdrr->raw == NULL) {
+ if (!sdrr->raw) {
lprintf(LOG_ERR, "ipmitool: cannot obtain SDR record %04x", header->id);
- if (sdrr != NULL) {
+ if (sdrr) {
free(sdrr);
sdrr = NULL;
}
return -1;
}
- if (sdr_list_head == NULL)
+ if (!sdr_list_head)
sdr_list_head = sdrr;
else
sdr_list_tail->next = sdrr;
@@ -4389,14 +4507,14 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
sdr_list_tail = sdrr;
}
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
/* now write to file */
fp = ipmi_open_file_write(ofile);
- if (fp == NULL)
+ if (!fp)
return -1;
- for (sdrr = sdr_list_head; sdrr != NULL; sdrr = sdrr->next) {
+ for (sdrr = sdr_list_head; sdrr; sdrr = sdrr->next) {
int r;
uint8_t h[5];
@@ -4451,9 +4569,9 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
int x;
uint8_t sensor_type = 0;
- if (type == NULL ||
- strncasecmp(type, "help", 4) == 0 ||
- strncasecmp(type, "list", 4) == 0) {
+ if (!type ||
+ strcasecmp(type, "help") == 0 ||
+ strcasecmp(type, "list") == 0) {
printf("Sensor Types:\n");
for (x = 1; x < SENSOR_TYPE_MAX; x += 2) {
printf("\t%-25s (0x%02x) %-25s (0x%02x)\n",
@@ -4463,7 +4581,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
return 0;
}
- if (strncmp(type, "0x", 2) == 0) {
+ if (!strcmp(type, "0x")) {
/* begins with 0x so let it be entered as raw hex value */
if (str2uchar(type, &sensor_type) != 0) {
lprintf(LOG_ERR,
@@ -4473,9 +4591,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
}
} else {
for (x = 1; x < SENSOR_TYPE_MAX; x++) {
- if (strncasecmp(sensor_type_desc[x], type,
- __maxlen(type,
- sensor_type_desc[x])) == 0) {
+ if (strcasecmp(sensor_type_desc[x], type) == 0) {
sensor_type = x;
break;
}
@@ -4495,7 +4611,7 @@ ipmi_sdr_print_type(struct ipmi_intf *intf, char *type)
list = ipmi_sdr_find_sdr_bysensortype(intf, sensor_type);
- for (entry = list; entry != NULL; entry = entry->next) {
+ for (entry = list; entry; entry = entry->next) {
rc = ipmi_sdr_print_listentry(intf, entry);
}
@@ -4521,9 +4637,9 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr)
unsigned instance = 0;
int rc = 0;
- if (entitystr == NULL ||
- strncasecmp(entitystr, "help", 4) == 0 ||
- strncasecmp(entitystr, "list", 4) == 0) {
+ if (!entitystr ||
+ strcasecmp(entitystr, "help") == 0 ||
+ strcasecmp(entitystr, "list") == 0) {
print_valstr_2col(entity_id_vals, "Entity IDs", -1);
return 0;
}
@@ -4537,9 +4653,8 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr)
int i, j=0;
/* now try string input */
- for (i = 0; entity_id_vals[i].str != NULL; i++) {
- if (strncasecmp(entitystr, entity_id_vals[i].str,
- __maxlen(entitystr, entity_id_vals[i].str)) == 0) {
+ for (i = 0; entity_id_vals[i].str; i++) {
+ if (strcasecmp(entitystr, entity_id_vals[i].str) == 0) {
entity.id = entity_id_vals[i].val;
entity.instance = 0x7f;
j=1;
@@ -4560,7 +4675,7 @@ ipmi_sdr_print_entity(struct ipmi_intf *intf, char *entitystr)
list = ipmi_sdr_find_sdr_byentity(intf, &entity);
- for (entry = list; entry != NULL; entry = entry->next) {
+ for (entry = list; entry; entry = entry->next) {
rc = ipmi_sdr_print_listentry(intf, entry);
}
@@ -4595,7 +4710,7 @@ ipmi_sdr_print_entry_byid(struct ipmi_intf *intf, int argc, char **argv)
for (i = 0; i < argc; i++) {
sdr = ipmi_sdr_find_sdr_byid(intf, argv[i]);
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR, "Unable to find sensor id '%s'",
argv[i]);
} else {
@@ -4626,41 +4741,41 @@ ipmi_sdr_main(struct ipmi_intf *intf, int argc, char **argv)
/* initialize random numbers used later */
srand(time(NULL));
- if (argc == 0)
+ if (argc == 0) {
return ipmi_sdr_print_sdr(intf, 0xfe);
- else if (strncmp(argv[0], "help", 4) == 0) {
+ } else if (!strcmp(argv[0], "help")) {
printf_sdr_usage();
- } else if (strncmp(argv[0], "list", 4) == 0
- || strncmp(argv[0], "elist", 5) == 0) {
-
- if (strncmp(argv[0], "elist", 5) == 0)
+ } else if (!strcmp(argv[0], "list")
+ || !strcmp(argv[0], "elist"))
+ {
+ if (!strcmp(argv[0], "elist"))
sdr_extended = 1;
else
sdr_extended = 0;
if (argc <= 1)
rc = ipmi_sdr_print_sdr(intf, 0xfe);
- else if (strncmp(argv[1], "all", 3) == 0)
+ else if (!strcmp(argv[1], "all"))
rc = ipmi_sdr_print_sdr(intf, 0xff);
- else if (strncmp(argv[1], "full", 4) == 0)
+ else if (!strcmp(argv[1], "full"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_FULL_SENSOR);
- else if (strncmp(argv[1], "compact", 7) == 0)
+ else if (!strcmp(argv[1], "compact"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_COMPACT_SENSOR);
- else if (strncmp(argv[1], "event", 5) == 0)
+ else if (!strcmp(argv[1], "event"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_EVENTONLY_SENSOR);
- else if (strncmp(argv[1], "mcloc", 5) == 0)
+ else if (!strcmp(argv[1], "mcloc"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_MC_DEVICE_LOCATOR);
- else if (strncmp(argv[1], "fru", 3) == 0)
+ else if (!strcmp(argv[1], "fru"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR);
- else if (strncmp(argv[1], "generic", 7) == 0)
+ else if (!strcmp(argv[1], "generic"))
rc = ipmi_sdr_print_sdr(intf,
SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR);
- else if (strcmp(argv[1], "help") == 0) {
+ else if (!strcmp(argv[1], "help")) {
lprintf(LOG_NOTICE,
"usage: sdr %s [all|full|compact|event|mcloc|fru|generic]",
argv[0]);
@@ -4675,35 +4790,35 @@ ipmi_sdr_main(struct ipmi_intf *intf, int argc, char **argv)
argv[0]);
return (-1);
}
- } else if (strncmp(argv[0], "type", 4) == 0) {
+ } else if (!strcmp(argv[0], "type")) {
sdr_extended = 1;
rc = ipmi_sdr_print_type(intf, argv[1]);
- } else if (strncmp(argv[0], "entity", 6) == 0) {
+ } else if (!strcmp(argv[0], "entity")) {
sdr_extended = 1;
rc = ipmi_sdr_print_entity(intf, argv[1]);
- } else if (strncmp(argv[0], "info", 4) == 0) {
+ } else if (!strcmp(argv[0], "info")) {
rc = ipmi_sdr_print_info(intf);
- } else if (strncmp(argv[0], "get", 3) == 0) {
+ } else if (!strcmp(argv[0], "get")) {
rc = ipmi_sdr_print_entry_byid(intf, argc - 1, &argv[1]);
- } else if (strncmp(argv[0], "dump", 4) == 0) {
+ } else if (!strcmp(argv[0], "dump")) {
if (argc < 2) {
lprintf(LOG_ERR, "Not enough parameters given.");
lprintf(LOG_NOTICE, "usage: sdr dump <file>");
return (-1);
}
rc = ipmi_sdr_dump_bin(intf, argv[1]);
- } else if (strncmp(argv[0], "fill", 4) == 0) {
+ } else if (!strcmp(argv[0], "fill")) {
if (argc <= 1) {
lprintf(LOG_ERR, "Not enough parameters given.");
lprintf(LOG_NOTICE, "usage: sdr fill sensors");
lprintf(LOG_NOTICE, "usage: sdr fill file <file>");
lprintf(LOG_NOTICE, "usage: sdr fill range <range>");
return (-1);
- } else if (strncmp(argv[1], "sensors", 7) == 0) {
+ } else if (!strcmp(argv[1], "sensors")) {
rc = ipmi_sdr_add_from_sensors(intf, 21);
- } else if (strncmp(argv[1], "nosat", 5) == 0) {
+ } else if (!strcmp(argv[1], "nosat")) {
rc = ipmi_sdr_add_from_sensors(intf, 0);
- } else if (strncmp(argv[1], "file", 4) == 0) {
+ } else if (!strcmp(argv[1], "file")) {
if (argc < 3) {
lprintf(LOG_ERR,
"Not enough parameters given.");
@@ -4712,7 +4827,7 @@ ipmi_sdr_main(struct ipmi_intf *intf, int argc, char **argv)
return (-1);
}
rc = ipmi_sdr_add_from_file(intf, argv[2]);
- } else if (strncmp(argv[1], "range", 4) == 0) {
+ } else if (!strcmp(argv[1], "range")) {
if (argc < 3) {
lprintf(LOG_ERR,
"Not enough parameters given.");
diff --git a/lib/ipmi_sdradd.c b/lib/ipmi_sdradd.c
index 52848a3..87063bb 100644
--- a/lib/ipmi_sdradd.c
+++ b/lib/ipmi_sdradd.c
@@ -80,7 +80,7 @@ partial_send(struct ipmi_intf *intf, struct ipmi_rq *req, uint16_t *id)
{
struct ipmi_rs *rsp;
rsp = intf->sendrecv(intf, req);
- if (rsp == NULL) {
+ if (!rsp) {
return -1;
}
@@ -115,7 +115,7 @@ ipmi_sdr_add_record(struct ipmi_intf *intf, struct sdr_record_list *sdrr)
}
sdr_rq = (struct sdr_add_rq *)malloc(sizeof(*sdr_rq) + sdr_max_write_len);
- if (sdr_rq == NULL) {
+ if (!sdr_rq) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -202,11 +202,11 @@ ipmi_sdr_repo_clear(struct ipmi_intf *intf)
for (try = 0; try < 5; try++) {
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to clear SDRR");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Unable to clear SDRR: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -248,11 +248,11 @@ sdrr_get_records(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr,
queue->head = NULL;
queue->tail = NULL;
- while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, itr))) {
struct sdr_record_list *sdrr;
sdrr = malloc(sizeof (struct sdr_record_list));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -263,10 +263,10 @@ sdrr_get_records(struct ipmi_intf *intf, struct ipmi_sdr_iterator *itr,
sdrr->type = header->type;
sdrr->length = header->length;
sdrr->raw = ipmi_sdr_get_record(intf, header, itr);
- (void)ipmi_sdr_print_name_from_rawentry(intf, sdrr->id, sdrr->type,sdrr->raw);
+ (void)ipmi_sdr_print_name_from_rawentry(sdrr->id, sdrr->type,sdrr->raw);
/* put in the record queue */
- if (queue->head == NULL)
+ if (!queue->head)
queue->head = sdrr;
else
queue->tail->next = sdrr;
@@ -295,12 +295,12 @@ sdr_copy_to_sdrr(struct ipmi_intf *intf, int use_builtin,
printf("Load SDRs from 0x%x\n", from_addr);
rc = sdrr_get_records(intf, itr, &sdrr_queue);
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
/* ... */
/* write the SDRs to the destination SDR Repository */
intf->target_addr = to_addr;
- for (sdrr = sdrr_queue.head; sdrr != NULL; sdrr = sdrr_next) {
+ for (sdrr = sdrr_queue.head; sdrr; sdrr = sdrr_next) {
sdrr_next = sdrr->next;
rc = ipmi_sdr_add_record(intf, sdrr);
if(rc < 0){
@@ -433,7 +433,7 @@ int ipmi_parse_range_list(const char *rangeList, unsigned char * pHexList)
do
{
- if(nextString != NULL)
+ if(nextString)
{
(*nextString)= 0;
nextString ++;
@@ -446,8 +446,7 @@ int ipmi_parse_range_list(const char *rangeList, unsigned char * pHexList)
/* At this point, it is a single entry or a range */
rangeString = strstr( inProcessString, "-" );
- if(rangeString == NULL)
- {
+ if (!rangeString) {
unsigned char decValue = 0;
/* Single entry */
@@ -597,7 +596,7 @@ ipmi_sdr_read_records(const char *filename, struct sdrr_queue *queue)
lprintf(LOG_DEBUG, "binHdr[4] (length) = 0x%02x", binHdr[4]);
sdrr = malloc(sizeof(*sdrr));
- if (sdrr == NULL) {
+ if (!sdrr) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
rc = -1;
break;
@@ -607,7 +606,8 @@ ipmi_sdr_read_records(const char *filename, struct sdrr_queue *queue)
sdrr->type = binHdr[3];
sdrr->length = binHdr[4];
- if ((sdrr->raw = malloc(sdrr->length)) == NULL) {
+ sdrr->raw = malloc(sdrr->length);
+ if (!sdrr->raw) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
free(sdrr);
sdrr = NULL;
@@ -626,7 +626,7 @@ ipmi_sdr_read_records(const char *filename, struct sdrr_queue *queue)
}
/* put in the record queue */
- if (queue->head == NULL)
+ if (!queue->head)
queue->head = sdrr;
else
queue->tail->next = sdrr;
@@ -654,7 +654,7 @@ ipmi_sdr_add_from_file(struct ipmi_intf *intf, const char *ifile)
}
/* write the SDRs to the SDR Repository */
- for (sdrr = sdrr_queue.head; sdrr != NULL; sdrr = sdrr_next) {
+ for (sdrr = sdrr_queue.head; sdrr; sdrr = sdrr_next) {
sdrr_next = sdrr->next;
rc = ipmi_sdr_add_record(intf, sdrr);
if(rc < 0){
diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c
index 8b0395e..31c0eea 100644
--- a/lib/ipmi_sel.c
+++ b/lib/ipmi_sel.c
@@ -29,7 +29,6 @@
* 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 _BSD_SOURCE
#include <string.h>
#include <strings.h>
@@ -38,6 +37,7 @@
#include <time.h>
#include <ctype.h>
#include <errno.h>
+#include <stdbool.h>
#include <ipmitool/helper.h>
#include <ipmitool/log.h>
@@ -50,8 +50,9 @@
#include <ipmitool/ipmi_fru.h>
#include <ipmitool/ipmi_sensor.h>
#include <ipmitool/ipmi_strings.h>
+#include <ipmitool/ipmi_quantaoem.h>
+#include <ipmitool/ipmi_time.h>
-extern int verbose;
static int sel_extended = 0;
static int sel_oem_nrecs = 0;
@@ -123,13 +124,13 @@ int ipmi_sel_oem_init(const char * filename)
int i, j, k, n, byte;
char buf[15][150];
- if (filename == NULL) {
+ if (!filename) {
lprintf(LOG_ERR, "No SEL OEM filename provided");
return -1;
}
fp = ipmi_open_file_read(filename);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Could not open %s file", filename);
return -1;
}
@@ -193,7 +194,7 @@ int ipmi_sel_oem_init(const char * filename)
return 0;
}
-static void ipmi_sel_oem_message(struct sel_event_record * evt, int verbose)
+static void ipmi_sel_oem_message(struct sel_event_record * evt)
{
/*
* Note: although we have a verbose argument, currently the output
@@ -238,34 +239,6 @@ ipmi_get_event_type(uint8_t code)
}
static char *
-ipmi_sel_timestamp(uint32_t stamp)
-{
- static char tbuf[40];
- time_t s = (time_t)stamp;
- memset(tbuf, 0, 40);
- strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&s));
- return tbuf;
-}
-
-static char *
-ipmi_sel_timestamp_date(uint32_t stamp)
-{
- static char tbuf[11];
- time_t s = (time_t)stamp;
- strftime(tbuf, sizeof(tbuf), "%m/%d/%Y", gmtime(&s));
- return tbuf;
-}
-
-static char *
-ipmi_sel_timestamp_time(uint32_t stamp)
-{
- static char tbuf[9];
- time_t s = (time_t)stamp;
- strftime(tbuf, sizeof(tbuf), "%H:%M:%S", gmtime(&s));
- return tbuf;
-}
-
-static char *
hex2ascii (uint8_t * hexChars, uint8_t numBytes)
{
int count;
@@ -315,11 +288,11 @@ ipmi_get_oem(struct ipmi_intf * intf)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get Device ID command failed");
return IPMI_OEM_UNKNOWN;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get Device ID command failed: %#x %s",
rsp->ccode, val2str(rsp->ccode, completion_code_vals));
return IPMI_OEM_UNKNOWN;
@@ -348,11 +321,11 @@ ipmi_sel_add_entry(struct ipmi_intf * intf, struct sel_event_record * rec)
ipmi_sel_print_std_entry(intf, rec);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Add SEL Entry failed");
return -1;
}
- else if (rsp->ccode > 0) {
+ else if (rsp->ccode) {
lprintf(LOG_ERR, "Add SEL Entry failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -373,15 +346,15 @@ ipmi_sel_add_entries_fromfile(struct ipmi_intf * intf, const char * filename)
uint8_t rqdata[8];
struct sel_event_record sel_event;
- if (filename == NULL)
+ if (!filename)
return -1;
fp = ipmi_open_file_read(filename);
- if (fp == NULL)
+ if (!fp)
return -1;
while (feof(fp) == 0) {
- if (fgets(buf, 1024, fp) == NULL)
+ if (!fgets(buf, 1024, fp))
continue;
/* clip off optional comment tail indicated by # */
@@ -447,25 +420,26 @@ ipmi_sel_add_entries_fromfile(struct ipmi_intf * intf, const char * filename)
return rc;
}
-static struct ipmi_event_sensor_types oem_kontron_event_reading_types[] __attribute__((unused)) = {
+static struct ipmi_event_sensor_types __UNUSED__(oem_kontron_event_reading_types[]) = {
{ 0x70 , 0x00 , 0xff, "Code Assert" },
{ 0x71 , 0x00 , 0xff, "Code Assert" },
{ 0, 0, 0xFF, NULL }
};
-
+
+/* NOTE: unused paramter kept in for consistency. */
char *
-get_kontron_evt_desc(struct ipmi_intf *intf, struct sel_event_record * rec)
+get_kontron_evt_desc(struct ipmi_intf *__UNUSED__(intf), struct sel_event_record *rec)
{
- char * description = NULL;
+ char *description = NULL;
/*
* Kontron OEM events are described in the product's user manual, but are limited in favor of
- * sensor specific
+ * sensor specific
*/
/* Only standard records are defined so far */
if( rec->record_type < 0xC0 ){
const struct ipmi_event_sensor_types *st=NULL;
- for ( st=oem_kontron_event_types ; st->desc != NULL; st++){
+ for (st = oem_kontron_event_types; st->desc; st++){
if (st->code == rec->sel_type.standard_type.event_type ){
size_t len =strlen(st->desc);
description = (char*)malloc( len + 1 );
@@ -480,10 +454,10 @@ get_kontron_evt_desc(struct ipmi_intf *intf, struct sel_event_record * rec)
}
char *
-get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
+get_viking_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
{
/*
- * Newisys OEM event descriptions can be retrieved through an
+ * Viking OEM event descriptions can be retrieved through an
* OEM IPMI command.
*/
struct ipmi_rs * rsp;
@@ -506,12 +480,12 @@ get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
req.msg.data = msg_data;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
if (verbose)
lprintf(LOG_ERR, "Error issuing OEM command");
return NULL;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
if (verbose)
lprintf(LOG_ERR, "OEM command returned error code: %s",
val2str(rsp->ccode, completion_code_vals));
@@ -521,17 +495,17 @@ get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
/* Verify our response before we use it */
if (rsp->data_len < 5)
{
- lprintf(LOG_ERR, "Newisys OEM response too short");
+ lprintf(LOG_ERR, "Viking OEM response too short");
return NULL;
}
else if (rsp->data_len != (4 + rsp->data[3]))
{
- lprintf(LOG_ERR, "Newisys OEM response has unexpected length");
+ lprintf(LOG_ERR, "Viking OEM response has unexpected length");
return NULL;
}
- else if (IPM_DEV_MANUFACTURER_ID(rsp->data) != IPMI_OEM_NEWISYS)
+ else if (IPM_DEV_MANUFACTURER_ID(rsp->data) != IPMI_OEM_VIKING)
{
- lprintf(LOG_ERR, "Newisys OEM response has unexpected length");
+ lprintf(LOG_ERR, "Viking OEM response has unexpected length");
return NULL;
}
@@ -565,9 +539,9 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
if (rec->sel_type.standard_type.event_type != 0x6F) {
return NULL;
}
- /* Allocate mem for te Description string */
+ /* Allocate mem for the Description string */
desc = malloc(sizeof(char) * SIZE_OF_DESC);
- if (desc == NULL) {
+ if (!desc) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return NULL;
}
@@ -583,17 +557,17 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, " Error getting system info");
- if (desc != NULL) {
+ if (desc) {
free(desc);
desc = NULL;
}
return NULL;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, " Error getting system info: %s",
val2str(rsp->ccode, completion_code_vals));
- if (desc != NULL) {
+ if (desc) {
free(desc);
desc = NULL;
}
@@ -602,7 +576,7 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
/* check the chipset type */
oem_id = ipmi_get_oem_id(intf);
if (oem_id == 0) {
- if (desc != NULL) {
+ if (desc) {
free(desc);
desc = NULL;
}
@@ -705,7 +679,7 @@ get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
/*
* Function : Decoding the SEL OEM Bytes for the DELL Platforms.
- * Description : The below fucntion will decode the SEL Events OEM Bytes for the Dell specific Sensors only.
+ * Description : The below function will decode the SEL Events OEM Bytes for the Dell specific Sensors only.
* The below function will append the additional information Strings/description to the normal sel desc.
* With this the SEL will display additional information sent via OEM Bytes of the SEL Record.
* NOTE : Specific to DELL Platforms only.
@@ -738,7 +712,7 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
if (0x6F == rec->sel_type.standard_type.event_type)
{
sensor_type = rec->sel_type.standard_type.sensor_type;
- /* Allocate mem for te Description string */
+ /* Allocate mem for the Description string */
desc = (char*)malloc(SIZE_OF_DESC);
if(NULL == desc)
return NULL;
@@ -787,17 +761,17 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
if (NULL == rsp)
{
lprintf(LOG_ERR, " Error getting system info");
- if (desc != NULL) {
+ if (desc) {
free(desc);
desc = NULL;
}
return NULL;
}
- else if (rsp->ccode > 0)
+ else if (rsp->ccode)
{
lprintf(LOG_ERR, " Error getting system info: %s",
val2str(rsp->ccode, completion_code_vals));
- if (desc != NULL) {
+ if (desc) {
free(desc);
desc = NULL;
}
@@ -896,11 +870,11 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
if(SENSOR_TYPE_EVT_LOG == sensor_type)
{
if(0x03 == (data1 & MASK_LOWER_NIBBLE))
- snprintf(desc,SIZE_OF_DESC,"All Even Logging Dissabled");
+ snprintf(desc,SIZE_OF_DESC,"All Even Logging Disabled");
}
}
/*
- * Based on the above error, we need to find whcih memory slot or
+ * Based on the above error, we need to find which memory slot or
* Card has got the Errors/Sel Generated.
*/
if(data1 & OEM_CODE_IN_BYTE2 )
@@ -1042,7 +1016,7 @@ char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
}
break;
- /* This Event is for BMC to Othe Hardware or CPU . */
+ /* This Event is for BMC to other Hardware or CPU . */
case SENSOR_TYPE_VER_CHANGE:
if((0x02 == (data1 & MASK_LOWER_NIBBLE))&&((data1 & OEM_CODE_IN_BYTE2) && (data1 & OEM_CODE_IN_BYTE3)))
{
@@ -1231,8 +1205,8 @@ ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
switch (ipmi_get_oem(intf))
{
- case IPMI_OEM_NEWISYS:
- desc = get_newisys_evt_desc(intf, rec);
+ case IPMI_OEM_VIKING:
+ desc = get_viking_evt_desc(intf, rec);
break;
case IPMI_OEM_KONTRON:
desc = get_kontron_evt_desc(intf, rec);
@@ -1244,6 +1218,9 @@ ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
case IPMI_OEM_SUPERMICRO_47488:
desc = get_supermicro_evt_desc(intf, rec);
break;
+ case IPMI_OEM_QUANTA:
+ desc = oem_qct_get_evt_desc(intf, rec);
+ break;
case IPMI_OEM_UNKNOWN:
default:
break;
@@ -1282,9 +1259,9 @@ ipmi_get_first_event_sensor_type(struct ipmi_intf *intf,
code = event_type;
}
- for (evt = start; evt->desc != NULL || next != NULL; evt++) {
+ for (evt = start; evt->desc || next; evt++) {
/* check if VITA sensor event types has finished */
- if (evt->desc == NULL) {
+ if (!evt->desc) {
/* proceed with next table */
evt = next;
next = NULL;
@@ -1303,7 +1280,7 @@ ipmi_get_next_event_sensor_type(const struct ipmi_event_sensor_types *evt)
{
const struct ipmi_event_sensor_types *start = evt;
- for (evt = start + 1; evt->desc != NULL; evt++) {
+ for (evt = start + 1; evt->desc; evt++) {
if (evt->code == start->code) {
return evt;
}
@@ -1321,7 +1298,7 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
char *sfx = NULL; /* This will be assigned if the Platform is DELL,
additional info is appended to the current Description */
- if (desc == NULL)
+ if (!desc)
return;
*desc = NULL;
@@ -1349,6 +1326,9 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
sfx = ipmi_get_oem_desc(intf, rec);
break;
/* add your oem sensor assignation here */
+ case IPMI_OEM_QUANTA:
+ sfx = ipmi_get_oem_desc(intf, rec);
+ break;
default:
lprintf(LOG_DEBUG, "oem sensor type %x using standard type supplied description",
rec->sel_type.standard_type.sensor_type );
@@ -1359,9 +1339,12 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
case IPMI_OEM_SUPERMICRO:
case IPMI_OEM_SUPERMICRO_47488:
sfx = ipmi_get_oem_desc(intf, rec);
- break;
+ break;
+ case IPMI_OEM_QUANTA:
+ sfx = ipmi_get_oem_desc(intf, rec);
+ break;
default:
- break;
+ break;
}
}
/*
@@ -1387,10 +1370,11 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
offset = rec->sel_type.standard_type.event_data[0] & 0xf;
for (evt = ipmi_get_first_event_sensor_type(intf,
- rec->sel_type.standard_type.sensor_type,
- rec->sel_type.standard_type.event_type);
- evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) {
- if ((evt->offset == offset && evt->desc != NULL) &&
+ rec->sel_type.standard_type.sensor_type,
+ rec->sel_type.standard_type.event_type);
+ evt; evt = ipmi_get_next_event_sensor_type(evt))
+ {
+ if ((evt->offset == offset && evt->desc) &&
((evt->data == ALL_OFFSETS_SPECIFIED) ||
((rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK) &&
(evt->data == rec->sel_type.standard_type.event_data[1]))))
@@ -1513,7 +1497,7 @@ ipmi_get_sensor_type(struct ipmi_intf *intf, uint8_t code)
type = ipmi_get_generic_sensor_type(code);
}
- if (type == NULL) {
+ if (!type) {
type = "Unknown";
}
@@ -1537,10 +1521,10 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SEL Info command failed");
return -1;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -1583,14 +1567,14 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
printf("Last Add Time : Not Available\n");
else
printf("Last Add Time : %s\n",
- ipmi_sel_timestamp(buf2long(rsp->data + 5)));
+ ipmi_timestamp_numeric(buf2long(rsp->data + 5)));
if ((!memcmp(rsp->data + 9, &fs, 4)) ||
(!memcmp(rsp->data + 9, &zeros, 4)))
printf("Last Del Time : Not Available\n");
else
printf("Last Del Time : %s\n",
- ipmi_sel_timestamp(buf2long(rsp->data + 9)));
+ ipmi_timestamp_numeric(buf2long(rsp->data + 9)));
printf("Overflow : %s\n",
@@ -1618,12 +1602,12 @@ ipmi_sel_get_info(struct ipmi_intf * intf)
req.msg.cmd = IPMI_CMD_GET_SEL_ALLOC_INFO;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR,
"Get SEL Allocation Info command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR,
"Get SEL Allocation Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
@@ -1664,11 +1648,11 @@ ipmi_sel_get_std_entry(struct ipmi_intf * intf, uint16_t id,
req.msg.data_len = 6;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SEL Entry %x command failed", id);
return 0;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get SEL Entry %x command failed: %s",
id, val2str(rsp->ccode, completion_code_vals));
return 0;
@@ -1751,7 +1735,7 @@ ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt
{
char * description;
- if (fp == NULL)
+ if (!fp)
return;
ipmi_get_event_desc(intf, evt, &description);
@@ -1766,9 +1750,9 @@ ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt
evt->sel_type.standard_type.event_data[2],
ipmi_get_sensor_type(intf, evt->sel_type.standard_type.sensor_type),
evt->sel_type.standard_type.sensor_num,
- (description != NULL) ? description : "Unknown");
+ description ? description : "Unknown");
- if (description != NULL) {
+ if (description) {
free(description);
description = NULL;
}
@@ -1828,18 +1812,19 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
}
else {
if (evt->record_type < 0xc0)
- printf("%s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp));
+ printf("%s", ipmi_timestamp_date(evt->sel_type.standard_type.timestamp));
else
- printf("%s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp));
+ printf("%s", ipmi_timestamp_date(evt->sel_type.oem_ts_type.timestamp));
+
if (csv_output)
printf(",");
else
printf(" | ");
-
+
if (evt->record_type < 0xc0)
- printf("%s", ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
+ printf("%s", ipmi_timestamp_time(evt->sel_type.standard_type.timestamp));
else
- printf("%s", ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
+ printf("%s", ipmi_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
if (csv_output)
printf(",");
@@ -1877,13 +1862,13 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++)
printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]);
}
- ipmi_sel_oem_message(evt, 0);
+ ipmi_sel_oem_message(evt);
printf ("\n");
return;
}
/* lookup SDR entry based on sensor number and type */
- if (sdr != NULL) {
+ if (sdr) {
printf("%s ", ipmi_get_sensor_type(intf,
evt->sel_type.standard_type.sensor_type));
switch (sdr->type) {
@@ -1940,7 +1925,7 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
printf("Asserted");
}
- if (sdr != NULL && evt->sel_type.standard_type.event_type == 1) {
+ if (sdr && evt->sel_type.standard_type.event_type == 1) {
/*
* Threshold Event
*/
@@ -1970,8 +1955,20 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
(trigger_reading==(int)trigger_reading) ? 0 : 2,
trigger_reading);
if (threshold_reading_provided) {
+ /* According to Table 29-6, Event Data byte 1 contains,
+ * among other info, the offset from the Threshold type
+ * code. According to Table 42-2, all even offsets
+ * are 'going low', and all odd offsets are 'going high'
+ */
+ bool going_high =
+ (evt->sel_type.standard_type.event_data[0]
+ & EVENT_OFFSET_MASK) % 2;
+ if (evt->sel_type.standard_type.event_dir) {
+ /* Event is de-asserted so the inequality is reversed */
+ going_high = !going_high;
+ }
printf(" %s Threshold %.*f %s",
- ((evt->sel_type.standard_type.event_data[0] & 0xf) % 2) ? ">" : "<",
+ going_high ? ">" : "<",
(threshold_reading==(int)threshold_reading) ? 0 : 2,
threshold_reading,
ipmi_sdr_get_unit_string(sdr->record.common->unit.pct,
@@ -1986,9 +1983,12 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
case IPMI_OEM_SUPERMICRO:
case IPMI_OEM_SUPERMICRO_47488:
print_sensor = 0;
- break;
+ break;
+ case IPMI_OEM_QUANTA:
+ print_sensor = 0;
+ break;
default:
- break;
+ break;
}
/*
* Sensor-Specific Discrete
@@ -2043,11 +2043,11 @@ ipmi_sel_print_std_entry_verbose(struct ipmi_intf * intf, struct sel_event_recor
{
printf(" Timestamp : ");
if (evt->record_type < 0xc0)
- printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp),
- ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
+ printf("%s %s", ipmi_timestamp_date(evt->sel_type.standard_type.timestamp),
+ ipmi_timestamp_time(evt->sel_type.standard_type.timestamp));
else
- printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp),
- ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
+ printf("%s %s", ipmi_timestamp_date(evt->sel_type.oem_ts_type.timestamp),
+ ipmi_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
printf("\n");
}
@@ -2068,7 +2068,7 @@ ipmi_sel_print_std_entry_verbose(struct ipmi_intf * intf, struct sel_event_recor
for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++)
printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]);
printf(" [%s]\n\n",hex2ascii (evt->sel_type.oem_nots_type.oem_defined, SEL_OEM_NOTS_DATA_LEN));
- ipmi_sel_oem_message(evt, 1);
+ ipmi_sel_oem_message(evt);
}
return;
}
@@ -2111,7 +2111,7 @@ ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_
evt->sel_type.standard_type.gen_id,
evt->sel_type.standard_type.sensor_num,
evt->sel_type.standard_type.sensor_type);
- if (sdr == NULL)
+ if (!sdr)
{
ipmi_sel_print_std_entry_verbose(intf, evt);
return;
@@ -2133,8 +2133,8 @@ ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_
if (evt->record_type < 0xe0)
{
printf(" Timestamp : ");
- printf("%s %s\n", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp),
- ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
+ printf("%s %s\n", ipmi_timestamp_date(evt->sel_type.standard_type.timestamp),
+ ipmi_timestamp_time(evt->sel_type.standard_type.timestamp));
}
@@ -2268,11 +2268,11 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SEL Info command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2285,21 +2285,6 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
return 0;
}
- memset(&req, 0, sizeof(req));
- req.msg.netfn = IPMI_NETFN_STORAGE;
- req.msg.cmd = IPMI_CMD_RESERVE_SEL;
-
- rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- lprintf(LOG_ERR, "Reserve SEL command failed");
- return -1;
- }
- if (rsp->ccode > 0) {
- lprintf(LOG_ERR, "Reserve SEL command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
- return -1;
- }
-
if (count < 0) {
/** Show only the most recent 'count' records. */
int i;
@@ -2307,11 +2292,11 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get SEL Info command failed");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get SEL Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2336,7 +2321,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
}
}
- if (savefile != NULL) {
+ if (savefile) {
fp = ipmi_open_file_write(savefile);
}
@@ -2361,7 +2346,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
else
ipmi_sel_print_std_entry(intf, &evt);
- if (fp != NULL) {
+ if (fp) {
if (binary)
fwrite(&evt, 1, 16, fp);
else
@@ -2373,7 +2358,7 @@ __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * sav
}
}
- if (fp != NULL)
+ if (fp)
fclose(fp);
return 0;
@@ -2410,7 +2395,7 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana,
* the command line
*/
sel_iana = iana;
- if (strncmp("pps", format, 3) == 0) {
+ if (!strcmp("pps", format)) {
/* Parser for the following format */
/* 0x001F: Event: at Mar 27 06:41:10 2007;from:(0x9a,0,7);
* sensor:(0xc3,119); event:0x6f(asserted): 0xA3 0x00 0x88
@@ -2418,13 +2403,13 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana,
* Supports a tweak for hotswap events that are already interpreted.
*/
fp = ipmi_open_file(readfile, 0);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Failed to open file '%s' for reading.",
readfile);
return (-1);
}
buffer = (char *)malloc((size_t)256);
- if (buffer == NULL) {
+ if (!buffer) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
fclose(fp);
return (-1);
@@ -2433,7 +2418,7 @@ ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana,
/* Only allow complete lines to be parsed,
* hardcoded maximum line length
*/
- if (fgets(buffer, 256, fp) == NULL) {
+ if (!fgets(buffer, 256, fp)) {
status = (-1);
break;
}
@@ -2687,11 +2672,11 @@ ipmi_sel_reserve(struct ipmi_intf * intf)
req.msg.cmd = IPMI_CMD_RESERVE_SEL;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_WARN, "Unable to reserve SEL");
return 0;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf("Unable to reserve SEL: %s",
val2str(rsp->ccode, completion_code_vals));
return 0;
@@ -2713,8 +2698,6 @@ ipmi_sel_get_time(struct ipmi_intf * intf)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
- static char tbuf[40];
- uint32_t timei;
time_t time;
memset(&req, 0, sizeof(req));
@@ -2723,13 +2706,12 @@ ipmi_sel_get_time(struct ipmi_intf * intf)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- lprintf(LOG_ERR, "Get SEL Time command failed");
- return -1;
- }
- if (rsp->ccode > 0) {
+ if (!rsp || rsp->ccode) {
lprintf(LOG_ERR, "Get SEL Time command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ rsp
+ ? val2str(rsp->ccode, completion_code_vals)
+ : "Unknown"
+ );
return -1;
}
if (rsp->data_len != 4) {
@@ -2738,15 +2720,8 @@ ipmi_sel_get_time(struct ipmi_intf * intf)
return -1;
}
- memcpy(&timei, rsp->data, 4);
-#if WORDS_BIGENDIAN
- time = (time_t)(BSWAP_32(timei));
-#else
- time = (time_t)timei;
-#endif
-
- strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&time));
- printf("%s\n", tbuf);
+ time = ipmi32toh(rsp->data);
+ printf("%s\n", ipmi_timestamp_numeric(time));
return 0;
}
@@ -2762,76 +2737,65 @@ ipmi_sel_get_time(struct ipmi_intf * intf)
static int
ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
{
- struct ipmi_rs * rsp;
- struct ipmi_rq req;
- struct tm tm = {0};
- time_t t;
- uint32_t timei;
- const char * time_format = "%m/%d/%Y %H:%M:%S";
+ struct ipmi_rs *rsp;
+ struct ipmi_rq req;
+ struct tm tm = {0};
+ uint8_t msg_data[4] = {0};
+ time_t t;
+ const char *time_format = "%x %X"; /* Use locale-defined format */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_STORAGE;
req.msg.cmd = IPMI_SET_SEL_TIME;
/* See if user requested set to current client system time */
- if (strncasecmp(time_string, "now", 3) == 0) {
+ if (strcasecmp(time_string, "now") == 0) {
t = time(NULL);
+ /*
+ * Now we have local time in t, but BMC requires UTC
+ */
+ t = ipmi_localtime2utc(t);
}
else {
- /* Now how do we get our time_t from our ascii version? */
- if (strptime(time_string, time_format, &tm) == 0) {
- lprintf(LOG_ERR, "Specified time could not be parsed");
- return -1;
+ bool error = true; /* Assume the string is invalid */
+ /* Now let's extract time_t from the supplied string */
+ if (strptime(time_string, time_format, &tm) != NULL) {
+ tm.tm_isdst = (-1); /* look up DST information */
+ t = mktime(&tm);
+ if (t >= 0) {
+ /* Surprisingly, the user hasn't mistaken ;) */
+ error = false;
+ }
}
- tm.tm_isdst = (-1); /* look up DST information */
- t = mktime(&tm);
- if (t < 0) {
+
+ if (error) {
lprintf(LOG_ERR, "Specified time could not be parsed");
return -1;
}
+
+ /*
+ * If `-c` wasn't specified then t we've just got is in local timesone
+ */
+ if (!time_in_utc) {
+ t = ipmi_localtime2utc(t);
+ }
}
- {
- //modify UTC time to local time expressed in number of seconds from 1/1/70 0:0:0 1970 GMT
- struct tm * tm_tmp = {0};
- int gt_year,gt_yday,gt_hour,gt_min,lt_year,lt_yday,lt_hour,lt_min;
- int delta_hour;
- tm_tmp=gmtime(&t);
- gt_year=tm_tmp->tm_year;
- gt_yday=tm_tmp->tm_yday;
- gt_hour=tm_tmp->tm_hour;
- gt_min=tm_tmp->tm_min;
- memset(&*tm_tmp, 0, sizeof(struct tm));
- tm_tmp=localtime(&t);
- lt_year=tm_tmp->tm_year;
- lt_yday=tm_tmp->tm_yday;
- lt_hour=tm_tmp->tm_hour;
- lt_min=tm_tmp->tm_min;
- delta_hour=lt_hour - gt_hour;
- if ( (lt_year > gt_year) || ((lt_year == gt_year) && (lt_yday > gt_yday)) )
- delta_hour += 24;
- if ( (lt_year < gt_year) || ((lt_year == gt_year) && (lt_yday < gt_yday)) )
- delta_hour -= 24;
-
- t += (delta_hour * 60 * 60) + (lt_min - gt_min) * 60;
- }
-
- timei = (uint32_t)t;
- req.msg.data = (uint8_t *)&timei;
- req.msg.data_len = 4;
-
-#if WORDS_BIGENDIAN
- timei = BSWAP_32(timei);
-#endif
+ /*
+ * At this point `t` is UTC. Convert it to LE and send.
+ */
+
+ req.msg.data = msg_data;
+ htoipmi32(t, req.msg.data);
+ req.msg.data_len = sizeof(msg_data);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
- lprintf(LOG_ERR, "Set SEL Time command failed");
- return -1;
- }
- if (rsp->ccode > 0) {
+ if (!rsp || rsp->ccode) {
lprintf(LOG_ERR, "Set SEL Time command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ rsp
+ ? val2str(rsp->ccode, completion_code_vals)
+ : "Unknown"
+ );
return -1;
}
@@ -2840,8 +2804,6 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
return 0;
}
-
-
static int
ipmi_sel_clear(struct ipmi_intf * intf)
{
@@ -2869,11 +2831,11 @@ ipmi_sel_clear(struct ipmi_intf * intf)
req.msg.data_len = 6;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to clear SEL");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Unable to clear SEL: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -2892,7 +2854,7 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
uint8_t msg_data[4];
int rc = 0;
- if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
+ if (!argc || !strcmp(argv[0], "help")) {
lprintf(LOG_ERR, "usage: delete <id>...<id>\n");
return -1;
}
@@ -2923,11 +2885,11 @@ ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to delete entry %d", id);
rc = -1;
}
- else if (rsp->ccode > 0) {
+ else if (rsp->ccode) {
lprintf(LOG_ERR, "Unable to delete entry %d: %s", id,
val2str(rsp->ccode, completion_code_vals));
rc = -1;
@@ -2953,16 +2915,11 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
int rc = 0;
uint16_t id;
- if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
+ if (!argc || !strcmp(argv[0], "help")) {
lprintf(LOG_ERR, "usage: sel get <id>...<id>");
return (-1);
}
- if (ipmi_sel_reserve(intf) == 0) {
- lprintf(LOG_ERR, "Unable to reserve SEL");
- return (-1);
- }
-
for (i = 0; i < argc; i++) {
if (str2ushort(argv[i], &id) != 0) {
lprintf(LOG_ERR, "Given SEL ID '%s' is invalid.",
@@ -2994,7 +2951,7 @@ ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
evt.sel_type.standard_type.gen_id,
evt.sel_type.standard_type.sensor_num,
evt.sel_type.standard_type.sensor_type);
- if (sdr == NULL) {
+ if (!sdr) {
continue;
}
@@ -3042,10 +2999,10 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
if (argc == 0)
rc = ipmi_sel_get_info(intf);
- else if (strncmp(argv[0], "help", 4) == 0)
+ else if (!strcmp(argv[0], "help"))
lprintf(LOG_ERR, "SEL Commands: "
"info clear delete list elist get add time save readraw writeraw interpret");
- else if (strncmp(argv[0], "interpret", 9) == 0) {
+ else if (!strcmp(argv[0], "interpret")) {
uint32_t iana = 0;
if (argc < 4) {
lprintf(LOG_NOTICE, "usage: sel interpret iana filename format(pps)");
@@ -3058,37 +3015,37 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
}
rc = ipmi_sel_interpret(intf, iana, argv[2], argv[3]);
}
- else if (strncmp(argv[0], "info", 4) == 0)
+ else if (!strcmp(argv[0], "info"))
rc = ipmi_sel_get_info(intf);
- else if (strncmp(argv[0], "save", 4) == 0) {
+ else if (!strcmp(argv[0], "save")) {
if (argc < 2) {
lprintf(LOG_NOTICE, "usage: sel save <filename>");
return 0;
}
rc = ipmi_sel_save_entries(intf, 0, argv[1]);
}
- else if (strncmp(argv[0], "add", 3) == 0) {
+ else if (!strcmp(argv[0], "add")) {
if (argc < 2) {
lprintf(LOG_NOTICE, "usage: sel add <filename>");
return 0;
}
rc = ipmi_sel_add_entries_fromfile(intf, argv[1]);
}
- else if (strncmp(argv[0], "writeraw", 8) == 0) {
+ else if (!strcmp(argv[0], "writeraw")) {
if (argc < 2) {
lprintf(LOG_NOTICE, "usage: sel writeraw <filename>");
return 0;
}
rc = ipmi_sel_writeraw(intf, argv[1]);
}
- else if (strncmp(argv[0], "readraw", 7) == 0) {
+ else if (!strcmp(argv[0], "readraw")) {
if (argc < 2) {
lprintf(LOG_NOTICE, "usage: sel readraw <filename>");
return 0;
}
rc = ipmi_sel_readraw(intf, argv[1]);
}
- else if (strncmp(argv[0], "ereadraw", 8) == 0) {
+ else if (!strcmp(argv[0], "ereadraw")) {
if (argc < 2) {
lprintf(LOG_NOTICE, "usage: sel ereadraw <filename>");
return 0;
@@ -3096,8 +3053,9 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
sel_extended = 1;
rc = ipmi_sel_readraw(intf, argv[1]);
}
- else if (strncmp(argv[0], "list", 4) == 0 ||
- strncmp(argv[0], "elist", 5) == 0) {
+ else if (!strcmp(argv[0], "list")
+ || !strcmp(argv[0], "elist"))
+ {
/*
* Usage:
* list - show all SEL entries
@@ -3108,7 +3066,7 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
int sign = 1;
char *countstr = NULL;
- if (strncmp(argv[0], "elist", 5) == 0)
+ if (!strcmp(argv[0], "elist"))
sel_extended = 1;
else
sel_extended = 0;
@@ -3119,10 +3077,10 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
else if (argc == 3) {
countstr = argv[2];
- if (strncmp(argv[1], "last", 4) == 0) {
+ if (!strcmp(argv[1], "last")) {
sign = -1;
}
- else if (strncmp(argv[1], "first", 5) != 0) {
+ else if (strcmp(argv[1], "first")) {
lprintf(LOG_ERR, "Unknown sel list option");
return -1;
}
@@ -3139,26 +3097,26 @@ int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
rc = ipmi_sel_list_entries(intf,count);
}
- else if (strncmp(argv[0], "clear", 5) == 0)
+ else if (!strcmp(argv[0], "clear"))
rc = ipmi_sel_clear(intf);
- else if (strncmp(argv[0], "delete", 6) == 0) {
+ else if (!strcmp(argv[0], "delete")) {
if (argc < 2)
lprintf(LOG_ERR, "usage: sel delete <id>...<id>");
else
rc = ipmi_sel_delete(intf, argc-1, &argv[1]);
}
- else if (strncmp(argv[0], "get", 3) == 0) {
+ else if (!strcmp(argv[0], "get")) {
if (argc < 2)
lprintf(LOG_ERR, "usage: sel get <entry>");
else
rc = ipmi_sel_show_entry(intf, argc-1, &argv[1]);
}
- else if (strncmp(argv[0], "time", 4) == 0) {
+ else if (!strcmp(argv[0], "time")) {
if (argc < 2)
lprintf(LOG_ERR, "sel time commands: get set");
- else if (strncmp(argv[1], "get", 3) == 0)
+ else if (!strcmp(argv[1], "get"))
ipmi_sel_get_time(intf);
- else if (strncmp(argv[1], "set", 3) == 0) {
+ else if (!strcmp(argv[1], "set")) {
if (argc < 3)
lprintf(LOG_ERR, "usage: sel time set \"mm/dd/yyyy hh:mm:ss\"");
else
diff --git a/lib/ipmi_sensor.c b/lib/ipmi_sensor.c
index a0b7eb8..45d6d6d 100644
--- a/lib/ipmi_sensor.c
+++ b/lib/ipmi_sensor.c
@@ -62,7 +62,7 @@ ipmi_sensor_get_sensor_reading_factors(
char id[17];
- if (intf == NULL || sensor == NULL)
+ if (!intf || !sensor)
return -1;
memset(id, 0, sizeof(id));
@@ -80,7 +80,7 @@ ipmi_sensor_get_sensor_reading_factors(
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error updating reading factor for sensor %s (#%02x)",
id, sensor->cmn.keys.sensor_num);
return -1;
@@ -164,12 +164,30 @@ ipmi_sensor_print_fc_discrete(struct ipmi_intf *intf,
sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 3);
- if (sr == NULL) {
+ if (!sr) {
return -1;
}
if (csv_output) {
- /* NOT IMPLEMENTED */
+ printf("%s", sr->s_id);
+ if (sr->s_reading_valid) {
+ if (sr->s_has_analog_value) {
+ /* don't show discrete component */
+ printf(",%s,%s,%s",
+ sr->s_a_str, sr->s_a_units, "ok");
+ } else {
+ printf(",0x%x,%s,0x%02x%02x",
+ sr->s_reading, "discrete",
+ sr->s_data2, sr->s_data3);
+ }
+ } else {
+ printf(",%s,%s,%s",
+ "na", "discrete", "na");
+ }
+ printf(",%s,%s,%s,%s,%s,%s",
+ "na", "na", "na", "na", "na", "na");
+
+ printf("\n");
} else {
if (verbose == 0) {
/* output format
@@ -242,6 +260,184 @@ print_thresh_setting(struct sdr_record_full_sensor *full,
}
}
+static void
+dump_sensor_fc_thredshold_csv(
+ int thresh_available,
+ const char *thresh_status,
+ struct ipmi_rs *rsp,
+ struct sensor_reading *sr)
+{
+ printf("%s", sr->s_id);
+ if (sr->s_reading_valid) {
+ if (sr->s_has_analog_value)
+ printf(",%.3f,%s,%s",
+ sr->s_a_val, sr->s_a_units, thresh_status);
+ else
+ printf(",0x%x,%s,%s",
+ sr->s_reading, sr->s_a_units, thresh_status);
+ } else {
+ printf(",%s,%s,%s",
+ "na", sr->s_a_units, "na");
+ }
+ if (thresh_available && sr->full) {
+#define PTS(bit, dataidx) { \
+print_thresh_setting(sr->full, rsp->data[0] & (bit), \
+rsp->data[(dataidx)], ",", "%.3f", "0x%x", "%s"); \
+}
+ PTS(LOWER_NON_RECOV_SPECIFIED, 3);
+ PTS(LOWER_CRIT_SPECIFIED, 2);
+ PTS(LOWER_NON_CRIT_SPECIFIED, 1);
+ PTS(UPPER_NON_CRIT_SPECIFIED, 4);
+ PTS(UPPER_CRIT_SPECIFIED, 5);
+ PTS(UPPER_NON_RECOV_SPECIFIED, 6);
+#undef PTS
+ } else {
+ printf(",%s,%s,%s,%s,%s,%s",
+ "na", "na", "na", "na", "na", "na");
+ }
+ printf("\n");
+}
+
+/* output format
+ * id value units status thresholds....
+ */
+static void
+dump_sensor_fc_thredshold(
+ int thresh_available,
+ const char *thresh_status,
+ struct ipmi_rs *rsp,
+ struct sensor_reading *sr)
+{
+ printf("%-16s ", sr->s_id);
+ if (sr->s_reading_valid) {
+ if (sr->s_has_analog_value)
+ printf("| %-10.3f | %-10s | %-6s",
+ sr->s_a_val, sr->s_a_units, thresh_status);
+ else
+ printf("| 0x%-8x | %-10s | %-6s",
+ sr->s_reading, sr->s_a_units, thresh_status);
+ } else {
+ printf("| %-10s | %-10s | %-6s",
+ "na", sr->s_a_units, "na");
+ }
+ if (thresh_available && sr->full) {
+#define PTS(bit, dataidx) { \
+print_thresh_setting(sr->full, rsp->data[0] & (bit), \
+rsp->data[(dataidx)], "| ", "%-10.3f", "0x%-8x", "%-10s"); \
+}
+ PTS(LOWER_NON_RECOV_SPECIFIED, 3);
+ PTS(LOWER_CRIT_SPECIFIED, 2);
+ PTS(LOWER_NON_CRIT_SPECIFIED, 1);
+ PTS(UPPER_NON_CRIT_SPECIFIED, 4);
+ PTS(UPPER_CRIT_SPECIFIED, 5);
+ PTS(UPPER_NON_RECOV_SPECIFIED, 6);
+#undef PTS
+ } else {
+ printf("| %-10s| %-10s| %-10s| %-10s| %-10s| %-10s",
+ "na", "na", "na", "na", "na", "na");
+ }
+
+ printf("\n");
+}
+
+static void
+dump_sensor_fc_thredshold_verbose(
+ int thresh_available,
+ const char *thresh_status,
+ struct ipmi_intf *intf,
+ struct sdr_record_common_sensor *sensor,
+ struct ipmi_rs *rsp,
+ struct sensor_reading *sr)
+{
+ printf("Sensor ID : %s (0x%x)\n",
+ sr->s_id, sensor->keys.sensor_num);
+
+ printf(" Entity ID : %d.%d\n",
+ sensor->entity.id, sensor->entity.instance);
+
+ printf(" Sensor Type (Threshold) : %s\n",
+ ipmi_get_sensor_type(intf, sensor->sensor.type));
+
+ printf(" Sensor Reading : ");
+ if (sr->s_reading_valid) {
+ if (sr->full) {
+ uint16_t raw_tol = __TO_TOL(sr->full->mtol);
+ if (sr->s_has_analog_value) {
+ double tol =
+ sdr_convert_sensor_tolerance(sr->full,
+ raw_tol);
+ printf("%.*f (+/- %.*f) %s\n",
+ (sr->s_a_val == (int)
+ sr->s_a_val) ? 0 : 3,
+ sr->s_a_val,
+ (tol == (int) tol) ? 0 : 3, tol,
+ sr->s_a_units);
+ } else {
+ printf("0x%x (+/- 0x%x) %s\n",
+ sr->s_reading,
+ raw_tol,
+ sr->s_a_units);
+ }
+ } else {
+ printf("0x%x %s\n",
+ sr->s_reading, sr->s_a_units);
+ }
+ printf(" Status : %s\n", thresh_status);
+
+ if (thresh_available) {
+ if (sr->full) {
+#define PTS(bit, dataidx, str) { \
+print_thresh_setting(sr->full, rsp->data[0] & (bit), \
+ rsp->data[(dataidx)], \
+ (str), "%.3f\n", "0x%x\n", "%s\n"); \
+}
+ PTS(LOWER_NON_RECOV_SPECIFIED, 3, " Lower Non-Recoverable : ");
+ PTS(LOWER_CRIT_SPECIFIED, 2, " Lower Critical : ");
+ PTS(LOWER_NON_CRIT_SPECIFIED, 1, " Lower Non-Critical : ");
+ PTS(UPPER_NON_CRIT_SPECIFIED, 4, " Upper Non-Critical : ");
+ PTS(UPPER_CRIT_SPECIFIED, 5, " Upper Critical : ");
+ PTS(UPPER_NON_RECOV_SPECIFIED, 6, " Upper Non-Recoverable : ");
+#undef PTS
+
+ }
+ ipmi_sdr_print_sensor_hysteresis(sensor, sr->full,
+ sr->full ? sr->full->threshold.hysteresis.positive :
+ sr->compact->threshold.hysteresis.positive,
+ "Positive Hysteresis");
+
+ ipmi_sdr_print_sensor_hysteresis(sensor, sr->full,
+ sr->full ? sr->full->threshold.hysteresis.negative :
+ sr->compact->threshold.hysteresis.negative,
+ "Negative Hysteresis");
+ } else {
+ printf(" Sensor Threshold Settings not available\n");
+ }
+ } else {
+ printf(" Unable to read sensor: Device Not Present\n\n");
+ }
+
+ ipmi_sdr_print_sensor_event_status(intf,
+ sensor->keys.
+ sensor_num,
+ sensor->sensor.type,
+ sensor->event_type,
+ ANALOG_SENSOR,
+ sensor->keys.owner_id,
+ sensor->keys.lun,
+ sensor->keys.channel);
+ ipmi_sdr_print_sensor_event_enable(intf,
+ sensor->keys.
+ sensor_num,
+ sensor->sensor.type,
+ sensor->event_type,
+ ANALOG_SENSOR,
+ sensor->keys.owner_id,
+ sensor->keys.lun,
+ sensor->keys.channel);
+
+ printf("\n");
+}
+
static int
ipmi_sensor_print_fc_threshold(struct ipmi_intf *intf,
struct sdr_record_common_sensor *sensor,
@@ -253,7 +449,7 @@ ipmi_sensor_print_fc_threshold(struct ipmi_intf *intf,
sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr_record_type, 3);
- if (sr == NULL) {
+ if (!sr) {
return -1;
}
@@ -266,137 +462,17 @@ ipmi_sensor_print_fc_threshold(struct ipmi_intf *intf,
sensor->keys.sensor_num, sensor->keys.owner_id,
sensor->keys.lun, sensor->keys.channel);
- if ((rsp == NULL) || (rsp->ccode > 0) || (rsp->data_len == 0))
+ if (!rsp || rsp->ccode || !rsp->data_len)
thresh_available = 0;
if (csv_output) {
- /* NOT IMPLEMENTED */
+ dump_sensor_fc_thredshold_csv(thresh_available, thresh_status, rsp, sr);
} else {
if (verbose == 0) {
- /* output format
- * id value units status thresholds....
- */
- printf("%-16s ", sr->s_id);
- if (sr->s_reading_valid) {
- if (sr->s_has_analog_value)
- printf("| %-10.3f | %-10s | %-6s",
- sr->s_a_val, sr->s_a_units, thresh_status);
- else
- printf("| 0x%-8x | %-10s | %-6s",
- sr->s_reading, sr->s_a_units, thresh_status);
- } else {
- printf("| %-10s | %-10s | %-6s",
- "na", sr->s_a_units, "na");
- }
- if (thresh_available && sr->full) {
-#define PTS(bit, dataidx) { \
- print_thresh_setting(sr->full, rsp->data[0] & (bit), \
- rsp->data[(dataidx)], "| ", "%-10.3f", "0x-8x", "%-10s"); \
-}
- PTS(LOWER_NON_RECOV_SPECIFIED, 3);
- PTS(LOWER_CRIT_SPECIFIED, 2);
- PTS(LOWER_NON_CRIT_SPECIFIED, 1);
- PTS(UPPER_NON_CRIT_SPECIFIED, 4);
- PTS(UPPER_CRIT_SPECIFIED, 5);
- PTS(UPPER_NON_RECOV_SPECIFIED, 6);
-#undef PTS
- } else {
- printf
- ("| %-10s| %-10s| %-10s| %-10s| %-10s| %-10s",
- "na", "na", "na", "na", "na", "na");
- }
-
- printf("\n");
+ dump_sensor_fc_thredshold(thresh_available, thresh_status, rsp, sr);
} else {
- printf("Sensor ID : %s (0x%x)\n",
- sr->s_id, sensor->keys.sensor_num);
-
- printf(" Entity ID : %d.%d\n",
- sensor->entity.id, sensor->entity.instance);
-
- printf(" Sensor Type (Threshold) : %s\n",
- ipmi_get_sensor_type(intf, sensor->sensor.
- type));
-
- printf(" Sensor Reading : ");
- if (sr->s_reading_valid) {
- if (sr->full) {
- uint16_t raw_tol = __TO_TOL(sr->full->mtol);
- if (sr->s_has_analog_value) {
- double tol =
- sdr_convert_sensor_tolerance(sr->full,
- raw_tol);
- printf("%.*f (+/- %.*f) %s\n",
- (sr->s_a_val == (int)
- sr->s_a_val) ? 0 : 3,
- sr->s_a_val,
- (tol == (int) tol) ? 0 : 3, tol,
- sr->s_a_units);
- } else {
- printf("0x%x (+/- 0x%x) %s\n",
- sr->s_reading,
- raw_tol,
- sr->s_a_units);
- }
- } else {
- printf("0x%x %s\n", sr->s_reading,
- sr->s_a_units);
- }
- printf(" Status : %s\n", thresh_status);
-
- if (thresh_available) {
- if (sr->full) {
-#define PTS(bit, dataidx, str) { \
-print_thresh_setting(sr->full, rsp->data[0] & (bit), \
- rsp->data[(dataidx)], \
- (str), "%.3f\n", "0x%x\n", "%s\n"); \
-}
-
- PTS(LOWER_NON_RECOV_SPECIFIED, 3, " Lower Non-Recoverable : ");
- PTS(LOWER_CRIT_SPECIFIED, 2, " Lower Critical : ");
- PTS(LOWER_NON_CRIT_SPECIFIED, 1, " Lower Non-Critical : ");
- PTS(UPPER_NON_CRIT_SPECIFIED, 4, " Upper Non-Critical : ");
- PTS(UPPER_CRIT_SPECIFIED, 5, " Upper Critical : ");
- PTS(UPPER_NON_RECOV_SPECIFIED, 6, " Upper Non-Recoverable : ");
-#undef PTS
-
- }
- ipmi_sdr_print_sensor_hysteresis(sensor, sr->full,
- sr->full ? sr->full->threshold.hysteresis.positive :
- sr->compact->threshold.hysteresis.positive,
- "Positive Hysteresis");
-
- ipmi_sdr_print_sensor_hysteresis(sensor, sr->full,
- sr->full ? sr->full->threshold.hysteresis.negative :
- sr->compact->threshold.hysteresis.negative,
- "Negative Hysteresis");
- } else {
- printf(" Sensor Threshold Settings not available\n");
- }
- } else {
- printf(" Unable to read sensor: Device Not Present\n\n");
- }
-
- ipmi_sdr_print_sensor_event_status(intf,
- sensor->keys.
- sensor_num,
- sensor->sensor.type,
- sensor->event_type,
- ANALOG_SENSOR,
- sensor->keys.owner_id,
- sensor->keys.lun,
- sensor->keys.channel);
- ipmi_sdr_print_sensor_event_enable(intf,
- sensor->keys.
- sensor_num,
- sensor->sensor.type,
- sensor->event_type,
- ANALOG_SENSOR,
- sensor->keys.owner_id,
- sensor->keys.lun,
- sensor->keys.channel);
-
- printf("\n");
+ dump_sensor_fc_thredshold_verbose(thresh_available, thresh_status,
+ intf, sensor, rsp, sr);
}
}
@@ -424,16 +500,16 @@ ipmi_sensor_list(struct ipmi_intf *intf)
lprintf(LOG_DEBUG, "Querying SDR for sensor list");
itr = ipmi_sdr_start(intf, 0);
- if (itr == NULL) {
+ if (!itr) {
lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1;
}
- while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
+ while ((header = ipmi_sdr_get_next_header(intf, itr))) {
uint8_t *rec;
rec = ipmi_sdr_get_record(intf, header, itr);
- if (rec == NULL) {
+ if (!rec) {
lprintf(LOG_DEBUG, "rec == NULL");
continue;
}
@@ -456,7 +532,7 @@ ipmi_sensor_list(struct ipmi_intf *intf)
/* rc = (r == 0) ? rc : r; */
}
- ipmi_sdr_end(intf, itr);
+ ipmi_sdr_end(itr);
return rc;
}
@@ -481,11 +557,11 @@ __ipmi_sensor_set_threshold(struct ipmi_intf *intf,
rsp = ipmi_sensor_set_sensor_thresholds(intf, num, mask, setting,
target, lun, channel);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting threshold");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Error setting threshold: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -529,7 +605,7 @@ ipmi_sensor_set_threshold(struct ipmi_intf *intf, int argc, char **argv)
struct sdr_record_list *sdr;
- if (argc < 3 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc < 3 || !strcmp(argv[0], "help")) {
print_sensor_thresh_usage();
return 0;
}
@@ -537,7 +613,7 @@ ipmi_sensor_set_threshold(struct ipmi_intf *intf, int argc, char **argv)
id = argv[0];
thresh = argv[1];
- if (strncmp(thresh, "upper", 5) == 0) {
+ if (!strcmp(thresh, "upper")) {
if (argc < 5) {
lprintf(LOG_ERR,
"usage: sensor thresh <id> upper <unc> <ucr> <unr>");
@@ -559,7 +635,7 @@ ipmi_sensor_set_threshold(struct ipmi_intf *intf, int argc, char **argv)
argv[4]);
return (-1);
}
- } else if (strncmp(thresh, "lower", 5) == 0) {
+ } else if (!strcmp(thresh, "lower")) {
if (argc < 5) {
lprintf(LOG_ERR,
"usage: sensor thresh <id> lower <lnr> <lcr> <lnc>");
@@ -582,17 +658,17 @@ ipmi_sensor_set_threshold(struct ipmi_intf *intf, int argc, char **argv)
return (-1);
}
} else {
- if (strncmp(thresh, "unr", 3) == 0)
+ if (!strcmp(thresh, "unr"))
settingMask = UPPER_NON_RECOV_SPECIFIED;
- else if (strncmp(thresh, "ucr", 3) == 0)
+ else if (!strcmp(thresh, "ucr"))
settingMask = UPPER_CRIT_SPECIFIED;
- else if (strncmp(thresh, "unc", 3) == 0)
+ else if (!strcmp(thresh, "unc"))
settingMask = UPPER_NON_CRIT_SPECIFIED;
- else if (strncmp(thresh, "lnc", 3) == 0)
+ else if (!strcmp(thresh, "lnc"))
settingMask = LOWER_NON_CRIT_SPECIFIED;
- else if (strncmp(thresh, "lcr", 3) == 0)
+ else if (!strcmp(thresh, "lcr"))
settingMask = LOWER_CRIT_SPECIFIED;
- else if (strncmp(thresh, "lnr", 3) == 0)
+ else if (!strcmp(thresh, "lnr"))
settingMask = LOWER_NON_RECOV_SPECIFIED;
else {
lprintf(LOG_ERR,
@@ -612,7 +688,7 @@ ipmi_sensor_set_threshold(struct ipmi_intf *intf, int argc, char **argv)
/* lookup by sensor name */
sdr = ipmi_sdr_find_sdr_byid(intf, id);
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR, "Sensor data record not found!");
return -1;
}
@@ -721,7 +797,7 @@ ipmi_sensor_set_threshold(struct ipmi_intf *intf, int argc, char **argv)
sdr->record.common->keys.owner_id,
sdr->record.common->keys.lun,
sdr->record.common->keys.channel);
- if ((rsp == NULL) || (rsp->ccode > 0)) {
+ if (!rsp || rsp->ccode) {
lprintf(LOG_ERR, "Sensor data record not found!");
return -1;
}
@@ -810,7 +886,7 @@ ipmi_sensor_get_reading(struct ipmi_intf *intf, int argc, char **argv)
struct sdr_record_list *sdr;
int i, rc=0;
- if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc < 1 || !strcmp(argv[0], "help")) {
lprintf(LOG_NOTICE, "sensor reading <id> ... [id]");
lprintf(LOG_NOTICE, " id : name of desired sensor");
return -1;
@@ -818,7 +894,7 @@ ipmi_sensor_get_reading(struct ipmi_intf *intf, int argc, char **argv)
for (i = 0; i < argc; i++) {
sdr = ipmi_sdr_find_sdr_byid(intf, argv[i]);
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR, "Sensor \"%s\" not found!",
argv[i]);
rc = -1;
@@ -833,7 +909,7 @@ ipmi_sensor_get_reading(struct ipmi_intf *intf, int argc, char **argv)
struct sdr_record_common_sensor *sensor = sdr->record.common;
sr = ipmi_sdr_read_sensor_value(intf, sensor, sdr->type, 3);
- if (sr == NULL) {
+ if (!sr) {
rc = -1;
continue;
}
@@ -874,7 +950,7 @@ ipmi_sensor_get(struct ipmi_intf *intf, int argc, char **argv)
lprintf(LOG_ERR, "Not enough parameters given.");
print_sensor_get_usage();
return (-1);
- } else if (strcmp(argv[0], "help") == 0) {
+ } else if (!strcmp(argv[0], "help")) {
print_sensor_get_usage();
return 0;
}
@@ -882,7 +958,7 @@ ipmi_sensor_get(struct ipmi_intf *intf, int argc, char **argv)
/* lookup by sensor name */
for (i = 0; i < argc; i++) {
sdr = ipmi_sdr_find_sdr_byid(intf, argv[i]);
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR, "Sensor data record \"%s\" not found!",
argv[i]);
rc = -1;
@@ -919,15 +995,15 @@ ipmi_sensor_main(struct ipmi_intf *intf, int argc, char **argv)
if (argc == 0) {
rc = ipmi_sensor_list(intf);
- } else if (strncmp(argv[0], "help", 4) == 0) {
+ } else if (!strcmp(argv[0], "help")) {
lprintf(LOG_NOTICE, "Sensor Commands: list thresh get reading");
- } else if (strncmp(argv[0], "list", 4) == 0) {
+ } else if (!strcmp(argv[0], "list")) {
rc = ipmi_sensor_list(intf);
- } else if (strncmp(argv[0], "thresh", 5) == 0) {
+ } else if (!strcmp(argv[0], "thresh")) {
rc = ipmi_sensor_set_threshold(intf, argc - 1, &argv[1]);
- } else if (strncmp(argv[0], "get", 3) == 0) {
+ } else if (!strcmp(argv[0], "get")) {
rc = ipmi_sensor_get(intf, argc - 1, &argv[1]);
- } else if (strncmp(argv[0], "reading", 7) == 0) {
+ } else if (!strcmp(argv[0], "reading")) {
rc = ipmi_sensor_get_reading(intf, argc - 1, &argv[1]);
} else {
lprintf(LOG_ERR, "Invalid sensor command: %s", argv[0]);
diff --git a/lib/ipmi_session.c b/lib/ipmi_session.c
index 141f0f4..70a3521 100644
--- a/lib/ipmi_session.c
+++ b/lib/ipmi_session.c
@@ -288,12 +288,12 @@ ipmi_get_session_info(struct ipmi_intf * intf,
}
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL)
+ if (!rsp)
{
lprintf(LOG_ERR, "Get Session Info command failed");
retval = -1;
}
- else if (rsp->ccode > 0)
+ else if (rsp->ccode)
{
lprintf(LOG_ERR, "Get Session Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
@@ -302,15 +302,19 @@ ipmi_get_session_info(struct ipmi_intf * intf,
if (retval < 0)
{
- if ((session_request_type == IPMI_SESSION_REQUEST_CURRENT) &&
- (strncmp(intf->name, "lan", 3) != 0))
+ if (session_request_type == IPMI_SESSION_REQUEST_CURRENT
+ && strcmp(intf->name, "lan"))
+ {
lprintf(LOG_ERR, "It is likely that the channel in use "
"does not support sessions");
+ }
}
else
{
- memcpy(&session_info, rsp->data, rsp->data_len);
- print_session_info(&session_info, rsp->data_len);
+ memcpy(&session_info, rsp->data,
+ __min(rsp->data_len, sizeof(session_info)));
+ print_session_info(&session_info,
+ __min(rsp->data_len, sizeof(session_info)));
}
break;
@@ -322,13 +326,13 @@ ipmi_get_session_info(struct ipmi_intf * intf,
rqdata[0] = i++;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL)
+ if (!rsp)
{
lprintf(LOG_ERR, "Get Session Info command failed");
retval = -1;
break;
}
- else if (rsp->ccode > 0 && rsp->ccode != 0xCC && rsp->ccode != 0xCB)
+ else if (rsp->ccode && rsp->ccode != 0xCC && rsp->ccode != 0xCB)
{
lprintf(LOG_ERR, "Get Session Info command failed: %s",
val2str(rsp->ccode, completion_code_vals));
@@ -341,8 +345,10 @@ ipmi_get_session_info(struct ipmi_intf * intf,
break;
}
- memcpy(&session_info, rsp->data, rsp->data_len);
- print_session_info(&session_info, rsp->data_len);
+ memcpy(&session_info, rsp->data,
+ __min(rsp->data_len, sizeof(session_info)));
+ print_session_info(&session_info,
+ __min(rsp->data_len, sizeof(session_info)));
} while (i <= session_info.session_slot_count);
break;
@@ -365,14 +371,14 @@ ipmi_session_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int retval = 0;
- if (argc == 0 || strncmp(argv[0], "help", 4) == 0)
+ if (!argc || !strcmp(argv[0], "help"))
{
printf_session_usage();
}
- else if (strncmp(argv[0], "info", 4) == 0)
+ else if (!strcmp(argv[0], "info"))
{
- if ((argc < 2) || strncmp(argv[1], "help", 4) == 0)
+ if (argc < 2 || !strcmp(argv[1], "help"))
{
printf_session_usage();
}
@@ -381,11 +387,11 @@ ipmi_session_main(struct ipmi_intf * intf, int argc, char ** argv)
Ipmi_Session_Request_Type session_request_type = 0;
uint32_t id_or_handle = 0;
- if (strncmp(argv[1], "active", 6) == 0)
+ if (!strcmp(argv[1], "active"))
session_request_type = IPMI_SESSION_REQUEST_CURRENT;
- else if (strncmp(argv[1], "all", 3) == 0)
+ else if (!strcmp(argv[1], "all"))
session_request_type = IPMI_SESSION_REQUEST_ALL;
- else if (strncmp(argv[1], "id", 2) == 0)
+ else if (!strcmp(argv[1], "id"))
{
if (argc >= 3)
{
@@ -404,7 +410,7 @@ ipmi_session_main(struct ipmi_intf * intf, int argc, char ** argv)
retval = -1;
}
}
- else if (strncmp(argv[1], "handle", 6) == 0)
+ else if (!strcmp(argv[1], "handle"))
{
if (argc >= 3)
{
diff --git a/lib/ipmi_sol.c b/lib/ipmi_sol.c
index 3acd5bb..8e7285c 100644
--- a/lib/ipmi_sol.c
+++ b/lib/ipmi_sol.c
@@ -29,11 +29,6 @@
* 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 _XOPEN_SOURCE
-#define _BSD_SOURCE || \
- (_XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
- !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
#include <stdlib.h>
#include <string.h>
@@ -130,11 +125,11 @@ ipmi_sol_payload_access(struct ipmi_intf * intf, uint8_t channel,
/* payload 1 is SOL */
data[2] = 0x02;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error %sabling SOL payload for user %d on channel %d",
enable ? "en" : "dis", userid, channel);
rc = (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Error %sabling SOL payload for user %d on channel %d: %s",
enable ? "en" : "dis", userid, channel,
val2str(rsp->ccode, completion_code_vals));
@@ -164,7 +159,7 @@ ipmi_sol_payload_access_status(struct ipmi_intf * intf,
data[1] = userid & 0x3f; /* user id */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error. No valid response received.");
return -1;
}
@@ -219,7 +214,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -257,7 +252,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -295,7 +290,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -335,7 +330,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -374,7 +369,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -413,7 +408,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -451,7 +446,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -489,7 +484,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -528,7 +523,7 @@ ipmi_get_sol_info(
data[3] = 0x00; /* block selector */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error: No response requesting SOL parameter '%s'",
val2str(data[1], sol_parameter_vals));
return (-1);
@@ -546,7 +541,7 @@ ipmi_get_sol_info(
}
break;
case 0x80:
- if( intf->session != NULL ) {
+ if (intf->session) {
lprintf(LOG_ERR, "Info: SOL parameter '%s' not supported - defaulting to %d",
val2str(data[1], sol_parameter_vals), intf->ssn_params.port);
params->payload_port = intf->ssn_params.port;
@@ -653,13 +648,14 @@ ipmi_print_sol_info(struct ipmi_intf * intf, uint8_t channel)
*
* function will return -1 if value is not valid, or
* will return 0 if valid.
+ *
+ * base parameter currently unused, left in for extension.
*/
-int ipmi_sol_set_param_isvalid_uint8_t( const char *strval,
- const char *name,
- int base,
- uint8_t minval,
- uint8_t maxval,
- uint8_t *out_value)
+int ipmi_sol_set_param_isvalid_uint8_t(const char *strval,
+ const char *name,
+ uint8_t minval,
+ uint8_t maxval,
+ uint8_t *out_value)
{
if (str2uchar(strval, out_value) != 0 || (*out_value < minval)
|| (*out_value > maxval)) {
@@ -871,7 +867,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
/* validate user-supplied input */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 1, 255, &data[2]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 1, 255, &data[2]))
return -1;
/* We need other values to complete the request */
@@ -897,7 +893,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
/* validate user-supplied input */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 255, &data[3]))
return -1;
/* We need other values to complete the request */
@@ -923,7 +919,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_SOL_RETRY;
/* validate user input, 7 is max value */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 7, &data[2]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 7, &data[2]))
return -1;
/* We need other values to complete the request */
@@ -949,7 +945,7 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
data[1] = SOL_PARAMETER_SOL_RETRY;
/* validate user-supplied input */
- if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 0, 255, &data[3]))
+ if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 255, &data[3]))
return -1;
/* We need other values to complete the request */
@@ -1073,13 +1069,13 @@ ipmi_sol_set_param(struct ipmi_intf * intf,
/* The command proper */
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Error setting SOL parameter '%s'", param);
return -1;
}
- if (!(!strncmp(param, "set-in-progress", 15) && !strncmp(value, "commit-write", 12)) &&
- rsp->ccode > 0) {
+ if (!(!strcmp(param, "set-in-progress") && !strcmp(value, "commit-write")) &&
+ rsp->ccode) {
switch (rsp->ccode) {
case 0x80:
lprintf(LOG_ERR, "Error setting SOL parameter '%s': "
@@ -1491,7 +1487,7 @@ ipmi_sol_keepalive_using_sol(struct ipmi_intf * intf)
if (end.tv_sec - _start_keepalive.tv_sec > SOL_KEEPALIVE_TIMEOUT) {
memset(&v2_payload, 0, sizeof(v2_payload));
v2_payload.payload.sol_packet.character_count = 0;
- if (intf->send_sol(intf, &v2_payload) == NULL)
+ if (!intf->send_sol(intf, &v2_payload))
return -1;
/* good return, reset start time */
gettimeofday(&_start_keepalive, 0);
@@ -1542,7 +1538,7 @@ ipmi_sol_red_pill(struct ipmi_intf * intf, int instance)
buffer_size -= 4;
buffer = (char*)malloc(buffer_size);
- if (buffer == NULL) {
+ if (!buffer) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
@@ -1709,7 +1705,7 @@ ipmi_sol_activate(struct ipmi_intf * intf, int looptest, int interval,
* This command is only available over RMCP+ (the lanplus
* interface).
*/
- if (strncmp(intf->name, "lanplus", 7) != 0)
+ if (strcmp(intf->name, "lanplus"))
{
lprintf(LOG_ERR, "Error: This command is only available over the "
"lanplus interface");
@@ -1822,9 +1818,6 @@ ipmi_sol_activate(struct ipmi_intf * intf, int looptest, int interval,
(ap_rsp.payload_udp_port[1] << 8) |
ap_rsp.payload_udp_port[0];
- intf->session->timeout = 1;
-
-
/* NOTE: the spec does allow for SOL traffic to be sent on
* a different port. we do not yet support that feature. */
if (intf->session->sol_data.port != intf->ssn_params.port)
@@ -1915,10 +1908,13 @@ int
ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int retval = 0;
- if (!argc || !strncmp(argv[0], "help", 4)) {
+ const char *instance_kw = "instance=";
+ size_t instance_len = strlen(instance_kw);
+
+ if (!argc || !strcmp(argv[0], "help")) {
/* Help */
print_sol_usage();
- } else if (!strncmp(argv[0], "info", 4)) {
+ } else if (!strcmp(argv[0], "info")) {
/* Info */
uint8_t channel;
if (argc == 1) {
@@ -1933,7 +1929,7 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
retval = ipmi_print_sol_info(intf, channel);
- } else if (!strncmp(argv[0], "payload", 7)) {
+ } else if (!strcmp(argv[0], "payload")) {
/* Payload enable or disable */
uint8_t channel = 0xe;
uint8_t userid = 1;
@@ -1952,25 +1948,25 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
}
- if (!strncmp(argv[1], "enable", 6)) {
+ if (!strcmp(argv[1], "enable")) {
enable = 1;
- } else if (!strncmp(argv[1], "disable", 7)) {
+ } else if (!strcmp(argv[1], "disable")) {
enable = 0;
- } else if (!strncmp(argv[1], "status", 6)) {
+ } else if (!strcmp(argv[1], "status")) {
return ipmi_sol_payload_access_status(intf, channel, userid);
} else {
print_sol_usage();
return -1;
}
retval = ipmi_sol_payload_access(intf, channel, userid, enable);
- } else if (!strncmp(argv[0], "set", 3)) {
+ } else if (!strcmp(argv[0], "set")) {
/* Set a parameter value */
uint8_t channel = 0xe;
uint8_t guard = 1;
if (argc == 3) {
channel = 0xe;
} else if (argc == 4) {
- if (!strncmp(argv[3], "noguard", 7)) {
+ if (!strcmp(argv[3], "noguard")) {
guard = 0;
} else {
if (is_ipmi_channel_num(argv[3], &channel) != 0) {
@@ -1981,7 +1977,7 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
if (is_ipmi_channel_num(argv[3], &channel) != 0) {
return (-1);
}
- if (!strncmp(argv[4], "noguard", 7)) {
+ if (!strcmp(argv[4], "noguard")) {
guard = 0;
}
} else {
@@ -1989,16 +1985,16 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
retval = ipmi_sol_set_param(intf, channel, argv[1], argv[2], guard);
- } else if (!strncmp(argv[0], "activate", 8)) {
+ } else if (!strcmp(argv[0], "activate")) {
/* Activate */
int i;
uint8_t instance = 1;
for (i = 1; i < argc; i++) {
- if (!strncmp(argv[i], "usesolkeepalive", 15)) {
+ if (!strcmp(argv[i], "usesolkeepalive")) {
_use_sol_for_keepalive = 1;
- } else if (!strncmp(argv[i], "nokeepalive", 11)) {
+ } else if (!strcmp(argv[i], "nokeepalive")) {
_disable_keepalive = 1;
- } else if (!strncmp(argv[i], "instance=", 9)) {
+ } else if (!strncmp(argv[i], instance_kw, instance_len)) {
if (str2uchar(argv[i] + 9, &instance) != 0) {
lprintf(LOG_ERR, "Given instance '%s' is invalid.", argv[i] + 9);
print_sol_usage();
@@ -2010,12 +2006,12 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
}
}
retval = ipmi_sol_activate(intf, 0, 0, instance);
- } else if (!strncmp(argv[0], "deactivate", 10)) {
- /* Dectivate */
+ } else if (!strcmp(argv[0], "deactivate")) {
+ /* Deactivate */
int i;
uint8_t instance = 1;
for (i = 1; i < argc; i++) {
- if (!strncmp(argv[i], "instance=", 9)) {
+ if (!strncmp(argv[i], instance_kw, instance_len)) {
if (str2uchar(argv[i] + 9, &instance) != 0) {
lprintf(LOG_ERR,
"Given instance '%s' is invalid.",
@@ -2029,8 +2025,8 @@ ipmi_sol_main(struct ipmi_intf * intf, int argc, char ** argv)
}
}
retval = ipmi_sol_deactivate(intf, instance);
- } else if (!strncmp(argv[0], "looptest", 8)) {
- /* SOL loop test: Activate and then Dectivate */
+ } else if (!strcmp(argv[0], "looptest")) {
+ /* SOL loop test: Activate and then Deactivate */
int cnt = 200;
int interval = 100; /* Unit is: ms */
uint8_t instance = 1;
diff --git a/lib/ipmi_strings.c b/lib/ipmi_strings.c
index 94b2abd..26b359f 100644
--- a/lib/ipmi_strings.c
+++ b/lib/ipmi_strings.c
@@ -30,77 +30,58 @@
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
+#include <ctype.h>
+#include <limits.h>
#include <stddef.h>
+
#include <ipmitool/ipmi_strings.h>
#include <ipmitool/ipmi_constants.h>
#include <ipmitool/ipmi_sensor.h>
#include <ipmitool/ipmi_sel.h> /* for IPMI_OEM */
+#include <ipmitool/log.h>
+
+/*
+ * These are put at the head so they are found first because they
+ * may overlap with IANA specified numbers found in the registry.
+ */
+static const struct valstr ipmi_oem_info_head[] = {
+ { IPMI_OEM_UNKNOWN, "Unknown" }, /* IPMI Unknown */
+ { IPMI_OEM_RESERVED, "Unspecified" }, /* IPMI Reserved */
+ { UINT32_MAX , NULL },
+};
-const struct valstr ipmi_oem_info[] = {
-
- { IPMI_OEM_UNKNOWN, "Unknown" },
- { IPMI_OEM_HP, "Hewlett-Packard" },
- { IPMI_OEM_SUN, "Sun Microsystems" },
- { IPMI_OEM_INTEL, "Intel Corporation" },
- { IPMI_OEM_LMC, "LMC" },
- { IPMI_OEM_RADISYS, "RadiSys Corporation" },
- { IPMI_OEM_TYAN, "Tyan Computer Corporation" },
- { IPMI_OEM_NEWISYS, "Newisys" },
- { IPMI_OEM_SUPERMICRO, "Supermicro" },
- { IPMI_OEM_GOOGLE, "Google" },
- { IPMI_OEM_KONTRON, "Kontron" },
- { IPMI_OEM_NOKIA, "Nokia" },
- { IPMI_OEM_PICMG, "PICMG" },
- { IPMI_OEM_PEPPERCON, "Peppercon AG" },
- { IPMI_OEM_DELL, "DELL Inc" },
- { IPMI_OEM_NEC, "NEC" },
- { IPMI_OEM_MAGNUM, "Magnum Technologies" },
- { IPMI_OEM_FUJITSU_SIEMENS, "Fujitsu Siemens" },
- { IPMI_OEM_TATUNG, "Tatung" },
- { IPMI_OEM_AMI, "AMI" },
- { IPMI_OEM_RARITAN, "Raritan" },
- { IPMI_OEM_AVOCENT, "Avocent" },
- { IPMI_OEM_OSA, "OSA" },
- { IPMI_OEM_TOSHIBA, "Toshiba" },
- { IPMI_OEM_HITACHI_116, "Hitachi" },
- { IPMI_OEM_HITACHI_399, "Hitachi" },
- { IPMI_OEM_NOKIA_SOLUTIONS_AND_NETWORKS, "Nokia Solutions and Networks" },
- { IPMI_OEM_BULL, "Bull Company" },
- { IPMI_OEM_PPS, "Pigeon Point Systems" },
- { IPMI_OEM_BROADCOM, "Broadcom Corporation" },
- { IPMI_OEM_ERICSSON, "Ericsson AB"},
- { IPMI_OEM_QUANTA, "Quanta" },
- { IPMI_OEM_VITA, "VITA" },
- { IPMI_OEM_ADVANTECH, "Advantech" },
- /************************************************************************
- * Add ID String for IANA Enterprise Number of IBM & ADLINK
- * https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers
- * 2
- * IBM
- * Kristine Adamson
- * adamson&us.ibm.com
- * 4769
- * IBM Corporation
- * Victor Sample
- * vsample&us.ibm.com
- * 20301
- * IBM eServer X
- * Lynn Fore
- * sls&us.ibm.com
- * 24339
- * ADLINK TECHNOLOGY INC.
- * Ryan Hsu
- * ryan.hsu&adlinktech.com
- ************************************************************************/
- { IPMI_OEM_IBM_2, "IBM" },
- { IPMI_OEM_IBM_4769, "IBM Corporation" },
- { IPMI_OEM_IBM_20301, "IBM eServer X" },
- { IPMI_OEM_ADLINK_24339, "ADLINK Technology Inc." },
- { 0xffff , NULL },
+/*
+ * These are our own technical values. We don't want them to take precedence
+ * over IANA's defined values, so they go at the very end of the array.
+ */
+static const struct valstr ipmi_oem_info_tail[] = {
+ { IPMI_OEM_DEBUG, "A Debug Assisting Company, Ltd." },
+ { UINT32_MAX , NULL },
};
+/*
+ * This is used when ipmi_oem_info couldn't be allocated.
+ * ipmitool would report all OEMs as unknown, but would be functional otherwise.
+ */
+static const struct valstr ipmi_oem_info_dummy[] = {
+ { UINT32_MAX , NULL },
+};
+
+/* This will point to an array filled from IANA's enterprise numbers registry */
+const struct valstr *ipmi_oem_info;
+
+/* Single-linked list of OEM valstrs */
+typedef struct oem_valstr_list_s {
+ struct valstr valstr;
+ struct oem_valstr_list_s *next;
+} oem_valstr_list_t;
+
const struct oemvalstr ipmi_oem_product_info[] = {
/* Keep OEM grouped together */
+
+ /* For ipmitool debugging */
+ { IPMI_OEM_DEBUG, 0x1234, "Great Debuggable BMC" },
+
/* Intel stuff, thanks to Tim Bell */
{ IPMI_OEM_INTEL, 0x000C, "TSRLT2" },
{ IPMI_OEM_INTEL, 0x001B, "TIGPR2U" },
@@ -114,6 +95,7 @@ const struct oemvalstr ipmi_oem_product_info[] = {
{ IPMI_OEM_INTEL, 0x0808, "MPCBL0001" },
{ IPMI_OEM_INTEL, 0x0811, "TIGW1U" },
{ IPMI_OEM_INTEL, 0x4311, "NSI2U" },
+
/* Kontron */
{ IPMI_OEM_KONTRON,4000, "AM4000 AdvancedMC" },
{ IPMI_OEM_KONTRON,4001, "AM4001 AdvancedMC" },
@@ -141,10 +123,13 @@ const struct oemvalstr ipmi_oem_product_info[] = {
{ IPMI_OEM_KONTRON,5007, "AT8050" },
{ IPMI_OEM_KONTRON,5301, "AT8400" },
{ IPMI_OEM_KONTRON,5303, "AT8901" },
+
/* Broadcom */
{ IPMI_OEM_BROADCOM, 5725, "BCM5725" },
+
/* Ericsson */
{ IPMI_OEM_ERICSSON, 0x0054, "Phantom" },
+
/* Advantech */
/* ATCA Blades */
{ IPMI_OEM_ADVANTECH, 0x3393, "MIC-3393" },
@@ -227,6 +212,7 @@ const struct oemvalstr ipmi_oem_product_info[] = {
{ IPMI_OEM_ADVANTECH, 0x9212, "ESP-9212" },
{ IPMI_OEM_ADVANTECH, 0x6000, "CGS-6000" },
{ IPMI_OEM_ADVANTECH, 0x6010, "CGS-6010" },
+
/* ADLINK Technology Inc. */
/* AdvancedTCA Processor Blades */
{ IPMI_OEM_ADLINK_24339, 0x3100, "aTCA-3100" },
@@ -283,6 +269,668 @@ const struct oemvalstr ipmi_oem_product_info[] = {
{ IPMI_OEM_ADLINK_24339, 0x0410, "MXN-0410" },
{ IPMI_OEM_ADLINK_24339, 0x2600, "MCN-2600" },
{ IPMI_OEM_ADLINK_24339, 0x1500, "MCN-1500" },
+ /* Supermicro */
+ { IPMI_OEM_SUPERMICRO, 0x0001, "X8DT3/i/-LN4" },
+ { IPMI_OEM_SUPERMICRO, 0x0002, "C2SLM-OC012" },
+ { IPMI_OEM_SUPERMICRO, 0x0003, "X8DTW-3/i/-LN4" },
+ { IPMI_OEM_SUPERMICRO, 0x0006, "X8DTL-3/i" },
+ { IPMI_OEM_SUPERMICRO, 0x0007, "X8DTT-IBX" },
+ { IPMI_OEM_SUPERMICRO, 0x0008, "X8DTT-B-SG" },
+ { IPMI_OEM_SUPERMICRO, 0x0009, "X8STi-3/-LN4" },
+ { IPMI_OEM_SUPERMICRO, 0x000A, "B8DT3" },
+ { IPMI_OEM_SUPERMICRO, 0x0100, "X8DAH+" },
+ { IPMI_OEM_SUPERMICRO, 0x0101, "B8DTL" },
+ { IPMI_OEM_SUPERMICRO, 0x0400, "X8DTH-6/i" },
+ { IPMI_OEM_SUPERMICRO, 0x0401, "X8DTH-RC014" },
+ { IPMI_OEM_SUPERMICRO, 0x0403, "X8DA6/i-X" },
+ { IPMI_OEM_SUPERMICRO, 0x0404, "X8DT6/E" },
+ { IPMI_OEM_SUPERMICRO, 0x0409, "H8QI6/E(+)(-F)" },
+ { IPMI_OEM_SUPERMICRO, 0x040B, "X8DTW-6+/i+" },
+ { IPMI_OEM_SUPERMICRO, 0x040D, "X8SII/X8SI6" },
+ { IPMI_OEM_SUPERMICRO, 0x0410, "X8DTL-6/L" },
+ { IPMI_OEM_SUPERMICRO, 0x0600, "X8DTU" },
+ { IPMI_OEM_SUPERMICRO, 0x0601, "X8DAL-3/i" },
+ { IPMI_OEM_SUPERMICRO, 0x0602, "X7SLA" },
+ { IPMI_OEM_SUPERMICRO, 0x0603, "C2SEM-Q" },
+ { IPMI_OEM_SUPERMICRO, 0x0604, "winbond IPMI (Aten)" },
+ { IPMI_OEM_SUPERMICRO, 0x0605, "X8SIL" },
+ { IPMI_OEM_SUPERMICRO, 0x0606, "X8DTG-4" },
+ { IPMI_OEM_SUPERMICRO, 0x0607, "C2G41" },
+ { IPMI_OEM_SUPERMICRO, 0x0608, "X8DTG-DF" },
+ { IPMI_OEM_SUPERMICRO, 0x0609, "X8DTS" },
+ { IPMI_OEM_SUPERMICRO, 0x060A, "X7SPA" },
+ { IPMI_OEM_SUPERMICRO, 0x060B, "X8SIA" },
+ { IPMI_OEM_SUPERMICRO, 0x060C, "X8DTU+" },
+ { IPMI_OEM_SUPERMICRO, 0x060C, "X8DTU-LN4F+" },
+ { IPMI_OEM_SUPERMICRO, 0x060D, "X8DTU-6TF+" },
+ { IPMI_OEM_SUPERMICRO, 0x060E, "X8SIT" },
+ { IPMI_OEM_SUPERMICRO, 0x060F, "X8DTN+-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0610, "X8QB6/E" },
+ { IPMI_OEM_SUPERMICRO, 0x0611, "AOC-STGN-I2S" },
+ { IPMI_OEM_SUPERMICRO, 0x0612, "B8DTT" },
+ { IPMI_OEM_SUPERMICRO, 0x0613, "X8DTT-C-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0614, "X8DTU-F-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x061A, "X8SIU" },
+ { IPMI_OEM_SUPERMICRO, 0x061B, "X8DTT-HA" },
+ { IPMI_OEM_SUPERMICRO, 0x061C, "B8DT6-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x061D, "C7SIA" },
+ { IPMI_OEM_SUPERMICRO, 0x061E, "B8DTT-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x061E, "X9SCL" },
+ { IPMI_OEM_SUPERMICRO, 0x061F, "B8DTP" },
+ { IPMI_OEM_SUPERMICRO, 0x0620, "B8DTG" },
+ { IPMI_OEM_SUPERMICRO, 0x0621, "X8OBN" },
+ { IPMI_OEM_SUPERMICRO, 0x0622, "C7P67" },
+ { IPMI_OEM_SUPERMICRO, 0x0623, "C7Q67" },
+ { IPMI_OEM_SUPERMICRO, 0x0624, "X9SCM" },
+ { IPMI_OEM_SUPERMICRO, 0x0625, "B9DRi" },
+ { IPMI_OEM_SUPERMICRO, 0x0626, "X9DR3-LN4F+" },
+ { IPMI_OEM_SUPERMICRO, 0x0627, "X7SPT-DF-D525" },
+ { IPMI_OEM_SUPERMICRO, 0x0628, "X9DR3/i-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0629, "X9SRT-F" },
+ { IPMI_OEM_SUPERMICRO, 0x062A, "X9SRA" },
+ { IPMI_OEM_SUPERMICRO, 0x062B, "X9SRi" },
+ { IPMI_OEM_SUPERMICRO, 0x062C, "X9DAi" },
+ { IPMI_OEM_SUPERMICRO, 0x062D, "X8SIL-SIOM-FI005" },
+ { IPMI_OEM_SUPERMICRO, 0x062E, "X8STE-DS018" },
+ { IPMI_OEM_SUPERMICRO, 0x062F, "X9DRT-HF" },
+ { IPMI_OEM_SUPERMICRO, 0x0630, "X9DRW-3TF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0631, "X9SCA/X9SCI" },
+ { IPMI_OEM_SUPERMICRO, 0x0632, "X8DTG-QF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0633, "X9SCV-Q" },
+ { IPMI_OEM_SUPERMICRO, 0x0634, "X9SCD" },
+ { IPMI_OEM_SUPERMICRO, 0x0635, "X9DAL-6/i" },
+ { IPMI_OEM_SUPERMICRO, 0x0636, "X9DRW-3F" },
+ { IPMI_OEM_SUPERMICRO, 0x0637, "X9DBU-3F" },
+ { IPMI_OEM_SUPERMICRO, 0x0638, "X8QB6-LF" },
+ { IPMI_OEM_SUPERMICRO, 0x0640, "X9SCL/SCM-II" },
+ { IPMI_OEM_SUPERMICRO, 0x0641, "X9SCV-LN4F+" },
+ { IPMI_OEM_SUPERMICRO, 0x0642, "C7Q67-H" },
+ { IPMI_OEM_SUPERMICRO, 0x0644, "X9SAE" },
+ { IPMI_OEM_SUPERMICRO, 0x0645, "C7H61" },
+ { IPMI_OEM_SUPERMICRO, 0x0646, "X9SCFF" },
+ { IPMI_OEM_SUPERMICRO, 0x0647, "X9SCAA" },
+ { IPMI_OEM_SUPERMICRO, 0x0647, "X9SCE-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0648, "C7B75" },
+ { IPMI_OEM_SUPERMICRO, 0x0650, "X9SPV-M4" },
+ { IPMI_OEM_SUPERMICRO, 0x0651, "X9SBAA" },
+ { IPMI_OEM_SUPERMICRO, 0x0652, "AOC-CGP-i2" },
+ { IPMI_OEM_SUPERMICRO, 0x0653, "C7Z87" },
+ { IPMI_OEM_SUPERMICRO, 0x0654, "C7Q87" },
+ { IPMI_OEM_SUPERMICRO, 0x0655, "AOC-XEH-IN2" },
+ { IPMI_OEM_SUPERMICRO, 0x0656, "AOC-SGP-i2" },
+ { IPMI_OEM_SUPERMICRO, 0x0657, "C7Z87-OCE" },
+ { IPMI_OEM_SUPERMICRO, 0x0658, "AOC-STG-B4S" },
+ { IPMI_OEM_SUPERMICRO, 0x0659, "AOC-STGN-I1S" },
+ { IPMI_OEM_SUPERMICRO, 0x0660, "X9DRD-3/iF" },
+ { IPMI_OEM_SUPERMICRO, 0x0661, "B1SA4-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0661, "X9SRG" },
+ { IPMI_OEM_SUPERMICRO, 0x0662, "X9DRG-QF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0663, "X9SRW" },
+ { IPMI_OEM_SUPERMICRO, 0x0664, "X9DRH-7F" },
+ { IPMI_OEM_SUPERMICRO, 0x0665, "X9DRG-QF" },
+ { IPMI_OEM_SUPERMICRO, 0x0666, "X9DRT-D-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0667, "X9DRL-3/iF" },
+ { IPMI_OEM_SUPERMICRO, 0x0668, "X9SRD" },
+ { IPMI_OEM_SUPERMICRO, 0x0669, "X9DRX+-F" },
+ { IPMI_OEM_SUPERMICRO, 0x066A, "B9DRT" },
+ { IPMI_OEM_SUPERMICRO, 0x066B, "X9SRL-F" },
+ { IPMI_OEM_SUPERMICRO, 0x066C, "B9DRG" },
+ { IPMI_OEM_SUPERMICRO, 0x066D, "X9DR6+-F-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x066E, "X9DR6-LN4F+-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x066F, "X9DRW-LN4F+-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x0690, "2208" },
+ { IPMI_OEM_SUPERMICRO, 0x0691, "2308" },
+ { IPMI_OEM_SUPERMICRO, 0x0700, "X9DRT-HF-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x0701, "X9DRT-HIBQF-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x0702, "X9DRD-7LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x0703, "X9DBL-6F" },
+ { IPMI_OEM_SUPERMICRO, 0x0704, "X9DR7/E-TF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0705, "X9DR7/E-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x0706, "X9DRT-HF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0707, "X9QR7-TF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0708, "X9DRT-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0709, "X9DA7/E" },
+ { IPMI_OEM_SUPERMICRO, 0x070A, "X9DRF-F" },
+ { IPMI_OEM_SUPERMICRO, 0x070B, "X9SRL-CF" },
+ { IPMI_OEM_SUPERMICRO, 0x070C, "X9SRD-CD" },
+ { IPMI_OEM_SUPERMICRO, 0x070D, "B9DR7" },
+ { IPMI_OEM_SUPERMICRO, 0x070E, "X9DAX-7" },
+ { IPMI_OEM_SUPERMICRO, 0x070F, "X9QR7-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0710, "X9SRE" },
+ { IPMI_OEM_SUPERMICRO, 0x0711, "X9DRG-HTF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0712, "B9DRG-X" },
+ { IPMI_OEM_SUPERMICRO, 0x0713, "X9DRFF-7" },
+ { IPMI_OEM_SUPERMICRO, 0x0714, "X9SRH-7F" },
+ { IPMI_OEM_SUPERMICRO, 0x0715, "X9DRW-7TPF" },
+ { IPMI_OEM_SUPERMICRO, 0x0716, "X9DBU-3F-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0x0717, "X9DRFF-7+/i+" },
+ { IPMI_OEM_SUPERMICRO, 0x0718, "X9DRFF-7G+" },
+ { IPMI_OEM_SUPERMICRO, 0x0719, "B9DRP" },
+ { IPMI_OEM_SUPERMICRO, 0x0720, "X9DRW-7TPF+" },
+ { IPMI_OEM_SUPERMICRO, 0x0721, "X9DBS-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0722, "X9DB3-TPF" },
+ { IPMI_OEM_SUPERMICRO, 0x0723, "X9DRL-7F/EF" },
+ { IPMI_OEM_SUPERMICRO, 0x0724, "X9DRH-if-NV" },
+ { IPMI_OEM_SUPERMICRO, 0x0725, "X9DRG+HF+II" },
+ { IPMI_OEM_SUPERMICRO, 0x0726, "X10QBi" },
+ { IPMI_OEM_SUPERMICRO, 0x0727, "X9DRW-CF31/CTF31" },
+ { IPMI_OEM_SUPERMICRO, 0x0728, "X10DRI/T" },
+ { IPMI_OEM_SUPERMICRO, 0x0729, "B9DRG-E" },
+ { IPMI_OEM_SUPERMICRO, 0x0730, "X9DAX-HFT" },
+ { IPMI_OEM_SUPERMICRO, 0x0731, "X9DRT-P" },
+ { IPMI_OEM_SUPERMICRO, 0x0732, "X9DRG-OF" },
+ { IPMI_OEM_SUPERMICRO, 0x0733, "X9DB3-CPU-AI026" },
+ { IPMI_OEM_SUPERMICRO, 0x0734, "AOC-STG-I2T" },
+ { IPMI_OEM_SUPERMICRO, 0x0743, "X9SPU" },
+ { IPMI_OEM_SUPERMICRO, 0x0801, "X10SLL" },
+ { IPMI_OEM_SUPERMICRO, 0x0802, "X10SLA" },
+ { IPMI_OEM_SUPERMICRO, 0x0803, "X10SLH" },
+ { IPMI_OEM_SUPERMICRO, 0x0804, "X10SL7-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0805, "X10SAE" },
+ { IPMI_OEM_SUPERMICRO, 0x0806, "X10SLM-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x0807, "X10SLE" },
+ { IPMI_OEM_SUPERMICRO, 0x0808, "LSI3008" },
+ { IPMI_OEM_SUPERMICRO, 0x0809, "LSI3108" },
+ { IPMI_OEM_SUPERMICRO, 0x0810, "X10SLD" },
+ { IPMI_OEM_SUPERMICRO, 0x0811, "X10SLM-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0812, "X10SLL+-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0813, "X10SEAA-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x0814, "X10SLX-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0815, "X10SLV" },
+ { IPMI_OEM_SUPERMICRO, 0x0816, "X10SBA" },
+ { IPMI_OEM_SUPERMICRO, 0x0817, "X10SLE-DF" },
+ { IPMI_OEM_SUPERMICRO, 0x0818, "X10SAT" },
+ { IPMI_OEM_SUPERMICRO, 0x0819, "X10SLV-Q" },
+ { IPMI_OEM_SUPERMICRO, 0x0820, "A1SAM" },
+ { IPMI_OEM_SUPERMICRO, 0x0820, "X9SKV" },
+ { IPMI_OEM_SUPERMICRO, 0x0821, "X10DRW-i(T)" },
+ { IPMI_OEM_SUPERMICRO, 0x0822, "X10DRFF(-C)" },
+ { IPMI_OEM_SUPERMICRO, 0x0823, "AOC-CTG-I1S" },
+ { IPMI_OEM_SUPERMICRO, 0x0824, "X10DRT-P" },
+ { IPMI_OEM_SUPERMICRO, 0x0825, "X10SRE-DS018" },
+ { IPMI_OEM_SUPERMICRO, 0x0826, "X10SRE-EXP-SI030" },
+ { IPMI_OEM_SUPERMICRO, 0x0827, "X9QRH-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0828, "A1SA2-2750F" },
+ { IPMI_OEM_SUPERMICRO, 0x0829, "C7Z97-OCE" },
+ { IPMI_OEM_SUPERMICRO, 0x0830, "X10DRFR" },
+ { IPMI_OEM_SUPERMICRO, 0x0831, "X10DRL-i" },
+ { IPMI_OEM_SUPERMICRO, 0x0832, "X10SRL" },
+ { IPMI_OEM_SUPERMICRO, 0x0833, "X10SRW-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0834, "X10SRI" },
+ { IPMI_OEM_SUPERMICRO, 0x0835, "X10DRC/i-LN4+/T4+" },
+ { IPMI_OEM_SUPERMICRO, 0x0836, "X10DAi" },
+ { IPMI_OEM_SUPERMICRO, 0x0837, "X10DRT-D-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0838, "X10SRH-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0839, "AOC-SLG3-2E4" },
+ { IPMI_OEM_SUPERMICRO, 0x083A, "X10DBT-T" },
+ { IPMI_OEM_SUPERMICRO, 0x083B, "X10DDW-iT" },
+ { IPMI_OEM_SUPERMICRO, 0x083C, "A1SA7-2750F" },
+ { IPMI_OEM_SUPERMICRO, 0x083D, "LSI 2116" },
+ { IPMI_OEM_SUPERMICRO, 0x083E, "B10DRi" },
+ { IPMI_OEM_SUPERMICRO, 0x083F, "B9QR7" },
+ { IPMI_OEM_SUPERMICRO, 0x0840, "B9DRG-3M" },
+ { IPMI_OEM_SUPERMICRO, 0x0841, "X9DRD-iT+" },
+ { IPMI_OEM_SUPERMICRO, 0x0842, "X10SLH-N6-ST031" },
+ { IPMI_OEM_SUPERMICRO, 0x0843, "X10DRG-H(T)" },
+ { IPMI_OEM_SUPERMICRO, 0x0844, "X10DRU-i+" },
+ { IPMI_OEM_SUPERMICRO, 0x0845, "X10DDW-iN" },
+ { IPMI_OEM_SUPERMICRO, 0x0846, "B1DRi" },
+ { IPMI_OEM_SUPERMICRO, 0x0847, "AOC-UR-i4XT" },
+ { IPMI_OEM_SUPERMICRO, 0x0848, "AOC-2UR68-i4G" },
+ { IPMI_OEM_SUPERMICRO, 0x0849, "AOC-UR-i4G" },
+ { IPMI_OEM_SUPERMICRO, 0x084A, "AOC-S40G-i2Q" },
+ { IPMI_OEM_SUPERMICRO, 0x084B, "X10SRG" },
+ { IPMI_OEM_SUPERMICRO, 0x084C, "C7Z97" },
+ { IPMI_OEM_SUPERMICRO, 0x084C, "C7Z97-MF" },
+ { IPMI_OEM_SUPERMICRO, 0x084D, "AOC-STGN-i1SF" },
+ { IPMI_OEM_SUPERMICRO, 0x084F, "AOC-STGN-i2SF" },
+ { IPMI_OEM_SUPERMICRO, 0x0850, "AOC-PG-i4M" },
+ { IPMI_OEM_SUPERMICRO, 0x0851, "PMC PM8076" },
+ { IPMI_OEM_SUPERMICRO, 0x0852, "X10DRG-Q" },
+ { IPMI_OEM_SUPERMICRO, 0x0853, "X10QBL" },
+ { IPMI_OEM_SUPERMICRO, 0x0854, "X10DRU-X" },
+ { IPMI_OEM_SUPERMICRO, 0x0855, "H9SKV-420" },
+ { IPMI_OEM_SUPERMICRO, 0x0856, "C7X99" },
+ { IPMI_OEM_SUPERMICRO, 0x0857, "X10SRA" },
+ { IPMI_OEM_SUPERMICRO, 0x0858, "X10DRT-H" },
+ { IPMI_OEM_SUPERMICRO, 0x0859, "X10DRH-C" },
+ { IPMI_OEM_SUPERMICRO, 0x085A, "A1SRM-LN7F" },
+ { IPMI_OEM_SUPERMICRO, 0x085A, "A1SRM-LN7F" },
+ { IPMI_OEM_SUPERMICRO, 0x085B, "X10DRT-HA/HB-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x085C, "X10DRU-XLL" },
+ { IPMI_OEM_SUPERMICRO, 0x085D, "AOC-UR-i2XT" },
+ { IPMI_OEM_SUPERMICRO, 0x085E, "AOC-2UR6-i4XT" },
+ { IPMI_OEM_SUPERMICRO, 0x085F, "AOC-2UR68-i2XT" },
+ { IPMI_OEM_SUPERMICRO, 0x0860, "X10DRL-C/CT" },
+ { IPMI_OEM_SUPERMICRO, 0x0861, "B10DRT" },
+ { IPMI_OEM_SUPERMICRO, 0x0862, "B1SL1-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0863, "RSC-W2-66" },
+ { IPMI_OEM_SUPERMICRO, 0x0864, "X10DRW-E/NT" },
+ { IPMI_OEM_SUPERMICRO, 0x0865, "X10DRD-i/LTP" },
+ { IPMI_OEM_SUPERMICRO, 0x0866, "AOC-SLG3-2E4R" },
+ { IPMI_OEM_SUPERMICRO, 0x0867, "AOC-SLG3-4E4R" },
+ { IPMI_OEM_SUPERMICRO, 0x0868, "AOC-SLG3-2E4" },
+ { IPMI_OEM_SUPERMICRO, 0x0869, "AOC-URN2-i4XT" },
+ { IPMI_OEM_SUPERMICRO, 0x086A, "AOC-URN2-i2XT" },
+ { IPMI_OEM_SUPERMICRO, 0x086B, "X10DRS" },
+ { IPMI_OEM_SUPERMICRO, 0x086C, "X10DAL-i" },
+ { IPMI_OEM_SUPERMICRO, 0x086D, "X10SDV-TLN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x086E, "X10DDW-iN" },
+ { IPMI_OEM_SUPERMICRO, 0x086F, "X10DRT-L" },
+ { IPMI_OEM_SUPERMICRO, 0x0870, "AOC-URN2-ii2SX" },
+ { IPMI_OEM_SUPERMICRO, 0x0871, "AOC-2UR68-i2XS" },
+ { IPMI_OEM_SUPERMICRO, 0x0872, "X10QRH+" },
+ { IPMI_OEM_SUPERMICRO, 0x0873, "AOC-2URN4-i4XT" },
+ { IPMI_OEM_SUPERMICRO, 0x0874, "AOC-2UR8N4-i2XT" },
+ { IPMI_OEM_SUPERMICRO, 0x0875, "AOC-2UR66-i4G" },
+ { IPMI_OEM_SUPERMICRO, 0x0876, "A2SCL-IN001" },
+ { IPMI_OEM_SUPERMICRO, 0x0877, "X10DRT-HB-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0878, "RSC-S2-88" },
+ { IPMI_OEM_SUPERMICRO, 0x0879, "X10DRD-I/L/NT" },
+ { IPMI_OEM_SUPERMICRO, 0x087A, "B1SD2-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x087B, "AOC-XEH-i2M" },
+ { IPMI_OEM_SUPERMICRO, 0x087C, "AOC-XEH-i4M" },
+ { IPMI_OEM_SUPERMICRO, 0x087D, "X10SRD-F" },
+ { IPMI_OEM_SUPERMICRO, 0x087E, "AOC-STG-i4S" },
+ { IPMI_OEM_SUPERMICRO, 0x087F, "X10DRFF-iG" },
+ { IPMI_OEM_SUPERMICRO, 0x0880, "X10DRT-XA-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0881, "X10DRT-XB-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0882, "X10DRX" },
+ { IPMI_OEM_SUPERMICRO, 0x0883, "K1SPI" },
+ { IPMI_OEM_SUPERMICRO, 0x0884, "X11SSH-F/-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x0885, "X11SSL-CF/-NF" },
+ { IPMI_OEM_SUPERMICRO, 0x0886, "X11SSA(-F)/X11SSi-LN4(F)" },
+ { IPMI_OEM_SUPERMICRO, 0x0887, "AOC-S8076L-L16e" },
+ { IPMI_OEM_SUPERMICRO, 0x0888, "X11SSZ" },
+ { IPMI_OEM_SUPERMICRO, 0x0889, "B10DRG" },
+ { IPMI_OEM_SUPERMICRO, 0x088A, "AOC-URN6-i2XT" },
+ { IPMI_OEM_SUPERMICRO, 0x088B, "C7Z170-SQ" },
+ { IPMI_OEM_SUPERMICRO, 0x088C, "AOM-S3108-H8S-SB" },
+ { IPMI_OEM_SUPERMICRO, 0x088D, "AOC-S100G-i2C" },
+ { IPMI_OEM_SUPERMICRO, 0x088E, "AOC-PIO-i2G" },
+ { IPMI_OEM_SUPERMICRO, 0x088F, "AOM-PIO-i2XT" },
+ { IPMI_OEM_SUPERMICRO, 0x0890, "X11SSQ" },
+ { IPMI_OEM_SUPERMICRO, 0x0891, "X11SBA" },
+ { IPMI_OEM_SUPERMICRO, 0x0892, "X10DRG-O+-CPU" },
+ { IPMI_OEM_SUPERMICRO, 0x0893, "X10DGQ" },
+ { IPMI_OEM_SUPERMICRO, 0x0894, "X11SSV-Q" },
+ { IPMI_OEM_SUPERMICRO, 0x0895, "X11SAE" },
+ { IPMI_OEM_SUPERMICRO, 0x0896, "X11SSL/M-F" },
+ { IPMI_OEM_SUPERMICRO, 0x0897, "B1SD1-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0898, "X11SSE" },
+ { IPMI_OEM_SUPERMICRO, 0x0899, "X10DRH" },
+ { IPMI_OEM_SUPERMICRO, 0x089A, "X11SLL" },
+ { IPMI_OEM_SUPERMICRO, 0x089B, "X11SSW-F" },
+ { IPMI_OEM_SUPERMICRO, 0x089C, "X11SSH-CTF" },
+ { IPMI_OEM_SUPERMICRO, 0x089D, "X10DSC+" },
+ { IPMI_OEM_SUPERMICRO, 0x089E, "AOC-URN2-i4GXS" },
+ { IPMI_OEM_SUPERMICRO, 0x089F, "X11SAE-M" },
+ { IPMI_OEM_SUPERMICRO, 0x0901, "X11SSM" },
+ { IPMI_OEM_SUPERMICRO, 0x0902, "C7Z170-OCE" },
+ { IPMI_OEM_SUPERMICRO, 0x0903, "AOC-CTGS-i2T" },
+ { IPMI_OEM_SUPERMICRO, 0x0904, "AOC-2UR6N4-i4XT" },
+ { IPMI_OEM_SUPERMICRO, 0x0905, "K1SPI-KA-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0906, "K1SPi-KB-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x0907, "X11SAT(-F)" },
+ { IPMI_OEM_SUPERMICRO, 0x0908, "B2SS2" },
+ { IPMI_OEM_SUPERMICRO, 0x0909, "X11SSD-F" },
+ { IPMI_OEM_SUPERMICRO, 0x090A, "AOC-SLG3-4E4" },
+ { IPMI_OEM_SUPERMICRO, 0x090B, "AOC-MTG-i4S" },
+ { IPMI_OEM_SUPERMICRO, 0x090C, "AOC-MTG-I2s" },
+ { IPMI_OEM_SUPERMICRO, 0x090D, "X11SRE-DS018" },
+ { IPMI_OEM_SUPERMICRO, 0x090E, "K1SPE(-T)" },
+ { IPMI_OEM_SUPERMICRO, 0x090F, "A2SDi" },
+ { IPMI_OEM_SUPERMICRO, 0x0910, "A2SDi-H" },
+ { IPMI_OEM_SUPERMICRO, 0x0911, "X10DRT-PS" },
+ { IPMI_OEM_SUPERMICRO, 0x0912, "AOC-MG-i2" },
+ { IPMI_OEM_SUPERMICRO, 0x0913, "AOC-MG-i4" },
+ { IPMI_OEM_SUPERMICRO, 0x0914, "AOC-STGS-i1T" },
+ { IPMI_OEM_SUPERMICRO, 0x0915, "AOC-STGS-i2T" },
+ { IPMI_OEM_SUPERMICRO, 0x0916, "X10DSC-TP4S" },
+ { IPMI_OEM_SUPERMICRO, 0x0917, "X11DPi-N(T)" },
+ { IPMI_OEM_SUPERMICRO, 0x0918, "AOC-UR-i4GXS" },
+ { IPMI_OEM_SUPERMICRO, 0x0919, "X10SDD-F" },
+ { IPMI_OEM_SUPERMICRO, 0x091A, "AOC-2UR6-i4xT+" },
+ { IPMI_OEM_SUPERMICRO, 0x091B, "AOC-UR-i4XT+" },
+ { IPMI_OEM_SUPERMICRO, 0x091C, "X11DPU" },
+ { IPMI_OEM_SUPERMICRO, 0x091D, "X11SSW-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x091E, "X10SD7-AC107" },
+ { IPMI_OEM_SUPERMICRO, 0x091F, "AOC-MTG-i4T" },
+ { IPMI_OEM_SUPERMICRO, 0x0920, "AOC-MTG-i2T" },
+ { IPMI_OEM_SUPERMICRO, 0x0921, "X10SDV-7TP8F" },
+ { IPMI_OEM_SUPERMICRO, 0x0922, "X10SRW-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x0923, "AOM-X10OBI-PCH" },
+ { IPMI_OEM_SUPERMICRO, 0x0924, "X10SRM-(T)F" },
+ { IPMI_OEM_SUPERMICRO, 0x0925, "AOC-MHIBF-2QG" },
+ { IPMI_OEM_SUPERMICRO, 0x0926, "AOC-MHIBF-1QG" },
+ { IPMI_OEM_SUPERMICRO, 0x0927, "X11DPT-PS" },
+ { IPMI_OEM_SUPERMICRO, 0x0928, "AOC-S25G-b2S" },
+ { IPMI_OEM_SUPERMICRO, 0x0929, "AOC-2UR66-i4XTF" },
+ { IPMI_OEM_SUPERMICRO, 0x092A, "AOC-M25G-b2S" },
+ { IPMI_OEM_SUPERMICRO, 0x092B, "X10DSN-TS" },
+ { IPMI_OEM_SUPERMICRO, 0x092C, "AOC-S8069L-16xR" },
+ { IPMI_OEM_SUPERMICRO, 0x092D, "X10SDE-DF" },
+ { IPMI_OEM_SUPERMICRO, 0x092E, "AOC-2UR68-B2TS" },
+ { IPMI_OEM_SUPERMICRO, 0x092F, "AOC-S40G-i1Q" },
+ { IPMI_OEM_SUPERMICRO, 0x0930, "X11SSQ-L" },
+ { IPMI_OEM_SUPERMICRO, 0x0931, "B2SS1-CF" },
+ { IPMI_OEM_SUPERMICRO, 0x0932, "X10DRL-LN4" },
+ { IPMI_OEM_SUPERMICRO, 0x0933, "P8DTU" },
+ { IPMI_OEM_SUPERMICRO, 0x0934, "AOC-MHFI-i1C" },
+ { IPMI_OEM_SUPERMICRO, 0x0935, "AOC-STG-i4T" },
+ { IPMI_OEM_SUPERMICRO, 0x0936, "AOC-UR-i4XTF" },
+ { IPMI_OEM_SUPERMICRO, 0x0937, "X11DPT" },
+ { IPMI_OEM_SUPERMICRO, 0x0938, "X11DPT" },
+ { IPMI_OEM_SUPERMICRO, 0x0939, "X11SSV-M4" },
+ { IPMI_OEM_SUPERMICRO, 0x093A, "X11SSV-M4F" },
+ { IPMI_OEM_SUPERMICRO, 0x093B, "AOC-STGF-i2S" },
+ { IPMI_OEM_SUPERMICRO, 0x093C, "A2SAV" },
+ { IPMI_OEM_SUPERMICRO, 0x093D, "AOC-S3216L-L16iT" },
+ { IPMI_OEM_SUPERMICRO, 0x093E, "X10DRT-B+" },
+ { IPMI_OEM_SUPERMICRO, 0x093F, "C7Z270-CG-L" },
+ { IPMI_OEM_SUPERMICRO, 0x0940, "C7Z270-CG" },
+ { IPMI_OEM_SUPERMICRO, 0x0941, "X11SPi-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0942, "K1SPE" },
+ { IPMI_OEM_SUPERMICRO, 0x0943, "C7Z270-PG" },
+ { IPMI_OEM_SUPERMICRO, 0x0944, "C7H270-CG-ML" },
+ { IPMI_OEM_SUPERMICRO, 0x0945, "C7Q270-CB-ML" },
+ { IPMI_OEM_SUPERMICRO, 0x0946, "X10SDV" },
+ { IPMI_OEM_SUPERMICRO, 0x0947, "A2SAN" },
+ { IPMI_OEM_SUPERMICRO, 0x0948, "AOC-C25G-m2S" },
+ { IPMI_OEM_SUPERMICRO, 0x0949, "AOC-MH25G-m2S2T" },
+ { IPMI_OEM_SUPERMICRO, 0x094A, "AOC-2UR68-m2TS" },
+ { IPMI_OEM_SUPERMICRO, 0x094B, "AOC-S100G-m2C" },
+ { IPMI_OEM_SUPERMICRO, 0x094C, "AOC-S25G-m2S" },
+ { IPMI_OEM_SUPERMICRO, 0x094D, "AOC-MHIBF" },
+ { IPMI_OEM_SUPERMICRO, 0x094E, "AOC-MH25G-b2S2G" },
+ { IPMI_OEM_SUPERMICRO, 0x094F, "P8DNU" },
+ { IPMI_OEM_SUPERMICRO, 0x0950, "X10DRW-SE" },
+ { IPMI_OEM_SUPERMICRO, 0x0951, "B2SS1(2)-MTF" },
+ { IPMI_OEM_SUPERMICRO, 0x0952, "X11SPX-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0953, "X11SPW-(c)TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0954, "AOC-C25G-m1S" },
+ { IPMI_OEM_SUPERMICRO, 0x0955, "X11SSW" },
+ { IPMI_OEM_SUPERMICRO, 0x0956, "AOC-MHIBF-m1Q2G" },
+ { IPMI_OEM_SUPERMICRO, 0x0957, "AOC-MHIBF-m2Q2G" },
+ { IPMI_OEM_SUPERMICRO, 0x0958, "X11SSH" },
+ { IPMI_OEM_SUPERMICRO, 0x0959, "R10SR2" },
+ { IPMI_OEM_SUPERMICRO, 0x095A, "X10DGO" },
+ { IPMI_OEM_SUPERMICRO, 0x095B, "X11DPU-XLL" },
+ { IPMI_OEM_SUPERMICRO, 0x095C, "X11DPU-X" },
+ { IPMI_OEM_SUPERMICRO, 0x095D, "X11SPM-T(P)F" },
+ { IPMI_OEM_SUPERMICRO, 0x095E, "X11SPH-NCTPF" },
+ { IPMI_OEM_SUPERMICRO, 0x095F, "X11SAA" },
+ { IPMI_OEM_SUPERMICRO, 0x0960, "X11SAN" },
+ { IPMI_OEM_SUPERMICRO, 0x0961, "P9DSC" },
+ { IPMI_OEM_SUPERMICRO, 0x0962, "X11DPT-B+" },
+ { IPMI_OEM_SUPERMICRO, 0x0963, "H11DSU-i" },
+ { IPMI_OEM_SUPERMICRO, 0x0964, "H11DSi-NT" },
+ { IPMI_OEM_SUPERMICRO, 0x0965, "C7B250-CB-ML" },
+ { IPMI_OEM_SUPERMICRO, 0x0966, "B11DPT" },
+ { IPMI_OEM_SUPERMICRO, 0x0967, "X11DDW" },
+ { IPMI_OEM_SUPERMICRO, 0x0968, "X11DPL-i" },
+ { IPMI_OEM_SUPERMICRO, 0x0969, "A2SDi-HLN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x096A, "C7C232-CB-ML" },
+ { IPMI_OEM_SUPERMICRO, 0x096B, "X11DPT-P-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0x096C, "X11DPU-Z+" },
+ { IPMI_OEM_SUPERMICRO, 0x096D, "X11DPG-Qt" },
+ { IPMI_OEM_SUPERMICRO, 0x096E, "X11SPL-F" },
+ { IPMI_OEM_SUPERMICRO, 0x096F, "AOC-IBH-X4ED" },
+ { IPMI_OEM_SUPERMICRO, 0x0970, "C7Z270-CG-M" },
+ { IPMI_OEM_SUPERMICRO, 0x0971, "X11SRE-EXP-SI030" },
+ { IPMI_OEM_SUPERMICRO, 0x0972, "SAS3216" },
+ { IPMI_OEM_SUPERMICRO, 0x0973, "SAS3508" },
+ { IPMI_OEM_SUPERMICRO, 0x0974, "SAS3516" },
+ { IPMI_OEM_SUPERMICRO, 0x0975, "SAS3316" },
+ { IPMI_OEM_SUPERMICRO, 0x0976, "SAS3324" },
+ { IPMI_OEM_SUPERMICRO, 0x0977, "X11DPFR-SN" },
+ { IPMI_OEM_SUPERMICRO, 0x0978, "AOC-S25G-i2S" },
+ { IPMI_OEM_SUPERMICRO, 0x0979, "BMB-IBD-E3616" },
+ { IPMI_OEM_SUPERMICRO, 0x097A, "X11DAI-N" },
+ { IPMI_OEM_SUPERMICRO, 0x097B, "C7X299" },
+ { IPMI_OEM_SUPERMICRO, 0x097C, "AOC-IBH_X4ES" },
+ { IPMI_OEM_SUPERMICRO, 0x097D, "C7B250-CB-i" },
+ { IPMI_OEM_SUPERMICRO, 0x097E, "X11SPG-F" },
+ { IPMI_OEM_SUPERMICRO, 0x097F, "X11QPH+" },
+ { IPMI_OEM_SUPERMICRO, 0x0980, "X11OPi" },
+ { IPMI_OEM_SUPERMICRO, 0x0981, "X11DPH-i" },
+ { IPMI_OEM_SUPERMICRO, 0x0982, "A2SDV-TLN5F" },
+ { IPMI_OEM_SUPERMICRO, 0x0983, "AOC-M25G-m4S" },
+ { IPMI_OEM_SUPERMICRO, 0x0984, "X11SRM-(V)F" },
+ { IPMI_OEM_SUPERMICRO, 0x0985, "P9DSU-C" },
+ { IPMI_OEM_SUPERMICRO, 0x0986, "X11SDV" },
+ { IPMI_OEM_SUPERMICRO, 0x0987, "X11SDV-TLN2F" },
+ { IPMI_OEM_SUPERMICRO, 0x0988, "X11DGQ" },
+ { IPMI_OEM_SUPERMICRO, 0x0989, "B10DRE" },
+ { IPMI_OEM_SUPERMICRO, 0x098A, "H11DST-B" },
+ { IPMI_OEM_SUPERMICRO, 0x098B, "X11SSN" },
+ { IPMI_OEM_SUPERMICRO, 0x098C, "X11DPX-T" },
+ { IPMI_OEM_SUPERMICRO, 0x098D, "A2SAP-H/E/L" },
+ { IPMI_OEM_SUPERMICRO, 0x098E, "X11SRA-R/F" },
+ { IPMI_OEM_SUPERMICRO, 0x098F, "B11QPi" },
+ { IPMI_OEM_SUPERMICRO, 0x0991, "C7Z370-CG-L" },
+ { IPMI_OEM_SUPERMICRO, 0x0992, "B11SPi-CPU-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x0993, "AOC-URN4-i2TS" },
+ { IPMI_OEM_SUPERMICRO, 0x0994, "AOC-B25G-M2S" },
+ { IPMI_OEM_SUPERMICRO, 0x0995, "X11DPG-SN" },
+ { IPMI_OEM_SUPERMICRO, 0x0996, "AOC-MTG-b2T" },
+ { IPMI_OEM_SUPERMICRO, 0x0997, "B11DPE" },
+ { IPMI_OEM_SUPERMICRO, 0x0998, "C7Z370-CG-iW" },
+ { IPMI_OEM_SUPERMICRO, 0x0999, "AOC-MHIBE-m1CG" },
+ { IPMI_OEM_SUPERMICRO, 0x099A, "X11DPS-R" },
+ { IPMI_OEM_SUPERMICRO, 0x099B, "AOC-OPH-WFR" },
+ { IPMI_OEM_SUPERMICRO, 0x099C, "SAS 3616" },
+ { IPMI_OEM_SUPERMICRO, 0x099C, "SAS 3616" },
+ { IPMI_OEM_SUPERMICRO, 0x099D, "X11DSC+" },
+ { IPMI_OEM_SUPERMICRO, 0x099E, "C7Z390-PGW" },
+ { IPMI_OEM_SUPERMICRO, 0x099F, "C7Z390-CG-IW" },
+ { IPMI_OEM_SUPERMICRO, 0x1111, "H8DCR-3" },
+ { IPMI_OEM_SUPERMICRO, 0x1211, "H8DC8" },
+ { IPMI_OEM_SUPERMICRO, 0x1311, "H8QM8-2" },
+ { IPMI_OEM_SUPERMICRO, 0x1411, "H8DA8-2" },
+ { IPMI_OEM_SUPERMICRO, 0x1511, "H8DMR-82" },
+ { IPMI_OEM_SUPERMICRO, 0x1611, "H8DM8-2" },
+ { IPMI_OEM_SUPERMICRO, 0x1711, "H8SMI-2" },
+ { IPMI_OEM_SUPERMICRO, 0x1811, "H8SSL-I2" },
+ { IPMI_OEM_SUPERMICRO, 0x1911, "H8DMU" },
+ { IPMI_OEM_SUPERMICRO, 0x1A01, "C7B360-CB-M" },
+ { IPMI_OEM_SUPERMICRO, 0x1A02, "C7C242-CB-M" },
+ { IPMI_OEM_SUPERMICRO, 0x1A03, "H11SSL-i/c/nc" },
+ { IPMI_OEM_SUPERMICRO, 0x1A04, "B10KNM" },
+ { IPMI_OEM_SUPERMICRO, 0x1A05, "AOM-M25G-i2S" },
+ { IPMI_OEM_SUPERMICRO, 0x1A06, "X11DPG-OT-CPU" },
+ { IPMI_OEM_SUPERMICRO, 0x1A07, "B11SPE-CPU-TF/25G" },
+ { IPMI_OEM_SUPERMICRO, 0x1A08, "AOC-STG-b2T" },
+ { IPMI_OEM_SUPERMICRO, 0x1A09, "AOC-URN4-b2XT" },
+ { IPMI_OEM_SUPERMICRO, 0x1A1A, "A2SD1-3750F/3955F" },
+ { IPMI_OEM_SUPERMICRO, 0x1A1B, "X11SCE-F" },
+ { IPMI_OEM_SUPERMICRO, 0x1A1C, "X11DSF" },
+ { IPMI_OEM_SUPERMICRO, 0x1A1D, "X11SCA-F/W" },
+ { IPMI_OEM_SUPERMICRO, 0x1A1E, "X11DAC" },
+ { IPMI_OEM_SUPERMICRO, 0x1A1F, "X11SCL-F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B01, "X11DSN-TS" },
+ { IPMI_OEM_SUPERMICRO, 0x1B02, "X11DGO-T" },
+ { IPMI_OEM_SUPERMICRO, 0x1B03, "AOC-2UR688-i4XTF" },
+ { IPMI_OEM_SUPERMICRO, 0x1B04, "X11DPT-LC019" },
+ { IPMI_OEM_SUPERMICRO, 0x1B05, "X11SCQ" },
+ { IPMI_OEM_SUPERMICRO, 0x1B06, "X11SCQ-L" },
+ { IPMI_OEM_SUPERMICRO, 0x1B07, "X11SCW-F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B08, "C9X299-PG300" },
+ { IPMI_OEM_SUPERMICRO, 0x1B09, "X11SCZ-F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B0A, "B10DRT-IBF2" },
+ { IPMI_OEM_SUPERMICRO, 0x1B0B, "AOC-STG-b2T" },
+ { IPMI_OEM_SUPERMICRO, 0x1B0C, "AOC-B25G-6X4D" },
+ { IPMI_OEM_SUPERMICRO, 0x1B0D, "X11SCV-Q/L" },
+ { IPMI_OEM_SUPERMICRO, 0x1B0E, "X11SCL-IF" },
+ { IPMI_OEM_SUPERMICRO, 0x1B0F, "X11SCM" },
+ { IPMI_OEM_SUPERMICRO, 0x1B10, "A2SDV-LN8F/LN10PF" },
+ { IPMI_OEM_SUPERMICRO, 0x1B11, "X11SCH-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B12, "AOC-SGP-i4" },
+ { IPMI_OEM_SUPERMICRO, 0x1B13, "AOC-4UR66-i4XTF" },
+ { IPMI_OEM_SUPERMICRO, 0x1B14, "C9X299-PG300F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B15, "X11SCL-LN4F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B16, "AOM-PICO-3L" },
+ { IPMI_OEM_SUPERMICRO, 0x1B17, "X11DPFF-SN" },
+ { IPMI_OEM_SUPERMICRO, 0x1B18, "C7B360-CB-ML" },
+ { IPMI_OEM_SUPERMICRO, 0x1B19, "H11SSW-NT/iN" },
+ { IPMI_OEM_SUPERMICRO, 0x1B1A, "C9Z390-CG(W)" },
+ { IPMI_OEM_SUPERMICRO, 0x1B1B, "AOC-CTG-i2S" },
+ { IPMI_OEM_SUPERMICRO, 0x1B1C, "X11SDD" },
+ { IPMI_OEM_SUPERMICRO, 0x1B1D, "X11DPT-L" },
+ { IPMI_OEM_SUPERMICRO, 0x1B1E, "AOC-URN4-B2ts" },
+ { IPMI_OEM_SUPERMICRO, 0x1B1F, "X11DPG-HGX2" },
+ { IPMI_OEM_SUPERMICRO, 0x1B20, "AOC-SLG2-2TM2" },
+ { IPMI_OEM_SUPERMICRO, 0x1B21, "AOC-SLG2-4TM2" },
+ { IPMI_OEM_SUPERMICRO, 0x1B22, "AOC-SMG2-2TM2" },
+ { IPMI_OEM_SUPERMICRO, 0x1B23, "RSC-UM2R-8+-NI22" },
+ { IPMI_OEM_SUPERMICRO, 0x1B24, "BPN-6S3008S6" },
+ { IPMI_OEM_SUPERMICRO, 0x1B25, "X11DPU-ZE+" },
+ { IPMI_OEM_SUPERMICRO, 0x1B26, "AOC-2UR68-b2TS" },
+ { IPMI_OEM_SUPERMICRO, 0x1B27, "AOC-S100G-b1C" },
+ { IPMI_OEM_SUPERMICRO, 0x1B28, "X11SPA-TF" },
+ { IPMI_OEM_SUPERMICRO, 0x1B29, "B2SC1" },
+ { IPMI_OEM_SUPERMICRO, 0x1B2A, "AOC-2MG-i8" },
+ { IPMI_OEM_SUPERMICRO, 0x1B2B, "H12SSW-iN" },
+ { IPMI_OEM_SUPERMICRO, 0x1B2C, "H12SSW-NT" },
+ { IPMI_OEM_SUPERMICRO, 0x1B2D, "M11SDV" },
+ { IPMI_OEM_SUPERMICRO, 0x1B2E, "AOC-MG-b2" },
+ { IPMI_OEM_SUPERMICRO, 0x1B2F, "AOM-SMF-TP4F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B31, "AOC-M25G-m2S" },
+ { IPMI_OEM_SUPERMICRO, 0x1B32, "B11SRE-CPU" },
+ { IPMI_OEM_SUPERMICRO, 0x1B33, "B11SRE" },
+ { IPMI_OEM_SUPERMICRO, 0x1B34, "X11SPA-T" },
+ { IPMI_OEM_SUPERMICRO, 0x1B35, "X11SDW" },
+ { IPMI_OEM_SUPERMICRO, 0x1B36, "X11SCD-F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B37, "X11DPU-V" },
+ { IPMI_OEM_SUPERMICRO, 0x1B38, "X11DPT-BV" },
+ { IPMI_OEM_SUPERMICRO, 0x1B39, "B11SCG-ZTF" },
+ { IPMI_OEM_SUPERMICRO, 0x1B3A, "H12DST-B" },
+ { IPMI_OEM_SUPERMICRO, 0x1B3B, "X11SDS-8C" },
+ { IPMI_OEM_SUPERMICRO, 0x1B3C, "AOM-SDW-B16X2" },
+ { IPMI_OEM_SUPERMICRO, 0x1B3D, "B11SCG-CTF" },
+ { IPMI_OEM_SUPERMICRO, 0x1B3E, "AOC-S100G-b2C" },
+ { IPMI_OEM_SUPERMICRO, 0x1B3F, "X11SPD-F" },
+ { IPMI_OEM_SUPERMICRO, 0x1B41, "X11SRL-F" },
+ { IPMI_OEM_SUPERMICRO, 0x2011, "H8SMU" },
+ { IPMI_OEM_SUPERMICRO, 0x2111, "M8QME" },
+ { IPMI_OEM_SUPERMICRO, 0x2211, "H8DMT" },
+ { IPMI_OEM_SUPERMICRO, 0x2311, "BHDME" },
+ { IPMI_OEM_SUPERMICRO, 0x2411, "H8DMT-IBX" },
+ { IPMI_OEM_SUPERMICRO, 0x2511, "H8DME-2-LS006" },
+ { IPMI_OEM_SUPERMICRO, 0x8080, "X7DB8" },
+ { IPMI_OEM_SUPERMICRO, 0x8180, "X7DA8" },
+ { IPMI_OEM_SUPERMICRO, 0x8280, "PDSMI-LN4" },
+ { IPMI_OEM_SUPERMICRO, 0x8380, "X7DBP-X" },
+ { IPMI_OEM_SUPERMICRO, 0x8480, "X7DBR-8+" },
+ { IPMI_OEM_SUPERMICRO, 0x8580, "PDSML" },
+ { IPMI_OEM_SUPERMICRO, 0x8680, "X7DVL" },
+ { IPMI_OEM_SUPERMICRO, 0x8780, "PDSBA" },
+ { IPMI_OEM_SUPERMICRO, 0x8880, "X7DBX" },
+ { IPMI_OEM_SUPERMICRO, 0x8980, "X7DBP-8" },
+ { IPMI_OEM_SUPERMICRO, 0x9080, "X7DB8-X" },
+ { IPMI_OEM_SUPERMICRO, 0x9180, "PDSME+" },
+ { IPMI_OEM_SUPERMICRO, 0x9280, "X7DBR-3" },
+ { IPMI_OEM_SUPERMICRO, 0x9380, "PDSLM" },
+ { IPMI_OEM_SUPERMICRO, 0x9480, "X7DAL-E" },
+ { IPMI_OEM_SUPERMICRO, 0x9580, "X6QT8" },
+ { IPMI_OEM_SUPERMICRO, 0x9680, "X7DBN" },
+ { IPMI_OEM_SUPERMICRO, 0x9780, "X7DBU" },
+ { IPMI_OEM_SUPERMICRO, 0x9880, "PDSMU+" },
+ { IPMI_OEM_SUPERMICRO, 0x9980, "X7DBT" },
+ { IPMI_OEM_SUPERMICRO, 0xA011, "H8DM3-2" },
+ { IPMI_OEM_SUPERMICRO, 0xA080, "X7DVL-3" },
+ { IPMI_OEM_SUPERMICRO, 0xA111, "H8DA3-2" },
+ { IPMI_OEM_SUPERMICRO, 0xA211, "H8QM3-2" },
+ { IPMI_OEM_SUPERMICRO, 0xA280, "X7DW3+" },
+ { IPMI_OEM_SUPERMICRO, 0xA311, "H8QM3-EX" },
+ { IPMI_OEM_SUPERMICRO, 0xA380, "X7QC3" },
+ { IPMI_OEM_SUPERMICRO, 0xA480, "X7DCL-3" },
+ { IPMI_OEM_SUPERMICRO, 0xA511, "H8DI3+" },
+ { IPMI_OEM_SUPERMICRO, 0xA580, "AOC-USAS-L8I" },
+ { IPMI_OEM_SUPERMICRO, 0xA611, "BHQIE" },
+ { IPMI_OEM_SUPERMICRO, 0xA680, "X7DCA-3/i" },
+ { IPMI_OEM_SUPERMICRO, 0xA711, "H8SGL" },
+ { IPMI_OEM_SUPERMICRO, 0xA780, "B7DC3" },
+ { IPMI_OEM_SUPERMICRO, 0xA811, "H8DGU" },
+ { IPMI_OEM_SUPERMICRO, 0xA811, "H8DGU" },
+ { IPMI_OEM_SUPERMICRO, 0xA880, "X8DA3/i" },
+ { IPMI_OEM_SUPERMICRO, 0xA911, "H8DGG-QF" },
+ { IPMI_OEM_SUPERMICRO, 0xA980, "X7SB3" },
+ { IPMI_OEM_SUPERMICRO, 0xAA11, "H8DGT" },
+ { IPMI_OEM_SUPERMICRO, 0xAA80, "X7DWT-C-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0xAA80, "X7SBL-LN1/LN2" },
+ { IPMI_OEM_SUPERMICRO, 0xAB11, "H8QG6" },
+ { IPMI_OEM_SUPERMICRO, 0xAB80, "C2SBM-Q" },
+ { IPMI_OEM_SUPERMICRO, 0xAC11, "H8DGU-LN4" },
+ { IPMI_OEM_SUPERMICRO, 0xAC80, "X7DWU" },
+ { IPMI_OEM_SUPERMICRO, 0xAD11, "BHQME" },
+ { IPMI_OEM_SUPERMICRO, 0xAD11, "H8DGT-HIBQF-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0xAE11, "H8QGI-F-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0xAE80, "PDSMP-JN001" },
+ { IPMI_OEM_SUPERMICRO, 0xAF11, "H8DGU-LN4F+-AI034" },
+ { IPMI_OEM_SUPERMICRO, 0xAF80, "AOC-UTG-I2" },
+ { IPMI_OEM_SUPERMICRO, 0xB080, "B7DBE" },
+ { IPMI_OEM_SUPERMICRO, 0xB180, "X7DBI+" },
+ { IPMI_OEM_SUPERMICRO, 0xB280, "X7DVL-L" },
+ { IPMI_OEM_SUPERMICRO, 0xB380, "X7DWN" },
+ { IPMI_OEM_SUPERMICRO, 0xB480, "AOC-UG-i4" },
+ { IPMI_OEM_SUPERMICRO, 0xB580, "PDSBM-LN2" },
+ { IPMI_OEM_SUPERMICRO, 0xB680, "X7DGT-ATOKAP" },
+ { IPMI_OEM_SUPERMICRO, 0xB780, "C2SBA" },
+ { IPMI_OEM_SUPERMICRO, 0xB780, "X7DWT-CD-SG007" },
+ { IPMI_OEM_SUPERMICRO, 0xB880, "C2SEA" },
+ { IPMI_OEM_SUPERMICRO, 0xB980, "Winbond IPMI (AMI)" },
+ { IPMI_OEM_SUPERMICRO, 0xBA11, "H8SCM-F" },
+ { IPMI_OEM_SUPERMICRO, 0xBA80, "C2SBX" },
+ { IPMI_OEM_SUPERMICRO, 0xBA80, "X7SLM-L" },
+ { IPMI_OEM_SUPERMICRO, 0xBB11, "BHDGT" },
+ { IPMI_OEM_SUPERMICRO, 0xBB80, "B7DCE" },
+ { IPMI_OEM_SUPERMICRO, 0xBC11, "BHQG6/E" },
+ { IPMI_OEM_SUPERMICRO, 0xBC11, "H8DG6/i-F" },
+ { IPMI_OEM_SUPERMICRO, 0xBC80, "X7DWT/-INF" },
+ { IPMI_OEM_SUPERMICRO, 0xBD11, "H8DCT-IBQF" },
+ { IPMI_OEM_SUPERMICRO, 0xBD11, "H8DGT-C" },
+ { IPMI_OEM_SUPERMICRO, 0xBD80, "C2SBM" },
+ { IPMI_OEM_SUPERMICRO, 0xBE11, "H8DCT" },
+ { IPMI_OEM_SUPERMICRO, 0xBE80, "C2SBC" },
+ { IPMI_OEM_SUPERMICRO, 0xBE80, "C2SBC" },
+ { IPMI_OEM_SUPERMICRO, 0xBF11, "H8DME-EX-LS006" },
+ { IPMI_OEM_SUPERMICRO, 0xBF80, "C2SBi" },
+ { IPMI_OEM_SUPERMICRO, 0xC080, "AOC-USAS-H4i" },
+ { IPMI_OEM_SUPERMICRO, 0xC180, "AOC-USAS-H8i" },
+ { IPMI_OEM_SUPERMICRO, 0xC280, "B7DW3" },
+ { IPMI_OEM_SUPERMICRO, 0xC380, "AOC-USASLP-H8iR" },
+ { IPMI_OEM_SUPERMICRO, 0xCA11, "H8QGL" },
+ { IPMI_OEM_SUPERMICRO, 0xCB11, "H8DGT-CM" },
+ { IPMI_OEM_SUPERMICRO, 0xCD11, "H8DCL-6F" },
+ { IPMI_OEM_SUPERMICRO, 0xCE11, "H8DCT-HLN4F" },
+ { IPMI_OEM_SUPERMICRO, 0xCF11, "H8SML-7/i(F)" },
+ { IPMI_OEM_SUPERMICRO, 0xD011, "H8QG7" },
+ { IPMI_OEM_SUPERMICRO, 0xD080, "X7DWP" },
+ { IPMI_OEM_SUPERMICRO, 0xD111, "H8SME-F" },
+ { IPMI_OEM_SUPERMICRO, 0xD180, "X7SBi" },
+ { IPMI_OEM_SUPERMICRO, 0xD280, "X7SB4/E" },
+ { IPMI_OEM_SUPERMICRO, 0xD380, "X7SBA" },
+ { IPMI_OEM_SUPERMICRO, 0xD480, "X7SBi-LN4" },
+ { IPMI_OEM_SUPERMICRO, 0xD580, "X7SBF" },
+ { IPMI_OEM_SUPERMICRO, 0xD680, "X7DCA-3/i" },
+ { IPMI_OEM_SUPERMICRO, 0xDA80, "C2SBM-Q" },
+ { IPMI_OEM_SUPERMICRO, 0xDB80, "X7DCU" },
+ { IPMI_OEM_SUPERMICRO, 0xDC80, "X7DCA-L" },
+ { IPMI_OEM_SUPERMICRO, 0xDD80, "X7SBX" },
+ { IPMI_OEM_SUPERMICRO, 0xDE80, "X7DCT-10G" },
+ { IPMI_OEM_SUPERMICRO, 0xDF80, "X7DWE" },
+ { IPMI_OEM_SUPERMICRO, 0xF080, "X7SBT" },
+ { IPMI_OEM_SUPERMICRO, 0xF180, "X7SBU" },
+ { IPMI_OEM_SUPERMICRO, 0xF280, "X8DTN+" },
+ { IPMI_OEM_SUPERMICRO, 0xF380, "X8SAX" },
+ { IPMI_OEM_SUPERMICRO, 0xF480, "X7DCX" },
+ { IPMI_OEM_SUPERMICRO, 0xF580, "X8ST3" },
+ /* YADRO */
+ { IPMI_OEM_YADRO, 0x0001, "VESNIN BMC" },
+ { IPMI_OEM_YADRO, 0x000A, "TATLIN.UNIFIED Storage Controller BMC" },
+ { IPMI_OEM_YADRO, 0x0014, "VEGMAN Series BMC" },
+ { IPMI_OEM_YADRO, 0x0015, "TATLIN.ARCHIVE/xS BMC" },
{ 0xffffff , 0xffff , NULL },
};
@@ -385,8 +1033,8 @@ const struct valstr ipmi_privlvl_vals[] = {
{ IPMI_SESSION_PRIV_OPERATOR, "OPERATOR" },
{ IPMI_SESSION_PRIV_ADMIN, "ADMINISTRATOR" },
{ IPMI_SESSION_PRIV_OEM, "OEM" },
- { 0xF, "NO ACCESS" },
- { 0xFF, NULL },
+ { IPMI_SESSION_PRIV_NOACCESS, "NO ACCESS" },
+ { UINT8_MAX, NULL },
};
@@ -617,6 +1265,25 @@ const struct valstr ipmi_chassis_power_control_vals[] = {
{ 0x00, NULL },
};
+/*
+ * See Table 28-11, Get System Restart Cause Command
+ */
+const struct valstr ipmi_chassis_restart_cause_vals[] = {
+ { 0x0, "unknown" },
+ { 0x1, "chassis power control command" },
+ { 0x2, "reset via pushbutton" },
+ { 0x3, "power-up via pushbutton" },
+ { 0x4, "watchdog expired" },
+ { 0x5, "OEM" },
+ { 0x6, "power-up due to always-restore power policy" },
+ { 0x7, "power-up due to restore-previous power policy" },
+ { 0x8, "reset via PEF" },
+ { 0x9, "power-cycle via PEF" },
+ { 0xa, "soft reset" },
+ { 0xb, "power-up via RTC wakeup" },
+ { 0xFF, NULL },
+};
+
const struct valstr ipmi_auth_algorithms[] = {
{ IPMI_AUTH_RAKP_NONE, "none" },
{ IPMI_AUTH_RAKP_HMAC_SHA1, "hmac_sha1" },
@@ -787,3 +1454,327 @@ const struct oemvalstr picmg_busres_shmc_status_vals[] = {
{ 0xffffff, 0x00, NULL }
};
+
+
+/**
+ * A helper function to count repetitions of the same byte
+ * at the beginning of a string.
+ */
+static
+size_t count_bytes(const char *s, unsigned char c)
+{
+ size_t count;
+
+ for (count = 0; s && s[0] == c; ++s, ++count);
+
+ return count;
+}
+
+/**
+ * Parse the IANA PEN registry file.
+ *
+ * See https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers
+ * The expected entry format is:
+ *
+ * Decimal
+ * | Organization
+ * | | Contact
+ * | | | Email
+ * | | | |
+ * 0
+ * Reserved
+ * Internet Assigned Numbers Authority
+ * iana&iana.org
+ *
+ * That is, IANA PEN at position 0, enterprise name at position 2.
+ */
+#define IANA_NAME_OFFSET 2
+#define IANA_PEN_REGISTRY "enterprise-numbers"
+static
+int oem_info_list_load(oem_valstr_list_t **list)
+{
+ FILE *in = NULL;
+ char *home;
+ oem_valstr_list_t *oemlist = *list;
+ int count = 0;
+
+ /*
+ * First try to open user's local registry if HOME is set
+ */
+ if ((home = getenv("HOME"))) {
+ char path[PATH_MAX + 1] = { 0 };
+ snprintf(path, PATH_MAX, "%s%s",
+ home,
+ PATH_SEPARATOR IANAUSERDIR PATH_SEPARATOR IANA_PEN_REGISTRY);
+ in = fopen(path, "r");
+ }
+
+ if (!in) {
+ /*
+ * Now open the system default file
+ */
+ in = fopen(IANADIR PATH_SEPARATOR IANA_PEN_REGISTRY, "r");
+ if (!in) {
+ lperror(LOG_ERR, "IANA PEN registry open failed");
+ return -1;
+ }
+ }
+
+ /*
+ * Read the registry file line by line, fill in the linked list,
+ * and count the entries. No sorting is done, entries will come in
+ * reverse registry order.
+ */
+ while (!feof(in)) {
+ oem_valstr_list_t *item;
+ char *line = NULL;
+ char *endptr = NULL;
+ size_t len = 0;
+ long iana;
+
+ if (!getline(&line, &len, in)) {
+ /* Either an EOF or an empty line. Start over. */
+ continue;
+ }
+
+ /*
+ * Check if the line starts with a digit. If so, take it as IANA PEN.
+ * Any numbers not starting at position 0 are discarded.
+ */
+ iana = strtol(line, &endptr, 10);
+ if (!isdigit(line[0]) || endptr == line) {
+ free_n(&line);
+ continue;
+ }
+ free_n(&line);
+
+ /*
+ * Now as we have the enterprise number, we're expecting the
+ * organization name to immediately follow.
+ */
+ len = 0;
+ if (!getline(&line, &len, in)) {
+ /*
+ * Either an EOF or an empty line. Neither one can happen in
+ * a valid registry entry. Start over.
+ */
+ continue;
+ }
+
+ if (len < IANA_NAME_OFFSET + 1
+ || count_bytes(line, ' ') != IANA_NAME_OFFSET)
+ {
+ /*
+ * This is not a valid line, it doesn't start with
+ * a correct-sized indentation or is too short.
+ * Start over.
+ */
+ free_n(&line);
+ continue;
+ }
+
+ /* Adjust to real line length, don't count the indentation */
+ len = strnlen(line + IANA_NAME_OFFSET, len - IANA_NAME_OFFSET);
+
+ /* Don't count the trailing newline */
+ if (line[IANA_NAME_OFFSET + len - 1] == '\n') {
+ --len;
+ }
+
+ item = malloc(sizeof(oem_valstr_list_t));
+ if (!item) {
+ lperror(LOG_ERR, "IANA PEN registry entry allocation failed");
+ free_n(&line);
+ /* Just stop reading, and process what has already been read */
+ break;
+ }
+
+ /*
+ * Looks like we have a valid entry, store it in the list.
+ */
+ item->valstr.val = iana;
+ item->valstr.str = malloc(len + 1); /* Add 1 for \0 terminator */
+ if (!item->valstr.str) {
+ lperror(LOG_ERR, "IANA PEN registry string allocation failed");
+ free_n(&line);
+ free_n(&item);
+ /* Just stop reading, and process what has already been read */
+ break;
+ }
+
+ /*
+ * Most other valstr arrays are constant and all of them aren't meant
+ * for modification, so the string inside 'struct valstr' is const.
+ * Here we're loading the strings dynamically so we intentionally
+ * cast to a non-const type to be able to modify data here and
+ * keep the compiler silent about it. Restrictions still apply to
+ * other places where these strings are used.
+ */
+ snprintf((void *)item->valstr.str, len + 1,
+ "%s", line + IANA_NAME_OFFSET);
+ free_n(&line);
+ item->next = oemlist;
+ oemlist = item;
+ ++count;
+ }
+ fclose (in);
+
+ *list = oemlist;
+ return count;
+}
+
+/**
+ * Free the allocated list items and, if needed, strings.
+ */
+static
+void
+oem_info_list_free(oem_valstr_list_t **list, bool free_strings)
+{
+ while ((*list)->next) {
+ oem_valstr_list_t *item = *list;
+ *list = item->next;
+ if (free_strings) {
+ free_n(&item->valstr.str);
+ }
+ free_n(&item);
+ }
+}
+
+/**
+ * Initialize the ipmi_oem_info array from a list
+ */
+static
+bool
+oem_info_init_from_list(oem_valstr_list_t *oemlist, size_t count)
+{
+ /* Do not count terminators */
+ size_t head_entries = ARRAY_SIZE(ipmi_oem_info_head) - 1;
+ size_t tail_entries = ARRAY_SIZE(ipmi_oem_info_tail) - 1;
+ static oem_valstr_list_t *item;
+ bool rc = false;
+ int oemlist_debug = LOG_DEBUG + 4; /* Require six -v options */
+
+ /* Include static entries and the terminator */
+ count += head_entries + tail_entries + 1;
+
+ /*
+ * Allocate as much memory as needed to accomodata all the entries
+ * of the loaded linked list, plus the static head and tail, not including
+ * their terminating entries, plus the terminating entry for the new
+ * array.
+ */
+ ipmi_oem_info = malloc(count * sizeof(*ipmi_oem_info));
+
+ if (!ipmi_oem_info) {
+ /*
+ * We can't identify OEMs without an allocated ipmi_oem_info.
+ * Report an error, set the pointer to dummy and clean up.
+ */
+ lperror(LOG_ERR, "IANA PEN registry array allocation failed");
+ ipmi_oem_info = ipmi_oem_info_dummy;
+ goto out;
+ }
+
+ lprintf(oemlist_debug, " Allocating %6zu entries", count);
+
+ /* Add a terminator at the very end */
+ --count;
+ ((struct valstr *)ipmi_oem_info)[count].val = -1;
+ ((struct valstr *)ipmi_oem_info)[count].str = NULL;
+
+ /* Add tail entries from the end */
+ while (count-- < SIZE_MAX && tail_entries--) {
+ ((struct valstr *)ipmi_oem_info)[count] =
+ ipmi_oem_info_tail[tail_entries];
+
+ lprintf(oemlist_debug, " [%6zu] %8d | %s", count,
+ ipmi_oem_info[count].val, ipmi_oem_info[count].str);
+ }
+
+ /* Now add the loaded entries */
+ item = oemlist;
+ while (count < SIZE_MAX && item->next) {
+ ((struct valstr *)ipmi_oem_info)[count] =
+ item->valstr;
+
+ lprintf(oemlist_debug, " [%6zu] %8d | %s", count,
+ ipmi_oem_info[count].val, ipmi_oem_info[count].str);
+
+ item = item->next;
+ --count;
+ }
+
+ /* Now add head entries */
+ while (count < SIZE_MAX && head_entries--) {
+ ((struct valstr *)ipmi_oem_info)[count] =
+ ipmi_oem_info_head[head_entries];
+ lprintf(oemlist_debug, " [%6zu] %8d | %s", count,
+ ipmi_oem_info[count].val, ipmi_oem_info[count].str);
+ --count;
+ }
+
+ rc = true;
+
+out:
+ return rc;
+}
+
+int ipmi_oem_info_init()
+{
+ oem_valstr_list_t terminator = { { -1, NULL}, NULL }; /* Terminator */
+ oem_valstr_list_t *oemlist = &terminator;
+ bool free_strings = true;
+ size_t count;
+ int rc = -4;
+
+ lprintf(LOG_INFO, "Loading IANA PEN Registry...");
+
+ if (ipmi_oem_info) {
+ lprintf(LOG_INFO, "IANA PEN Registry is already loaded");
+ rc = 0;
+ goto out;
+ }
+
+ if (!(count = oem_info_list_load(&oemlist))) {
+ /*
+ * We can't identify OEMs without a loaded registry.
+ * Set the pointer to dummy and return.
+ */
+ ipmi_oem_info = ipmi_oem_info_dummy;
+ goto out;
+ }
+
+ /* In the array was allocated, don't free the strings at cleanup */
+ free_strings = !oem_info_init_from_list(oemlist, count);
+
+ rc = IPMI_CC_OK;
+
+out:
+ oem_info_list_free(&oemlist, free_strings);
+ return rc;
+}
+
+void ipmi_oem_info_free()
+{
+ /* Start with the dynamically allocated entries */
+ size_t i = ARRAY_SIZE(ipmi_oem_info_head) - 1;
+
+ if (ipmi_oem_info == ipmi_oem_info_dummy) {
+ return;
+ }
+
+ /*
+ * Proceed dynamically allocated entries until we hit the first
+ * entry of ipmi_oem_info_tail[], which is statically allocated.
+ */
+ while (ipmi_oem_info
+ && ipmi_oem_info[i].val < UINT32_MAX
+ && ipmi_oem_info[i].str != ipmi_oem_info_tail[0].str)
+ {
+ free_n(&((struct valstr *)ipmi_oem_info)[i].str);
+ ++i;
+ }
+
+ /* Free the array itself */
+ free_n(&ipmi_oem_info);
+}
diff --git a/lib/ipmi_sunoem.c b/lib/ipmi_sunoem.c
index ecbcbd9..d03900d 100644
--- a/lib/ipmi_sunoem.c
+++ b/lib/ipmi_sunoem.c
@@ -29,7 +29,6 @@
* 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 _XOPEN_SOURCE
#include <stdlib.h>
#include <stdio.h>
@@ -197,7 +196,7 @@ static void
__sdr_list_empty(struct sdr_record_list * head)
{
struct sdr_record_list * e, *f;
- for (e = head; e != NULL; e = f) {
+ for (e = head; e; e = f) {
f = e->next;
free(e);
}
@@ -254,7 +253,7 @@ sunoem_led_get(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev,
uint8_t rqdata[7];
int rqdata_len;
- if (dev == NULL) {
+ if (!dev) {
*loc_rsp = NULL;
return (SUNOEM_EC_INVALID_ARG);
}
@@ -283,10 +282,10 @@ sunoem_led_get(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev,
* Just return NULL if there was
* an error.
*/
- if (rsp == NULL) {
+ if (!rsp) {
*loc_rsp = NULL;
return (SUNOEM_EC_BMC_NOT_RESPONDING);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
*loc_rsp = rsp;
return (SUNOEM_EC_BMC_CCODE_NONZERO);
} else {
@@ -304,7 +303,7 @@ sunoem_led_set(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev,
uint8_t rqdata[9];
int rqdata_len;
- if (dev == NULL)
+ if (!dev)
return NULL;
rqdata[0] = dev->dev_slave_addr;
@@ -330,10 +329,10 @@ sunoem_led_set(struct ipmi_intf * intf, struct sdr_record_generic_locator * dev,
req.msg.data_len = rqdata_len;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM Set LED command failed.");
return NULL;
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM Set LED command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return NULL;
@@ -361,11 +360,11 @@ sunoem_led_get_byentity(struct ipmi_intf * intf, uint8_t entity_id,
elist = ipmi_sdr_find_sdr_byentity(intf, &entity);
- if (elist == NULL)
+ if (!elist)
ret_get = -1;
/* for each generic sensor get its led state */
- for (e = elist; e != NULL; e = e->next) {
+ for (e = elist; e; e = e->next) {
if (e->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR)
continue;
@@ -404,11 +403,11 @@ sunoem_led_set_byentity(struct ipmi_intf * intf, uint8_t entity_id,
elist = ipmi_sdr_find_sdr_byentity(intf, &entity);
- if (elist == NULL)
+ if (!elist)
ret_set = -1;
/* for each generic sensor set its led state */
- for (e = elist; e != NULL; e = e->next) {
+ for (e = elist; e; e = e->next) {
if (e->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR)
continue;
@@ -417,7 +416,7 @@ sunoem_led_set_byentity(struct ipmi_intf * intf, uint8_t entity_id,
if (rsp && rsp->data_len == 0) {
led_print((const char *) e->record.genloc->id_string, PRINT_NORMAL,
ledmode);
- } else if (rsp == NULL) {
+ } else if (!rsp) {
ret_set = -1;
}
}
@@ -435,14 +434,14 @@ sunoem_led_set_byentity(struct ipmi_intf * intf, uint8_t entity_id,
* Access Address" field, 0x20 if the LED is local
* [byte 3] hwInfo The OEM field from the SDR record
* [byte 4] force 1 = directly access the device
- * 0 = go thru its controller
+ * 0 = go through its controller
* Ignored if LED is local
*
* The format below is for Sun Blade Modular systems only
* [byte 4] entityID The entityID field from the SDR record
* [byte 5] entityIns The entityIns field from the SDR record
* [byte 6] force 1 = directly access the device
- * 0 = go thru its controller
+ * 0 = go through its controller
* Ignored if LED is local
*/
static int
@@ -460,7 +459,7 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv)
* sunoem led/sbled get <id> [type]
*/
- if (argc < 1 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc < 1 || !strcmp(argv[0], "help")) {
ipmi_sunoem_usage();
return (0);
}
@@ -472,15 +471,15 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv)
"Unknown ledtype, will use data from the SDR oem field");
}
- if (strncasecmp(argv[0], "all", 3) == 0) {
+ if (strcasecmp(argv[0], "all") == 0) {
/* do all generic sensors */
alist = ipmi_sdr_find_sdr_bytype(intf,
SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR);
- if (alist == NULL)
+ if (!alist)
return (-1);
- for (a = alist; a != NULL; a = a->next) {
+ for (a = alist; a; a = a->next) {
if (a->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR)
continue;
if (a->record.genloc->entity.logical)
@@ -511,7 +510,7 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv)
/* look up generic device locator record in SDR */
sdr = ipmi_sdr_find_sdr_byid(intf, argv[0]);
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR, "No Sensor Data Record found for %s", argv[0]);
return (-1);
}
@@ -556,14 +555,14 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv)
/* get entity assoc records */
alist = ipmi_sdr_find_sdr_bytype(intf, SDR_RECORD_TYPE_ENTITY_ASSOC);
- if (alist == NULL)
+ if (!alist)
return (-1);
- for (a = alist; a != NULL; a = a->next) {
+ for (a = alist; a; a = a->next) {
if (a->type != SDR_RECORD_TYPE_ENTITY_ASSOC)
continue;
assoc = a->record.entassoc;
- if (assoc == NULL)
+ if (!assoc)
continue;
/* check that the entity id/instance matches our generic record */
@@ -625,7 +624,7 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv)
* [byte 3] hwInfo The OEM field from the SDR record
* [byte 4] mode LED Mode: OFF, ON, STANDBY, SLOW, FAST
* [byte 5] force TRUE - directly access the device
- * FALSE - go thru its controller
+ * FALSE - go through its controller
* Ignored if LED is local
* [byte 6] role Used by BMC for authorization purposes
*
@@ -633,7 +632,7 @@ ipmi_sunoem_led_get(struct ipmi_intf * intf, int argc, char ** argv)
* [byte 5] entityID The entityID field from the SDR record
* [byte 6] entityIns The entityIns field from the SDR record
* [byte 7] force TRUE - directly access the device
- * FALSE - go thru its controller
+ * FALSE - go through its controller
* Ignored if LED is local
* [byte 8] role Used by BMC for authorization purposes
*
@@ -658,7 +657,7 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv)
* sunoem led/sbled set <id> <mode> [type]
*/
- if (argc < 2 || strncmp(argv[0], "help", 4) == 0) {
+ if (argc < 2 || !strcmp(argv[0], "help")) {
ipmi_sunoem_usage();
return (0);
}
@@ -679,21 +678,21 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv)
"Unknown ledtype, will use data from the SDR oem field");
}
- if (strncasecmp(argv[0], "all", 3) == 0) {
+ if (strcasecmp(argv[0], "all") == 0) {
/* do all generic sensors */
alist = ipmi_sdr_find_sdr_bytype(intf,
SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR);
- if (alist == NULL)
+ if (!alist)
return (-1);
- for (a = alist; a != NULL; a = a->next) {
+ for (a = alist; a; a = a->next) {
if (a->type != SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR)
continue;
if (a->record.genloc->entity.logical)
continue;
rsp = sunoem_led_set(intf, a->record.genloc, ledtype, ledmode);
- if (rsp && rsp->ccode == 0)
+ if (rsp && !rsp->ccode)
led_print((const char *) a->record.genloc->id_string,
PRINT_NORMAL, ledmode);
else
@@ -710,7 +709,7 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv)
/* look up generic device locator records in SDR */
sdr = ipmi_sdr_find_sdr_byid(intf, argv[0]);
- if (sdr == NULL) {
+ if (!sdr) {
lprintf(LOG_ERR, "No Sensor Data Record found for %s", argv[0]);
return (-1);
}
@@ -725,7 +724,7 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv)
* handle physical entity
*/
rsp = sunoem_led_set(intf, sdr->record.genloc, ledtype, ledmode);
- if (rsp && rsp->ccode == 0)
+ if (rsp && !rsp->ccode)
led_print(argv[0], PRINT_NORMAL, ledmode);
else
return (-1);
@@ -742,14 +741,14 @@ ipmi_sunoem_led_set(struct ipmi_intf * intf, int argc, char ** argv)
/* get entity assoc records */
alist = ipmi_sdr_find_sdr_bytype(intf, SDR_RECORD_TYPE_ENTITY_ASSOC);
- if (alist == NULL)
+ if (!alist)
return (-1);
- for (a = alist; a != NULL; a = a->next) {
+ for (a = alist; a; a = a->next) {
if (a->type != SDR_RECORD_TYPE_ENTITY_ASSOC)
continue;
assoc = a->record.entassoc;
- if (assoc == NULL)
+ if (!assoc)
continue;
/* check that the entity id/instance matches our generic record */
@@ -813,10 +812,10 @@ ipmi_sunoem_sshkey_del(struct ipmi_intf * intf, uint8_t uid)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to delete ssh key for UID %d", uid);
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Unable to delete ssh key for UID %d: %s", uid,
val2str(rsp->ccode, completion_code_vals));
return (-1);
@@ -839,13 +838,13 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile)
int32_t r = 0;
int32_t size = 0;
- if (ifile == NULL) {
+ if (!ifile) {
lprintf(LOG_ERR, "Invalid or misisng input filename.");
return (-1);
}
fp = ipmi_open_file_read(ifile);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Unable to open file '%s' for reading.", ifile);
return (-1);
}
@@ -857,7 +856,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile)
if (fseek(fp, 0, SEEK_END) == (-1)) {
lprintf(LOG_ERR, "Failed to seek in file '%s'.", ifile);
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
@@ -866,13 +865,13 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile)
size = (int32_t) ftell(fp);
if (size < 0) {
lprintf(LOG_ERR, "Failed to seek in file '%s'.", ifile);
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
} else if (size == 0) {
lprintf(LOG_ERR, "File '%s' is empty.", ifile);
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
@@ -880,7 +879,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile)
if (fseek(fp, 0, SEEK_SET) == (-1)) {
lprintf(LOG_ERR, "Failed to seek in file '%s'.", ifile);
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
@@ -900,7 +899,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile)
printf("failed\n");
lprintf(LOG_ERR, "Unable to read %ld bytes from file '%s'.", i_size,
ifile);
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
@@ -917,7 +916,7 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile)
printf("failed\n");
lprintf(LOG_ERR, "Unable to pack byte %ld from file '%s'.", r,
ifile);
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
@@ -930,23 +929,23 @@ ipmi_sunoem_sshkey_set(struct ipmi_intf * intf, uint8_t uid, char * ifile)
req.msg.data_len = i_size + 3;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf("failed\n");
lprintf(LOG_ERR, "Unable to set ssh key for UID %d.", uid);
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
- } /* if (rsp == NULL) */
- if (rsp->ccode != 0) {
+ }
+ if (rsp->ccode) {
printf("failed\n");
lprintf(LOG_ERR, "Unable to set ssh key for UID %d, %s.", uid,
val2str(rsp->ccode, completion_code_vals));
- if (fp != NULL)
+ if (fp)
fclose(fp);
return (-1);
- } /* if (rsp->ccode != 0) */
+ }
}
printf("done\n");
@@ -1077,7 +1076,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[])
memset(&cli_req, 0, sizeof(cli_req));
cli_req.version = SunOemCliActingVersion;
cli_req.command_response = SUNOEM_CLI_CMD_OPEN;
- if (argc > 0 && strcmp(argv[0], "force") == 0) {
+ if (argc > 0 && !strcmp(argv[0], "force")) {
cli_req.command_response = SUNOEM_CLI_CMD_FORCE;
argc--;
argv++;
@@ -1091,16 +1090,15 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[])
while (1) {
cli_req.version = SunOemCliActingVersion;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM cli command failed");
return (-1);
}
cli_rsp = (sunoem_cli_msg_t *) rsp->data;
- if ((cli_rsp->command_response != 0) || (rsp->ccode != 0)) {
- if (strncmp(cli_rsp->buf, SUNOEM_CLI_INVALID_VER_ERR,
- sizeof(SUNOEM_CLI_INVALID_VER_ERR) - 1) == 0
- || strncmp(&(cli_rsp->buf[1]), SUNOEM_CLI_INVALID_VER_ERR,
- sizeof(SUNOEM_CLI_INVALID_VER_ERR) - 1) == 0) {
+ if (cli_rsp->command_response || rsp->ccode) {
+ if (!strcmp(cli_rsp->buf, SUNOEM_CLI_INVALID_VER_ERR)
+ || !strcmp(&(cli_rsp->buf[1]), SUNOEM_CLI_INVALID_VER_ERR))
+ {
if (SunOemCliActingVersion == SUNOEM_CLI_VERSION) {
/* Server doesn't support version SUNOEM_CLI_VERSION
Fall back to legacy version, and try again*/
@@ -1110,8 +1108,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[])
/* Server doesn't support legacy version either */
lprintf(LOG_ERR, "Failed to connect: %s", cli_rsp->buf);
return (-1);
- } else if (strncmp(cli_rsp->buf, SUNOEM_CLI_BUSY_ERR,
- sizeof(SUNOEM_CLI_BUSY_ERR) - 1) == 0) {
+ } else if (!strcmp(cli_rsp->buf, SUNOEM_CLI_BUSY_ERR)) {
if (retries++ < SUNOEM_CLI_MAX_RETRY) {
lprintf(LOG_INFO, "Failed to connect: %s, retrying",
cli_rsp->buf);
@@ -1155,7 +1152,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[])
return (-1);
}
}
- while (rsp->ccode == 0 && cli_rsp->command_response == 0) {
+ while (!rsp->ccode && cli_rsp->command_response == 0) {
int rc = 0;
int count = 0;
cli_req.buf[0] = '\0';
@@ -1197,7 +1194,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[])
} else if (arg_num >= argc) {
/* Last arg was sent. Set EOF */
cli_req.command_response = SUNOEM_CLI_CMD_EOF;
- } else if (strncmp(argv[arg_num], "@wait=", 6) == 0) {
+ } else if (!strcmp(argv[arg_num], "@wait=")) {
/* This is a wait command */
char *s = &argv[arg_num][6];
delay = 0;
@@ -1254,7 +1251,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[])
req.msg.data_len = SUNOEM_CLI_HEADER + count;
for (retries = 0; retries <= SUNOEM_CLI_MAX_RETRY; retries++) {
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Communication error.");
error = 1;
goto cleanup;
@@ -1281,7 +1278,7 @@ ipmi_sunoem_cli(struct ipmi_intf * intf, int argc, char *argv[])
fflush(NULL); /* Flush partial lines to stdout */
count = 0; /* Don't re-send the client's data */
if (cli_req.command_response == SUNOEM_CLI_CMD_EOF
- && cli_rsp->command_response != 0 && rsp->ccode == 0) {
+ && cli_rsp->command_response != 0 && !rsp->ccode) {
cli_rsp->command_response = 1;
}
} while (cli_rsp->command_response == 0 && cli_rsp->buf[0] != '\0');
@@ -1381,7 +1378,7 @@ ipmi_sunoem_echo(struct ipmi_intf * intf, int argc, char *argv[])
gettimeofday(&end_time, NULL);
resp_time = ((end_time.tv_sec - start_time.tv_sec) * 1000)
+ ((end_time.tv_usec - start_time.tv_usec) / 1000);
- if ((rsp == NULL) || (rsp->ccode != 0)) {
+ if (!rsp || rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM echo command failed. Seq # %d",
echo_req.seq_num);
rc = (-2);
@@ -1466,7 +1463,7 @@ typedef struct
/*
* When adding new fields (using the spare bytes),
* add it immediately after the spare field to
- * ensure backward compatability.
+ * ensure backward compatibility.
*
* e.g. char version[40];
* unsigned char spare[11];
@@ -1501,11 +1498,11 @@ ipmi_sunoem_getversion(struct ipmi_intf * intf,
req.msg.data_len = 0;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM Get SP Version Failed.");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM Get SP Version Failed: %d", rsp->ccode);
return (-1);
}
@@ -1651,11 +1648,11 @@ ipmi_sunoem_nacname(struct ipmi_intf * intf, int argc, char *argv[])
req.msg.data_len = sizeof(sunoem_nacname_t);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM nacname command failed.");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM nacname command failed: %d", rsp->ccode);
return (-1);
}
@@ -1800,7 +1797,7 @@ ipmi_sunoem_getval(struct ipmi_intf * intf, int argc, char *argv[])
}
if ((ipmi_sunoem_checkversion(intf, &supp_ver) < 0)
- && (!strncmp(argv[0], sp_path, strlen(sp_path)))) {
+ && (!strcmp(argv[0], sp_path))) {
argv[0][1] = 'X'; /*replace SP by X to gain access to hidden properties*/
memmove(&argv[0][2], &argv[0][3], strlen(argv[0]) - 2);
}
@@ -1821,11 +1818,11 @@ ipmi_sunoem_getval(struct ipmi_intf * intf, int argc, char *argv[])
req.msg.data_len = sizeof(sunoem_getval_t);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM getval1 command failed.");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM getval1 command failed: %d", rsp->ccode);
return (-1);
}
@@ -1843,12 +1840,12 @@ ipmi_sunoem_getval(struct ipmi_intf * intf, int argc, char *argv[])
req.msg.data_len = sizeof(sunoem_getval_t);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM getval2 command failed.");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM getval2 command failed: %d", rsp->ccode);
return (-1);
}
@@ -1911,12 +1908,12 @@ send_luapi_prop_name(struct ipmi_intf * intf, int len, char *prop_name,
req.msg.data_len = sizeof(sunoem_setval_t);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM setval prop name: response is NULL");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM setval prop name: request failed: %d",
rsp->ccode);
return (-1);
@@ -1984,12 +1981,12 @@ send_luapi_prop_value(struct ipmi_intf * intf, int len, char *prop_value,
req.msg.data_len = sizeof(sunoem_setval_t);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM setval prop value: response is NULL");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM setval prop value: request failed: %d",
rsp->ccode);
return (-1);
@@ -2077,12 +2074,12 @@ ipmi_sunoem_setval(struct ipmi_intf * intf, int argc, char *argv[])
req.msg.data_len = sizeof(sunoem_setval_t);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM setval command failed.");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM setval command failed: %d", rsp->ccode);
return (-1);
}
@@ -2167,7 +2164,7 @@ ipmi_sunoem_getfile(struct ipmi_intf * intf, int argc, char *argv[])
/* Create the destination file */
fp = ipmi_open_file_write(argv[1]);
- if (fp == NULL) {
+ if (!fp) {
lprintf(LOG_ERR, "Unable to open file: %s", argv[1]);
return (-1);
}
@@ -2188,12 +2185,12 @@ ipmi_sunoem_getfile(struct ipmi_intf * intf, int argc, char *argv[])
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM getfile command failed.");
fclose(fp);
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM getfile command failed: %d", rsp->ccode);
fclose(fp);
return (-1);
@@ -2301,12 +2298,12 @@ ipmi_sunoem_getbehavior(struct ipmi_intf * intf, int argc, char *argv[])
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Sun OEM getbehavior command failed.");
return (-1);
}
- if (rsp->ccode != 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Sun OEM getbehavior command failed: %d", rsp->ccode);
return (-1);
}
@@ -2323,27 +2320,29 @@ ipmi_sunoem_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int rc = 0;
- if (argc == 0 || strcmp(argv[0], "help") == 0) {
+ if (!argc || !strcmp(argv[0], "help")) {
ipmi_sunoem_usage();
return (0);
- } /* if (argc == 0 || strcmp(argv[0], "help") == 0) */
+ }
- if (strcmp(argv[0], "cli") == 0) {
+ if (!strcmp(argv[0], "cli")) {
rc = ipmi_sunoem_cli(intf, argc - 1, &argv[1]);
- } else if ((strcmp(argv[0], "led") == 0) || (strcmp(argv[0], "sbled") == 0)) {
+ } else if (!strcmp(argv[0], "led")
+ || !strcmp(argv[0], "sbled"))
+ {
if (argc < 2) {
ipmi_sunoem_usage();
return (-1);
}
- if (strcmp(argv[1], "get") == 0) {
+ if (!strcmp(argv[1], "get")) {
if (argc < 3) {
char * arg[] = { "all" };
rc = ipmi_sunoem_led_get(intf, 1, arg);
} else {
rc = ipmi_sunoem_led_get(intf, argc - 2, &(argv[2]));
}
- } else if (strcmp(argv[1], "set") == 0) {
+ } else if (!strcmp(argv[1], "set")) {
if (argc < 4) {
ipmi_sunoem_usage();
return (-1);
@@ -2353,7 +2352,7 @@ ipmi_sunoem_main(struct ipmi_intf * intf, int argc, char ** argv)
ipmi_sunoem_usage();
return (-1);
}
- } else if (strcmp(argv[0], "sshkey") == 0) {
+ } else if (!strcmp(argv[0], "sshkey")) {
uint8_t uid = 0;
if (argc < 3) {
ipmi_sunoem_usage();
@@ -2371,10 +2370,10 @@ ipmi_sunoem_main(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
- if (strcmp(argv[1], "del") == 0) {
+ if (!strcmp(argv[1], "del")) {
/* number of arguments, three, is already checked at this point */
rc = ipmi_sunoem_sshkey_del(intf, uid);
- } else if (strcmp(argv[1], "set") == 0) {
+ } else if (!strcmp(argv[1], "set")) {
if (argc < 4) {
ipmi_sunoem_usage();
return (-1);
@@ -2384,39 +2383,39 @@ ipmi_sunoem_main(struct ipmi_intf * intf, int argc, char ** argv)
ipmi_sunoem_usage();
return (-1);
}
- } else if (strcmp(argv[0], "ping") == 0) {
+ } else if (!strcmp(argv[0], "ping")) {
if (argc < 2) {
ipmi_sunoem_usage();
return (-1);
}
rc = ipmi_sunoem_echo(intf, argc - 1, &(argv[1]));
- } else if (strcmp(argv[0], "version") == 0) {
+ } else if (!strcmp(argv[0], "version")) {
rc = ipmi_sunoem_version(intf);
- } else if (strcmp(argv[0], "nacname") == 0) {
+ } else if (!strcmp(argv[0], "nacname")) {
if (argc < 2) {
ipmi_sunoem_usage();
return (-1);
}
rc = ipmi_sunoem_nacname(intf, argc - 1, &(argv[1]));
- } else if (strcmp(argv[0], "getval") == 0) {
+ } else if (!strcmp(argv[0], "getval")) {
if (argc < 2) {
ipmi_sunoem_usage();
return (-1);
}
rc = ipmi_sunoem_getval(intf, argc - 1, &(argv[1]));
- } else if (strcmp(argv[0], "setval") == 0) {
+ } else if (!strcmp(argv[0], "setval")) {
if (argc < 3) {
ipmi_sunoem_usage();
return (-1);
}
rc = ipmi_sunoem_setval(intf, argc - 1, &(argv[1]));
- } else if (strcmp(argv[0], "getfile") == 0) {
+ } else if (!strcmp(argv[0], "getfile")) {
if (argc < 3) {
ipmi_sunoem_usage();
return (-1);
}
rc = ipmi_sunoem_getfile(intf, argc - 1, &(argv[1]));
- } else if (strcmp(argv[0], "getbehavior") == 0) {
+ } else if (!strcmp(argv[0], "getbehavior")) {
if (argc < 2) {
ipmi_sunoem_usage();
return (-1);
@@ -2425,7 +2424,7 @@ ipmi_sunoem_main(struct ipmi_intf * intf, int argc, char ** argv)
} else {
lprintf(LOG_ERR, "Invalid sunoem command: %s", argv[0]);
return (-1);
- } /* if (strcmp(argv[0], "cli") == 0) */
+ }
return (rc);
}
diff --git a/lib/ipmi_time.c b/lib/ipmi_time.c
new file mode 100644
index 0000000..aecd656
--- /dev/null
+++ b/lib/ipmi_time.c
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2018 Alexander Amelkin. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of the copyright holder, nor the names of
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
+ * THE COPYRIGHT HOLDER AND ITS LICENSORS SHALL NOT BE LIABLE
+ * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
+ * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
+ * THE COPYRIGHT HOLDER OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
+ * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
+ * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
+ * THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS
+ * SOFTWARE, EVEN IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGES.
+ */
+
+#include <time.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h> /* snprintf */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ipmitool/ipmi_time.h>
+
+bool time_in_utc; /* Set by '-Z' command line option */
+
+time_t
+ipmi_localtime2utc(time_t local)
+{
+ struct tm tm;
+ gmtime_r(&local, &tm);
+ tm.tm_isdst = (-1);
+ return mktime(&tm);
+}
+
+/**
+ * @brief Convert a timestamp to a formatted string,
+ * considering the '-Z' option. Acts as if tzset() was called.
+ *
+ * @param[out] s The output string buffer
+ * @param[in] max The size of the output string buffer including the
+ * terminating null byte
+ * @param[in] format The format string, as in strftime(), ignored for
+ * special timestamp values as per section 37.1 of
+ * IPMI v2.0 specification rev 1.1.
+ * @param[in] stamp The time stamp to convert
+ *
+ * @returns the number of bytes written to s or 0, see strftime()
+ */
+size_t
+ipmi_strftime(char *s, size_t max, const char *format, time_t stamp)
+{
+ struct tm tm;
+ /*
+ * There is a bug in gcc since 4.3.2 and still not fixed in 8.1.0.
+ * Even if __attribute__((format(strftime... is specified for a wrapper
+ * function around strftime, gcc still complains about strftime being
+ * called from the wrapper with a "non-literal" format argument.
+ *
+ * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39438
+ *
+ * The following macro uses an "ugly cast" from that discussion to
+ * silence the compiler. The format string is checked for the wrapper
+ * because __attribute__((format)) is specified in the header file.
+ */
+ #define wrapstrftime(buf, buflen, fmt, t) \
+ ((size_t (*)(char *, size_t, const char *, const struct tm *))\
+ strftime)(buf, buflen, fmt, t)
+
+
+ if (IPMI_TIME_UNSPECIFIED == stamp) {
+ return snprintf(s, max, "Unknown");
+ }
+ else if (stamp <= IPMI_TIME_INIT_DONE) {
+ /* Timestamp is relative to BMC start, no GMT offset */
+ gmtime_r(&stamp, &tm);
+
+ return wrapstrftime(s, max, format, &tm);
+ }
+
+ if (time_in_utc || ipmi_timestamp_is_special(stamp)) {
+ /*
+ * The user wants the time reported in UTC or the stamp represents the
+ * number of seconds since system power on. In any case, don't apply
+ * the timezone offset.
+ */
+ gmtime_r(&stamp, &tm);
+ daylight = -1;
+ } else {
+ /*
+ * The user wants the time reported in local time zone.
+ */
+ localtime_r(&stamp, &tm);
+ }
+ return wrapstrftime(s, max, format, &tm);
+}
+
+/**
+ * @brief Convert a timestamp to string, considering the '-Z' option.
+ * Similar to asctime_r(), but takes time_t instead of struct tm,
+ * and the string is in form "Wed Jun 30 21:49:08 1993 TZD" without
+ * the new line at the end.
+ *
+ * @param[in] stamp The timestamp to convert
+ * @param[out] outbuf The buffer to write the string to.
+ * @param[in] len The maximum length of the output buffer.
+ * Recommended size is IPMI_ASCTIME_SZ.
+ *
+ * @returns outbuf
+ */
+char *
+ipmi_asctime_r(const time_t stamp, ipmi_datebuf_t outbuf)
+{
+ if (ipmi_timestamp_is_special(stamp)) {
+ if (stamp < SECONDS_A_DAY) {
+ ipmi_strftime(outbuf, IPMI_ASCTIME_SZ, "S+%H:%M:%S", stamp);
+ }
+ /*
+ * IPMI_TIME_INIT_DONE is over 17 years. This should never
+ * happen normally, but we'll support this anyway.
+ */
+ else {
+ ipmi_strftime(outbuf, IPMI_ASCTIME_SZ, "S+%yy %jd %H:%M:%S", stamp);
+ }
+ }
+
+ ipmi_strftime(outbuf, IPMI_ASCTIME_SZ, "%c %Z", stamp);
+ return outbuf;
+}
+
+char *
+ipmi_timestamp_fmt(uint32_t stamp, const char *fmt)
+{
+ /*
+ * It's assumed that supplied 'fmt' is never longer
+ * than IPMI_ASCTIME_SZ
+ */
+ static ipmi_datebuf_t datebuf;
+ /*
+ * There is a bug in gcc since 4.3.2 and still not fixed in 8.1.0.
+ * Even if __attribute__((format(strftime... is specified for a wrapper
+ * function around strftime, gcc still complains about strftime being
+ * called from the wrapper with a "non-literal" format argument.
+ *
+ * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39438
+ *
+ * The following call uses an "ugly cast" from that discussion to
+ * silence the compiler. The format string is checked for the wrapper
+ * because __attribute__((format)) is specified in the header file.
+ */
+ ((size_t (*)(char *, size_t, const char *, time_t))
+ ipmi_strftime)(datebuf, sizeof(datebuf), fmt, stamp);
+
+ return datebuf;
+}
+
+char *
+ipmi_timestamp_string(uint32_t stamp)
+{
+ if (!ipmi_timestamp_is_valid(stamp)) {
+ return "Unspecified";
+ }
+
+ if (ipmi_timestamp_is_special(stamp)) {
+ if (stamp < SECONDS_A_DAY) {
+ return ipmi_timestamp_fmt(stamp, "S+ %H:%M:%S");
+ }
+ /*
+ * IPMI_TIME_INIT_DONE is over 17 years. This should never
+ * happen normally, but we'll support this anyway.
+ */
+ else {
+ return ipmi_timestamp_fmt(stamp, "S+ %y years %j days %H:%M:%S");
+ }
+ }
+ return ipmi_timestamp_fmt(stamp, "%c %Z");
+}
+
+char *
+ipmi_timestamp_numeric(uint32_t stamp)
+{
+ if (!ipmi_timestamp_is_valid(stamp)) {
+ return "Unspecified";
+ }
+
+ if (ipmi_timestamp_is_special(stamp)) {
+ if (stamp < SECONDS_A_DAY) {
+ return ipmi_timestamp_fmt(stamp, "S+ %H:%M:%S");
+ }
+ /*
+ * IPMI_TIME_INIT_DONE is over 17 years. This should never
+ * happen normally, but we'll support this anyway.
+ */
+ else {
+ return ipmi_timestamp_fmt(stamp, "S+ %y/%j %H:%M:%S");
+ }
+ }
+ return ipmi_timestamp_fmt(stamp, "%x %X %Z");
+}
+
+char *
+ipmi_timestamp_date(uint32_t stamp)
+{
+ if (!ipmi_timestamp_is_valid(stamp)) {
+ return "Unspecified";
+ }
+
+ if (ipmi_timestamp_is_special(stamp)) {
+ return ipmi_timestamp_fmt(stamp, "S+ %y/%j");
+ }
+ return ipmi_timestamp_fmt(stamp, "%x");
+}
+
+char *
+ipmi_timestamp_time(uint32_t stamp)
+{
+ if (!ipmi_timestamp_is_valid(stamp)) {
+ return "Unspecified";
+ }
+
+ /* Format is the same for both normal and special timestamps */
+ return ipmi_timestamp_fmt(stamp, "%X %Z");
+}
diff --git a/lib/ipmi_tsol.c b/lib/ipmi_tsol.c
index d89bcfd..7cf1bcc 100644
--- a/lib/ipmi_tsol.c
+++ b/lib/ipmi_tsol.c
@@ -29,7 +29,6 @@
* 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 _DEFAULT_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
@@ -104,11 +103,11 @@ ipmi_tsol_command(struct ipmi_intf *intf, char *recvip, int port,
data[5] = (port & 0xff);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to perform TSOL command");
return (-1);
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Unable to perform TSOL command: %s",
val2str(rsp->ccode, completion_code_vals));
return (-1);
@@ -149,11 +148,11 @@ ipmi_tsol_send_keystroke(struct ipmi_intf *intf, char *buff, int length)
rsp = intf->sendrecv(intf, &req);
if (verbose) {
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Unable to send keystroke");
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Unable to send keystroke: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -377,12 +376,12 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv)
char out_buff[IPMI_BUF_SIZE * 8];
char buff[IPMI_BUF_SIZE + 4];
int fd_socket, result, i;
- int out_buff_fill, in_buff_fill;
+ size_t out_buff_fill, in_buff_fill;
int ip1, ip2, ip3, ip4;
int read_only = 0, rows = 0, cols = 0;
int port = IPMI_TSOL_DEF_PORT;
- if (strlen(intf->name) < 3 || strncmp(intf->name, "lan", 3) != 0) {
+ if (strlen(intf->name) < 3 || strcmp(intf->name, "lan")) {
lprintf(LOG_ERR, "Error: Tyan SOL is only available over lan interface");
return (-1);
}
@@ -398,17 +397,13 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv)
rows = ip1;
} else if (sscanf(argv[i], "cols=%d", &ip1) == 1) {
cols = ip1;
- } else if (strlen(argv[i]) == 2
- && strncmp(argv[i], "ro", 2) == 0) {
+ } else if (!strcmp(argv[i], "ro")) {
read_only = 1;
- } else if (strlen(argv[i]) == 2
- && strncmp(argv[i], "rw", 2) == 0) {
+ } else if (!strcmp(argv[i], "rw")) {
read_only = 0;
- } else if (strlen(argv[i]) == 7
- && strncmp(argv[i], "altterm", 7) == 0) {
+ } else if (!strcmp(argv[i], "altterm")) {
_altterm = 1;
- } else if (strlen(argv[i]) == 4
- && strncmp(argv[i], "help", 4) == 0) {
+ } else if (!strcmp(argv[i], "help")) {
print_tsol_usage();
return 0;
} else {
@@ -430,7 +425,7 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv)
if (result <= 0) {
struct hostent *host = gethostbyname((const char *)intf->ssn_params.hostname);
- if (host == NULL ) {
+ if (!host ) {
lprintf(LOG_ERR, "Address lookup for %s failed",
intf->ssn_params.hostname);
return -1;
@@ -460,7 +455,7 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv)
/*
* retrieve local IP address if not supplied on command line
*/
- if (recvip == NULL) {
+ if (!recvip) {
/* must connect first */
result = intf->open(intf);
if (result < 0) {
@@ -476,7 +471,7 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv)
}
recvip = inet_ntoa(myaddr.sin_addr);
- if (recvip == NULL) {
+ if (!recvip) {
lprintf(LOG_ERR, "Unable to find local IP address");
close(fd_socket);
return -1;
@@ -539,7 +534,7 @@ ipmi_tsol_main(struct ipmi_intf *intf, int argc, char **argv)
if ((fds[0].revents & POLLIN) && (sizeof(out_buff) > out_buff_fill)) {
socklen_t sin_len = sizeof(sin);
- int buff_size = sizeof(buff);
+ size_t buff_size = sizeof(buff);
if ((sizeof(out_buff) - out_buff_fill + 4) < buff_size) {
buff_size = (sizeof(out_buff) - out_buff_fill) + 4;
if ((buff_size - 4) <= 0) {
diff --git a/lib/ipmi_user.c b/lib/ipmi_user.c
index 2780e61..2068c93 100644
--- a/lib/ipmi_user.c
+++ b/lib/ipmi_user.c
@@ -29,10 +29,6 @@
* 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 _BSD_SOURCE || \
- (_XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
- !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
#include <stdlib.h>
#include <string.h>
@@ -72,27 +68,27 @@ _ipmi_get_user_access(struct ipmi_intf *intf,
struct ipmi_rq req = {0};
struct ipmi_rs *rsp;
uint8_t data[2];
- if (user_access_rsp == NULL) {
+ if (!user_access_rsp) {
return (-3);
}
data[0] = user_access_rsp->channel & 0x0F;
- data[1] = user_access_rsp->user_id & 0x3F;
+ data[1] = IPMI_UID(user_access_rsp->user_id);
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = IPMI_GET_USER_ACCESS;
req.msg.data = data;
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 4) {
return (-2);
}
- user_access_rsp->max_user_ids = rsp->data[0] & 0x3F;
+ user_access_rsp->max_user_ids = IPMI_UID(rsp->data[0]);
user_access_rsp->enable_status = rsp->data[1] & 0xC0;
- user_access_rsp->enabled_user_ids = rsp->data[1] & 0x3F;
- user_access_rsp->fixed_user_ids = rsp->data[2] & 0x3F;
+ user_access_rsp->enabled_user_ids = IPMI_UID(rsp->data[1]);
+ user_access_rsp->fixed_user_ids = IPMI_UID(rsp->data[2]);
user_access_rsp->callin_callback = rsp->data[3] & 0x40;
user_access_rsp->link_auth = rsp->data[3] & 0x20;
user_access_rsp->ipmi_messaging = rsp->data[3] & 0x10;
@@ -114,18 +110,18 @@ _ipmi_get_user_name(struct ipmi_intf *intf, struct user_name_t *user_name_ptr)
struct ipmi_rq req = {0};
struct ipmi_rs *rsp;
uint8_t data[1];
- if (user_name_ptr == NULL) {
+ if (!user_name_ptr) {
return (-3);
}
- data[0] = user_name_ptr->user_id & 0x3F;
+ data[0] = IPMI_UID(user_name_ptr->user_id);
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = IPMI_GET_USER_NAME;
req.msg.data = data;
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
- } else if (rsp->ccode > 0) {
+ } else if (rsp->ccode) {
return rsp->ccode;
} else if (rsp->data_len != 16) {
return (-2);
@@ -151,7 +147,7 @@ _ipmi_set_user_access(struct ipmi_intf *intf,
uint8_t data[4];
struct ipmi_rq req = {0};
struct ipmi_rs *rsp;
- if (user_access_req == NULL) {
+ if (!user_access_req) {
return (-3);
}
data[0] = change_priv_limit_only ? 0x00 : 0x80;
@@ -165,7 +161,7 @@ _ipmi_set_user_access(struct ipmi_intf *intf,
data[0] |= 0x10;
}
data[0] |= (user_access_req->channel & 0x0F);
- data[1] = user_access_req->user_id & 0x3F;
+ data[1] = IPMI_UID(user_access_req->user_id);
data[2] = user_access_req->privilege_limit & 0x0F;
data[3] = user_access_req->session_limit & 0x0F;
req.msg.netfn = IPMI_NETFN_APP;
@@ -173,7 +169,7 @@ _ipmi_set_user_access(struct ipmi_intf *intf,
req.msg.data = data;
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
} else {
return rsp->ccode;
@@ -200,14 +196,14 @@ _ipmi_set_user_password(struct ipmi_intf *intf, uint8_t user_id,
uint8_t *data;
uint8_t data_len = (is_twenty_byte) ? 22 : 18;
data = malloc(sizeof(uint8_t) * data_len);
- if (data == NULL) {
+ if (!data) {
return (-4);
}
memset(data, 0, data_len);
data[0] = (is_twenty_byte) ? 0x80 : 0x00;
- data[0] |= (0x0F & user_id);
+ data[0] |= IPMI_UID(user_id);
data[1] = 0x03 & operation;
- if (password != NULL) {
+ if (password) {
size_t copy_len = strlen(password);
if (copy_len > (data_len - 2)) {
copy_len = data_len - 2;
@@ -224,7 +220,7 @@ _ipmi_set_user_password(struct ipmi_intf *intf, uint8_t user_id,
rsp = intf->sendrecv(intf, &req);
free(data);
data = NULL;
- if (rsp == NULL) {
+ if (!rsp) {
return (-1);
}
return rsp->ccode;
@@ -371,18 +367,20 @@ ipmi_user_set_username(
req.msg.data_len = sizeof(msg_data);
memset(msg_data, 0, sizeof(msg_data));
+ user_id = IPMI_UID(user_id);
+
/* The channel number will remain constant throughout this function */
msg_data[0] = user_id;
strncpy((char *)(msg_data + 1), name, strlen(name));
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Set User Name command failed (user %d, name %s)",
user_id, name);
return -1;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Set User Name command failed (user %d, name %s): %s",
user_id, name, val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -436,7 +434,7 @@ print_user_usage(void)
lprintf(LOG_NOTICE,
" set name <user id> <username>");
lprintf(LOG_NOTICE,
-" set password <user id> [<password> <16|20>]");
+" set password <user id> [<password> [<16|20>]]");
lprintf(LOG_NOTICE,
" disable <user id>");
lprintf(LOG_NOTICE,
@@ -553,7 +551,7 @@ ipmi_user_test(struct ipmi_intf *intf, int argc, char **argv)
if (argc == 3) {
/* We need to prompt for a password */
password = ask_password(user_id);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (-1);
}
@@ -615,7 +613,7 @@ ipmi_user_mod(struct ipmi_intf *intf, int argc, char **argv)
if (is_ipmi_user_id(argv[1], &user_id)) {
return (-1);
}
- operation = (strncmp(argv[0], "disable", 7) == 0) ?
+ operation = (!strcmp(argv[0], "disable")) ?
IPMI_PASSWORD_DISABLE_USER : IPMI_PASSWORD_ENABLE_USER;
ccode = _ipmi_set_user_password(intf, user_id, operation,
@@ -628,12 +626,17 @@ ipmi_user_mod(struct ipmi_intf *intf, int argc, char **argv)
return 0;
}
+#define USER_PW_IPMI15_LEN 16 /* IPMI 1.5 only allowed for 16 bytes */
+#define USER_PW_IPMI20_LEN 20 /* IPMI 2.0 allows for 20 bytes */
+#define USER_PW_MAX_LEN USER_PW_IPMI20_LEN
+
int
ipmi_user_password(struct ipmi_intf *intf, int argc, char **argv)
{
char *password = NULL;
int ccode = 0;
- uint8_t password_type = 16;
+ uint8_t password_type = USER_PW_IPMI15_LEN;
+ size_t password_len;
uint8_t user_id = 0;
if (is_ipmi_user_id(argv[2], &user_id)) {
return (-1);
@@ -642,52 +645,63 @@ ipmi_user_password(struct ipmi_intf *intf, int argc, char **argv)
if (argc == 3) {
/* We need to prompt for a password */
char *tmp;
+ size_t tmplen;
password = ask_password(user_id);
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (-1);
}
tmp = ask_password(user_id);
- if (tmp == NULL) {
+ tmplen = strnlen(tmp, USER_PW_MAX_LEN + 1);
+ if (!tmp) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return (-1);
}
- if (strlen(password) != strlen(tmp)
- || strncmp(password, tmp, strlen(tmp))) {
- lprintf(LOG_ERR, "Passwords do not match.");
+ if (strncmp(password, tmp, tmplen)) {
+ lprintf(LOG_ERR, "Passwords do not match or are "
+ "longer than %d", USER_PW_MAX_LEN);
return (-1);
}
} else {
password = argv[3];
- if (argc > 4) {
- if ((str2uchar(argv[4], &password_type) != 0)
- || (password_type != 16 && password_type != 20)) {
- lprintf(LOG_ERR, "Invalid password length '%s'", argv[4]);
- return (-1);
- }
- } else {
- password_type = 16;
- }
}
- if (password == NULL) {
+ if (!password) {
lprintf(LOG_ERR, "Unable to parse password argument.");
return (-1);
- } else if (strlen(password) > 20) {
- lprintf(LOG_ERR, "Password is too long (> 20 bytes)");
+ }
+
+ password_len = strnlen(password, USER_PW_MAX_LEN + 1);
+
+ if (argc > 4) {
+ if ((str2uchar(argv[4], &password_type) != 0)
+ || (password_type != USER_PW_IPMI15_LEN
+ && password_type != USER_PW_IPMI20_LEN))
+ {
+ lprintf(LOG_ERR, "Invalid password length '%s'",
+ argv[4]);
+ return (-1);
+ }
+ } else if (password_len > USER_PW_IPMI15_LEN) {
+ password_type = USER_PW_IPMI20_LEN;
+ }
+
+ if (password_len > password_type) {
+ lprintf(LOG_ERR, "Password is too long (> %d bytes)",
+ password_type);
return (-1);
}
ccode = _ipmi_set_user_password(intf, user_id,
- IPMI_PASSWORD_SET_PASSWORD, password,
- password_type > 16);
+ IPMI_PASSWORD_SET_PASSWORD, password,
+ password_type > USER_PW_IPMI15_LEN);
if (eval_ccode(ccode) != 0) {
lprintf(LOG_ERR, "Set User Password command failed (user %d)",
- user_id);
+ user_id);
return (-1);
} else {
printf("Set User Password command successful (user %d)\n",
- user_id);
+ user_id);
return 0;
}
}
@@ -726,32 +740,34 @@ ipmi_user_main(struct ipmi_intf *intf, int argc, char **argv)
print_user_usage();
return (-1);
}
- if (strncmp(argv[0], "help", 4) == 0) {
+ if (!strcmp(argv[0], "help")) {
/* Help */
print_user_usage();
return 0;
- } else if (strncmp(argv[0], "summary", 7) == 0) {
+ } else if (!strcmp(argv[0], "summary")) {
return ipmi_user_summary(intf, argc, argv);
- } else if (strncmp(argv[0], "list", 4) == 0) {
+ } else if (!strcmp(argv[0], "list")) {
return ipmi_user_list(intf, argc, argv);
- } else if (strncmp(argv[0], "test", 4) == 0) {
+ } else if (!strcmp(argv[0], "test")) {
return ipmi_user_test(intf, argc, argv);
- } else if (strncmp(argv[0], "set", 3) == 0) {
+ } else if (!strcmp(argv[0], "set")) {
/* Set */
- if ((argc >= 3)
- && (strncmp("password", argv[1], 8) == 0)) {
+ if (argc >= 3
+ && !strcmp("password", argv[1]))
+ {
return ipmi_user_password(intf, argc, argv);
- } else if ((argc >= 2)
- && (strncmp("name", argv[1], 4) == 0)) {
+ } else if (argc >= 2
+ && !strcmp("name", argv[1]))
+ {
return ipmi_user_name(intf, argc, argv);
} else {
print_user_usage();
return (-1);
}
- } else if (strncmp(argv[0], "priv", 4) == 0) {
+ } else if (!strcmp(argv[0], "priv")) {
return ipmi_user_priv(intf, argc, argv);
- } else if ((strncmp(argv[0], "disable", 7) == 0)
- || (strncmp(argv[0], "enable", 6) == 0)) {
+ } else if (!strcmp(argv[0], "disable")
+ || !strcmp(argv[0], "enable")) {
return ipmi_user_mod(intf, argc, argv);
} else {
lprintf(LOG_ERR, "Invalid user command: '%s'\n", argv[0]);
diff --git a/lib/ipmi_vita.c b/lib/ipmi_vita.c
index 3900974..2771809 100644
--- a/lib/ipmi_vita.c
+++ b/lib/ipmi_vita.c
@@ -190,7 +190,7 @@ vita_discover(struct ipmi_intf *intf)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received");
} else if (rsp->ccode == 0xC1) {
lprintf(LOG_INFO, "Invalid completion code received: %s",
@@ -198,7 +198,7 @@ vita_discover(struct ipmi_intf *intf)
} else if (rsp->ccode == 0xCC) {
lprintf(LOG_INFO, "Invalid data field received: %s",
val2str(rsp->ccode, completion_code_vals));
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_INFO, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
} else if (rsp->data_len < 5) {
@@ -240,9 +240,9 @@ ipmi_vita_ipmb_address(struct ipmi_intf *intf)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received");
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
} else if (rsp->data_len < 7) {
@@ -284,10 +284,10 @@ ipmi_vita_getaddr(struct ipmi_intf *intf, int argc, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -332,10 +332,10 @@ ipmi_vita_get_vso_capabilities(struct ipmi_intf *intf)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -402,10 +402,10 @@ ipmi_vita_set_fru_activation(struct ipmi_intf *intf,
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -444,10 +444,10 @@ ipmi_vita_get_fru_state_policy_bits(struct ipmi_intf *intf, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -499,10 +499,10 @@ ipmi_vita_set_fru_state_policy_bits(struct ipmi_intf *intf, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -540,10 +540,10 @@ ipmi_vita_get_led_properties(struct ipmi_intf *intf, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -585,10 +585,10 @@ ipmi_vita_get_led_color_capabilities(struct ipmi_intf *intf, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -603,14 +603,14 @@ ipmi_vita_get_led_color_capabilities(struct ipmi_intf *intf, char **argv)
printf("LED Color Capabilities: ");
for (i = 0; i < 8; i++) {
if (rsp->data[1] & (0x01 << i)) {
- printf("%s, ", led_color_str[i]);
+ printf("%s, ", picmg_led_color_str(i));
}
}
putchar('\n');
printf("Default LED Color in\n");
- printf(" LOCAL control: %s\n", led_color_str[rsp->data[2]]);
- printf(" OVERRIDE state: %s\n", led_color_str[rsp->data[3]]);
+ printf(" LOCAL control: %s\n", picmg_led_color_str(rsp->data[2]));
+ printf(" OVERRIDE state: %s\n", picmg_led_color_str(rsp->data[3]));
if (rsp->data_len == 5) {
printf("LED flags:\n");
@@ -649,10 +649,10 @@ ipmi_vita_get_led_state(struct ipmi_intf *intf, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -692,7 +692,7 @@ ipmi_vita_get_led_state(struct ipmi_intf *intf, char **argv)
}
printf(" Local Control On-Duration: %x\n", rsp->data[3]);
printf(" Local Control Color: %x\t[%s]\n",
- rsp->data[4], led_color_str[rsp->data[4] & 7]);
+ rsp->data[4], picmg_led_color_str(rsp->data[4] & 7));
}
/* override state or lamp test */
@@ -707,7 +707,7 @@ ipmi_vita_get_led_state(struct ipmi_intf *intf, char **argv)
}
printf(" Override On-Duration: %x\n", rsp->data[6]);
printf(" Override Color: %x\t[%s]\n",
- rsp->data[7], led_color_str[rsp->data[7] & 7]);
+ rsp->data[7], picmg_led_color_str(rsp->data[7] & 7));
if (rsp->data[1] == 0x04) {
printf(" Lamp test duration: %x\n", rsp->data[8]);
}
@@ -749,10 +749,10 @@ ipmi_vita_set_led_state(struct ipmi_intf *intf, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -796,10 +796,10 @@ ipmi_vita_fru_control(struct ipmi_intf *intf, char **argv)
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "No valid response received.");
return -1;
- } else if (rsp->ccode != 0) {
+ } else if (rsp->ccode) {
lprintf(LOG_ERR, "Invalid completion code received: %s",
val2str(rsp->ccode, completion_code_vals));
return -1;
@@ -819,48 +819,48 @@ ipmi_vita_fru_control(struct ipmi_intf *intf, char **argv)
static int
ipmi_vita_get_cmd(int argc, char **argv)
{
- if (argc < 1 || !strncmp(argv[0], "help", 4)) {
+ if (argc < 1 || !strcmp(argv[0], "help")) {
return VITA_CMD_HELP;
}
/* Get VSO Properties */
- if (!strncmp(argv[0], "properties", 10)) {
+ if (!strcmp(argv[0], "properties")) {
return VITA_CMD_PROPERTIES;
}
/* FRU Control command */
- if (!strncmp(argv[0], "frucontrol", 10)) {
+ if (!strcmp(argv[0], "frucontrol")) {
return VITA_CMD_FRUCONTROL;
}
/* Get FRU Address Info command */
- if (!strncmp(argv[0], "addrinfo", 8)) {
+ if (!strcmp(argv[0], "addrinfo")) {
return VITA_CMD_ADDRINFO;
}
/* Set FRU Activation (activate) command */
- if (!strncmp(argv[0], "activate", 8)) {
+ if (!strcmp(argv[0], "activate")) {
return VITA_CMD_ACTIVATE;
}
/* Set FRU Activation (deactivate) command */
- if (!strncmp(argv[0], "deactivate", 10)) {
+ if (!strcmp(argv[0], "deactivate")) {
return VITA_CMD_DEACTIVATE;
}
/* FRU State Policy Bits commands */
- if (!strncmp(argv[0], "policy", 6)) {
+ if (!strcmp(argv[0], "policy")) {
if (argc < 2) {
return VITA_CMD_UNKNOWN;
}
/* Get FRU State Policy Bits command */
- if (!strncmp(argv[1], "get", 3)) {
+ if (!strcmp(argv[1], "get")) {
return VITA_CMD_POLICY_GET;
}
/* Set FRU State Policy Bits command */
- if (!strncmp(argv[1], "set", 3)) {
+ if (!strcmp(argv[1], "set")) {
return VITA_CMD_POLICY_SET;
}
@@ -869,28 +869,28 @@ ipmi_vita_get_cmd(int argc, char **argv)
}
/* FRU LED commands */
- if (!strncmp(argv[0], "led", 3)) {
+ if (!strcmp(argv[0], "led")) {
if (argc < 2) {
return VITA_CMD_UNKNOWN;
}
/* FRU LED Get Properties */
- if (!strncmp(argv[1], "prop", 4)) {
+ if (!strcmp(argv[1], "prop")) {
return VITA_CMD_LED_PROP;
}
/* FRU LED Get Capabilities */
- if (!strncmp(argv[1], "cap", 3)) {
+ if (!strcmp(argv[1], "cap")) {
return VITA_CMD_LED_CAP;
}
/* FRU LED Get State */
- if (!strncmp(argv[1], "get", 3)) {
+ if (!strcmp(argv[1], "get")) {
return VITA_CMD_LED_GET;
}
/* FRU LED Set State */
- if (!strncmp(argv[1], "set", 3)) {
+ if (!strcmp(argv[1], "set")) {
return VITA_CMD_LED_SET;
}
diff --git a/lib/log.c b/lib/log.c
index 2738e18..ecc47a8 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -29,9 +29,6 @@
* 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 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 || \
- _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || \
- /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
#include <unistd.h>
#include <stdio.h>
@@ -111,12 +108,12 @@ void log_init(const char * name, int isdaemon, int verbose)
if (!logpriv)
return;
- if (name != NULL)
+ if (name)
logpriv->name = strdup(name);
else
logpriv->name = strdup(LOG_NAME_DEFAULT);
- if (logpriv->name == NULL)
+ if (!logpriv->name)
fprintf(stderr, "ipmitool: malloc failure\n");
logpriv->daemon = isdaemon;
@@ -147,13 +144,8 @@ void log_halt(void)
logpriv = NULL;
}
-int log_level_get(void)
+void log_level_set(int verbose)
{
- return logpriv->level;
-}
-
-void log_level_set(int level)
-{
- logpriv->level = level;
+ logpriv->level = verbose + LOG_NOTICE;
}