Added support for IT8705F super I/O chips.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
12 using System.Collections.Generic;
14 using System.Management;
17 namespace OpenHardwareMonitor.Hardware.Mainboard {
19 internal class SMBIOS {
21 private readonly byte[] raw;
22 private readonly Structure[] table;
24 private readonly Version version;
25 private readonly BIOSInformation biosInformation;
26 private readonly SystemInformation systemInformation;
27 private readonly BaseBoardInformation baseBoardInformation;
29 private static string ReadSysFS(string path) {
31 if (File.Exists(path)) {
32 using (StreamReader reader = new StreamReader(path))
33 return reader.ReadLine();
43 int p = (int)Environment.OSVersion.Platform;
44 if ((p == 4) || (p == 128)) {
48 string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
49 string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
50 string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
51 this.baseBoardInformation = new BaseBoardInformation(
52 boardVendor, boardName, boardVersion, null);
54 string systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor");
55 string productName = ReadSysFS("/sys/class/dmi/id/product_name");
56 string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
57 this.systemInformation = new SystemInformation(systemVendor,
58 productName, productVersion, null, null);
60 string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
61 string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
62 this.biosInformation = new BIOSInformation(biosVendor, biosVersion);
65 List<Structure> structureList = new List<Structure>();
68 byte majorVersion = 0;
69 byte minorVersion = 0;
71 ManagementObjectCollection collection;
72 using (ManagementObjectSearcher searcher =
73 new ManagementObjectSearcher("root\\WMI",
74 "SELECT * FROM MSSMBios_RawSMBiosTables")) {
75 collection = searcher.Get();
78 foreach (ManagementObject mo in collection) {
79 raw = (byte[])mo["SMBiosData"];
80 majorVersion = (byte)mo["SmbiosMajorVersion"];
81 minorVersion = (byte)mo["SmbiosMinorVersion"];
86 if (majorVersion > 0 || minorVersion > 0)
87 version = new Version(majorVersion, minorVersion);
89 if (raw != null && raw.Length > 0) {
91 byte type = raw[offset];
92 while (offset + 4 < raw.Length && type != 127) {
95 int length = raw[offset + 1];
96 ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);
98 if (offset + length > raw.Length)
100 byte[] data = new byte[length];
101 Array.Copy(raw, offset, data, 0, length);
104 List<string> stringsList = new List<string>();
105 if (offset < raw.Length && raw[offset] == 0)
108 while (offset < raw.Length && raw[offset] != 0) {
109 StringBuilder sb = new StringBuilder();
110 while (offset < raw.Length && raw[offset] != 0) {
111 sb.Append((char)raw[offset]); offset++;
114 stringsList.Add(sb.ToString());
119 this.biosInformation = new BIOSInformation(
120 type, handle, data, stringsList.ToArray());
121 structureList.Add(this.biosInformation); break;
123 this.systemInformation = new SystemInformation(
124 type, handle, data, stringsList.ToArray());
125 structureList.Add(this.systemInformation); break;
126 case 0x02: this.baseBoardInformation = new BaseBoardInformation(
127 type, handle, data, stringsList.ToArray());
128 structureList.Add(this.baseBoardInformation); break;
129 default: structureList.Add(new Structure(
130 type, handle, data, stringsList.ToArray())); break;
135 table = structureList.ToArray();
139 public string GetReport() {
140 StringBuilder r = new StringBuilder();
142 if (version != null) {
143 r.Append("SMBIOS Version: "); r.AppendLine(version.ToString(2));
148 r.Append("BIOS Vendor: "); r.AppendLine(BIOS.Vendor);
149 r.Append("BIOS Version: "); r.AppendLine(BIOS.Version);
153 if (System != null) {
154 r.Append("System Manufacturer: ");
155 r.AppendLine(System.ManufacturerName);
156 r.Append("System Name: ");
157 r.AppendLine(System.ProductName);
158 r.Append("System Version: ");
159 r.AppendLine(System.Version);
164 r.Append("Mainboard Manufacturer: ");
165 r.AppendLine(Board.ManufacturerName);
166 r.Append("Mainboard Name: ");
167 r.AppendLine(Board.ProductName);
168 r.Append("Mainboard Version: ");
169 r.AppendLine(Board.Version);
174 string base64 = Convert.ToBase64String(raw);
175 r.AppendLine("SMBIOS Table");
178 for (int i = 0; i < Math.Ceiling(base64.Length / 64.0); i++) {
180 for (int j = 0; j < 0x40; j++) {
181 int index = (i << 6) | j;
182 if (index < base64.Length) {
183 r.Append(base64[index]);
194 public BIOSInformation BIOS {
195 get { return biosInformation; }
198 public SystemInformation System {
199 get { return systemInformation; }
202 public BaseBoardInformation Board {
203 get { return baseBoardInformation; }
206 public class Structure {
207 private readonly byte type;
208 private readonly ushort handle;
210 private readonly byte[] data;
211 private readonly string[] strings;
213 protected string GetString(int offset) {
214 if (offset < data.Length && data[offset] > 0 &&
215 data[offset] <= strings.Length)
216 return strings[data[offset] - 1];
221 public Structure(byte type, ushort handle, byte[] data, string[] strings)
224 this.handle = handle;
226 this.strings = strings;
229 public byte Type { get { return type; } }
231 public ushort Handle { get { return handle; } }
234 public class BIOSInformation : Structure {
236 private readonly string vendor;
237 private readonly string version;
239 public BIOSInformation(string vendor, string version)
240 : base (0x00, 0, null, null)
242 this.vendor = vendor;
243 this.version = version;
246 public BIOSInformation(byte type, ushort handle, byte[] data,
248 : base(type, handle, data, strings)
250 this.vendor = GetString(0x04);
251 this.version = GetString(0x05);
254 public string Vendor { get { return vendor; } }
256 public string Version { get { return version; } }
259 public class SystemInformation : Structure {
261 private readonly string manufacturerName;
262 private readonly string productName;
263 private readonly string version;
264 private readonly string serialNumber;
265 private readonly string family;
267 public SystemInformation(string manufacturerName, string productName,
268 string version, string serialNumber, string family)
269 : base (0x01, 0, null, null)
271 this.manufacturerName = manufacturerName;
272 this.productName = productName;
273 this.version = version;
274 this.serialNumber = serialNumber;
275 this.family = family;
278 public SystemInformation(byte type, ushort handle, byte[] data,
280 : base(type, handle, data, strings)
282 this.manufacturerName = GetString(0x04);
283 this.productName = GetString(0x05);
284 this.version = GetString(0x06);
285 this.serialNumber = GetString(0x07);
286 this.family = GetString(0x1A);
289 public string ManufacturerName { get { return manufacturerName; } }
291 public string ProductName { get { return productName; } }
293 public string Version { get { return version; } }
295 public string SerialNumber { get { return serialNumber; } }
297 public string Family { get { return family; } }
301 public class BaseBoardInformation : Structure {
303 private readonly string manufacturerName;
304 private readonly string productName;
305 private readonly string version;
306 private readonly string serialNumber;
307 private readonly Manufacturer manufacturer;
308 private readonly Model model;
310 private static Manufacturer GetManufacturer(string name) {
313 return Manufacturer.Alienware;
315 return Manufacturer.Apple;
317 return Manufacturer.ASRock;
318 case "ASUSTeK Computer INC.":
319 case "ASUSTeK COMPUTER INC.":
320 return Manufacturer.ASUS;
322 return Manufacturer.Dell;
325 return Manufacturer.DFI;
327 return Manufacturer.ECS;
328 case "EPoX COMPUTER CO., LTD":
329 return Manufacturer.EPoX;
331 return Manufacturer.EVGA;
332 case "First International Computer, Inc.":
333 return Manufacturer.FIC;
335 case "FUJITSU SIEMENS":
336 return Manufacturer.Fujitsu;
337 case "Gigabyte Technology Co., Ltd.":
338 return Manufacturer.Gigabyte;
339 case "Hewlett-Packard":
340 return Manufacturer.HP;
342 return Manufacturer.IBM;
345 case "Intel Corporation":
346 case "INTEL Corporation":
347 return Manufacturer.Intel;
350 return Manufacturer.Lenovo;
351 case "Micro-Star International":
352 case "MICRO-STAR INTERNATIONAL CO., LTD":
353 case "MICRO-STAR INTERNATIONAL CO.,LTD":
355 return Manufacturer.MSI;
357 return Manufacturer.Shuttle;
359 return Manufacturer.Supermicro;
361 return Manufacturer.Toshiba;
363 return Manufacturer.XFX;
364 case "To be filled by O.E.M.":
365 return Manufacturer.Unknown;
367 return Manufacturer.Unknown;
371 private static Model GetModel(string name) {
374 return Model._880GMH_USB3;
375 case "ASRock AOD790GX/128M":
376 return Model.AOD790GX_128M;
378 return Model.P55_Deluxe;
379 case "Crosshair III Formula":
380 return Model.Crosshair_III_Formula;
381 case "M2N-SLI DELUXE":
382 return Model.M2N_SLI_DELUXE;
384 return Model.M4A79XTD_EVO;
385 case "P5W DH Deluxe":
386 return Model.P5W_DH_Deluxe;
390 return Model.P6X58D_E;
394 return Model.P8P67_EVO;
396 return Model.P8P67_PRO;
398 return Model.P8P67_M_PRO;
401 case "Rampage Extreme":
402 return Model.Rampage_Extreme;
403 case "Rampage II GENE":
404 return Model.Rampage_II_GENE;
405 case "LP BI P45-T2RS Elite":
406 return Model.LP_BI_P45_T2RS_Elite;
407 case "LP DK P55-T3eH9":
408 return Model.LP_DK_P55_T3eH9;
410 return Model.A890GXM_A;
411 case "X58 SLI Classified":
412 return Model.X58_SLI_Classified;
414 return Model._965P_S3;
416 return Model.EP45_DS3R;
418 return Model.EP45_UD3R;
420 return Model.EX58_EXTREME;
421 case "GA-MA770T-UD3":
422 return Model.GA_MA770T_UD3;
423 case "GA-MA785GMT-UD2H":
424 return Model.GA_MA785GMT_UD2H;
426 return Model.H67A_UD3H_B3;
428 return Model.P35_DS3;
430 return Model.P35_DS3L;
432 return Model.P55_UD4;
434 return Model.P55M_UD4;
436 return Model.P67A_UD4_B3;
438 return Model.P8Z68_V_PRO;
440 return Model.X38_DS5;
442 return Model.X58A_UD3R;
444 return Model.Z68X_UD7_B3;
447 case "Base Board Product Name":
448 case "To be filled by O.E.M.":
449 return Model.Unknown;
451 return Model.Unknown;
455 public BaseBoardInformation(string manufacturerName, string productName,
456 string version, string serialNumber)
457 : base(0x02, 0, null, null)
459 this.manufacturerName = manufacturerName;
460 this.manufacturer = GetManufacturer(manufacturerName);
461 this.productName = productName;
462 this.model = GetModel(productName);
463 this.version = version;
464 this.serialNumber = serialNumber;
467 public BaseBoardInformation(byte type, ushort handle, byte[] data,
469 : base(type, handle, data, strings) {
471 this.manufacturerName = GetString(0x04).Trim();
472 this.manufacturer = GetManufacturer(this.manufacturerName);
473 this.productName = GetString(0x05).Trim();
474 this.model = GetModel(this.productName);
475 this.version = GetString(0x06).Trim();
476 this.serialNumber = GetString(0x07).Trim();
479 public string ManufacturerName { get { return manufacturerName; } }
481 public string ProductName { get { return productName; } }
483 public string Version { get { return version; } }
485 public string SerialNumber { get { return serialNumber; } }
487 public Manufacturer Manufacturer { get { return manufacturer; } }
489 public Model Model { get { return model; } }