Added (partial) SMBIOS support for Linux by reading from sysfs.

This commit is contained in:
Michael Möller
2010-06-07 20:03:48 +00:00
parent bee7a9b80b
commit 57dbd750e0
4 changed files with 335 additions and 263 deletions

View File

@@ -140,10 +140,9 @@ namespace OpenHardwareMonitor.GUI {
UnitManager.TemperatureUnit == TemperatureUnit.Celcius;
fahrenheitToolStripMenuItem.Checked = !celciusToolStripMenuItem.Checked;
// Hide the system tray and auto startup menu items on Unix
// Hide the auto startup menu item on Unix
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
minTrayMenuItem.Visible = false;
startupMenuItem.Visible = false;
}

View File

@@ -107,6 +107,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
r.AppendLine();
r.Append(smbios.GetReport());
if (lpcio != null)
r.Append(lpcio.GetReport());
return r.ToString();

View File

@@ -37,6 +37,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Management;
using System.Text;
@@ -44,22 +45,49 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
public class SMBIOS {
private byte[] raw;
private Structure[] table;
private BIOSInformation biosInformation = null;
private BaseBoardInformation baseBoardInformation = null;
private string ReadSysFS(string path) {
try {
if (File.Exists(path)) {
using (StreamReader reader = new StreamReader(path))
return reader.ReadLine();
} else {
return null;
}
} catch {
return null;
}
}
public SMBIOS() {
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
return;
if ((p == 4) || (p == 128)) {
this.raw = null;
this.table = null;
string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
this.baseBoardInformation = new BaseBoardInformation(
boardVendor, boardName, boardVersion, null);
string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
this.biosInformation = new BIOSInformation(biosVendor, biosVersion);
} else {
List<Structure> structureList = new List<Structure>();
byte[] raw = null;
raw = null;
try {
ManagementObjectCollection collection = new ManagementObjectSearcher(
"root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
ManagementObjectCollection collection =
new ManagementObjectSearcher("root\\WMI",
"SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
foreach (ManagementObject mo in collection) {
raw = (byte[])mo["SMBiosData"];
@@ -111,6 +139,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
table = structureList.ToArray();
}
}
public string GetReport() {
StringBuilder r = new StringBuilder();
@@ -129,6 +158,24 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
r.AppendLine();
}
if (raw != null) {
string base64 = Convert.ToBase64String(raw);
r.AppendLine("SMBIOS Table");
r.AppendLine();
for (int i = 0; i < Math.Ceiling(base64.Length / 64.0); i++) {
r.Append(" ");
for (int j = 0; j < 0x40; j++) {
int index = (i << 6) | j;
if (index < base64.Length) {
r.Append(base64[index]);
}
}
r.AppendLine();
}
r.AppendLine();
}
return r.ToString();
}
@@ -173,10 +220,17 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
private string vendor;
private string version;
public BIOSInformation(string vendor, string version)
: base (0x00, 0, null, null)
{
this.vendor = vendor;
this.version = version;
}
public BIOSInformation(byte type, ushort handle, byte[] data,
string[] strings)
: base(type, handle, data, strings) {
: base(type, handle, data, strings)
{
this.vendor = GetString(0x04);
this.version = GetString(0x05);
}
@@ -195,14 +249,8 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
private Manufacturer manufacturer;
private Model model;
public BaseBoardInformation(byte type, ushort handle, byte[] data,
string[] strings)
: base(type, handle, data, strings) {
this.manufacturerName = GetString(0x04).Trim();
this.productName = GetString(0x05).Trim();
this.version = GetString(0x06).Trim();
this.serialNumber = GetString(0x07).Trim();
private void SetManufacturerName(string manufacturerName) {
this.manufacturerName = manufacturerName;
switch (manufacturerName) {
case "ASUSTeK Computer INC.":
@@ -224,6 +272,10 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
default:
manufacturer = Manufacturer.Unknown; break;
}
}
private void SetProductName(string productName) {
this.productName = productName;
switch (productName) {
case "Crosshair III Formula":
@@ -259,6 +311,26 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
}
}
public BaseBoardInformation(string manufacturerName, string productName,
string version, string serialNumber)
: base(0x02, 0, null, null)
{
SetManufacturerName(manufacturerName);
SetProductName(productName);
this.version = version;
this.serialNumber = serialNumber;
}
public BaseBoardInformation(byte type, ushort handle, byte[] data,
string[] strings)
: base(type, handle, data, strings) {
SetManufacturerName(GetString(0x04).Trim());
SetProductName(GetString(0x05).Trim());
this.version = GetString(0x06).Trim();
this.serialNumber = GetString(0x07).Trim();
}
public string ManufacturerName { get { return manufacturerName; } }
public string ProductName { get { return productName; } }