Added Added a mainboard specific configuration for the Shuttle SH67Hx barebones. Added the SMBIOS system information to the report.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2011
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
41 using System.Management;
44 namespace OpenHardwareMonitor.Hardware.Mainboard {
46 internal class SMBIOS {
48 private readonly byte[] raw;
49 private readonly Structure[] table;
51 private readonly Version version;
52 private readonly BIOSInformation biosInformation;
53 private readonly SystemInformation systemInformation;
54 private readonly BaseBoardInformation baseBoardInformation;
56 private static string ReadSysFS(string path) {
58 if (File.Exists(path)) {
59 using (StreamReader reader = new StreamReader(path))
60 return reader.ReadLine();
70 int p = (int)Environment.OSVersion.Platform;
71 if ((p == 4) || (p == 128)) {
75 string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
76 string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
77 string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
78 this.baseBoardInformation = new BaseBoardInformation(
79 boardVendor, boardName, boardVersion, null);
81 string systemVendor = ReadSysFS("/sys/class/dmi/id/sys_vendor");
82 string productName = ReadSysFS("/sys/class/dmi/id/product_name");
83 string productVersion = ReadSysFS("/sys/class/dmi/id/product_version");
84 this.systemInformation = new SystemInformation(systemVendor,
85 productName, productVersion, null, null);
87 string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
88 string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
89 this.biosInformation = new BIOSInformation(biosVendor, biosVersion);
92 List<Structure> structureList = new List<Structure>();
95 byte majorVersion = 0;
96 byte minorVersion = 0;
98 ManagementObjectCollection collection;
99 using (ManagementObjectSearcher searcher =
100 new ManagementObjectSearcher("root\\WMI",
101 "SELECT * FROM MSSMBios_RawSMBiosTables")) {
102 collection = searcher.Get();
105 foreach (ManagementObject mo in collection) {
106 raw = (byte[])mo["SMBiosData"];
107 majorVersion = (byte)mo["SmbiosMajorVersion"];
108 minorVersion = (byte)mo["SmbiosMinorVersion"];
113 if (majorVersion > 0 || minorVersion > 0)
114 version = new Version(majorVersion, minorVersion);
116 if (raw != null && raw.Length > 0) {
118 byte type = raw[offset];
119 while (offset + 4 < raw.Length && type != 127) {
122 int length = raw[offset + 1];
123 ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);
125 if (offset + length > raw.Length)
127 byte[] data = new byte[length];
128 Array.Copy(raw, offset, data, 0, length);
131 List<string> stringsList = new List<string>();
132 if (offset < raw.Length && raw[offset] == 0)
135 while (offset < raw.Length && raw[offset] != 0) {
136 StringBuilder sb = new StringBuilder();
137 while (offset < raw.Length && raw[offset] != 0) {
138 sb.Append((char)raw[offset]); offset++;
141 stringsList.Add(sb.ToString());
146 this.biosInformation = new BIOSInformation(
147 type, handle, data, stringsList.ToArray());
148 structureList.Add(this.biosInformation); break;
150 this.systemInformation = new SystemInformation(
151 type, handle, data, stringsList.ToArray());
152 structureList.Add(this.systemInformation); break;
153 case 0x02: this.baseBoardInformation = new BaseBoardInformation(
154 type, handle, data, stringsList.ToArray());
155 structureList.Add(this.baseBoardInformation); break;
156 default: structureList.Add(new Structure(
157 type, handle, data, stringsList.ToArray())); break;
162 table = structureList.ToArray();
166 public string GetReport() {
167 StringBuilder r = new StringBuilder();
169 if (version != null) {
170 r.Append("SMBIOS Version: "); r.AppendLine(version.ToString(2));
175 r.Append("BIOS Vendor: "); r.AppendLine(BIOS.Vendor);
176 r.Append("BIOS Version: "); r.AppendLine(BIOS.Version);
180 if (System != null) {
181 r.Append("System Manufacturer: ");
182 r.AppendLine(System.ManufacturerName);
183 r.Append("System Name: ");
184 r.AppendLine(System.ProductName);
185 r.Append("System Version: ");
186 r.AppendLine(System.Version);
191 r.Append("Mainboard Manufacturer: ");
192 r.AppendLine(Board.ManufacturerName);
193 r.Append("Mainboard Name: ");
194 r.AppendLine(Board.ProductName);
195 r.Append("Mainboard Version: ");
196 r.AppendLine(Board.Version);
201 string base64 = Convert.ToBase64String(raw);
202 r.AppendLine("SMBIOS Table");
205 for (int i = 0; i < Math.Ceiling(base64.Length / 64.0); i++) {
207 for (int j = 0; j < 0x40; j++) {
208 int index = (i << 6) | j;
209 if (index < base64.Length) {
210 r.Append(base64[index]);
221 public BIOSInformation BIOS {
222 get { return biosInformation; }
225 public SystemInformation System {
226 get { return systemInformation; }
229 public BaseBoardInformation Board {
230 get { return baseBoardInformation; }
233 public class Structure {
234 private readonly byte type;
235 private readonly ushort handle;
237 private readonly byte[] data;
238 private readonly string[] strings;
240 protected string GetString(int offset) {
241 if (offset < data.Length && data[offset] > 0 &&
242 data[offset] <= strings.Length)
243 return strings[data[offset] - 1];
248 public Structure(byte type, ushort handle, byte[] data, string[] strings)
251 this.handle = handle;
253 this.strings = strings;
256 public byte Type { get { return type; } }
258 public ushort Handle { get { return handle; } }
261 public class BIOSInformation : Structure {
263 private readonly string vendor;
264 private readonly string version;
266 public BIOSInformation(string vendor, string version)
267 : base (0x00, 0, null, null)
269 this.vendor = vendor;
270 this.version = version;
273 public BIOSInformation(byte type, ushort handle, byte[] data,
275 : base(type, handle, data, strings)
277 this.vendor = GetString(0x04);
278 this.version = GetString(0x05);
281 public string Vendor { get { return vendor; } }
283 public string Version { get { return version; } }
286 public class SystemInformation : Structure {
288 private readonly string manufacturerName;
289 private readonly string productName;
290 private readonly string version;
291 private readonly string serialNumber;
292 private readonly string family;
294 public SystemInformation(string manufacturerName, string productName,
295 string version, string serialNumber, string family)
296 : base (0x01, 0, null, null)
298 this.manufacturerName = manufacturerName;
299 this.productName = productName;
300 this.version = version;
301 this.serialNumber = serialNumber;
302 this.family = family;
305 public SystemInformation(byte type, ushort handle, byte[] data,
307 : base(type, handle, data, strings)
309 this.manufacturerName = GetString(0x04);
310 this.productName = GetString(0x05);
311 this.version = GetString(0x06);
312 this.serialNumber = GetString(0x07);
313 this.family = GetString(0x1A);
316 public string ManufacturerName { get { return manufacturerName; } }
318 public string ProductName { get { return productName; } }
320 public string Version { get { return version; } }
322 public string SerialNumber { get { return serialNumber; } }
324 public string Family { get { return family; } }
328 public class BaseBoardInformation : Structure {
330 private readonly string manufacturerName;
331 private readonly string productName;
332 private readonly string version;
333 private readonly string serialNumber;
334 private readonly Manufacturer manufacturer;
335 private readonly Model model;
337 private static Manufacturer GetManufacturer(string name) {
340 return Manufacturer.Alienware;
342 return Manufacturer.Apple;
344 return Manufacturer.ASRock;
345 case "ASUSTeK Computer INC.":
346 return Manufacturer.ASUS;
348 return Manufacturer.Dell;
351 return Manufacturer.DFI;
353 return Manufacturer.ECS;
354 case "EPoX COMPUTER CO., LTD":
355 return Manufacturer.EPoX;
357 return Manufacturer.EVGA;
358 case "First International Computer, Inc.":
359 return Manufacturer.FIC;
361 case "FUJITSU SIEMENS":
362 return Manufacturer.Fujitsu;
363 case "Gigabyte Technology Co., Ltd.":
364 return Manufacturer.Gigabyte;
365 case "Hewlett-Packard":
366 return Manufacturer.HP;
368 return Manufacturer.IBM;
371 case "Intel Corporation":
372 case "INTEL Corporation":
373 return Manufacturer.Intel;
376 return Manufacturer.Lenovo;
377 case "Micro-Star International":
378 case "MICRO-STAR INTERNATIONAL CO., LTD":
379 case "MICRO-STAR INTERNATIONAL CO.,LTD":
381 return Manufacturer.MSI;
383 return Manufacturer.Shuttle;
385 return Manufacturer.Supermicro;
387 return Manufacturer.Toshiba;
389 return Manufacturer.XFX;
390 case "To be filled by O.E.M.":
391 return Manufacturer.Unknown;
393 return Manufacturer.Unknown;
397 private static Model GetModel(string name) {
400 return Model._880GMH_USB3;
401 case "ASRock AOD790GX/128M":
402 return Model.AOD790GX_128M;
404 return Model.P55_Deluxe;
405 case "Crosshair III Formula":
406 return Model.Crosshair_III_Formula;
407 case "M2N-SLI DELUXE":
408 return Model.M2N_SLI_DELUXE;
410 return Model.M4A79XTD_EVO;
411 case "P5W DH Deluxe":
412 return Model.P5W_DH_Deluxe;
414 return Model.P6X58D_E;
418 return Model.P8P67_EVO;
420 return Model.P8P67_PRO;
422 return Model.P8P67_M_PRO;
423 case "Rampage Extreme":
424 return Model.Rampage_Extreme;
425 case "Rampage II GENE":
426 return Model.Rampage_II_GENE;
427 case "LP BI P45-T2RS Elite":
428 return Model.LP_BI_P45_T2RS_Elite;
429 case "LP DK P55-T3eH9":
430 return Model.LP_DK_P55_T3eH9;
432 return Model.A890GXM_A;
433 case "X58 SLI Classified":
434 return Model.X58_SLI_Classified;
436 return Model._965P_S3;
438 return Model.EP45_DS3R;
440 return Model.EP45_UD3R;
442 return Model.EX58_EXTREME;
443 case "GA-MA770T-UD3":
444 return Model.GA_MA770T_UD3;
445 case "GA-MA785GMT-UD2H":
446 return Model.GA_MA785GMT_UD2H;
448 return Model.H67A_UD3H_B3;
450 return Model.P35_DS3;
452 return Model.P35_DS3L;
454 return Model.P55_UD4;
456 return Model.P55M_UD4;
458 return Model.P67A_UD4_B3;
460 return Model.X38_DS5;
462 return Model.X58A_UD3R;
464 return Model.Z68X_UD7_B3;
467 case "Base Board Product Name":
468 case "To be filled by O.E.M.":
469 return Model.Unknown;
471 return Model.Unknown;
475 public BaseBoardInformation(string manufacturerName, string productName,
476 string version, string serialNumber)
477 : base(0x02, 0, null, null)
479 this.manufacturerName = manufacturerName;
480 this.manufacturer = GetManufacturer(manufacturerName);
481 this.productName = productName;
482 this.model = GetModel(productName);
483 this.version = version;
484 this.serialNumber = serialNumber;
487 public BaseBoardInformation(byte type, ushort handle, byte[] data,
489 : base(type, handle, data, strings) {
491 this.manufacturerName = GetString(0x04).Trim();
492 this.manufacturer = GetManufacturer(this.manufacturerName);
493 this.productName = GetString(0x05).Trim();
494 this.model = GetModel(this.productName);
495 this.version = GetString(0x06).Trim();
496 this.serialNumber = GetString(0x07).Trim();
499 public string ManufacturerName { get { return manufacturerName; } }
501 public string ProductName { get { return productName; } }
503 public string Version { get { return version; } }
505 public string SerialNumber { get { return serialNumber; } }
507 public Manufacturer Manufacturer { get { return manufacturer; } }
509 public Model Model { get { return model; } }