1 /* ----------------------------------------------------------------------- *
3 * Copyright 2011 Erwan Velu - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
29 #include "hdt-common.h"
32 void dump_hardware_security(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
33 if (!hardware
->dmi
.hardware_security
.filled
) {
35 add_s("dmi.warning","No hardware security structure found");
41 add_s("dmi.item","hardware_security");
42 add_hs(dmi
.hardware_security
.power_on_passwd_status
);
43 add_hs(dmi
.hardware_security
.keyboard_passwd_status
);
44 add_hs(dmi
.hardware_security
.administrator_passwd_status
);
45 add_hs(dmi
.hardware_security
.front_panel_reset_status
);
49 void dump_oem_strings(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
50 if (strlen(hardware
->dmi
.oem_strings
) == 0) {
52 add_s("dmi.warning","No OEM structure found");
57 add_s("dmi.item","OEM");
58 add_hs(dmi
.oem_strings
);
62 void dump_memory_size(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
64 add_s("dmi.item","memory size");
65 add_i("dmi.memory_size (KB)",hardware
->detected_memory_size
);
66 add_i("dmi.memory_size (MB)",(hardware
->detected_memory_size
+ (1 << 9)) >> 10);
70 void dump_memory_modules(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
72 if (hardware
->dmi
.memory_module_count
== 0) {
74 add_s("dmi.warning","No memory module structure found");
79 for (int module
=0; module
<hardware
->dmi
.memory_module_count
;module
++) {
80 if (hardware
->dmi
.memory_module
[module
].filled
== false) {
82 snprintf(msg
,sizeof(msg
),"Module %d doesn't contain any information", module
);
85 add_s("dmi.warning",msg
);
91 add_i("Memory module", module
);
92 add_s("dmi.memory_module.socket_designation", hardware
->dmi
.memory_module
[module
].socket_designation
);
93 add_s("dmi.memory_module.bank_connections", hardware
->dmi
.memory_module
[module
].bank_connections
);
94 add_s("dmi.memory_module.speed", hardware
->dmi
.memory_module
[module
].speed
);
95 add_s("dmi.memory_module.type", hardware
->dmi
.memory_module
[module
].type
);
96 add_s("dmi.memory_module.installed_size", hardware
->dmi
.memory_module
[module
].installed_size
);
97 add_s("dmi.memory_module.enabled_size", hardware
->dmi
.memory_module
[module
].enabled_size
);
98 add_s("dmi.memory_module.error_status", hardware
->dmi
.memory_module
[module
].error_status
);
103 void dump_cache(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
105 if (hardware
->dmi
.cache_count
== 0) {
107 add_s("dmi.warning","No cache structure found");
112 for (int cache
=0; cache
<hardware
->dmi
.cache_count
;cache
++) {
114 add_i("Cache", cache
);
115 add_s("dmi.cache.socket_designation", hardware
->dmi
.cache
[cache
].socket_designation
);
116 add_s("dmi.cache.configuration", hardware
->dmi
.cache
[cache
].configuration
);
117 add_s("dmi.cache.mode", hardware
->dmi
.cache
[cache
].mode
);
118 add_s("dmi.cache.location", hardware
->dmi
.cache
[cache
].location
);
119 add_i("dmi.cache.installed_size (KB)", hardware
->dmi
.cache
[cache
].installed_size
);
120 add_i("dmi.cache.max_size (KB)", hardware
->dmi
.cache
[cache
].max_size
);
121 add_s("dmi.cache.supported_sram_types", hardware
->dmi
.cache
[cache
].supported_sram_types
);
122 add_s("dmi.cache.installed_sram_types", hardware
->dmi
.cache
[cache
].installed_sram_types
);
123 add_i("dmi.cache.speed (ns)", hardware
->dmi
.cache
[cache
].speed
);
124 add_s("dmi.cache.error_correction_type", hardware
->dmi
.cache
[cache
].error_correction_type
);
125 add_s("dmi.cache.system_type", hardware
->dmi
.cache
[cache
].system_type
);
126 add_s("dmi.cache.associativity", hardware
->dmi
.cache
[cache
].associativity
);
130 void dump_memory_banks(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
132 if (hardware
->dmi
.memory_count
== 0) {
134 add_s("dmi.warning","No memory bank structure found");
139 for (int bank
=0; bank
<hardware
->dmi
.memory_count
;bank
++) {
141 if (hardware
->dmi
.memory
[bank
].filled
== false) {
143 snprintf(msg
,sizeof(msg
),"Bank %d doesn't contain any information", bank
);
146 add_s("dmi.warning",msg
);
152 add_i("Memory Bank", bank
);
153 add_s("dmi.memory.form_factor", hardware
->dmi
.memory
[bank
].form_factor
);
154 add_s("dmi.memory.type", hardware
->dmi
.memory
[bank
].type
);
155 add_s("dmi.memory.type_detail", hardware
->dmi
.memory
[bank
].type_detail
);
156 add_s("dmi.memory.speed", hardware
->dmi
.memory
[bank
].speed
);
157 add_s("dmi.memory.size", hardware
->dmi
.memory
[bank
].size
);
158 add_s("dmi.memory.device_set", hardware
->dmi
.memory
[bank
].device_set
);
159 add_s("dmi.memory.device_locator", hardware
->dmi
.memory
[bank
].device_locator
);
160 add_s("dmi.memory.bank_locator", hardware
->dmi
.memory
[bank
].bank_locator
);
161 add_s("dmi.memory.total_width", hardware
->dmi
.memory
[bank
].total_width
);
162 add_s("dmi.memory.data_width", hardware
->dmi
.memory
[bank
].data_width
);
163 add_s("dmi.memory.error", hardware
->dmi
.memory
[bank
].error
);
164 add_s("dmi.memory.vendor", hardware
->dmi
.memory
[bank
].manufacturer
);
165 add_s("dmi.memory.serial", hardware
->dmi
.memory
[bank
].serial
);
166 add_s("dmi.memory.asset_tag", hardware
->dmi
.memory
[bank
].asset_tag
);
167 add_s("dmi.memory.part_number", hardware
->dmi
.memory
[bank
].part_number
);
172 void dump_processor(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
173 if (hardware
->dmi
.processor
.filled
== false) {
175 add_s("dmi.warning","no processor structure found");
180 char voltage
[16]={0};
181 snprintf(voltage
,sizeof(voltage
),"%d.%02d",
182 hardware
->dmi
.processor
.voltage_mv
/ 1000,
183 hardware
->dmi
.processor
.voltage_mv
- ((hardware
->dmi
.processor
.voltage_mv
/ 1000) * 1000));
186 add_s("dmi.item","processor");
187 add_hs(dmi
.processor
.socket_designation
);
188 add_hs(dmi
.processor
.type
);
189 add_hs(dmi
.processor
.family
);
190 add_hs(dmi
.processor
.manufacturer
);
191 add_hs(dmi
.processor
.version
);
192 add_hi(dmi
.processor
.external_clock
);
193 add_hi(dmi
.processor
.max_speed
);
194 add_hi(dmi
.processor
.current_speed
);
195 add_hi(dmi
.processor
.signature
.type
);
196 add_hi(dmi
.processor
.signature
.family
);
197 add_hi(dmi
.processor
.signature
.model
);
198 add_hi(dmi
.processor
.signature
.stepping
);
199 add_hi(dmi
.processor
.signature
.minor_stepping
);
200 add_s("dmi.processor.voltage",voltage
);
201 add_hs(dmi
.processor
.status
);
202 add_hs(dmi
.processor
.upgrade
);
203 add_hs(dmi
.processor
.cache1
);
204 add_hs(dmi
.processor
.cache2
);
205 add_hs(dmi
.processor
.cache3
);
206 add_hs(dmi
.processor
.serial
);
207 add_hs(dmi
.processor
.part_number
);
208 add_hi(dmi
.processor
.core_count
);
209 add_hi(dmi
.processor
.core_enabled
);
210 add_hi(dmi
.processor
.thread_count
);
211 add_hs(dmi
.processor
.id
);
212 for (int i
= 0; i
< PROCESSOR_FLAGS_ELEMENTS
; i
++) {
213 if (((bool *) (&hardware
->dmi
.processor
.cpu_flags
))[i
] == true) {
214 add_s("dmi.processor.flag",(char *)cpu_flags_strings
[i
]);
220 void dump_battery(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
221 if (hardware
->dmi
.battery
.filled
== false) {
223 add_s("dmi.warning","no battery structure found");
229 add_s("dmi.item","battery");
230 add_hs(dmi
.battery
.manufacturer
);
231 add_hs(dmi
.battery
.manufacture_date
);
232 add_hs(dmi
.battery
.serial
);
233 add_hs(dmi
.battery
.name
);
234 add_hs(dmi
.battery
.chemistry
);
235 add_hs(dmi
.battery
.design_capacity
);
236 add_hs(dmi
.battery
.design_voltage
);
237 add_hs(dmi
.battery
.sbds
);
238 add_hs(dmi
.battery
.sbds_manufacture_date
);
239 add_hs(dmi
.battery
.sbds_chemistry
);
240 add_hs(dmi
.battery
.maximum_error
);
241 add_hs(dmi
.battery
.oem_info
);
245 void dump_ipmi(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
246 if (hardware
->dmi
.ipmi
.filled
== false) {
248 add_s("dmi.warning","no IPMI structure found");
253 char spec_ver
[16]={0};
256 snprintf(spec_ver
,sizeof(spec_ver
),"%u.%u",
257 hardware
->dmi
.ipmi
.major_specification_version
,
258 hardware
->dmi
.ipmi
.minor_specification_version
);
260 snprintf(i2c
,sizeof(i2c
),"0x%02x", hardware
->dmi
.ipmi
.I2C_slave_address
);
261 snprintf(base
,sizeof(base
),"%08X%08X",
262 (uint32_t)(hardware
->dmi
.ipmi
.base_address
>> 32),
263 (uint32_t)((hardware
->dmi
.ipmi
.base_address
& 0xFFFF) & ~1));
266 add_s("dmi.item","ipmi");
267 add_hs(dmi
.ipmi
.interface_type
);
268 add_s("dmi.ipmi.spec_version",spec_ver
);
269 add_hi(dmi
.ipmi
.I2C_slave_address
);
270 add_hi(dmi
.ipmi
.nv_address
);
271 add_s("dmi.ipmi.base_address",base
);
272 add_hi(dmi
.ipmi
.irq
);
276 void dump_chassis(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
277 if (hardware
->dmi
.chassis
.filled
== false) {
279 add_s("dmi.warning","no chassis structure found");
285 add_s("dmi.item","bios");
286 add_hs(dmi
.chassis
.manufacturer
);
287 add_hs(dmi
.chassis
.type
);
288 add_hs(dmi
.chassis
.lock
);
289 add_hs(dmi
.chassis
.version
);
290 add_hs(dmi
.chassis
.serial
);
291 add_s("dmi.chassis.asset_tag",del_multi_spaces(hardware
->dmi
.chassis
.asset_tag
));
292 add_hs(dmi
.chassis
.boot_up_state
);
293 add_hs(dmi
.chassis
.power_supply_state
);
294 add_hs(dmi
.chassis
.thermal_state
);
295 add_hs(dmi
.chassis
.security_status
);
296 add_hs(dmi
.chassis
.oem_information
);
297 add_hi(dmi
.chassis
.height
);
298 add_hi(dmi
.chassis
.nb_power_cords
);
302 void dump_bios(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
303 if (hardware
->dmi
.bios
.filled
== false) {
305 add_s("dmi.warning","no bios structure found");
309 char address
[16]={0};
310 char runtime
[16]={0};
312 snprintf(address
,sizeof(address
),"0x%04X0",hardware
->dmi
.bios
.address
);
313 snprintf(runtime
,sizeof(runtime
),"%u %s",hardware
->dmi
.bios
.runtime_size
, hardware
->dmi
.bios
.runtime_size_unit
);
314 snprintf(rom
,sizeof(rom
),"%u %s",hardware
->dmi
.bios
.rom_size
, hardware
->dmi
.bios
.rom_size_unit
);
317 add_s("dmi.item","bios");
318 add_hs(dmi
.bios
.vendor
);
319 add_hs(dmi
.bios
.version
);
320 add_hs(dmi
.bios
.release_date
);
321 add_hs(dmi
.bios
.bios_revision
);
322 add_hs(dmi
.bios
.firmware_revision
);
323 add_s("dmi.bios.address",address
);
324 add_s("dmi.bios.runtime_size",runtime
);
325 add_s("dmi.bios.rom_size",rom
);
326 for (int i
= 0; i
< BIOS_CHAR_NB_ELEMENTS
; i
++) {
327 if (((bool *) (&hardware
->dmi
.bios
.characteristics
))[i
] == true) {
328 add_s("dmi.bios.characteristics",(char *)bios_charac_strings
[i
]);
332 for (int i
= 0; i
< BIOS_CHAR_X1_NB_ELEMENTS
; i
++) {
333 if (((bool *) (&hardware
->dmi
.bios
.characteristics_x1
))[i
] == true) {
334 add_s("dmi.bios.characteristics",(char *)bios_charac_x1_strings
[i
]);
338 for (int i
= 0; i
< BIOS_CHAR_X2_NB_ELEMENTS
; i
++) {
339 if (((bool *) (&hardware
->dmi
.bios
.characteristics_x2
))[i
] == true) {
340 add_s("dmi.bios.characteristics",(char *)bios_charac_x2_strings
[i
]);
346 void dump_system(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
348 if (hardware
->dmi
.system
.filled
== false) {
350 add_s("dmi.warning","no system structure found");
354 char system_reset_status
[10]={0};
355 char watchdog_timer
[15]={0};
356 snprintf(system_reset_status
,sizeof(system_reset_status
),"%s", (hardware
->dmi
.system
.system_reset
.status
? "Enabled" :"Disabled"));
357 snprintf(watchdog_timer
,sizeof(watchdog_timer
),"%s", (hardware
->dmi
.system
.system_reset
.watchdog
? "Present" :"Not Present"));
360 add_s("dmi.item","system");
361 add_hs(dmi
.system
.manufacturer
);
362 add_hs(dmi
.system
.product_name
);
363 add_hs(dmi
.system
.version
);
364 add_hs(dmi
.system
.serial
);
365 add_hs(dmi
.system
.uuid
);
366 add_hs(dmi
.system
.wakeup_type
);
367 add_hs(dmi
.system
.sku_number
);
368 add_hs(dmi
.system
.family
);
369 add_hs(dmi
.system
.configuration_options
);
370 add_s("dmi.system.system_reset.status",system_reset_status
);
371 add_s("dmi.system.system_reset.watchdog",watchdog_timer
);
372 add_hs(dmi
.system
.system_reset
.boot_option
);
373 add_hs(dmi
.system
.system_reset
.boot_option_on_limit
);
374 add_hs(dmi
.system
.system_reset
.reset_count
);
375 add_hs(dmi
.system
.system_reset
.reset_limit
);
376 add_hs(dmi
.system
.system_reset
.timer_interval
);
377 add_hs(dmi
.system
.system_reset
.timeout
);
378 add_hs(dmi
.system
.system_boot_status
);
382 void dump_base_board(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
384 if (hardware
->dmi
.base_board
.filled
== false) {
386 add_s("dmi.warning","no base_board structure found");
392 add_s("dmi.item","base_board");
393 add_hs(dmi
.base_board
.manufacturer
);
394 add_hs(dmi
.base_board
.product_name
);
395 add_hs(dmi
.base_board
.version
);
396 add_hs(dmi
.base_board
.serial
);
397 add_hs(dmi
.base_board
.asset_tag
);
398 add_hs(dmi
.base_board
.location
);
399 add_hs(dmi
.base_board
.type
);
400 for (int i
= 0; i
< BASE_BOARD_NB_ELEMENTS
; i
++) {
401 if (((bool *) (&hardware
->dmi
.base_board
.features
))[i
] == true) {
402 add_s("dmi.base_board.features",(char *)base_board_features_strings
[i
]);
406 for (unsigned int i
= 0; i
< sizeof hardware
->dmi
.base_board
.devices_information
/
407 sizeof *hardware
->dmi
.base_board
.devices_information
; i
++) {
408 if (strlen(hardware
->dmi
.base_board
.devices_information
[i
].type
)) {
409 add_s("dmi.base_board.devices_information.type", hardware
->dmi
.base_board
.devices_information
[i
].type
);
410 add_i("dmi.base_board.devices_information.status", hardware
->dmi
.base_board
.devices_information
[i
].status
);
411 add_s("dmi.base_board.devices_information.description", hardware
->dmi
.base_board
.devices_information
[i
].description
);
417 void dump_dmi(struct s_hardware
*hardware
, ZZJSON_CONFIG
*config
, ZZJSON
**item
) {
420 add_hb(is_dmi_valid
);
422 if (hardware
->is_dmi_valid
== false) {
427 snprintf(buffer
,sizeof(buffer
),"%d.%d",hardware
->dmi
.dmitable
.major_version
, hardware
->dmi
.dmitable
.minor_version
);
428 add_s("dmi.version",buffer
);
432 dump_base_board(hardware
,config
,item
);
433 dump_system(hardware
,config
,item
);
434 dump_bios(hardware
,config
,item
);
435 dump_chassis(hardware
,config
,item
);
436 dump_ipmi(hardware
,config
,item
);
437 dump_battery(hardware
,config
,item
);
438 dump_processor(hardware
,config
,item
);
439 dump_cache(hardware
,config
,item
);
440 dump_memory_banks(hardware
,config
,item
);
441 dump_memory_modules(hardware
,config
,item
);
442 dump_memory_size(hardware
,config
,item
);
443 dump_oem_strings(hardware
,config
,item
);
444 dump_hardware_security(hardware
,config
,item
);