313 Commits

Author SHA1 Message Date
Patrick Venture
3737b035e8 fru: fix ipmi_fru_picmg_ext_edit as bool
Fix ipmi_fru_picmg_ext_edit to use bools instead
of an int treated as a boolean.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
6b003c3852 fru: use bool with ipmi_fru_oemkontron_edit
Convert ipmi_fru_oemkontron_edit to return a bool
type instead of an int used as a bool.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
8991f5a9a0 fru: change ipmi_fru_query_new_value to return bool
Change ipmi_fru_query_new_value to return the bool type
instead of an int that's being used as a boolean value.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
49384e47be fru: mark ipmi_fru_query_new_value as static
Mark ipmi_fru_query_new_value as static as it's only
used internally in this object.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
6dcb168442 fru: add fru_cc_rq2big helper method for code checks
Add fru_cc_rq2big helper method to reduce duplicate
code checking for specific size-based IPMI response
codes.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
1c4a00d26b fru: cleanup ipmi_fru_upg_ekeying
Cleanup ipmi_fru_upg_ekeying such that it exits from
one place that handles cleanup.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
aef8a1ccb4 fru: use ipmi_cc defined maros for return codes
Use the macros defined in ipmi_cc for IPMI return
codes instead of magic numbers.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
81761e6f60 fru: drop extraneous parentheses on negative returns
Drop extraneous parentheses when returning a
negative value.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
715c7b8a1f fru: delete unused variable matchInstance
Delete unused variable matchInstance.  The variable is repeatedly
assigned, but nothing reads it.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
92ee477cde fru: cleanup ipmi_fru_oemkontron_get
Cleanup style in method ipmi_fru_oemkontron_get as well as add inverted
logic checks to reduce indentation.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Patrick Venture
6d515dd06b fru: fixup array bounds checking
Fixup the following array bounds checking bugs:
[lib/ipmi_fru.c:1003]: (style) Array index 'i' is
used before limits check.
[lib/ipmi_fru.c:1127]: (style) Array index 'i' is
used before limits check.
[lib/ipmi_fru.c:1262]: (style) Array index 'i' is
used before limits check.

Signed-off-by: Patrick Venture <venture@google.com>
2019-02-13 21:28:14 +03:00
Josef Moellers
7941806a9b hpm: Adhere to centralized exiting
Replace `return`s with `goto`s to appropriate labels
(with or without closing the file).
2019-01-24 15:22:21 +03:00
Josef Moellers
4631d3f942 hpm: Minor refactoring
Remove an `if()` with a condition that is always true.
Merge two calls to time() into one.
2019-01-24 15:22:21 +03:00
Josef Moellers
272d9d0d9b hpm: Fix resource leak
fclose(pImageFile) was missing before returning from
HpmfwupgGetBufferFromFile()
2019-01-24 15:22:21 +03:00
Alexander Amelkin
0ca9c66b84
sol: Make interface timeout obey the -N option
For `sol activate` the timeout on lanplus interface was hard-coded
to 1 second, overriding the value set with the `-N` option.

Resolves ipmitool/ipmitool#87

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-12-28 16:33:18 +03:00
Alexander Amelkin
5183b2c288 Move led color static array to source file
Move led color static array from header to ipmi_picmg module
and introduce `picmg_led_color_str()` function for use in
ipmi_vita module.

Partially resolves ipmitool/ipmitool#13

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-23 16:41:06 +03:00
Patrick Venture
3e0ecc5edc move static objects to source file
Move static objects declared in headers to the source files where
they're used.

Partially resolves ipmitool/ipmitool#13

Signed-off-by: Patrick Venture <venture@google.com>
2018-11-23 16:41:06 +03:00
Patrick Venture
8ea6094118 cleanup all unused-parameter warnings
Cleanup all unused-parameter warnings.  Each warning was examined to
verify it wasn't simply a case of a build macro difference.

Partially resolves ipmitool/ipmitool#13

Signed-off-by: Patrick Venture <venture@google.com>
2018-11-23 16:41:06 +03:00
Patrick Venture
d6d9c85139 use __UNUSED__ macro instead of gcc specific attribute
Use __UNUSED__ macro defined in helper.h instead of the gcc-specific
attribute unused macro.

Partially resolves ipmitool/ipmitool#13

Signed-off-by: Patrick Venture <venture@google.com>
2018-11-23 16:41:06 +03:00
Alexander Amelkin
a4c1040420
fru: Fix processing of unspecified board mfg. date
FRU board mfg. date uses a different value for 'unspecified'
timestamp than the general IPMI specification.

This commit makes ekanalyzer and fru commands process unspecified
FRU dates properly, displaying 'Unspecified' instead of
'Mon Jan  1 03:00:00 1996'.

Resolves ipmitool/ipmitool#57

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-16 22:25:27 +03:00
Vernon Mauery
576d4855d9 [compiler-warnings-fixes] use correct fall through comment
In some of the SDR calculating code, there were switch statements that
had cases that would fall through deliberately into the next case. But
the compiler didn't like the comment and would complain about the fall
through anyway. This changes to a comment that the compiler recognizes.

Partially resolves ipmitool/ipmitool#13

Signed-off-by: Vernon Mauery <vernon.mauery@intel.com>
2018-11-11 14:55:43 +03:00
Vernon Mauery
f2780c5d86 [compiler-warnings-fixes] ipmi_start_daemon: check return values
Some return values were being ignored in ipmi_start_daemon. This adds
checks to the values and changes some hard-coded numbers into named
values.

Partially resolves ipmitool/ipmitool#13

Signed-off-by: Vernon Mauery <vernon.mauery@intel.com>
2018-11-11 14:55:43 +03:00
Vernon Mauery
dc9b4ebfc9 [compiler-warnings-fixes] ipmi_sdr.c: remove unused function parameters
Several functions were passed a struct ipmi_intf* even though it was
unused. This removes the unused parameters and changes calls and
signatures.

Partially resolves ipmitool/ipmitool#13

Signed-off-by: Vernon Mauery <vernon.mauery@intel.com>
2018-11-11 14:55:43 +03:00
Alexander Amelkin
6e2b688e24
lan: Fix processing disabled VLAN
Before this fix `ipmitool` would complain that VLAN ID
is out of range when trying to disable an already disabled VLAN
on a lan channel. With this fix it will properly report that
VLAN is already disabled.

Resolves ipmitool/ipmitool#55

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-11 11:57:12 +03:00
Alexander Amelkin
6c3d4b56c9
Make ipmitool respect system locale settings
Dates, times and floating point numbers from now on
will be displayed using system locale settings.

Resolves ipmitoo/ipmitool#23

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-08 21:26:32 +03:00
Alexander Amelkin
4f05b95f6c
Fix strftime() non-literal argument warning
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

This commit adds 'ugly hacks' from that discussion to call strftime()
from strftime-formatted wrappers and silence the warnings.

Partially resolves ipmitool/ipmitool#23

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-07 18:50:10 +03:00
Alexander Amelkin
f0d5c17ea7
Refactor timestamp handling
Handle all date/time stamps uniformly, taking in account the host
endianness. Respect the local time zone and the '-Z' option for
all ipmitool commands. Unify the date and time formatting.
Add correct handling of IPMI timestamps 'since system startup'
and for 'unspecified' timestamps.

Partially resolves ipmitool/ipmitool#23

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-07 18:11:58 +03:00
Alexander Amelkin
65a2c548d8 lanplus: Refactoring
Some minor formatting corrections.
Also introduced a new helper function to reduce nesting level.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-01 19:29:45 +03:00
Alexander Amelkin
1283382e82 lanplus: Fix -C option processing
Cipher suite ID is a byte as per IPMI spec.
Use the appropriate function and consider target endianness
(so write to a temporary variable).

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-11-01 19:29:45 +03:00
Vernon Mauery
7772254b62 lanplus: Auto-select 'best' cipher suite available
Based on current crypto alogrithms, one could rank cipher suites along
these lines:

17 > 3 >> all the rest

17 and 3 are the only cipher suites that implement any sort of
confidentiality alogorithm that is secure. In addition, any hmac-md5 or
md5 integrity algorithm used in integrity is weak at best and dangerous
for authentication.

This could possibly be enabled in a simpler mechanism by simply checking
for 17 and then choosing it before falling back to 3, but the way this
is implemented, it makes it easy to change the list of acceptable
algorithms from two to three or more items.

Resolves ipmitool/ipmitool#29

Signed-off-by: Vernon Mauery <vernon.mauery@intel.com>
2018-11-01 19:29:45 +03:00
eyjhbb@gmail.com
6f336d04f1 sensor: Refactor ipmi_sensor_print_fc_threshold()
Break the function into smaller pieces to reduce
complexity.
2018-09-25 14:32:46 +03:00
eyjhbb@gmail.com
9d49a6edfe sensor: Add support for csv output 2018-09-25 14:32:46 +03:00
Alexander Amelkin
4c155320be
general: Get rid of some unused parameter warnings
Silence the unused parameter warnings in helper.c
introduced earlier.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-21 18:10:28 +03:00
Alexander Amelkin
40d52b5fa1
mc: guid: Implement encoding autodetection
With this commit the GUID encoding is now by default detected
automatically based on the validity of the version field,
and the timestamp (for time-based version 1 GUIDs).

The version is considered valid if it is 1 through 5.
The timestamp is considered valid if the year is past UNIX Epoch
and before the current year.

Resolves ipmitool/ipmitool#25

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-21 18:10:28 +03:00
Alexander Amelkin
0b6abe8cd9
mc: guid: Fix timestamp decoding
Before this commit the 'Timestamp' line was always printed
for all versions of GUID, even for non-time-based ones.

Plus, only the time_low field was used, and it was used as if
it contained seconds since UNIX Epoch, which it didn't. In fact
this field along with other time_* fields constitute a single
60-bit value representing the count of 100ns intervals since
adoption of Gregorial calendar (00:00:00.00 15 Oct 1582).

For non-time-based versions of GUID, the time_* fields do
not represent any time at all.

So, after this commit, the timestamp will be properly decoded
for time-based GUID version 1 only. For other versions the
'Timestamp' line will not be displayed. A line showing the
GUID version will be added to the output.

Partially resolves ipmitool/ipmitool#25

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-21 17:30:26 +03:00
Alexander Amelkin
f43a78bfc3
mc: guid: Add support for non-standard encodings
There are lots of BMC implementations that violate the IPMI
specification in regard to GUID encoding and instead encode
GUIDs according to either RFC4122 or SMBIOS specifications.

This commit restores the default behavior of `mc guid` to
SMBIOS-based decoding and adds options to allow for decoding
according to IPMI or RFC4122 specifications.

It also allows to simply dump the received GUID as is
without any parsing.

It is possible that in future versions `ipmitool` will
change default behavior to 'ipmi' instead of 'smbios'.

Partially resolves ipmitool/ipmitool#25

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-21 17:30:25 +03:00
Alexander Amelkin
b44ec2fb65
mc: guid: Fix byte ordering to follow IPMI spec
Before this commit the bytes for the GUID 'node' part were displayed in
reverse order as if they were reported by BMC according to SMBIOS
specification, not accordint to IPMI.

The field order in guid_t was also specified according to RFC4122/SMBIOS,
which is the reverse of IPMI specification. It has now been fixed.

The time_low field of GUID was taken directly, without taking in
account the ipmitool host endianness. It is now properly converted
from IPMI little-endian to host byte order. Other GUID fields are
also properly converted now. As of now, ipmitool does not generally work
properly when built for a big-endian target, but that's out of scope
of this commit.

Please note that this commit most probably breaks the output of
`ipmitool mc guid` with most existing BMC implementations, but that's
just an indication of them being broken. A follow-up commit will
re-add support for the broken behavior.

Partially resolves ipmitool/ipmitool#25

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-21 17:30:25 +03:00
Alexander Amelkin
e9716e216d
Refactoring: optimize pointer checks
Remove all direct comparisons to 'NULL' for pointers.
Replace them with boolean-like 'if (ptr)' and 'if (!ptr)'.
This makes conditions shorter and easier to read.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-21 17:30:25 +03:00
Alexander Amelkin
9ecfb762bd
Refactoring: get rid of superfluous comparisons
Make code better readable by replacing `if (rsp->ccode > 0)`
and 'if (rsp->ccode != 0)' with just `if (rsp->ccode)` as
rsp->ccode is anyway an unsigned byte and can't be negative.
Also replace 'if (rsp->ccode == 0)' with 'if (!rsp->ccode)'.

All these changes make lines shorter and easier to read as
a non-zero ccode is an indication of some failure, and so !ccode
naturally reads as 'no error'.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-21 11:55:03 +03:00
Alexander Amelkin
bb1a4cc805
Refactoring. Improve code reuse ratio.
Add ARRAY_SIZE() macro.

Use the new macro in all places where array size is calculated by
means of sizeof(array)/sizeof(array[0]).

Fix minor bugs and warnings in the affected code.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-14 16:44:52 +03:00
Thorsten Horstmann
232773d171 general: Fix several misspellings
Fix misspellings found by codespell in code comments,
console output and documentation.

Resolves ipmitool/ipmitool#28
2018-08-06 15:59:06 +03:00
Alexander Amelkin
a8f3413dc2
mc: Fix compiler warnings
Fix a number of warnings in ipmi_mc.c, including a potentially
uninitialized variable for `mc watchdog set` command.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-02 00:48:32 +03:00
Alexander Amelkin
29e7d26edb
general: Add array_byteswap() to helper
Make unconditional array byte swapping publicly available

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-01 15:57:37 +03:00
Alexander Amelkin
7747d86cc4
lanplus: Make byteswapping generic
Get rid of lanplus-specific yet very generic in nature
lanplus_swap() function that unconditionally swaps bytes
in an arbitrary byte array. Move it to helper module and
add two conditionally working interfaces to it:

 - array_ntoh() for network (BE) to host conversion, and
 - array_letoh() for ipmi (LE) to host conversion.

The added functions will only perform byte swapping if
the target architecture differs in endianness from the
data source. array_ntoh() will only do swap on LE machines,
while array_letoh() will only do it on BE ones.

These functions are introduced for future use in other
places of ipmitool.

Partially resolves ipmitool/ipmitool#26

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-08-01 11:33:44 +03:00
qctbmc
5c033c06ab oem: Add basic support for Quanta 2018-07-28 19:15:10 +03:00
Alexander Amelkin
329ebdff84
mc: Fix manufacturer ID masking
A potential future problem has been identified in the manufacturer
ID processing code for `mc info` command. Only 16 of 24 bits were
used. This is fixed now.

Also added support for ID 0x0FFFFF, the 'reserved' value as per
IPMI specification. It is now reported as 'Unspecified' unlike other
non-listed IDs that are still reported as 'Unknown'.

ID 0xFFFFFE is used for debugging purposes in hope that IANA won't
reach that number of entities any soon. If it will though, then
IANA's assignment will take precedence.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-07-26 19:54:57 +03:00
Alexander Amelkin
6ee52071dd
Refactoring. Remove useless feature test macros.
There are lots of feature test macros like _POSIX_SOURCE,
_BSD_SOURCE, etc. chaotically placed at the beginning of
multiple files without apparent reason, sometime purely
erroneously.

This commit removes them all for the sake of cleaner code.

No new warnings are added due to that at least for gcc 5.4
on Linux with glibc 2.23.
2018-07-25 15:58:00 +03:00
Alexander Amelkin
b3d258b234
sel: Minor refactoring
Minor code duplication reduction

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
2018-07-20 19:12:33 +03:00
Alexander Amelkin
928716244d
sdr: Refactor/optimize code. No functional changes. 2018-07-20 14:23:33 +03:00
Alexander Amelkin
2de8a5e1a9
mc: Refix 861ffb4 2018-07-20 14:23:33 +03:00