4 #define ldmilib_c /* Define the library */
6 /* Include the Lua API header files */
12 extern void add_string_item(lua_State
*, const char*, const char*);
13 extern void add_int_item(lua_State
*, const char*, int);
14 typedef int (*table_fn
)(lua_State
*, s_dmi
*);
16 /* Add a Lua_String entry to the table on stack
17 xxx_P is the poiter version (i.e., pBase is a pointer)
18 xxx_S is the staic version (i.e., Base is the struct)
20 #define LUA_ADD_STR_P(pLua_state, pBase, Field) \
21 add_string_item(pLua_state, #Field, pBase->Field);
22 #define LUA_ADD_STR_S(pLua_state, Base, Field) \
23 add_string_item(pLua_state, #Field, Base.Field);
25 /* Add a Lua_Number entry to the table on stack
26 xxx_P is the poiter version (i.e., pBase is a pointer)
27 xxx_S is the staic version (i.e., Base is the struct)
29 #define LUA_ADD_NUM_P(pLua_state, pBase, Field) \
30 add_int_item(pLua_state, #Field, pBase->Field);
31 #define LUA_ADD_NUM_S(pLua_state, Base, Field) \
32 add_int_item(pLua_state, #Field, Base.Field);
34 /* Add a sub-DMI table to the table on stack
35 All (*table_fn)() have to be named as get_<tabel_name>_table() for this
36 macro to work. For example, for the bios subtable, the table_fn is
37 get_bios_table() and the subtable name is "bios".
38 All (*table_fn)() have to return 1 if a subtable is created on the stack
39 or 0 if the subtable is not created (no corresponding dim subtable found).
41 #define LUA_ADD_TABLE(pLua_state, pDmi, tb_name) \
42 add_dmi_sub_table(pLua_state, pDmi, #tb_name, get_ ## tb_name ## _table);
45 static void add_dmi_sub_table(lua_State
*L
, s_dmi
*dmi_ptr
, char *table_name
,
46 table_fn get_table_fn
)
48 if (get_table_fn(L
, dmi_ptr
)) { /* only adding it when it is there */
49 lua_pushstring(L
, table_name
);
56 void get_bool_table(lua_State
*L
, const char *str_table
[], int n_elem
,
60 for (i
= 0; i
< n_elem
; i
++) {
61 if (!str_table
[i
] || !*str_table
[i
]) /* aviod NULL/empty string */
64 lua_pushstring(L
, str_table
[i
]);
65 lua_pushboolean(L
, bool_table
[i
]);
72 ** {======================================================
74 ** =======================================================
76 static int get_bios_table(lua_State
*L
, s_dmi
*dmi_ptr
)
78 s_bios
*bios
= &dmi_ptr
->bios
;
84 LUA_ADD_STR_P(L
, bios
, vendor
)
85 LUA_ADD_STR_P(L
, bios
, version
)
86 LUA_ADD_STR_P(L
, bios
, release_date
)
87 LUA_ADD_STR_P(L
, bios
, bios_revision
)
88 LUA_ADD_STR_P(L
, bios
, firmware_revision
)
89 LUA_ADD_NUM_P(L
, bios
, address
)
90 LUA_ADD_NUM_P(L
, bios
, runtime_size
)
91 LUA_ADD_STR_P(L
, bios
, runtime_size_unit
)
92 LUA_ADD_NUM_P(L
, bios
, rom_size
)
93 LUA_ADD_STR_P(L
, bios
, rom_size_unit
)
95 /* bios characteristics */
96 lua_pushstring(L
, "chars");
98 get_bool_table(L
, bios_charac_strings
,
99 sizeof(s_characteristics
)/sizeof(bool),
100 (bool *)(&bios
->characteristics
));
101 get_bool_table(L
, bios_charac_x1_strings
,
102 sizeof(s_characteristics_x1
)/sizeof(bool),
103 (bool *)(&bios
->characteristics_x1
));
104 get_bool_table(L
, bios_charac_x2_strings
,
105 sizeof(s_characteristics_x2
)/sizeof(bool),
106 (bool *)(&bios
->characteristics_x2
));
113 static int get_system_table(lua_State
*L
, s_dmi
*dmi_ptr
)
115 s_system
*system
= &dmi_ptr
->system
;
121 LUA_ADD_STR_P(L
, system
, manufacturer
)
122 LUA_ADD_STR_P(L
, system
, product_name
)
123 LUA_ADD_STR_P(L
, system
, version
)
124 LUA_ADD_STR_P(L
, system
, serial
)
125 LUA_ADD_STR_P(L
, system
, uuid
)
126 LUA_ADD_STR_P(L
, system
, wakeup_type
)
127 LUA_ADD_STR_P(L
, system
, sku_number
)
128 LUA_ADD_STR_P(L
, system
, family
)
129 LUA_ADD_STR_P(L
, system
, system_boot_status
)
130 LUA_ADD_STR_P(L
, system
, configuration_options
)
133 if (system
->system_reset
.filled
) {
134 lua_pushstring(L
, "reset");
136 LUA_ADD_NUM_S(L
, system
->system_reset
, status
)
137 LUA_ADD_NUM_S(L
, system
->system_reset
, watchdog
)
138 LUA_ADD_STR_S(L
, system
->system_reset
, boot_option
)
139 LUA_ADD_STR_S(L
, system
->system_reset
, boot_option_on_limit
)
140 LUA_ADD_STR_S(L
, system
->system_reset
, reset_count
)
141 LUA_ADD_STR_S(L
, system
->system_reset
, reset_limit
)
142 LUA_ADD_STR_S(L
, system
->system_reset
, timer_interval
)
143 LUA_ADD_STR_S(L
, system
->system_reset
, timeout
)
151 static int get_base_board_table(lua_State
*L
, s_dmi
*dmi_ptr
)
153 s_base_board
*base_board
= &dmi_ptr
->base_board
;
154 int n_dev
= sizeof(base_board
->devices_information
) /
155 sizeof(base_board
->devices_information
[0]);
158 if (!base_board
->filled
)
162 LUA_ADD_STR_P(L
, base_board
, manufacturer
)
163 LUA_ADD_STR_P(L
, base_board
, product_name
)
164 LUA_ADD_STR_P(L
, base_board
, version
)
165 LUA_ADD_STR_P(L
, base_board
, serial
)
166 LUA_ADD_STR_P(L
, base_board
, asset_tag
)
167 LUA_ADD_STR_P(L
, base_board
, location
)
168 LUA_ADD_STR_P(L
, base_board
, type
)
170 /* base board features */
171 lua_pushstring(L
, "features");
173 get_bool_table(L
, base_board_features_strings
,
174 sizeof(s_base_board_features
)/sizeof(bool),
175 (bool *)(&base_board
->features
));
178 /* on-board devices */
179 for (has_dev
= 0, i
= 0; i
< n_dev
; i
++)
180 if (*base_board
->devices_information
[i
].type
)
184 lua_pushstring(L
, "devices");
186 for (i
= 0, j
= 1; i
< n_dev
; i
++) {
187 if (!*base_board
->devices_information
[i
].type
) /* empty device */
190 lua_pushinteger(L
, j
++);
192 LUA_ADD_STR_S(L
, base_board
->devices_information
[i
], type
)
193 LUA_ADD_STR_S(L
, base_board
->devices_information
[i
], description
)
194 LUA_ADD_NUM_S(L
, base_board
->devices_information
[i
], status
)
204 static int get_chassis_table(lua_State
*L
, s_dmi
*dmi_ptr
)
206 s_chassis
*chassis
= &dmi_ptr
->chassis
;
208 if (!chassis
->filled
)
212 LUA_ADD_STR_P(L
, chassis
, manufacturer
)
213 LUA_ADD_STR_P(L
, chassis
, type
)
214 LUA_ADD_STR_P(L
, chassis
, lock
)
215 LUA_ADD_STR_P(L
, chassis
, version
)
216 LUA_ADD_STR_P(L
, chassis
, serial
)
217 LUA_ADD_STR_P(L
, chassis
, asset_tag
)
218 LUA_ADD_STR_P(L
, chassis
, boot_up_state
)
219 LUA_ADD_STR_P(L
, chassis
, power_supply_state
)
220 LUA_ADD_STR_P(L
, chassis
, thermal_state
)
221 LUA_ADD_STR_P(L
, chassis
, security_status
)
222 LUA_ADD_STR_P(L
, chassis
, oem_information
)
223 LUA_ADD_NUM_P(L
, chassis
, height
)
224 LUA_ADD_NUM_P(L
, chassis
, nb_power_cords
)
230 static int get_processor_table(lua_State
*L
, s_dmi
*dmi_ptr
)
232 s_processor
*processor
= &dmi_ptr
->processor
;
233 s_signature
*signature
= &processor
->signature
;
235 if (!processor
->filled
)
239 LUA_ADD_STR_P(L
, processor
, socket_designation
)
240 LUA_ADD_STR_P(L
, processor
, type
)
241 LUA_ADD_STR_P(L
, processor
, family
)
242 LUA_ADD_STR_P(L
, processor
, manufacturer
)
243 LUA_ADD_STR_P(L
, processor
, version
)
244 LUA_ADD_NUM_P(L
, processor
, external_clock
)
245 LUA_ADD_NUM_P(L
, processor
, max_speed
)
246 LUA_ADD_NUM_P(L
, processor
, current_speed
)
247 LUA_ADD_NUM_P(L
, processor
, voltage_mv
)
248 LUA_ADD_STR_P(L
, processor
, status
)
249 LUA_ADD_STR_P(L
, processor
, upgrade
)
250 LUA_ADD_STR_P(L
, processor
, cache1
)
251 LUA_ADD_STR_P(L
, processor
, cache2
)
252 LUA_ADD_STR_P(L
, processor
, cache3
)
253 LUA_ADD_STR_P(L
, processor
, serial
)
254 LUA_ADD_STR_P(L
, processor
, part_number
)
255 LUA_ADD_STR_P(L
, processor
, id
)
256 LUA_ADD_NUM_P(L
, processor
, core_count
)
257 LUA_ADD_NUM_P(L
, processor
, core_enabled
)
258 LUA_ADD_NUM_P(L
, processor
, thread_count
)
260 /* processor signature */
261 lua_pushstring(L
, "signature");
263 LUA_ADD_NUM_P(L
, signature
, type
)
264 LUA_ADD_NUM_P(L
, signature
, family
)
265 LUA_ADD_NUM_P(L
, signature
, model
)
266 LUA_ADD_NUM_P(L
, signature
, stepping
)
267 LUA_ADD_NUM_P(L
, signature
, minor_stepping
)
270 /* processor flags */
271 lua_pushstring(L
, "flags");
273 get_bool_table(L
, cpu_flags_strings
,
274 sizeof(s_dmi_cpu_flags
)/sizeof(bool),
275 (bool *)(&processor
->cpu_flags
));
282 static int get_battery_table(lua_State
*L
, s_dmi
*dmi_ptr
)
284 s_battery
*battery
= &dmi_ptr
->battery
;
286 if (!battery
->filled
)
290 LUA_ADD_STR_P(L
, battery
, location
)
291 LUA_ADD_STR_P(L
, battery
, manufacturer
)
292 LUA_ADD_STR_P(L
, battery
, manufacture_date
)
293 LUA_ADD_STR_P(L
, battery
, serial
)
294 LUA_ADD_STR_P(L
, battery
, name
)
295 LUA_ADD_STR_P(L
, battery
, chemistry
)
296 LUA_ADD_STR_P(L
, battery
, design_capacity
)
297 LUA_ADD_STR_P(L
, battery
, design_voltage
)
298 LUA_ADD_STR_P(L
, battery
, sbds
)
299 LUA_ADD_STR_P(L
, battery
, sbds_serial
)
300 LUA_ADD_STR_P(L
, battery
, maximum_error
)
301 LUA_ADD_STR_P(L
, battery
, sbds_manufacture_date
)
302 LUA_ADD_STR_P(L
, battery
, sbds_chemistry
)
303 LUA_ADD_STR_P(L
, battery
, oem_info
)
309 static int get_memory_table(lua_State
*L
, s_dmi
*dmi_ptr
)
311 s_memory
*memory
= dmi_ptr
->memory
;
312 int i
, j
, n_mem
= dmi_ptr
->memory_count
;
314 if (n_mem
<= 0) /* no memory info */
319 for (j
= 1, i
= 0; i
< n_mem
; i
++) {
320 if (!memory
[i
].filled
)
323 lua_pushinteger(L
, j
++);
325 LUA_ADD_STR_S(L
, memory
[i
], manufacturer
)
326 LUA_ADD_STR_S(L
, memory
[i
], error
)
327 LUA_ADD_STR_S(L
, memory
[i
], total_width
)
328 LUA_ADD_STR_S(L
, memory
[i
], data_width
)
329 LUA_ADD_STR_S(L
, memory
[i
], size
)
330 LUA_ADD_STR_S(L
, memory
[i
], form_factor
)
331 LUA_ADD_STR_S(L
, memory
[i
], device_set
)
332 LUA_ADD_STR_S(L
, memory
[i
], device_locator
)
333 LUA_ADD_STR_S(L
, memory
[i
], bank_locator
)
334 LUA_ADD_STR_S(L
, memory
[i
], type
)
335 LUA_ADD_STR_S(L
, memory
[i
], type_detail
)
336 LUA_ADD_STR_S(L
, memory
[i
], speed
)
337 LUA_ADD_STR_S(L
, memory
[i
], serial
)
338 LUA_ADD_STR_S(L
, memory
[i
], asset_tag
)
339 LUA_ADD_STR_S(L
, memory
[i
], part_number
)
346 static int get_memory_module_table(lua_State
*L
, s_dmi
*dmi_ptr
)
348 s_memory_module
*memory_module
= dmi_ptr
->memory_module
;
349 int i
, j
, n_mem
= dmi_ptr
->memory_module_count
;
351 if (n_mem
<= 0) /* no memory module info */
356 for (j
= 1, i
= 0; i
< n_mem
; i
++) {
357 if (!memory_module
[i
].filled
)
360 lua_pushinteger(L
, j
++);
362 LUA_ADD_STR_S(L
, memory_module
[i
], socket_designation
)
363 LUA_ADD_STR_S(L
, memory_module
[i
], bank_connections
)
364 LUA_ADD_STR_S(L
, memory_module
[i
], speed
)
365 LUA_ADD_STR_S(L
, memory_module
[i
], type
)
366 LUA_ADD_STR_S(L
, memory_module
[i
], installed_size
)
367 LUA_ADD_STR_S(L
, memory_module
[i
], enabled_size
)
368 LUA_ADD_STR_S(L
, memory_module
[i
], error_status
)
375 static int get_cache_table(lua_State
*L
, s_dmi
*dmi_ptr
)
377 s_cache
*cache
= dmi_ptr
->cache
;
378 int i
, n_cache
= dmi_ptr
->cache_count
;
380 if (n_cache
<= 0) /* no cache info */
385 for (i
= 0; i
< n_cache
; i
++) {
386 lua_pushinteger(L
, i
+ 1);
388 LUA_ADD_STR_S(L
, cache
[i
], socket_designation
)
389 LUA_ADD_STR_S(L
, cache
[i
], configuration
)
390 LUA_ADD_STR_S(L
, cache
[i
], mode
)
391 LUA_ADD_STR_S(L
, cache
[i
], location
)
392 LUA_ADD_NUM_S(L
, cache
[i
], installed_size
)
393 LUA_ADD_NUM_S(L
, cache
[i
], max_size
)
394 LUA_ADD_STR_S(L
, cache
[i
], supported_sram_types
)
395 LUA_ADD_STR_S(L
, cache
[i
], installed_sram_types
)
396 LUA_ADD_NUM_S(L
, cache
[i
], speed
)
397 LUA_ADD_STR_S(L
, cache
[i
], error_correction_type
)
398 LUA_ADD_STR_S(L
, cache
[i
], system_type
)
399 LUA_ADD_STR_S(L
, cache
[i
], associativity
)
406 static int get_hardware_security_table(lua_State
*L
, s_dmi
*dmi_ptr
)
408 if (!dmi_ptr
->hardware_security
.filled
)
410 /* hardware_security */
412 LUA_ADD_STR_S(L
, dmi_ptr
->hardware_security
, power_on_passwd_status
)
413 LUA_ADD_STR_S(L
, dmi_ptr
->hardware_security
, keyboard_passwd_status
)
414 LUA_ADD_STR_S(L
, dmi_ptr
->hardware_security
, administrator_passwd_status
)
415 LUA_ADD_STR_S(L
, dmi_ptr
->hardware_security
, front_panel_reset_status
)
421 static int get_dmi_info_table(lua_State
*L
, s_dmi
*dmi_ptr
)
423 dmi_table
*dmitable
= &dmi_ptr
->dmitable
;
427 LUA_ADD_NUM_P(L
, dmitable
, num
)
428 LUA_ADD_NUM_P(L
, dmitable
, len
)
429 LUA_ADD_NUM_P(L
, dmitable
, ver
)
430 LUA_ADD_NUM_P(L
, dmitable
, base
)
431 LUA_ADD_NUM_P(L
, dmitable
, major_version
)
432 LUA_ADD_NUM_P(L
, dmitable
, minor_version
)
438 static int get_ipmi_table(lua_State
*L
, s_dmi
*dmi_ptr
)
440 s_ipmi
*ipmi
= &dmi_ptr
->ipmi
;
446 LUA_ADD_STR_P(L
, ipmi
, interface_type
)
447 LUA_ADD_NUM_P(L
, ipmi
, major_specification_version
)
448 LUA_ADD_NUM_P(L
, ipmi
, minor_specification_version
)
449 LUA_ADD_NUM_P(L
, ipmi
, I2C_slave_address
)
450 LUA_ADD_NUM_P(L
, ipmi
, nv_address
)
451 LUA_ADD_NUM_P(L
, ipmi
, base_address
)
452 LUA_ADD_NUM_P(L
, ipmi
, irq
)
457 ** {======================================================
458 ** End of DMI subtables
459 ** =======================================================
463 static int dmi_gettable(lua_State
*L
)
469 if ( ! dmi_iterate(&dmi
) ) {
470 printf("No DMI Structure found\n");
474 parse_dmitable(&dmi
);
476 LUA_ADD_NUM_S(L
, dmi
, memory_module_count
)
477 LUA_ADD_NUM_S(L
, dmi
, memory_count
)
478 LUA_ADD_NUM_S(L
, dmi
, cache_count
)
479 LUA_ADD_STR_S(L
, dmi
, oem_strings
)
481 LUA_ADD_TABLE(L
, &dmi
, bios
)
482 LUA_ADD_TABLE(L
, &dmi
, system
)
483 LUA_ADD_TABLE(L
, &dmi
, base_board
)
484 LUA_ADD_TABLE(L
, &dmi
, chassis
)
485 LUA_ADD_TABLE(L
, &dmi
, processor
)
486 LUA_ADD_TABLE(L
, &dmi
, battery
)
487 LUA_ADD_TABLE(L
, &dmi
, memory
)
488 LUA_ADD_TABLE(L
, &dmi
, memory_module
)
489 LUA_ADD_TABLE(L
, &dmi
, cache
)
490 LUA_ADD_TABLE(L
, &dmi
, ipmi
)
491 LUA_ADD_TABLE(L
, &dmi
, hardware_security
)
492 LUA_ADD_TABLE(L
, &dmi
, dmi_info
)
494 /* set global variable: lua_setglobal(L, "dmitable"); */
496 /* return number of return values on stack */
501 static int dmi_supported(lua_State
*L
)
505 if ( dmi_iterate(&dmi
) ) {
506 lua_pushboolean(L
, 1);
508 lua_pushboolean(L
, 0);
514 static const luaL_Reg dmilib
[] = {
515 {"gettable", dmi_gettable
},
516 {"supported", dmi_supported
},
521 LUALIB_API
int luaopen_dmi (lua_State
*L
) {
522 luaL_openlib(L
, LUA_DMILIBNAME
, dmilib
, 0);