Added a mainboard specific configuration for the ASUS P6T.
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-2012
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 case "ASUSTeK COMPUTER INC.":
347 return Manufacturer.ASUS;
349 return Manufacturer.Dell;
352 return Manufacturer.DFI;
354 return Manufacturer.ECS;
355 case "EPoX COMPUTER CO., LTD":
356 return Manufacturer.EPoX;
358 return Manufacturer.EVGA;
359 case "First International Computer, Inc.":
360 return Manufacturer.FIC;
362 case "FUJITSU SIEMENS":
363 return Manufacturer.Fujitsu;
364 case "Gigabyte Technology Co., Ltd.":
365 return Manufacturer.Gigabyte;
366 case "Hewlett-Packard":
367 return Manufacturer.HP;
369 return Manufacturer.IBM;
372 case "Intel Corporation":
373 case "INTEL Corporation":
374 return Manufacturer.Intel;
377 return Manufacturer.Lenovo;
378 case "Micro-Star International":
379 case "MICRO-STAR INTERNATIONAL CO., LTD":
380 case "MICRO-STAR INTERNATIONAL CO.,LTD":
382 return Manufacturer.MSI;
384 return Manufacturer.Shuttle;
386 return Manufacturer.Supermicro;
388 return Manufacturer.Toshiba;
390 return Manufacturer.XFX;
391 case "To be filled by O.E.M.":
392 return Manufacturer.Unknown;
394 return Manufacturer.Unknown;
398 private static Model GetModel(string name) {
401 return Model._880GMH_USB3;
402 case "ASRock AOD790GX/128M":
403 return Model.AOD790GX_128M;
405 return Model.P55_Deluxe;
406 case "Crosshair III Formula":
407 return Model.Crosshair_III_Formula;
408 case "M2N-SLI DELUXE":
409 return Model.M2N_SLI_DELUXE;
411 return Model.M4A79XTD_EVO;
412 case "P5W DH Deluxe":
413 return Model.P5W_DH_Deluxe;
417 return Model.P6X58D_E;
421 return Model.P8P67_EVO;
423 return Model.P8P67_PRO;
425 return Model.P8P67_M_PRO;
428 case "Rampage Extreme":
429 return Model.Rampage_Extreme;
430 case "Rampage II GENE":
431 return Model.Rampage_II_GENE;
432 case "LP BI P45-T2RS Elite":
433 return Model.LP_BI_P45_T2RS_Elite;
434 case "LP DK P55-T3eH9":
435 return Model.LP_DK_P55_T3eH9;
437 return Model.A890GXM_A;
438 case "X58 SLI Classified":
439 return Model.X58_SLI_Classified;
441 return Model._965P_S3;
443 return Model.EP45_DS3R;
445 return Model.EP45_UD3R;
447 return Model.EX58_EXTREME;
448 case "GA-MA770T-UD3":
449 return Model.GA_MA770T_UD3;
450 case "GA-MA785GMT-UD2H":
451 return Model.GA_MA785GMT_UD2H;
453 return Model.H67A_UD3H_B3;
455 return Model.P35_DS3;
457 return Model.P35_DS3L;
459 return Model.P55_UD4;
461 return Model.P55M_UD4;
463 return Model.P67A_UD4_B3;
465 return Model.X38_DS5;
467 return Model.X58A_UD3R;
469 return Model.Z68X_UD7_B3;
472 case "Base Board Product Name":
473 case "To be filled by O.E.M.":
474 return Model.Unknown;
476 return Model.Unknown;
480 public BaseBoardInformation(string manufacturerName, string productName,
481 string version, string serialNumber)
482 : base(0x02, 0, null, null)
484 this.manufacturerName = manufacturerName;
485 this.manufacturer = GetManufacturer(manufacturerName);
486 this.productName = productName;
487 this.model = GetModel(productName);
488 this.version = version;
489 this.serialNumber = serialNumber;
492 public BaseBoardInformation(byte type, ushort handle, byte[] data,
494 : base(type, handle, data, strings) {
496 this.manufacturerName = GetString(0x04).Trim();
497 this.manufacturer = GetManufacturer(this.manufacturerName);
498 this.productName = GetString(0x05).Trim();
499 this.model = GetModel(this.productName);
500 this.version = GetString(0x06).Trim();
501 this.serialNumber = GetString(0x07).Trim();
504 public string ManufacturerName { get { return manufacturerName; } }
506 public string ProductName { get { return productName; } }
508 public string Version { get { return version; } }
510 public string SerialNumber { get { return serialNumber; } }
512 public Manufacturer Manufacturer { get { return manufacturer; } }
514 public Model Model { get { return model; } }