Added an ISA bus mutex.
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-2010
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 {
49 private Structure[] table;
51 private BIOSInformation biosInformation = null;
52 private BaseBoardInformation baseBoardInformation = null;
54 private string ReadSysFS(string path) {
56 if (File.Exists(path)) {
57 using (StreamReader reader = new StreamReader(path))
58 return reader.ReadLine();
68 int p = (int)System.Environment.OSVersion.Platform;
69 if ((p == 4) || (p == 128)) {
73 string boardVendor = ReadSysFS("/sys/class/dmi/id/board_vendor");
74 string boardName = ReadSysFS("/sys/class/dmi/id/board_name");
75 string boardVersion = ReadSysFS("/sys/class/dmi/id/board_version");
76 this.baseBoardInformation = new BaseBoardInformation(
77 boardVendor, boardName, boardVersion, null);
79 string biosVendor = ReadSysFS("/sys/class/dmi/id/bios_vendor");
80 string biosVersion = ReadSysFS("/sys/class/dmi/id/bios_version");
81 this.biosInformation = new BIOSInformation(biosVendor, biosVersion);
84 List<Structure> structureList = new List<Structure>();
88 ManagementObjectCollection collection =
89 new ManagementObjectSearcher("root\\WMI",
90 "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
92 foreach (ManagementObject mo in collection) {
93 raw = (byte[])mo["SMBiosData"];
98 if (raw != null && raw.Length > 0) {
100 byte type = raw[offset];
101 while (offset + 4 < raw.Length && type != 127) {
104 int length = raw[offset + 1];
105 ushort handle = (ushort)((raw[offset + 2] << 8) | raw[offset + 3]);
107 if (offset + length > raw.Length)
109 byte[] data = new byte[length];
110 Array.Copy(raw, offset, data, 0, length);
113 List<string> stringsList = new List<string>();
114 if (offset < raw.Length && raw[offset] == 0)
117 while (offset < raw.Length && raw[offset] != 0) {
118 StringBuilder sb = new StringBuilder();
119 while (offset < raw.Length && raw[offset] != 0) {
120 sb.Append((char)raw[offset]); offset++;
123 stringsList.Add(sb.ToString());
128 this.biosInformation = new BIOSInformation(
129 type, handle, data, stringsList.ToArray());
130 structureList.Add(this.biosInformation); break;
131 case 0x02: this.baseBoardInformation = new BaseBoardInformation(
132 type, handle, data, stringsList.ToArray());
133 structureList.Add(this.baseBoardInformation); break;
134 default: structureList.Add(new Structure(
135 type, handle, data, stringsList.ToArray())); break;
140 table = structureList.ToArray();
144 public string GetReport() {
145 StringBuilder r = new StringBuilder();
147 if (biosInformation != null) {
148 r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor);
149 r.Append("BIOS Version: "); r.AppendLine(biosInformation.Version);
153 if (baseBoardInformation != null) {
154 r.Append("Mainboard Manufacturer: ");
155 r.AppendLine(baseBoardInformation.ManufacturerName);
156 r.Append("Mainboard Name: ");
157 r.AppendLine(baseBoardInformation.ProductName);
162 string base64 = Convert.ToBase64String(raw);
163 r.AppendLine("SMBIOS Table");
166 for (int i = 0; i < Math.Ceiling(base64.Length / 64.0); i++) {
168 for (int j = 0; j < 0x40; j++) {
169 int index = (i << 6) | j;
170 if (index < base64.Length) {
171 r.Append(base64[index]);
182 public BIOSInformation BIOS {
183 get { return biosInformation; }
186 public BaseBoardInformation Board {
187 get { return baseBoardInformation; }
190 public class Structure {
192 private ushort handle;
195 private string[] strings;
197 protected string GetString(int offset) {
198 if (offset < data.Length && data[offset] > 0 &&
199 data[offset] <= strings.Length)
200 return strings[data[offset] - 1];
205 public Structure(byte type, ushort handle, byte[] data, string[] strings)
208 this.handle = handle;
210 this.strings = strings;
213 public byte Type { get { return type; } }
215 public ushort Handle { get { return handle; } }
218 public class BIOSInformation : Structure {
220 private string vendor;
221 private string version;
223 public BIOSInformation(string vendor, string version)
224 : base (0x00, 0, null, null)
226 this.vendor = vendor;
227 this.version = version;
230 public BIOSInformation(byte type, ushort handle, byte[] data,
232 : base(type, handle, data, strings)
234 this.vendor = GetString(0x04);
235 this.version = GetString(0x05);
238 public string Vendor { get { return vendor; } }
240 public string Version { get { return version; } }
243 public class BaseBoardInformation : Structure {
245 private string manufacturerName;
246 private string productName;
247 private string version;
248 private string serialNumber;
249 private Manufacturer manufacturer;
252 private void SetManufacturerName(string manufacturerName) {
253 this.manufacturerName = manufacturerName;
255 switch (manufacturerName) {
257 manufacturer = Manufacturer.ASRock; break;
258 case "ASUSTeK Computer INC.":
259 manufacturer = Manufacturer.ASUS; break;
261 manufacturer = Manufacturer.Dell; break;
264 manufacturer = Manufacturer.DFI; break;
265 case "EPoX COMPUTER CO., LTD":
266 manufacturer = Manufacturer.EPoX; break;
268 manufacturer = Manufacturer.EVGA; break;
269 case "First International Computer, Inc.":
270 manufacturer = Manufacturer.FIC; break;
271 case "Gigabyte Technology Co., Ltd.":
272 manufacturer = Manufacturer.Gigabyte; break;
273 case "Hewlett-Packard":
274 manufacturer = Manufacturer.HP; break;
276 manufacturer = Manufacturer.IBM; break;
277 case "MICRO-STAR INTERNATIONAL CO., LTD":
278 case "MICRO-STAR INTERNATIONAL CO.,LTD":
279 manufacturer = Manufacturer.MSI; break;
281 manufacturer = Manufacturer.XFX; break;
282 case "To be filled by O.E.M.":
283 manufacturer = Manufacturer.Unknown; break;
285 manufacturer = Manufacturer.Unknown; break;
289 private void SetProductName(string productName) {
290 this.productName = productName;
292 switch (productName) {
294 model = Model._880GMH_USB3; break;
295 case "Crosshair III Formula":
296 model = Model.Crosshair_III_Formula; break;
297 case "M2N-SLI DELUXE":
298 model = Model.M2N_SLI_DELUXE; break;
300 model = Model.M4A79XTD_EVO; break;
301 case "P5W DH Deluxe":
302 model = Model.P5W_DH_Deluxe; break;
304 model = Model.P6X58D_E; break;
305 case "LP BI P45-T2RS Elite":
306 model = Model.LP_BI_P45_T2RS_Elite; break;
307 case "LP DK P55-T3eH9":
308 model = Model.LP_DK_P55_T3eH9; break;
309 case "X58 SLI Classified":
310 model = Model.X58_SLI_Classified; break;
312 model = Model._965P_S3; break;
314 model = Model.EP45_DS3R; break;
316 model = Model.EP45_UD3R; break;
318 model = Model.EX58_EXTREME; break;
319 case "GA-MA770T-UD3":
320 model = Model.GA_MA770T_UD3; break;
321 case "GA-MA785GMT-UD2H":
322 model = Model.GA_MA785GMT_UD2H; break;
324 model = Model.P35_DS3; break;
326 model = Model.P35_DS3L; break;
328 model = Model.P55_UD4; break;
330 model = Model.X38_DS5; break;
332 model = Model.X58A_UD3R; break;
333 case "To be filled by O.E.M.":
334 model = Model.Unknown; break;
336 model = Model.Unknown; break;
340 public BaseBoardInformation(string manufacturerName, string productName,
341 string version, string serialNumber)
342 : base(0x02, 0, null, null)
344 SetManufacturerName(manufacturerName);
345 SetProductName(productName);
346 this.version = version;
347 this.serialNumber = serialNumber;
350 public BaseBoardInformation(byte type, ushort handle, byte[] data,
352 : base(type, handle, data, strings) {
354 SetManufacturerName(GetString(0x04).Trim());
355 SetProductName(GetString(0x05).Trim());
356 this.version = GetString(0x06).Trim();
357 this.serialNumber = GetString(0x07).Trim();
360 public string ManufacturerName { get { return manufacturerName; } }
362 public string ProductName { get { return productName; } }
364 public string Version { get { return version; } }
366 public string SerialNumber { get { return serialNumber; } }
368 public Manufacturer Manufacturer { get { return manufacturer; } }
370 public Model Model { get { return model; } }