| | 5004 | } |
| | 5005 | |
| | 5006 | ######## |
| | 5007 | # IPMI # |
| | 5008 | ######## |
| | 5009 | |
| | 5010 | # Returns: number of IPMI interfaces found |
| | 5011 | sub ipmi_from_smbios |
| | 5012 | { |
| | 5013 | my ($version, $if, @ipmi_if); |
| | 5014 | |
| | 5015 | if (open(local *DMIDECODE, "dmidecode --version 2>/dev/null |")) { |
| | 5016 | $version = <DMIDECODE>; |
| | 5017 | close(DMIDECODE); |
| | 5018 | chomp $version if defined $version; |
| | 5019 | } |
| | 5020 | |
| | 5021 | if (!defined $version |
| | 5022 | || !($version =~ m/^(\d+).(\d+)$/) |
| | 5023 | || !(($1 == 2 && $2 >= 7) || $1 > 2)) { |
| | 5024 | print "# DMI data unavailable, please consider installing dmidecode 2.7\n". |
| | 5025 | "# or later for better results.\n"; |
| | 5026 | return; |
| | 5027 | } |
| | 5028 | |
| | 5029 | # Parse the output of dmidecode into an array of IPMI interfaces. |
| | 5030 | # Each entry is a hash with the following keys: type and addr. |
| | 5031 | $if = -1; |
| | 5032 | open(local *DMIDECODE, "dmidecode -t 38 2>/dev/null |") or return 0; |
| | 5033 | while (<DMIDECODE>) { |
| | 5034 | if (m/^IPMI Device Information/) { |
| | 5035 | $if++; |
| | 5036 | next; |
| | 5037 | } |
| | 5038 | next unless $if >= 0; |
| | 5039 | |
| | 5040 | if (m/^\tInterface Type: (.*)$/) { |
| | 5041 | $ipmi_if[$if]->{type} = "IPMI BMC $1"; |
| | 5042 | $ipmi_if[$if]->{type} =~ s/ \(.*//; |
| | 5043 | next; |
| | 5044 | } |
| | 5045 | if (m/^\tBase Address: (0x[0-9A-Fa-f]+) \(I\/O\)$/) { |
| | 5046 | $ipmi_if[$if]->{addr} = oct($1); |
| | 5047 | next; |
| | 5048 | } |
| | 5049 | } |
| | 5050 | close(DMIDECODE); |
| | 5051 | |
| | 5052 | foreach $if (@ipmi_if) { |
| | 5053 | if (exists $if->{addr}) { |
| | 5054 | printf("\%-60s", sprintf("Found `\%s' at 0x\%x... ", |
| | 5055 | $if->{type}, $if->{addr})); |
| | 5056 | } else { |
| | 5057 | printf("\%-60s", sprintf("Found `\%s'... ", |
| | 5058 | $if->{type})); |
| | 5059 | } |
| | 5060 | print "Success!\n". |
| | 5061 | " (confidence 8, driver `ipmisensors')\n"; |
| | 5062 | my $new_hash = { |
| | 5063 | conf => 8, |
| | 5064 | isa_addr => $if->{addr} || 0, |
| | 5065 | chipname => $if->{type}, |
| | 5066 | }; |
| | 5067 | add_isa_to_chips_detected("ipmisensors", $new_hash); |
| | 5068 | } |
| | 5069 | |
| | 5070 | return scalar @ipmi_if; |