Blame dmioem.c

Packit a55458
/*
Packit a55458
 * Decoding of OEM-specific entries
Packit a55458
 * This file is part of the dmidecode project.
Packit a55458
 *
Packit Service c8dcda
 *   Copyright (C) 2007-2020 Jean Delvare <jdelvare@suse.de>
Packit a55458
 *
Packit a55458
 *   This program is free software; you can redistribute it and/or modify
Packit a55458
 *   it under the terms of the GNU General Public License as published by
Packit a55458
 *   the Free Software Foundation; either version 2 of the License, or
Packit a55458
 *   (at your option) any later version.
Packit a55458
 *
Packit a55458
 *   This program is distributed in the hope that it will be useful,
Packit a55458
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a55458
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit a55458
 *   GNU General Public License for more details.
Packit a55458
 *
Packit a55458
 *   You should have received a copy of the GNU General Public License
Packit a55458
 *   along with this program; if not, write to the Free Software
Packit a55458
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
Packit a55458
 */
Packit a55458
Packit a55458
#include <stdio.h>
Packit a55458
#include <string.h>
Packit a55458
Packit a55458
#include "types.h"
Packit a55458
#include "dmidecode.h"
Packit a55458
#include "dmioem.h"
Packit Service 5576dd
#include "dmioutput.h"
Packit a55458
Packit a55458
/*
Packit a55458
 * Globals for vendor-specific decodes
Packit a55458
 */
Packit a55458
Packit a55458
enum DMI_VENDORS
Packit a55458
{
Packit a55458
	VENDOR_UNKNOWN,
Packit a55458
	VENDOR_ACER,
Packit a55458
	VENDOR_HP,
Packit a55458
	VENDOR_HPE,
Packit a55458
	VENDOR_IBM,
Packit a55458
	VENDOR_LENOVO,
Packit a55458
};
Packit a55458
Packit a55458
static enum DMI_VENDORS dmi_vendor = VENDOR_UNKNOWN;
Packit a55458
Packit a55458
/*
Packit a55458
 * Remember the system vendor for later use. We only actually store the
Packit a55458
 * value if we know how to decode at least one specific entry type for
Packit a55458
 * that vendor.
Packit a55458
 */
Packit a55458
void dmi_set_vendor(const char *s)
Packit a55458
{
Packit a55458
	int len;
Packit a55458
Packit a55458
	/*
Packit a55458
	 * Often DMI strings have trailing spaces. Ignore these
Packit a55458
	 * when checking for known vendor names.
Packit a55458
	 */
Packit a55458
	len = strlen(s);
Packit a55458
	while (len && s[len - 1] == ' ')
Packit a55458
		len--;
Packit a55458
Packit a55458
	if (strncmp(s, "Acer", len) == 0)
Packit a55458
		dmi_vendor = VENDOR_ACER;
Packit a55458
	else if (strncmp(s, "HP", len) == 0 || strncmp(s, "Hewlett-Packard", len) == 0)
Packit a55458
		dmi_vendor = VENDOR_HP;
Packit a55458
	else if (strncmp(s, "HPE", len) == 0 || strncmp(s, "Hewlett Packard Enterprise", len) == 0)
Packit a55458
		dmi_vendor = VENDOR_HPE;
Packit a55458
	else if (strncmp(s, "IBM", len) == 0)
Packit a55458
		dmi_vendor = VENDOR_IBM;
Packit a55458
	else if (strncmp(s, "LENOVO", len) == 0)
Packit a55458
		dmi_vendor = VENDOR_LENOVO;
Packit a55458
}
Packit a55458
Packit a55458
/*
Packit a55458
 * Acer-specific data structures are decoded here.
Packit a55458
 */
Packit a55458
Packit a55458
static int dmi_decode_acer(const struct dmi_header *h)
Packit a55458
{
Packit a55458
	u8 *data = h->data;
Packit a55458
	u16 cap;
Packit a55458
Packit a55458
	switch (h->type)
Packit a55458
	{
Packit a55458
		case 170:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: Acer Hotkey Function
Packit a55458
			 *
Packit a55458
			 * Source: acer-wmi kernel driver
Packit a55458
			 *
Packit a55458
			 * Probably applies to some laptop models of other
Packit a55458
			 * brands, including Fujitsu-Siemens, Medion, Lenovo,
Packit a55458
			 * and eMachines.
Packit a55458
			 */
Packit Service 5576dd
			pr_handle_name("Acer Hotkey Function");
Packit a55458
			if (h->length < 0x0F) break;
Packit a55458
			cap = WORD(data + 0x04);
Packit Service 41d7c7
			pr_attr("Function bitmap for Communication Button", "0x%04hx", cap);
Packit Service f2e95b
			pr_subattr("WiFi", "%s", cap & 0x0001 ? "Yes" : "No");
Packit Service f2e95b
			pr_subattr("3G", "%s", cap & 0x0040 ? "Yes" : "No");
Packit Service f2e95b
			pr_subattr("WiMAX", "%s", cap & 0x0080 ? "Yes" : "No");
Packit Service f2e95b
			pr_subattr("Bluetooth", "%s", cap & 0x0800 ? "Yes" : "No");
Packit Service 41d7c7
			pr_attr("Function bitmap for Application Button", "0x%04hx", WORD(data + 0x06));
Packit Service 41d7c7
			pr_attr("Function bitmap for Media Button", "0x%04hx", WORD(data + 0x08));
Packit Service 41d7c7
			pr_attr("Function bitmap for Display Button", "0x%04hx", WORD(data + 0x0A));
Packit Service 41d7c7
			pr_attr("Function bitmap for Others Button", "0x%04hx", WORD(data + 0x0C));
Packit Service 41d7c7
			pr_attr("Communication Function Key Number", "%d", data[0x0E]);
Packit a55458
			break;
Packit a55458
Packit a55458
		default:
Packit a55458
			return 0;
Packit a55458
	}
Packit a55458
	return 1;
Packit a55458
}
Packit a55458
Packit a55458
/*
Packit a55458
 * HPE-specific data structures are decoded here.
Packit a55458
 *
Packit a55458
 * Code contributed by John Cagle and Tyler Bell.
Packit a55458
 */
Packit a55458
Packit a55458
static void dmi_print_hp_net_iface_rec(u8 id, u8 bus, u8 dev, const u8 *mac)
Packit a55458
{
Packit a55458
	/* Some systems do not provide an id. nic_ctr provides an artificial
Packit a55458
	 * id, and assumes the records will be provided "in order".  Also,
Packit a55458
	 * using 0xFF marker is not future proof. 256 NICs is a lot, but
Packit a55458
	 * 640K ought to be enough for anybody(said no one, ever).
Packit a55458
	 * */
Packit a55458
	static u8 nic_ctr;
Packit Service 41d7c7
	char attr[8];
Packit a55458
Packit a55458
	if (id == 0xFF)
Packit a55458
		id = ++nic_ctr;
Packit a55458
Packit Service 41d7c7
	sprintf(attr, "NIC %hu", id);
Packit a55458
	if (dev == 0x00 && bus == 0x00)
Packit Service 41d7c7
		pr_attr(attr, "Disabled");
Packit a55458
	else if (dev == 0xFF && bus == 0xFF)
Packit Service 41d7c7
		pr_attr(attr, "Not Installed");
Packit a55458
	else
Packit a55458
	{
Packit Service 41d7c7
		pr_attr(attr, "PCI device %02x:%02x.%x, "
Packit Service 41d7c7
			"MAC address %02X:%02X:%02X:%02X:%02X:%02X",
Packit Service 41d7c7
			bus, dev >> 3, dev & 7,
Packit a55458
			mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Packit a55458
	}
Packit a55458
}
Packit a55458
Packit a55458
static int dmi_decode_hp(const struct dmi_header *h)
Packit a55458
{
Packit a55458
	u8 *data = h->data;
Packit a55458
	int nic, ptr;
Packit a55458
	u32 feat;
Packit a55458
	const char *company = (dmi_vendor == VENDOR_HP) ? "HP" : "HPE";
Packit a55458
Packit a55458
	switch (h->type)
Packit a55458
	{
Packit a55458
		case 204:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: HPE ProLiant System/Rack Locator
Packit a55458
			 */
Packit Service 5576dd
			pr_handle_name("%s ProLiant System/Rack Locator", company);
Packit a55458
			if (h->length < 0x0B) break;
Packit Service 41d7c7
			pr_attr("Rack Name", "%s", dmi_string(h, data[0x04]));
Packit Service 41d7c7
			pr_attr("Enclosure Name", "%s", dmi_string(h, data[0x05]));
Packit Service 41d7c7
			pr_attr("Enclosure Model", "%s", dmi_string(h, data[0x06]));
Packit Service 41d7c7
			pr_attr("Enclosure Serial", "%s", dmi_string(h, data[0x0A]));
Packit Service 41d7c7
			pr_attr("Enclosure Bays", "%d", data[0x08]);
Packit Service 41d7c7
			pr_attr("Server Bay", "%s", dmi_string(h, data[0x07]));
Packit Service 41d7c7
			pr_attr("Bays Filled", "%d", data[0x09]);
Packit a55458
			break;
Packit a55458
Packit a55458
		case 209:
Packit a55458
		case 221:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: HPE ProLiant NIC MAC Information
Packit a55458
			 *
Packit a55458
			 * This prints the BIOS NIC number,
Packit a55458
			 * PCI bus/device/function, and MAC address
Packit a55458
			 *
Packit a55458
			 * Type 209:
Packit a55458
			 * Offset |  Name  | Width | Description
Packit a55458
			 * -------------------------------------
Packit a55458
			 *  0x00  |  Type  | BYTE  | 0xD1, MAC Info
Packit a55458
			 *  0x01  | Length | BYTE  | Length of structure
Packit a55458
			 *  0x02  | Handle | WORD  | Unique handle
Packit a55458
			 *  0x04  | Dev No | BYTE  | PCI Device/Function No
Packit a55458
			 *  0x05  | Bus No | BYTE  | PCI Bus
Packit a55458
			 *  0x06  |   MAC  | 6B    | MAC addr
Packit a55458
			 *  0x0C  | NIC #2 | 8B    | Repeat 0x04-0x0B
Packit a55458
			 *
Packit a55458
			 * Type 221: is deprecated in the latest docs
Packit a55458
			 */
Packit Service 5576dd
			pr_handle_name("%s %s", company, h->type == 221 ?
Packit Service 5576dd
				       "BIOS iSCSI NIC PCI and MAC Information" :
Packit Service 5576dd
				       "BIOS PXE NIC PCI and MAC Information");
Packit a55458
			nic = 1;
Packit a55458
			ptr = 4;
Packit a55458
			while (h->length >= ptr + 8)
Packit a55458
			{
Packit a55458
				dmi_print_hp_net_iface_rec(nic,
Packit a55458
							   data[ptr + 0x01],
Packit a55458
							   data[ptr],
Packit a55458
							   &data[ptr + 0x02]);
Packit a55458
				nic++;
Packit a55458
				ptr += 8;
Packit a55458
			}
Packit a55458
			break;
Packit a55458
Packit a55458
		case 233:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: HPE ProLiant NIC MAC Information
Packit a55458
			 *
Packit a55458
			 * This prints the BIOS NIC number,
Packit a55458
			 * PCI bus/device/function, and MAC address
Packit a55458
			 *
Packit a55458
			 * Offset |  Name  | Width | Description
Packit a55458
			 * -------------------------------------
Packit a55458
			 *  0x00  |  Type  | BYTE  | 0xE9, NIC structure
Packit a55458
			 *  0x01  | Length | BYTE  | Length of structure
Packit a55458
			 *  0x02  | Handle | WORD  | Unique handle
Packit a55458
			 *  0x04  | Grp No | WORD  | 0 for single segment
Packit a55458
			 *  0x06  | Bus No | BYTE  | PCI Bus
Packit a55458
			 *  0x07  | Dev No | BYTE  | PCI Device/Function No
Packit a55458
			 *  0x08  |   MAC  | 32B   | MAC addr padded w/ 0s
Packit a55458
			 *  0x28  | Port No| BYTE  | Each NIC maps to a Port
Packit a55458
			 */
Packit Service 5576dd
			pr_handle_name("%s BIOS PXE NIC PCI and MAC Information",
Packit Service 5576dd
				       company);
Packit a55458
			if (h->length < 0x0E) break;
Packit a55458
			/* If the record isn't long enough, we don't have an ID
Packit a55458
			 * use 0xFF to use the internal counter.
Packit a55458
			 * */
Packit a55458
			nic = h->length > 0x28 ? data[0x28] : 0xFF;
Packit a55458
			dmi_print_hp_net_iface_rec(nic, data[0x06], data[0x07],
Packit a55458
						   &data[0x08]);
Packit a55458
			break;
Packit a55458
Packit a55458
		case 212:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: HPE 64-bit CRU Information
Packit a55458
			 *
Packit a55458
			 * Source: hpwdt kernel driver
Packit a55458
			 */
Packit Service 5576dd
			pr_handle_name("%s 64-bit CRU Information", company);
Packit a55458
			if (h->length < 0x18) break;
Packit a55458
			if (is_printable(data + 0x04, 4))
Packit Service 41d7c7
				pr_attr("Signature", "0x%08x (%c%c%c%c)",
Packit Service 41d7c7
					DWORD(data + 0x04),
Packit Service 41d7c7
					data[0x04], data[0x05],
Packit a55458
					data[0x06], data[0x07]);
Packit Service 41d7c7
			else
Packit Service 41d7c7
				pr_attr("Signature", "0x%08x", DWORD(data + 0x04));
Packit a55458
			if (DWORD(data + 0x04) == 0x55524324)
Packit a55458
			{
Packit a55458
				u64 paddr = QWORD(data + 0x08);
Packit a55458
				paddr.l += DWORD(data + 0x14);
Packit a55458
				if (paddr.l < DWORD(data + 0x14))
Packit a55458
					paddr.h++;
Packit Service 41d7c7
				pr_attr("Physical Address", "0x%08x%08x",
Packit a55458
					paddr.h, paddr.l);
Packit Service 41d7c7
				pr_attr("Length", "0x%08x", DWORD(data + 0x10));
Packit a55458
			}
Packit a55458
			break;
Packit a55458
Packit a55458
		case 219:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: HPE ProLiant Information
Packit a55458
			 *
Packit a55458
			 * Source: hpwdt kernel driver
Packit a55458
			 */
Packit Service 5576dd
			pr_handle_name("%s ProLiant Information", company);
Packit a55458
			if (h->length < 0x08) break;
Packit Service 41d7c7
			pr_attr("Power Features", "0x%08x", DWORD(data + 0x04));
Packit a55458
			if (h->length < 0x0C) break;
Packit Service 41d7c7
			pr_attr("Omega Features", "0x%08x", DWORD(data + 0x08));
Packit a55458
			if (h->length < 0x14) break;
Packit a55458
			feat = DWORD(data + 0x10);
Packit Service 41d7c7
			pr_attr("Misc. Features", "0x%08x", feat);
Packit Service f2e95b
			pr_subattr("iCRU", "%s", feat & 0x0001 ? "Yes" : "No");
Packit Service f2e95b
			pr_subattr("UEFI", "%s", feat & 0x1400 ? "Yes" : "No");
Packit a55458
			break;
Packit a55458
Packit a55458
		default:
Packit a55458
			return 0;
Packit a55458
	}
Packit a55458
	return 1;
Packit a55458
}
Packit a55458
Packit a55458
static int dmi_decode_ibm_lenovo(const struct dmi_header *h)
Packit a55458
{
Packit a55458
	u8 *data = h->data;
Packit a55458
Packit a55458
	switch (h->type)
Packit a55458
	{
Packit a55458
		case 131:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: ThinkVantage Technologies feature bits
Packit a55458
			 *
Packit a55458
			 * Source: Compal hel81 Service Manual Software Specification,
Packit a55458
			 *         documented under "System Management BIOS(SM BIOS)
Packit a55458
			 *         version 2.4 or greater"
Packit a55458
			 *
Packit a55458
			 * Offset |  Name         | Width   | Description
Packit a55458
			 * ----------------------------------------------
Packit a55458
			 *  0x00  | Type          | BYTE    | 0x83
Packit a55458
			 *  0x01  | Length        | BYTE    | 0x16
Packit a55458
			 *  0x02  | Handle        | WORD    | Varies
Packit a55458
			 *  0x04  | Version       | BYTE    | 0x01
Packit a55458
			 *  0x05  | TVT Structure | BYTEx16 | Each of the 128 bits represents a TVT feature:
Packit a55458
			 *        |               |         |  - bit 127 means diagnostics (PC Doctor) is available
Packit a55458
			 *        |               |         |    (http://www.pc-doctor.com/company/pr-articles/45-lenovo-introduces-thinkvantage-toolbox)
Packit a55458
			 *        |               |         |  - the rest (126-0) are reserved/unknown
Packit a55458
			 *
Packit a55458
			 * It must also be followed by a string containing
Packit a55458
			 * "TVT-Enablement". There exist other type 131 records
Packit a55458
			 * with different length and a different string, for
Packit a55458
			 * other purposes.
Packit a55458
			 */
Packit a55458
Packit a55458
			if (h->length != 0x16
Packit a55458
			 || strcmp(dmi_string(h, 1), "TVT-Enablement") != 0)
Packit a55458
				return 0;
Packit a55458
Packit Service 5576dd
			pr_handle_name("ThinkVantage Technologies");
Packit Service 41d7c7
			pr_attr("Version", "%u", data[0x04]);
Packit Service 41d7c7
			pr_attr("Diagnostics", "%s",
Packit a55458
				data[0x14] & 0x80 ? "Available" : "No");
Packit a55458
			break;
Packit a55458
Packit a55458
		case 135:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: Device Presence Detection bits
Packit a55458
			 *
Packit a55458
			 * Source: Compal hel81 Service Manual Software Specification,
Packit a55458
			 *         documented as "SMBIOS Type 135: Bulk for Lenovo
Packit a55458
			 *         Mobile PC Unique OEM Data" under appendix D.
Packit a55458
			 *
Packit a55458
			 * Offset |  Name                | Width | Description
Packit a55458
			 * ---------------------------------------------------
Packit a55458
			 *  0x00  | Type                 | BYTE  | 0x87
Packit a55458
			 *  0x01  | Length               | BYTE  | 0x0A
Packit a55458
			 *  0x02  | Handle               | WORD  | Varies
Packit a55458
			 *  0x04  | Signature            | WORD  | 0x5054 (ASCII for "TP")
Packit a55458
			 *  0x06  | OEM struct offset    | BYTE  | 0x07
Packit a55458
			 *  0x07  | OEM struct number    | BYTE  | 0x03, for this structure
Packit a55458
			 *  0x08  | OEM struct revision  | BYTE  | 0x01, for this format
Packit a55458
			 *  0x09  | Device presence bits | BYTE  | Each of the 8 bits indicates device presence:
Packit a55458
			 *        |                      |       |  - bit 0 indicates the presence of a fingerprint reader
Packit a55458
			 *        |                      |       |  - the rest (7-1) are reserved/unknown
Packit a55458
			 *
Packit a55458
			 * Other OEM struct number+rev combinations have been
Packit a55458
			 * seen in the wild but we don't know how to decode
Packit a55458
			 * them.
Packit a55458
			 */
Packit a55458
Packit a55458
			if (h->length < 0x0A || data[0x04] != 'T' || data[0x05] != 'P')
Packit a55458
				return 0;
Packit a55458
Packit a55458
			/* Bail out if not the expected format */
Packit a55458
			if (data[0x06] != 0x07 || data[0x07] != 0x03 || data[0x08] != 0x01)
Packit a55458
				return 0;
Packit a55458
Packit Service 5576dd
			pr_handle_name("ThinkPad Device Presence Detection");
Packit Service 41d7c7
			pr_attr("Fingerprint Reader", "%s",
Packit a55458
				data[0x09] & 0x01 ? "Present" : "No");
Packit a55458
			break;
Packit a55458
Packit a55458
		case 140:
Packit a55458
			/*
Packit a55458
			 * Vendor Specific: ThinkPad Embedded Controller Program
Packit a55458
			 *
Packit a55458
			 * Source: some guesswork, and publicly available information;
Packit a55458
			 *         Lenovo's BIOS update READMEs often contain the ECP IDs
Packit a55458
			 *         which match the first string in this type.
Packit a55458
			 *
Packit a55458
			 * Offset |  Name                | Width  | Description
Packit a55458
			 * ----------------------------------------------------
Packit a55458
			 *  0x00  | Type                 | BYTE   | 0x8C
Packit a55458
			 *  0x01  | Length               | BYTE   |
Packit a55458
			 *  0x02  | Handle               | WORD   | Varies
Packit a55458
			 *  0x04  | Signature            | BYTEx6 | ASCII for "LENOVO"
Packit a55458
			 *  0x0A  | OEM struct offset    | BYTE   | 0x0B
Packit a55458
			 *  0x0B  | OEM struct number    | BYTE   | 0x07, for this structure
Packit a55458
			 *  0x0C  | OEM struct revision  | BYTE   | 0x01, for this format
Packit a55458
			 *  0x0D  | ECP version ID       | STRING |
Packit a55458
			 *  0x0E  | ECP release date     | STRING |
Packit a55458
			 */
Packit a55458
Packit a55458
			if (h->length < 0x0F || memcmp(data + 4, "LENOVO", 6) != 0)
Packit a55458
				return 0;
Packit a55458
Packit a55458
			/* Bail out if not the expected format */
Packit a55458
			if (data[0x0A] != 0x0B || data[0x0B] != 0x07 || data[0x0C] != 0x01)
Packit a55458
				return 0;
Packit a55458
Packit Service 5576dd
			pr_handle_name("ThinkPad Embedded Controller Program");
Packit Service 41d7c7
			pr_attr("Version ID", "%s", dmi_string(h, 1));
Packit Service 41d7c7
			pr_attr("Release Date", "%s", dmi_string(h, 2));
Packit a55458
			break;
Packit a55458
Packit a55458
		default:
Packit a55458
			return 0;
Packit a55458
	}
Packit a55458
	return 1;
Packit a55458
}
Packit a55458
Packit a55458
/*
Packit a55458
 * Dispatch vendor-specific entries decoding
Packit a55458
 * Return 1 if decoding was successful, 0 otherwise
Packit a55458
 */
Packit a55458
int dmi_decode_oem(const struct dmi_header *h)
Packit a55458
{
Packit a55458
	switch (dmi_vendor)
Packit a55458
	{
Packit a55458
		case VENDOR_HP:
Packit a55458
		case VENDOR_HPE:
Packit a55458
			return dmi_decode_hp(h);
Packit a55458
		case VENDOR_ACER:
Packit a55458
			return dmi_decode_acer(h);
Packit a55458
		case VENDOR_IBM:
Packit a55458
		case VENDOR_LENOVO:
Packit a55458
			return dmi_decode_ibm_lenovo(h);
Packit a55458
		default:
Packit a55458
			return 0;
Packit a55458
	}
Packit a55458
}