summaryrefslogtreecommitdiff
path: root/com32/hdt/hdt-menu.c
blob: 50b3eaa82eec4f069c7539b9fe2177fcd2408b6f (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
/* ----------------------------------------------------------------------- *
 *
 *   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 <unistd.h>
#include <memory.h>
#include <syslinux/reboot.h>
#include "hdt-menu.h"

int start_menu_mode(struct s_hardware *hardware, char *version_string)
{
    struct s_hdt_menu hdt_menu;

    memset(&hdt_menu, 0, sizeof(hdt_menu));

    /* Setup the menu system */
    setup_menu(version_string);

    /* Compute all submenus */
    compute_submenus(&hdt_menu, hardware);

    /* Compute the main menu */
    compute_main_menu(&hdt_menu, hardware);

#ifdef WITH_MENU_DISPLAY
    t_menuitem *curr;
    char cmd[160];

    if (!quiet)
	more_printf("Starting Menu (%d menus)\n", hdt_menu.total_menu_count);
    curr = showmenus(hdt_menu.main_menu.menu);
    /* When we exit the menu, do we have something to do? */
    if (curr) {
	/* When want to execute something */
	if (curr->action == OPT_RUN) {
	    /* Tweak, we want to switch to the cli */
	    if (!strncmp
		(curr->data, HDT_SWITCH_TO_CLI, sizeof(HDT_SWITCH_TO_CLI))) {
		return HDT_RETURN_TO_CLI;
	    }
	    /* Tweak, we want to start the dump mode */
	    if (!strncmp
		(curr->data, HDT_DUMP, sizeof(HDT_DUMP))) {
		    dump(hardware);
	        return 0;
	    }
	    if (!strncmp
		(curr->data, HDT_REBOOT, sizeof(HDT_REBOOT))) {
		syslinux_reboot(1);
	    }
	    strcpy(cmd, curr->data);

	    /* Use specific syslinux call if needed */
	    if (issyslinux())
		runsyslinuxcmd(cmd);
	    else
		csprint(cmd, 0x07);
	    return 1;		// Should not happen when run from SYSLINUX
	}
    }
#endif
    return 0;
}

/* In the menu system, what to do on keyboard timeout */
TIMEOUTCODE ontimeout(void)
{
    // beep();
    return CODE_WAIT;
}

/* Keyboard handler for the menu system */
void keys_handler(t_menusystem * ms
		  __attribute__ ((unused)), t_menuitem * mi, int scancode)
{
    int nr, nc;

    /* 0xFFFF is an invalid helpid */
    if (scancode == KEY_F1 && mi->helpid != 0xFFFF) {
	runhelpsystem(mi->helpid);
    }

    /*
     * If user hit TAB, and item is an "executable" item
     * and user has privileges to edit it, edit it in place.
     */
    if ((scancode == KEY_TAB) && (mi->action == OPT_RUN)) {
//(isallowed(username,"editcmd") || isallowed(username,"root"))) {
	if (getscreensize(1, &nr, &nc)) {
	    /* Unknown screen size? */
	    nc = 80;
	    nr = 24;
	}
	/* User typed TAB and has permissions to edit command line */
	gotoxy(EDITPROMPT, 1);
	csprint("Command line:", 0x07);
	editstring(mi->data, ACTIONLEN);
	gotoxy(EDITPROMPT, 1);
	cprint(' ', 0x07, nc - 1);
    }
}

/* Setup the Menu system */
void setup_menu(char *version)
{
    /* Creating the menu */
    init_menusystem(version);
    set_window_size(0, 0, 25, 80);

    /* Do not use inactive attributes - they make little sense for HDT */
    set_normal_attr(-1, -1, 0x17, 0x1F);

    /* Register the menusystem handler */
    // reg_handler(HDLR_SCREEN,&msys_handler);
    reg_handler(HDLR_KEYS, &keys_handler);

    /* Register the ontimeout handler, with a time out of 10 seconds */
    reg_ontimeout(ontimeout, 1000, 0);
}

/* Compute Main' submenus */
void compute_submenus(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware)
{

    /* Compute this menu if a DMI table exists */
    if (hardware->is_dmi_valid) {
	if (hardware->dmi.ipmi.filled == true)
	    compute_ipmi(&hdt_menu->ipmi_menu, &hardware->dmi);
	if (hardware->dmi.base_board.filled == true)
	    compute_motherboard(&(hdt_menu->mobo_menu), &(hardware->dmi));
	if (hardware->dmi.chassis.filled == true)
	    compute_chassis(&(hdt_menu->chassis_menu), &(hardware->dmi));
	if (hardware->dmi.system.filled == true)
	    compute_system(&(hdt_menu->system_menu), &(hardware->dmi));
	compute_memory(hdt_menu, &(hardware->dmi), hardware);
	if (hardware->dmi.bios.filled == true)
	    compute_bios(&(hdt_menu->bios_menu), &(hardware->dmi));
	if (hardware->dmi.battery.filled == true)
	    compute_battery(&(hdt_menu->battery_menu), &(hardware->dmi));
    }

    compute_processor(&(hdt_menu->cpu_menu), hardware);
    compute_vpd(&(hdt_menu->vpd_menu), hardware);
    compute_disks(hdt_menu, hardware);

    compute_PCI(hdt_menu, hardware);
    compute_PXE(&(hdt_menu->pxe_menu), hardware);
    compute_kernel(&(hdt_menu->kernel_menu), hardware);
    
    compute_summarymenu(&(hdt_menu->summary_menu), hardware);
    compute_syslinuxmenu(&(hdt_menu->syslinux_menu), hardware);
    compute_VESA(hdt_menu, hardware);
    compute_ACPI(hdt_menu, hardware);
    compute_aboutmenu(&(hdt_menu->about_menu));
}

void compute_main_menu(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware)
{
    char menu_item[64];
    /* Let's count the number of menus we have */
    hdt_menu->total_menu_count = 0;
    hdt_menu->main_menu.items_count = 0;

    hdt_menu->main_menu.menu = add_menu(" Main Menu ", -1);
    set_item_options(-1, 24);

    snprintf(menu_item, sizeof(menu_item), "PC<I> Devices(%2d)\n",
	     hardware->nb_pci_devices);
    add_item(menu_item, "PCI Devices Menu", OPT_SUBMENU, NULL,
	     hdt_menu->pci_menu.menu);
    hdt_menu->main_menu.items_count++;
    hdt_menu->total_menu_count += hdt_menu->pci_menu.items_count;
    
    if (hdt_menu->disk_menu.items_count > 0) {
	snprintf(menu_item, sizeof(menu_item), "<D>isks      (%2d)\n",
		 hdt_menu->disk_menu.items_count);
	add_item(menu_item, "Disks Menu", OPT_SUBMENU, NULL,
		 hdt_menu->disk_menu.menu);
	hdt_menu->main_menu.items_count++;
	hdt_menu->total_menu_count += hdt_menu->disk_menu.items_count;
    }

    snprintf(menu_item, sizeof(menu_item), "<M>emory\n");
    add_item(menu_item, "Memory Menu", OPT_SUBMENU, NULL,
	     hdt_menu->memory_menu.menu);
    hdt_menu->main_menu.items_count++;
    hdt_menu->total_menu_count += hdt_menu->memory_menu.items_count;

    add_item("<P>rocessor", "Main Processor Menu", OPT_SUBMENU, NULL,
	     hdt_menu->cpu_menu.menu);
    hdt_menu->main_menu.items_count++;

    if (hardware->is_dmi_valid) {
	if (hardware->dmi.base_board.filled == true) {
	    add_item("M<o>therboard", "Motherboard Menu",
		     OPT_SUBMENU, NULL, hdt_menu->mobo_menu.menu);
	    hdt_menu->main_menu.items_count++;
	}

	if (hardware->dmi.bios.filled == true) {
	    add_item("<B>ios", "Bios Menu", OPT_SUBMENU, NULL,
		     hdt_menu->bios_menu.menu);
	    hdt_menu->main_menu.items_count++;
	}

	if (hardware->dmi.chassis.filled == true) {
	    add_item("<C>hassis", "Chassis Menu", OPT_SUBMENU, NULL,
		     hdt_menu->chassis_menu.menu);
	    hdt_menu->main_menu.items_count++;
	}

	if (hardware->dmi.system.filled == true) {
	    add_item("<S>ystem", "System Menu", OPT_SUBMENU, NULL,
		     hdt_menu->system_menu.menu);
	    hdt_menu->main_menu.items_count++;
	}

	if (hardware->dmi.battery.filled == true) {
	    add_item("Ba<t>tery", "Battery Menu", OPT_SUBMENU, NULL,
		     hdt_menu->battery_menu.menu);
	    hdt_menu->main_menu.items_count++;
	}
	if (hardware->dmi.ipmi.filled == true) {
	    add_item("I<P>MI", "IPMI Menu", OPT_SUBMENU, NULL,
		     hdt_menu->ipmi_menu.menu);
	    hdt_menu->main_menu.items_count++;
	}
    }

    if (hardware->is_vpd_valid == true) {
	add_item("<V>PD", "VPD Information Menu", OPT_SUBMENU, NULL,
		 hdt_menu->vpd_menu.menu);
	hdt_menu->main_menu.items_count++;
    }

    if (hardware->is_pxe_valid == true) {
	add_item("P<X>E", "PXE Information Menu", OPT_SUBMENU, NULL,
		 hdt_menu->pxe_menu.menu);
	hdt_menu->main_menu.items_count++;
    }

    if (hardware->is_vesa_valid == true) {
	add_item("<V>ESA", "VESA Information Menu", OPT_SUBMENU, NULL,
		 hdt_menu->vesa_menu.menu);
	hdt_menu->main_menu.items_count++;
    }

    if (hardware->is_acpi_valid == true) {
	add_item("<A>CPI", "ACPI Menu", OPT_SUBMENU, NULL,
		 hdt_menu->acpi_menu.menu);
	hdt_menu->main_menu.items_count++;
    }

    add_item("", "", OPT_SEP, "", 0);
    
    if ((hardware->modules_pcimap_return_code != -ENOMODULESPCIMAP) ||
	(hardware->modules_alias_return_code != -ENOMODULESALIAS)) {
	add_item("<K>ernel Modules", "Kernel Modules Menu", OPT_SUBMENU,
		 NULL, hdt_menu->kernel_menu.menu);
	hdt_menu->main_menu.items_count++;
    }
    
    add_item("S<y>slinux", "Syslinux Information Menu", OPT_SUBMENU, NULL,
	     hdt_menu->syslinux_menu.menu);
    hdt_menu->main_menu.items_count++;
    add_item("S<u>mmary", "Summary Information Menu", OPT_SUBMENU, NULL,
	     hdt_menu->summary_menu.menu);
    hdt_menu->main_menu.items_count++;

    add_item("", "", OPT_SEP, "", 0);

    add_item("S<w>itch to CLI", "Switch to Command Line", OPT_RUN,
	     HDT_SWITCH_TO_CLI, 0);

    if (hardware->is_pxe_valid == true) {
    add_item("<D>ump to tftp", "Dump to tftp", OPT_RUN,
	     HDT_DUMP, 0);
    }

    add_item("<A>bout", "About Menu", OPT_SUBMENU, NULL,
	     hdt_menu->about_menu.menu);
    add_item("<R>eboot", "Reboot", OPT_RUN, HDT_REBOOT, 0);
    add_item("E<x>it", "Exit", OPT_EXITMENU, NULL, 0);
    hdt_menu->main_menu.items_count++;

    hdt_menu->total_menu_count += hdt_menu->main_menu.items_count;
}