1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 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 * -----------------------------------------------------------------------
31 #include <syslinux/reboot.h>
34 int start_menu_mode(struct s_hardware
*hardware
, char *version_string
)
36 struct s_hdt_menu hdt_menu
;
38 memset(&hdt_menu
, 0, sizeof(hdt_menu
));
40 /* Setup the menu system */
41 setup_menu(version_string
);
43 /* Compute all submenus */
44 compute_submenus(&hdt_menu
, hardware
);
46 /* Compute the main menu */
47 compute_main_menu(&hdt_menu
, hardware
);
49 #ifdef WITH_MENU_DISPLAY
54 more_printf("Starting Menu (%d menus)\n", hdt_menu
.total_menu_count
);
55 curr
= showmenus(hdt_menu
.main_menu
.menu
);
56 /* When we exit the menu, do we have something to do? */
58 /* When want to execute something */
59 if (curr
->action
== OPT_RUN
) {
60 /* Tweak, we want to switch to the cli */
62 (curr
->data
, HDT_SWITCH_TO_CLI
, sizeof(HDT_SWITCH_TO_CLI
))) {
63 return HDT_RETURN_TO_CLI
;
66 (curr
->data
, HDT_REBOOT
, sizeof(HDT_REBOOT
))) {
69 strcpy(cmd
, curr
->data
);
71 /* Use specific syslinux call if needed */
76 return 1; // Should not happen when run from SYSLINUX
83 /* In the menu system, what to do on keyboard timeout */
84 TIMEOUTCODE
ontimeout(void)
90 /* Keyboard handler for the menu system */
91 void keys_handler(t_menusystem
* ms
92 __attribute__ ((unused
)), t_menuitem
* mi
, int scancode
)
96 /* 0xFFFF is an invalid helpid */
97 if (scancode
== KEY_F1
&& mi
->helpid
!= 0xFFFF) {
98 runhelpsystem(mi
->helpid
);
102 * If user hit TAB, and item is an "executable" item
103 * and user has privileges to edit it, edit it in place.
105 if ((scancode
== KEY_TAB
) && (mi
->action
== OPT_RUN
)) {
106 //(isallowed(username,"editcmd") || isallowed(username,"root"))) {
107 if (getscreensize(1, &nr
, &nc
)) {
108 /* Unknown screen size? */
112 /* User typed TAB and has permissions to edit command line */
113 gotoxy(EDITPROMPT
, 1);
114 csprint("Command line:", 0x07);
115 editstring(mi
->data
, ACTIONLEN
);
116 gotoxy(EDITPROMPT
, 1);
117 cprint(' ', 0x07, nc
- 1);
121 /* Setup the Menu system */
122 void setup_menu(char *version
)
124 /* Creating the menu */
125 init_menusystem(version
);
126 set_window_size(0, 0, 25, 80);
128 /* Do not use inactive attributes - they make little sense for HDT */
129 set_normal_attr(-1, -1, 0x17, 0x1F);
131 /* Register the menusystem handler */
132 // reg_handler(HDLR_SCREEN,&msys_handler);
133 reg_handler(HDLR_KEYS
, &keys_handler
);
135 /* Register the ontimeout handler, with a time out of 10 seconds */
136 reg_ontimeout(ontimeout
, 1000, 0);
139 /* Compute Main' submenus */
140 void compute_submenus(struct s_hdt_menu
*hdt_menu
, struct s_hardware
*hardware
)
143 /* Compute this menu if a DMI table exists */
144 if (hardware
->is_dmi_valid
) {
145 if (hardware
->dmi
.ipmi
.filled
== true)
146 compute_ipmi(&hdt_menu
->ipmi_menu
, &hardware
->dmi
);
147 if (hardware
->dmi
.base_board
.filled
== true)
148 compute_motherboard(&(hdt_menu
->mobo_menu
), &(hardware
->dmi
));
149 if (hardware
->dmi
.chassis
.filled
== true)
150 compute_chassis(&(hdt_menu
->chassis_menu
), &(hardware
->dmi
));
151 if (hardware
->dmi
.system
.filled
== true)
152 compute_system(&(hdt_menu
->system_menu
), &(hardware
->dmi
));
153 compute_memory(hdt_menu
, &(hardware
->dmi
), hardware
);
154 if (hardware
->dmi
.bios
.filled
== true)
155 compute_bios(&(hdt_menu
->bios_menu
), &(hardware
->dmi
));
156 if (hardware
->dmi
.battery
.filled
== true)
157 compute_battery(&(hdt_menu
->battery_menu
), &(hardware
->dmi
));
160 compute_processor(&(hdt_menu
->cpu_menu
), hardware
);
161 compute_vpd(&(hdt_menu
->vpd_menu
), hardware
);
162 compute_disks(hdt_menu
, hardware
);
164 compute_PCI(hdt_menu
, hardware
);
165 compute_PXE(&(hdt_menu
->pxe_menu
), hardware
);
166 compute_kernel(&(hdt_menu
->kernel_menu
), hardware
);
168 compute_summarymenu(&(hdt_menu
->summary_menu
), hardware
);
169 compute_syslinuxmenu(&(hdt_menu
->syslinux_menu
), hardware
);
170 compute_VESA(hdt_menu
, hardware
);
171 compute_ACPI(hdt_menu
, hardware
);
172 compute_aboutmenu(&(hdt_menu
->about_menu
));
175 void compute_main_menu(struct s_hdt_menu
*hdt_menu
, struct s_hardware
*hardware
)
178 /* Let's count the number of menus we have */
179 hdt_menu
->total_menu_count
= 0;
180 hdt_menu
->main_menu
.items_count
= 0;
182 hdt_menu
->main_menu
.menu
= add_menu(" Main Menu ", -1);
183 set_item_options(-1, 24);
185 snprintf(menu_item
, sizeof(menu_item
), "PC<I> Devices(%2d)\n",
186 hardware
->nb_pci_devices
);
187 add_item(menu_item
, "PCI Devices Menu", OPT_SUBMENU
, NULL
,
188 hdt_menu
->pci_menu
.menu
);
189 hdt_menu
->main_menu
.items_count
++;
190 hdt_menu
->total_menu_count
+= hdt_menu
->pci_menu
.items_count
;
192 if (hdt_menu
->disk_menu
.items_count
> 0) {
193 snprintf(menu_item
, sizeof(menu_item
), "<D>isks (%2d)\n",
194 hdt_menu
->disk_menu
.items_count
);
195 add_item(menu_item
, "Disks Menu", OPT_SUBMENU
, NULL
,
196 hdt_menu
->disk_menu
.menu
);
197 hdt_menu
->main_menu
.items_count
++;
198 hdt_menu
->total_menu_count
+= hdt_menu
->disk_menu
.items_count
;
201 snprintf(menu_item
, sizeof(menu_item
), "<M>emory\n");
202 add_item(menu_item
, "Memory Menu", OPT_SUBMENU
, NULL
,
203 hdt_menu
->memory_menu
.menu
);
204 hdt_menu
->main_menu
.items_count
++;
205 hdt_menu
->total_menu_count
+= hdt_menu
->memory_menu
.items_count
;
207 add_item("<P>rocessor", "Main Processor Menu", OPT_SUBMENU
, NULL
,
208 hdt_menu
->cpu_menu
.menu
);
209 hdt_menu
->main_menu
.items_count
++;
211 if (hardware
->is_dmi_valid
) {
212 if (hardware
->dmi
.base_board
.filled
== true) {
213 add_item("M<o>therboard", "Motherboard Menu",
214 OPT_SUBMENU
, NULL
, hdt_menu
->mobo_menu
.menu
);
215 hdt_menu
->main_menu
.items_count
++;
218 if (hardware
->dmi
.bios
.filled
== true) {
219 add_item("<B>ios", "Bios Menu", OPT_SUBMENU
, NULL
,
220 hdt_menu
->bios_menu
.menu
);
221 hdt_menu
->main_menu
.items_count
++;
224 if (hardware
->dmi
.chassis
.filled
== true) {
225 add_item("<C>hassis", "Chassis Menu", OPT_SUBMENU
, NULL
,
226 hdt_menu
->chassis_menu
.menu
);
227 hdt_menu
->main_menu
.items_count
++;
230 if (hardware
->dmi
.system
.filled
== true) {
231 add_item("<S>ystem", "System Menu", OPT_SUBMENU
, NULL
,
232 hdt_menu
->system_menu
.menu
);
233 hdt_menu
->main_menu
.items_count
++;
236 if (hardware
->dmi
.battery
.filled
== true) {
237 add_item("Ba<t>tery", "Battery Menu", OPT_SUBMENU
, NULL
,
238 hdt_menu
->battery_menu
.menu
);
239 hdt_menu
->main_menu
.items_count
++;
241 if (hardware
->dmi
.ipmi
.filled
== true) {
242 add_item("I<P>MI", "IPMI Menu", OPT_SUBMENU
, NULL
,
243 hdt_menu
->ipmi_menu
.menu
);
244 hdt_menu
->main_menu
.items_count
++;
248 if (hardware
->is_vpd_valid
== true) {
249 add_item("<V>PD", "VPD Information Menu", OPT_SUBMENU
, NULL
,
250 hdt_menu
->vpd_menu
.menu
);
251 hdt_menu
->main_menu
.items_count
++;
254 if (hardware
->is_pxe_valid
== true) {
255 add_item("P<X>E", "PXE Information Menu", OPT_SUBMENU
, NULL
,
256 hdt_menu
->pxe_menu
.menu
);
257 hdt_menu
->main_menu
.items_count
++;
260 if (hardware
->is_vesa_valid
== true) {
261 add_item("<V>ESA", "VESA Information Menu", OPT_SUBMENU
, NULL
,
262 hdt_menu
->vesa_menu
.menu
);
263 hdt_menu
->main_menu
.items_count
++;
266 if (hardware
->is_acpi_valid
== true) {
267 add_item("<A>CPI", "ACPI Menu", OPT_SUBMENU
, NULL
,
268 hdt_menu
->acpi_menu
.menu
);
269 hdt_menu
->main_menu
.items_count
++;
272 add_item("", "", OPT_SEP
, "", 0);
274 if ((hardware
->modules_pcimap_return_code
!= -ENOMODULESPCIMAP
) ||
275 (hardware
->modules_alias_return_code
!= -ENOMODULESALIAS
)) {
276 add_item("<K>ernel Modules", "Kernel Modules Menu", OPT_SUBMENU
,
277 NULL
, hdt_menu
->kernel_menu
.menu
);
278 hdt_menu
->main_menu
.items_count
++;
281 add_item("S<y>slinux", "Syslinux Information Menu", OPT_SUBMENU
, NULL
,
282 hdt_menu
->syslinux_menu
.menu
);
283 hdt_menu
->main_menu
.items_count
++;
284 add_item("S<u>mmary", "Summary Information Menu", OPT_SUBMENU
, NULL
,
285 hdt_menu
->summary_menu
.menu
);
286 hdt_menu
->main_menu
.items_count
++;
288 add_item("", "", OPT_SEP
, "", 0);
290 add_item("S<w>itch to CLI", "Switch to Command Line", OPT_RUN
,
291 HDT_SWITCH_TO_CLI
, 0);
292 add_item("<A>bout", "About Menu", OPT_SUBMENU
, NULL
,
293 hdt_menu
->about_menu
.menu
);
294 add_item("<R>eboot", "Reboot", OPT_RUN
, HDT_REBOOT
, 0);
295 add_item("E<x>it", "Exit", OPT_EXITMENU
, NULL
, 0);
296 hdt_menu
->main_menu
.items_count
++;
298 hdt_menu
->total_menu_count
+= hdt_menu
->main_menu
.items_count
;