Debian Codegraph @

src/utils/dmi/dmi.h

raw
1 /*
2 * MIT License
3 *
4 * Copyright(c) 2019 Intel Corporation. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 * Kamil Wiatrowski <[email protected]>
26 */
27
28 #ifndef UTILS_DMI_H
29 #define UTILS_DMI_H
30
31 /* Size of buffer for single dmi entry, just an estimation with big margin,
32 * could be increased if the new generation of platform requires it to.
33 */
34 #define DMI_MAX_LEN 256
35
36 #define DMI_OK 0
37 #define DMI_ERROR -1
38
39 /* Following values should match Types assigned in System Management BIOS
40 * (SMBIOS) Reference Specification
41 */
42 typedef enum dmi_type_e {
43 BIOS = 0,
44 SYSTEM,
45 BASEBOARD,
46 CHASSIS,
47 PROCESSOR,
48 MEMORY_CONTROLLER,
49 MEMORY_MODULE,
50 CACHE,
51 PORT_CONNECTOR,
52 SYSTEM_SLOTS,
53 ON_BOARD_DEVICES,
54 OEM_STRINGS,
55 SYSTEM_CONFIGURATION_OPTIONS,
56 BIOS_LANGUAGE,
57 GROUP_ASSOCIATIONS,
58 SYSTEM_EVENT_LOG,
59 PHYSICAL_MEMORY_ARRAY,
60 MEMORY_DEVICE,
61 MEMORY_ERROR_32_BIT,
62 MEMORY_ARRAY_MAPPED_ADDRESS,
63 MEMORY_DEVICE_MAPPED_ADDRESS,
64 BUILT_IN_POINTING_DEVICE,
65 PORTABLE_BATTERY,
66 SYSTEM_RESET,
67 HARDWARE_SECURITY,
68 SYSTEM_POWER_CONTROLS,
69 VOLTAGE_PROBE,
70 COOLING_DEVICE,
71 TEMPERATURE_PROBE,
72 ELECTRICAL_CURRENT_PROBE,
73 OUT_OF_BAND_REMOTE_ACCESS,
74 BOOT_INTEGRITY_SERVICES,
75 SYSTEM_BOOT,
76 MEMORY_ERROR_64_BIT,
77 MANAGEMENT_DEVICE,
78 MANAGEMENT_DEVICE_COMPONENT,
79 MANAGEMENT_DEVICE_THRESHOLD_DATA,
80 MEMORY_CHANNEL,
81 IPMI_DEVICE,
82 POWER_SUPPLY,
83 ADDITIONAL_INFORMATION,
84 ONBOARD_DEVICES_EXTENDED_INFORMATION,
85 MANAGEMENT_CONTROLLER_HOST_INTERFACE,
86 DMI_TYPE_ALL /* special type to read all SMBIOS handles */
87 } dmi_type;
88
89 typedef enum entry_type_e {
90 DMI_ENTRY_NONE,
91 DMI_ENTRY_NAME,
92 DMI_ENTRY_MAP,
93 DMI_ENTRY_LIST_NAME,
94 DMI_ENTRY_LIST_VALUE,
95 DMI_ENTRY_END
96 } entry_type;
97
98 typedef struct dmi_reader_s {
99 FILE *_fd;
100 char _buff[DMI_MAX_LEN];
101 int (*_read_next)(struct dmi_reader_s *reader);
102 /* Type of current entry */
103 entry_type current_type;
104 /* Entry name, the pointer changes after every read. */
105 char *name;
106 /* Entry value, the pointer changes after every read. */
107 char *value;
108 } dmi_reader_t;
109
110 /*
111 * NAME
112 * dmi_reader_init
113 *
114 * DESCRIPTION
115 * Initialize reader structure and use popen to read SMBIOS using dmidecode.
116 *
117 * PARAMETERS
118 * `reader' Pointer to dmi_reader structure, can't be NULL.
119 * `type' Type of DMI entries to read.
120 *
121 * RETURN VALUE
122 * DMI_OK upon success or DMI_ERROR if an error occurred.
123 *
124 * NOTES
125 * The dmi_reader_clean needs to be called to close pipe if
126 * reader hasn't finished yet. In case of error cleanup is
127 * done by the function itself.
128 */
129 int dmi_reader_init(dmi_reader_t *reader, const dmi_type type);
130
131 /*
132 * NAME
133 * dmi_reader_clean
134 *
135 * DESCRIPTION
136 * Clean up reader structure and close pipe.
137 *
138 * PARAMETERS
139 * `reader' Pointer to dmi_reader structure, can't be NULL.
140 */
141 void dmi_reader_clean(dmi_reader_t *reader);
142
143 /*
144 * NAME
145 * dmi_reader_next
146 *
147 * DESCRIPTION
148 * Read next entry and store values.
149 *
150 * PARAMETERS
151 * `reader' Pointer to dmi_reader structure, can't be NULL.
152 *
153 * RETURN VALUE
154 * DMI_OK upon success or DMI_ERROR if an error occurred.
155 *
156 * NOTES
157 * In case of error the function cleans the reader structure.
158 * After all entries are read the function sets state to DMI_ENTRY_END
159 * and no further clean-up is required.
160 */
161 int dmi_read_next(dmi_reader_t *reader);
162
163 #endif /* UTILS_DMI_H */