aboutsummaryrefslogtreecommitdiffstats
path: root/com32/hdt/hdt-cli-dmi.c
blob: 313445cdcdfe46fd9e3dc495a912862bdbf67965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2009 Erwan Velu - All Rights Reserved
 *
 *   Permission is hereby granted, free of charge, to any person
 *   obtaining a copy of this software and associated documentation
 *   files (the "Software"), to deal in the Software without
 *   restriction, including without limitation the rights to use,
 *   copy, modify, merge, publish, distribute, sublicense, and/or
 *   sell copies of the Software, and to permit persons to whom
 *   the Software is furnished to do so, subject to the following
 *   conditions:
 *
 *   The above copyright notice and this permission notice shall
 *   be included in all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *   OTHER DEALINGS IN THE SOFTWARE.
 *
 * -----------------------------------------------------------------------
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

#include "hdt-cli.h"
#include "hdt-common.h"

static void show_dmi_modules(int argc __unused, char **argv __unused,
			     struct s_hardware *hardware)
{
    char available_dmi_commands[1024];
    reset_more_printf();
    memset(available_dmi_commands, 0, sizeof(available_dmi_commands));

    more_printf("Available DMI modules on your system:\n");
    if (hardware->dmi.base_board.filled == true)
	more_printf("\t%s\n", CLI_DMI_BASE_BOARD);
    if (hardware->dmi.battery.filled == true)
	more_printf("\t%s\n", CLI_DMI_BATTERY);
    if (hardware->dmi.bios.filled == true)
	more_printf("\t%s\n", CLI_DMI_BIOS);
    if (hardware->dmi.chassis.filled == true)
	more_printf("\t%s\n", CLI_DMI_CHASSIS);
    for (int i = 0; i < hardware->dmi.memory_count; i++) {
	if (hardware->dmi.memory[i].filled == true) {
	    more_printf("\tbank <number>\n");
	    break;
	}
    }
    for (int i = 0; i < hardware->dmi.memory_module_count; i++) {
	if (hardware->dmi.memory_module[i].filled == true) {
	    more_printf("\tmodule <number>\n");
	    break;
	}
    }
    if (hardware->dmi.processor.filled == true)
	more_printf("\t%s\n", CLI_DMI_PROCESSOR);
    if (hardware->dmi.system.filled == true)
	more_printf("\t%s\n", CLI_DMI_SYSTEM);
    if (hardware->dmi.ipmi.filled == true)
	more_printf("\t%s\n", CLI_DMI_IPMI);
    if (hardware->dmi.cache_count)
	more_printf("\t%s\n", CLI_DMI_CACHE);
    if (strlen(hardware->dmi.oem_strings))
	more_printf("\t%s\n", CLI_DMI_OEM);
    if (hardware->dmi.hardware_security.filled)
	more_printf("\t%s\n", CLI_DMI_SECURITY);
}

static void show_dmi_base_board(int argc __unused, char **argv __unused,
				struct s_hardware *hardware)
{
    if (hardware->dmi.base_board.filled == false) {
	more_printf("base_board information not found on your system, see "
		    "`show list' to see which module is available.\n");
	return;
    }
    reset_more_printf();
    more_printf("Base board\n");
    more_printf(" Manufacturer : %s\n", hardware->dmi.base_board.manufacturer);
    more_printf(" Product Name : %s\n", hardware->dmi.base_board.product_name);
    more_printf(" Version      : %s\n", hardware->dmi.base_board.version);
    more_printf(" Serial       : %s\n", hardware->dmi.base_board.serial);
    more_printf(" Asset Tag    : %s\n", hardware->dmi.base_board.asset_tag);
    more_printf(" Location     : %s\n", hardware->dmi.base_board.location);
    more_printf(" Type         : %s\n", hardware->dmi.base_board.type);
    for (int i = 0; i < BASE_BOARD_NB_ELEMENTS; i++) {
	if (((bool *) (&hardware->dmi.base_board.features))[i] == true) {
	    more_printf(" %s\n", base_board_features_strings[i]);
	}
    }

    for (unsigned int i = 0;
	 i <
	 sizeof hardware->dmi.base_board.devices_information /
	 sizeof *hardware->dmi.base_board.devices_information; i++) {
	if (strlen(hardware->dmi.base_board.devices_information[i].type)) {
	    more_printf("On Board Device #%u Information\n", i)
		more_printf("  Type        : %s\n",
			    hardware->dmi.base_board.devices_information[i].
			    type);
	    more_printf("  Status      : %s\n",
			hardware->dmi.base_board.devices_information[i].
			status ? "Enabled" : "Disabled");
	    more_printf("  Description : %s\n",
			hardware->dmi.base_board.devices_information[i].
			description);
	}
    }
}

static void show_dmi_system(int argc __unused, char **argv __unused,
			    struct s_hardware *hardware)
{
    if (hardware->dmi.system.filled == false) {
	more_printf("system information not found on your system, see "
		    "`show list' to see which module is available.\n");
	return;
    }
    reset_more_printf();
    more_printf("System\n");
    more_printf(" Manufacturer : %s\n", hardware->dmi.system.manufacturer);
    more_printf(" Product Name : %s\n", hardware->dmi.system.product_name);
    more_printf(" Version      : %s\n", hardware->dmi.system.version);
    more_printf(" Serial       : %s\n", hardware->dmi.system.serial);
    more_printf(" UUID         : %s\n", hardware->dmi.system.uuid);
    more_printf(" Wakeup Type  : %s\n", hardware->dmi.system.wakeup_type);
    more_printf(" SKU Number   : %s\n", hardware->dmi.system.sku_number);
    more_printf(" Family       : %s\n", hardware->dmi.system.family);

    if (strlen(hardware->dmi.system.configuration_options)) {
	more_printf("System Configuration Options\n");
	more_printf("%s\n", hardware->dmi.system.configuration_options);
    }

    if (hardware->dmi.system.system_reset.filled) {
	more_printf("System Reset\n");
	more_printf("  Status               : %s\n",
		    (hardware->dmi.system.system_reset.
		     status ? "Enabled" : "Disabled"));
	more_printf("  Watchdog Timer       : %s\n",
		    (hardware->dmi.system.system_reset.
		     watchdog ? "Present" : "Not Present"));
	if (strlen(hardware->dmi.system.system_reset.boot_option))
	    more_printf("  Boot Option          : %s\n",
			hardware->dmi.system.system_reset.boot_option);
	if (strlen(hardware->dmi.system.system_reset.boot_option_on_limit))
	    more_printf("  Boot Option On Limit : %s\n",
			hardware->dmi.system.system_reset.boot_option_on_limit);
	if (strlen(hardware->dmi.system.system_reset.reset_count))
	    more_printf("  Reset Count          : %s\n",
			hardware->dmi.system.system_reset.reset_count);
	if (strlen(hardware->dmi.system.system_reset.reset_limit))
	    more_printf("  Reset Limit          : %s\n",
			hardware->dmi.system.system_reset.reset_limit);
	if (strlen(hardware->dmi.system.system_reset.timer_interval))
	    more_printf("  Timer Interval       : %s\n",
			hardware->dmi.system.system_reset.timer_interval);
	if (strlen(hardware->dmi.system.system_reset.timeout))
	    more_printf("  Timeout              : %s\n",
			hardware->dmi.system.system_reset.timeout);
    }

    more_printf("System Boot Information\n");
    more_printf(" Status       : %s\n",
		hardware->dmi.system.system_boot_status);
}

static void show_dmi_bios(int argc __unused, char **argv __unused,
			  struct s_hardware *hardware)
{
    if (hardware->dmi.bios.filled == false) {
	more_printf("bios information not found on your system, see "
		    "`show list' to see which module is available.\n");
	return;
    }
    reset_more_printf();
    more_printf("BIOS\n");
    more_printf(" Vendor            : %s\n", hardware->dmi.bios.vendor);
    more_printf(" Version           : %s\n", hardware->dmi.bios.version);
    more_printf(" Release Date      : %s\n", hardware->dmi.bios.release_date);
    more_printf(" Bios Revision     : %s\n", hardware->dmi.bios.bios_revision);
    if (strlen(hardware->dmi.bios.firmware_revision))
	more_printf(" Firmware Revision : %s\n",
		    hardware->dmi.bios.firmware_revision);
    more_printf(" Address           : 0x%04X0\n", hardware->dmi.bios.address);
    more_printf(" Runtime address   : %u %s\n",
		hardware->dmi.bios.runtime_size,
		hardware->dmi.bios.runtime_size_unit);
    more_printf(" Rom size          : %u %s\n", hardware->dmi.bios.rom_size,
		hardware->dmi.bios.rom_size_unit);

    for (int i = 0; i < BIOS_CHAR_NB_ELEMENTS; i++) {
	if (((bool *) (&hardware->dmi.bios.characteristics))[i] == true) {
	    more_printf(" %s\n", bios_charac_strings[i]);
	}
    }
    for (int i = 0; i < BIOS_CHAR_X1_NB_ELEMENTS; i++) {
	if (((bool *) (&hardware->dmi.bios.characteristics_x1))[i] == true) {
	    more_printf(" %s\n", bios_charac_x1_strings[i]);
	}
    }

    for (int i = 0; i < BIOS_CHAR_X2_NB_ELEMENTS; i++) {
	if (((bool *) (&hardware->dmi.bios.characteristics_x2))[i] == true) {
	    more_printf(" %s\n", bios_charac_x2_strings[i]);
	}
    }

}

static void show_dmi_chassis(int argc __unused, char **argv __unused,
			     struct s_hardware *hardware)
{
    if (hardware->dmi.chassis.filled == false) {
	more_printf("chassis information not found on your system, see "
		    "`show list' to see which module is available.\n");
	return;
    }
    reset_more_printf();
    more_printf("Chassis\n");
    more_printf(" Manufacturer       : %s\n",
		hardware->dmi.chassis.manufacturer);
    more_printf(" Type               : %s\n", hardware->dmi.chassis.type);
    more_printf(" Lock               : %s\n", hardware->dmi.chassis.lock);
    more_printf(" Version            : %s\n", hardware->dmi.chassis.version);
    more_printf(" Serial             : %s\n", hardware->dmi.chassis.serial);
    more_printf(" Asset Tag          : %s\n",
		del_multi_spaces(hardware->dmi.chassis.asset_tag));
    more_printf(" Boot up state      : %s\n",
		hardware->dmi.chassis.boot_up_state);
    more_printf(" Power supply state : %s\n",
		hardware->dmi.chassis.power_supply_state);
    more_printf(" Thermal state      : %s\n",
		hardware->dmi.chassis.thermal_state);
    more_printf(" Security Status    : %s\n",
		hardware->dmi.chassis.security_status);
    more_printf(" OEM Information    : %s\n",
		hardware->dmi.chassis.oem_information);
    more_printf(" Height             : %u\n", hardware->dmi.chassis.height);
    more_printf(" NB Power Cords     : %u\n",
		hardware->dmi.chassis.nb_power_cords);
}

static void show_dmi_ipmi(int argc __unused, char **argv __unused,
			  struct s_hardware *hardware)
{
    if (hardware->dmi.ipmi.filled == false) {
	more_printf("IPMI module not available\n");
	return;
    }
    reset_more_printf();
    more_printf("IPMI\n");
    more_printf(" Interface Type     : %s\n",
		hardware->dmi.ipmi.interface_type);
    more_printf(" Specification Ver. : %u.%u\n",
		hardware->dmi.ipmi.major_specification_version,
		hardware->dmi.ipmi.minor_specification_version);
    more_printf(" I2C Slave Address  : 0x%02x\n",
		hardware->dmi.ipmi.I2C_slave_address);
    more_printf(" Nv Storage Address : %u\n", hardware->dmi.ipmi.nv_address);
    uint32_t high = hardware->dmi.ipmi.base_address >> 32;
    uint32_t low = hardware->dmi.ipmi.base_address & 0xFFFF;
    more_printf(" Base Address       : %08X%08X\n", high, (low & ~1));
    more_printf(" IRQ                : %d\n", hardware->dmi.ipmi.irq);
}

static void show_dmi_battery(int argc __unused, char **argv __unused,
			     struct s_hardware *hardware)
{
    if (hardware->dmi.battery.filled == false) {
	more_printf("battery information not found on your system, see "
		    "`show list' to see which module is available.\n");
	return;
    }
    reset_more_printf();
    more_printf("Battery \n");
    more_printf(" Vendor             : %s\n",
		hardware->dmi.battery.manufacturer);
    more_printf(" Manufacture Date   : %s\n",
		hardware->dmi.battery.manufacture_date);
    more_printf(" Serial             : %s\n", hardware->dmi.battery.serial);
    more_printf(" Name               : %s\n", hardware->dmi.battery.name);
    more_printf(" Chemistry          : %s\n", hardware->dmi.battery.chemistry);
    more_printf(" Design Capacity    : %s\n",
		hardware->dmi.battery.design_capacity);
    more_printf(" Design Voltage     : %s\n",
		hardware->dmi.battery.design_voltage);
    more_printf(" SBDS               : %s\n", hardware->dmi.battery.sbds);
    more_printf(" SBDS Manuf. Date   : %s\n",
		hardware->dmi.battery.sbds_manufacture_date);
    more_printf(" SBDS Chemistry     : %s\n",
		hardware->dmi.battery.sbds_chemistry);
    more_printf(" Maximum Error      : %s\n",
		hardware->dmi.battery.maximum_error);
    more_printf(" OEM Info           : %s\n", hardware->dmi.battery.oem_info);
}

static void show_dmi_cpu(int argc __unused, char **argv __unused,
			 struct s_hardware *hardware)
{
    if (hardware->dmi.processor.filled == false) {
	more_printf("processor information not found on your system, see "
		    "`show list' to see which module is available.\n");
	return;
    }
    reset_more_printf();
    more_printf("CPU\n");
    more_printf(" Socket Designation : %s\n",
		hardware->dmi.processor.socket_designation);
    more_printf(" Type               : %s\n", hardware->dmi.processor.type);
    more_printf(" Family             : %s\n", hardware->dmi.processor.family);
    more_printf(" Manufacturer       : %s\n",
		hardware->dmi.processor.manufacturer);
    more_printf(" Version            : %s\n", hardware->dmi.processor.version);
    more_printf(" External Clock     : %u\n",
		hardware->dmi.processor.external_clock);
    more_printf(" Max Speed          : %u\n",
		hardware->dmi.processor.max_speed);
    more_printf(" Current Speed      : %u\n",
		hardware->dmi.processor.current_speed);
    more_printf(" Cpu Type           : %u\n",
		hardware->dmi.processor.signature.type);
    more_printf(" Cpu Family         : %u\n",
		hardware->dmi.processor.signature.family);
    more_printf(" Cpu Model          : %u\n",
		hardware->dmi.processor.signature.model);
    more_printf(" Cpu Stepping       : %u\n",
		hardware->dmi.processor.signature.stepping);
    more_printf(" Cpu Minor Stepping : %u\n",
		hardware->dmi.processor.signature.minor_stepping);
    more_printf("Voltage             : %d.%02d\n",
                hardware->dmi.processor.voltage_mv / 1000,
                hardware->dmi.processor.voltage_mv -
                ((hardware->dmi.processor.voltage_mv / 1000) * 1000));
    more_printf(" Status             : %s\n", hardware->dmi.processor.status);
    more_printf(" Upgrade            : %s\n", hardware->dmi.processor.upgrade);
    more_printf(" Cache L1 Handle    : %s\n", hardware->dmi.processor.cache1);
    more_printf(" Cache L2 Handle    : %s\n", hardware->dmi.processor.cache2);
    more_printf(" Cache L3 Handle    : %s\n", hardware->dmi.processor.cache3);
    more_printf(" Serial             : %s\n", hardware->dmi.processor.serial);
    more_printf(" Part Number        : %s\n",
		hardware->dmi.processor.part_number);
    more_printf(" ID                 : %s\n", hardware->dmi.processor.id);
    for (int i = 0; i < PROCESSOR_FLAGS_ELEMENTS; i++) {
	if (((bool *) (&hardware->dmi.processor.cpu_flags))[i] == true) {
	    more_printf(" %s\n", cpu_flags_strings[i]);
	}
    }
}

void show_dmi_memory_bank(int argc, char **argv, struct s_hardware *hardware)
{
    int bank = -1;

    /* Sanitize arguments */
    if (argc > 0)
	bank = strtol(argv[0], (char **)NULL, 10);

    if (errno == ERANGE || bank < 0) {
	more_printf("This bank number is incorrect\n");
	return;
    }

    if ((bank >= hardware->dmi.memory_count) || (bank < 0)) {
	more_printf("Bank %d number doesn't exist\n", bank);
	return;
    }
    if (hardware->dmi.memory[bank].filled == false) {
	more_printf("Bank %d doesn't contain any information\n", bank);
	return;
    }

    reset_more_printf();
    more_printf("Memory Bank %d\n", bank);
    more_printf(" Form Factor  : %s\n", hardware->dmi.memory[bank].form_factor);
    more_printf(" Type         : %s\n", hardware->dmi.memory[bank].type);
    more_printf(" Type Detail  : %s\n", hardware->dmi.memory[bank].type_detail);
    more_printf(" Speed        : %s\n", hardware->dmi.memory[bank].speed);
    more_printf(" Size         : %s\n", hardware->dmi.memory[bank].size);
    more_printf(" Device Set   : %s\n", hardware->dmi.memory[bank].device_set);
    more_printf(" Device Loc.  : %s\n",
		hardware->dmi.memory[bank].device_locator);
    more_printf(" Bank Locator : %s\n",
		hardware->dmi.memory[bank].bank_locator);
    more_printf(" Total Width  : %s\n", hardware->dmi.memory[bank].total_width);
    more_printf(" Data Width   : %s\n", hardware->dmi.memory[bank].data_width);
    more_printf(" Error        : %s\n", hardware->dmi.memory[bank].error);
    more_printf(" Vendor       : %s\n",
		hardware->dmi.memory[bank].manufacturer);
    more_printf(" Serial       : %s\n", hardware->dmi.memory[bank].serial);
    more_printf(" Asset Tag    : %s\n", hardware->dmi.memory[bank].asset_tag);
    more_printf(" Part Number  : %s\n", hardware->dmi.memory[bank].part_number);
}

static void show_dmi_cache(int argc, char **argv, struct s_hardware *hardware)
{
    if (!hardware->dmi.cache_count) {
	more_printf("cache information not found on your system, see "
		    "`show list' to see which module is available.\n");
	return;
    }

    int cache = strtol(argv[0], NULL, 10);

    if (argc != 1 || cache > hardware->dmi.cache_count) {
	more_printf("show cache [0-%d]\n", hardware->dmi.cache_count - 1);
	return;
    }

    reset_more_printf();

    more_printf("Cache Information #%d\n", cache);
    more_printf("  Socket Designation    : %s\n",
		hardware->dmi.cache[cache].socket_designation);
    more_printf("  Configuration         : %s\n",
		hardware->dmi.cache[cache].configuration);
    more_printf("  Operational Mode      : %s\n",
		hardware->dmi.cache[cache].mode);
    more_printf("  Location              : %s\n",
		hardware->dmi.cache[cache].location);
    more_printf("  Installed Size        : %u KB",
		hardware->dmi.cache[cache].installed_size);
    more_printf("\n");
    more_printf("  Maximum Size          : %u KB",
		hardware->dmi.cache[cache].max_size);
    more_printf("\n");
    more_printf("  Supported SRAM Types  : %s",
		hardware->dmi.cache[cache].supported_sram_types);
    more_printf("\n");
    more_printf("  Installed SRAM Type   : %s",
		hardware->dmi.cache[cache].installed_sram_types);
    more_printf("\n");
    more_printf("  Speed                 : %u ns",
		hardware->dmi.cache[cache].speed);
    more_printf("\n");
    more_printf("  Error Correction Type : %s\n",
		hardware->dmi.cache[cache].error_correction_type);
    more_printf("  System Type           : %s\n",
		hardware->dmi.cache[cache].system_type);
    more_printf("  Associativity         : %s\n",
		hardware->dmi.cache[cache].associativity);
}

void show_dmi_memory_module(int argc, char **argv, struct s_hardware *hardware)
{
    int module = -1;

    /* Sanitize arguments */
    if (argc > 0)
	module = strtol(argv[0], (char **)NULL, 10);

    if (errno == ERANGE || module < 0) {
	more_printf("This module number is incorrect\n");
	return;
    }

    if ((module >= hardware->dmi.memory_module_count) || (module < 0)) {
	more_printf("Module number %d doesn't exist\n", module);
	return;
    }

    if (hardware->dmi.memory_module[module].filled == false) {
	more_printf("Module %d doesn't contain any information\n", module);
	return;
    }

    reset_more_printf();
    more_printf("Memory Module %d\n", module);
    more_printf(" Socket Designation : %s\n",
		hardware->dmi.memory_module[module].socket_designation);
    more_printf(" Bank Connections   : %s\n",
		hardware->dmi.memory_module[module].bank_connections);
    more_printf(" Current Speed      : %s\n",
		hardware->dmi.memory_module[module].speed);
    more_printf(" Type               : %s\n",
		hardware->dmi.memory_module[module].type);
    more_printf(" Installed Size     : %s\n",
		hardware->dmi.memory_module[module].installed_size);
    more_printf(" Enabled Size       : %s\n",
		hardware->dmi.memory_module[module].enabled_size);
    more_printf(" Error Status       : %s\n",
		hardware->dmi.memory_module[module].error_status);
}

void main_show_dmi(int argc __unused, char **argv __unused,
		   struct s_hardware *hardware)
{

    if (hardware->is_dmi_valid == false) {
	more_printf("No valid DMI table found, exiting.\n");
	return;
    }
    reset_more_printf();
    more_printf("DMI Table version %u.%u found\n",
		hardware->dmi.dmitable.major_version,
		hardware->dmi.dmitable.minor_version);

    show_dmi_modules(0, NULL, hardware);
}

void show_dmi_memory_modules(int argc __unused, char **argv __unused,
			     struct s_hardware *hardware)
{
    /* Do we have so display unpopulated banks ? */
    int show_free_banks = 1;

    more_printf("Memory Size   : %lu MB (%lu KB)\n",
		(hardware->detected_memory_size + (1 << 9)) >> 10,
		hardware->detected_memory_size);

    if ((hardware->dmi.memory_count <= 0)
	&& (hardware->dmi.memory_module_count <= 0)) {
	more_printf("No memory bank found\n");
	return;
    }

    /* Sanitize arguments */
    if (argc > 0) {
	/* When we display a summary, there is no need to show the unpopulated banks
	 * The first argv is set to define this behavior
	 */
	show_free_banks = strtol(argv[0], NULL, 10);
	if (errno == ERANGE || show_free_banks < 0 || show_free_banks > 1)
	    goto usage;
    }

    reset_more_printf();
    /* If type 17 is available */
    if (hardware->dmi.memory_count > 0) {
	char bank_number[255];
	more_printf("Memory Banks\n");
	for (int i = 0; i < hardware->dmi.memory_count; i++) {
	    if (hardware->dmi.memory[i].filled == true) {
		memset(bank_number, 0, sizeof(bank_number));
		snprintf(bank_number, sizeof(bank_number), "%d ", i);
		if (show_free_banks == false) {
		    if (strncmp(hardware->dmi.memory[i].size, "Free", 4))
			more_printf(" bank %02d      : %s %s@%s\n",
				    i, hardware->dmi.memory[i].size,
				    hardware->dmi.memory[i].type,
				    hardware->dmi.memory[i].speed);
		} else {
		    more_printf(" bank %02d      : %s %s@%s\n", i,
				hardware->dmi.memory[i].size,
				hardware->dmi.memory[i].type,
				hardware->dmi.memory[i].speed);
		}
	    }
	}
    } else if (hardware->dmi.memory_module_count > 0) {
	/* Let's use type 6 as a fallback of type 17 */
	more_printf("Memory Modules\n");
	for (int i = 0; i < hardware->dmi.memory_module_count; i++) {
	    if (hardware->dmi.memory_module[i].filled == true) {
		more_printf(" module %02d    : %s %s@%s\n", i,
			    hardware->dmi.memory_module[i].enabled_size,
			    hardware->dmi.memory_module[i].type,
			    hardware->dmi.memory_module[i].speed);
	    }
	}
    }

    return;
    //printf("Type 'show bank<bank_number>' for more details.\n");

usage:
    more_printf("show memory <clear screen? <show free banks?>>\n");
    return;
}

void show_dmi_oem_strings(int argc __unused, char **argv __unused,
			  struct s_hardware *hardware)
{
    reset_more_printf();

    if (strlen(hardware->dmi.oem_strings))
	more_printf("OEM Strings\n%s", hardware->dmi.oem_strings);
}

void show_dmi_hardware_security(int argc __unused, char **argv __unused,
				struct s_hardware *hardware)
{
    reset_more_printf();

    if (!hardware->dmi.hardware_security.filled)
	return;

    more_printf("Hardware Security\n");
    more_printf("  Power-On Password Status      : %s\n",
		hardware->dmi.hardware_security.power_on_passwd_status);
    more_printf("  Keyboard Password Status      : %s\n",
		hardware->dmi.hardware_security.keyboard_passwd_status);
    more_printf("  Administrator Password Status : %s\n",
		hardware->dmi.hardware_security.administrator_passwd_status);
    more_printf("  Front Panel Reset Status      : %s\n",
		hardware->dmi.hardware_security.front_panel_reset_status);
}

struct cli_callback_descr list_dmi_show_modules[] = {
    {
     .name = CLI_DMI_BASE_BOARD,
     .exec = show_dmi_base_board,
     },
    {
     .name = CLI_DMI_BIOS,
     .exec = show_dmi_bios,
     },
    {
     .name = CLI_DMI_BATTERY,
     .exec = show_dmi_battery,
     },
    {
     .name = CLI_DMI_CHASSIS,
     .exec = show_dmi_chassis,
     },
    {
     .name = CLI_DMI_MEMORY,
     .exec = show_dmi_memory_modules,
     },
    {
     .name = CLI_DMI_MEMORY_BANK,
     .exec = show_dmi_memory_bank,
     },
    {
     .name = "module",
     .exec = show_dmi_memory_module,
     },
    {
     .name = CLI_DMI_PROCESSOR,
     .exec = show_dmi_cpu,
     },
    {
     .name = CLI_DMI_SYSTEM,
     .exec = show_dmi_system,
     },
    {
     .name = CLI_DMI_OEM,
     .exec = show_dmi_oem_strings,
     },
    {
     .name = CLI_DMI_SECURITY,
     .exec = show_dmi_hardware_security,
     },
    {
     .name = CLI_DMI_IPMI,
     .exec = show_dmi_ipmi,
     },
    {
     .name = CLI_DMI_CACHE,
     .exec = show_dmi_cache,
     },
    {
     .name = CLI_DMI_LIST,
     .exec = show_dmi_modules,
     },
    {
     .name = NULL,
     .exec = NULL,
     },
};

struct cli_module_descr dmi_show_modules = {
    .modules = list_dmi_show_modules,
    .default_callback = main_show_dmi,
};

struct cli_mode_descr dmi_mode = {
    .mode = DMI_MODE,
    .name = CLI_DMI,
    .default_modules = NULL,
    .show_modules = &dmi_show_modules,
    .set_modules = NULL,
};