Imported Upstream version 2.11
[platform/upstream/dmidecode.git] / dmioem.c
1 /*
2  * Decoding of OEM-specific entries
3  * This file is part of the dmidecode project.
4  *
5  *   Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org>
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 2 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, write to the Free Software
19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "types.h"
26 #include "dmidecode.h"
27 #include "dmioem.h"
28
29 /*
30  * Globals for vendor-specific decodes
31  */
32
33 enum DMI_VENDORS { VENDOR_UNKNOWN, VENDOR_HP };
34
35 static enum DMI_VENDORS dmi_vendor = VENDOR_UNKNOWN;
36
37 /*
38  * Remember the system vendor for later use. We only actually store the
39  * value if we know how to decode at least one specific entry type for
40  * that vendor.
41  */
42 void dmi_set_vendor(const char *s)
43 {
44         if (strcmp(s, "HP") == 0 || strcmp(s, "Hewlett-Packard") == 0)
45                 dmi_vendor = VENDOR_HP;
46 }
47
48 /*
49  * HP-specific data structures are decoded here.
50  *
51  * Code contributed by John Cagle.
52  */
53
54 static int dmi_decode_hp(const struct dmi_header *h)
55 {
56         u8 *data = h->data;
57         int nic, ptr;
58
59         switch (h->type)
60         {
61                 case 204:
62                         /*
63                          * Vendor Specific: HP ProLiant System/Rack Locator
64                          */
65                         printf("HP ProLiant System/Rack Locator\n");
66                         if (h->length < 0x0B) break;
67                         printf("\tRack Name: %s\n", dmi_string(h, data[0x04]));
68                         printf("\tEnclosure Name: %s\n", dmi_string(h, data[0x05]));
69                         printf("\tEnclosure Model: %s\n", dmi_string(h, data[0x06]));
70                         printf("\tEnclosure Serial: %s\n", dmi_string(h, data[0x0A]));
71                         printf("\tEnclosure Bays: %d\n", data[0x08]);
72                         printf("\tServer Bay: %s\n", dmi_string(h, data[0x07]));
73                         printf("\tBays Filled: %d\n", data[0x09]);
74                         break;
75
76                 case 209:
77                 case 221:
78                         /*
79                          * Vendor Specific: HP ProLiant NIC MAC Information
80                          *
81                          * This prints the BIOS NIC number,
82                          * PCI bus/device/function, and MAC address
83                          */
84                         printf(h->type == 221 ?
85                                 "HP BIOS iSCSI NIC PCI and MAC Information\n" :
86                                 "HP BIOS NIC PCI and MAC Information\n");
87                         nic = 1;
88                         ptr = 4;
89                         while (h->length >= ptr + 8)
90                         {
91                                 if (data[ptr] == 0x00 && data[ptr + 1] == 0x00)
92                                         printf("\tNIC %d: Disabled\n", nic);
93                                 else if (data[ptr] == 0xFF && data[ptr + 1] == 0xFF)
94                                         printf("\tNIC %d: Not Installed\n", nic);
95                                 else
96                                 {
97                                         printf("\tNIC %d: PCI device %02x:%02x.%x, "
98                                                 "MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
99                                                 nic, data[ptr + 1],
100                                                 data[ptr] >> 3, data[ptr] & 7,
101                                                 data[ptr + 2], data[ptr + 3],
102                                                 data[ptr + 4], data[ptr + 5],
103                                                 data[ptr + 6], data[ptr + 7]);
104                                 }
105                                 nic++;
106                                 ptr += 8;
107                         }
108                         break;
109
110                 default:
111                         return 0;
112         }
113         return 1;
114 }
115
116 /*
117  * Dispatch vendor-specific entries decoding
118  * Return 1 if decoding was successful, 0 otherwise
119  */
120 int dmi_decode_oem(const struct dmi_header *h)
121 {
122         switch (dmi_vendor)
123         {
124                 case VENDOR_HP:
125                         return dmi_decode_hp(h);
126                 default:
127                         return 0;
128         }
129 }