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
|
/* ----------------------------------------------------------------------- *
*
* Copyright 2009 Pierre-Alexandre Meyer - 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 <syslinux/config.h>
#include <syslinux/reboot.h>
#include "hdt-menu.h"
#include "hdt-cli.h"
#include "hdt-common.h"
/**
* cli_clear_screen - clear (erase) the entire screen
**/
static void cli_clear_screen(int argc __unused, char **argv __unused,
struct s_hardware *hardware __unused)
{
clear_screen();
}
/**
* main_show_modes - show availables modes
**/
static void main_show_modes(int argc __unused, char **argv __unused,
struct s_hardware *hardware __unused)
{
int i = 0;
reset_more_printf();
printf("Available modes:\n");
while (list_modes[i]) {
printf("%s ", list_modes[i]->name);
i++;
}
printf("\n");
}
/**
* cli_set_mode - set the mode of the cli, in the cli
*
* The mode number must be supplied in argv, position 0.
**/
static void cli_set_mode(int argc, char **argv, struct s_hardware *hardware)
{
cli_mode_t new_mode;
reset_more_printf();
if (argc <= 0) {
more_printf("Which mode?\n");
return;
}
/*
* Note! argv[0] is a string representing the mode, we need the
* equivalent cli_mode_t to pass it to set_mode.
*/
new_mode = mode_s_to_mode_t(argv[0]);
set_mode(new_mode, hardware);
}
/**
* do_exit - shared helper to exit a mode
**/
static void do_exit(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
int new_mode = HDT_MODE;
switch (hdt_cli.mode) {
case HDT_MODE:
new_mode = EXIT_MODE;
break;
default:
new_mode = HDT_MODE;
break;
}
dprintf("CLI DEBUG: Switching from mode %d to mode %d\n", hdt_cli.mode,
new_mode);
set_mode(new_mode, hardware);
}
/**
* show_cli_help - shared helper to show available commands
**/
static void show_cli_help(int argc __unused, char **argv __unused,
struct s_hardware *hardware __unused)
{
int j = 0;
struct cli_mode_descr *current_mode;
struct cli_callback_descr *associated_module = NULL;
find_cli_mode_descr(hdt_cli.mode, ¤t_mode);
printf("Available commands are:\n");
/* List first default modules of the mode */
if (current_mode->default_modules && current_mode->default_modules->modules) {
while (current_mode->default_modules->modules[j].name) {
printf("%s ", current_mode->default_modules->modules[j].name);
j++;
}
printf("\n");
}
/* List finally the default modules of the hdt mode */
if (current_mode->mode != hdt_mode.mode &&
hdt_mode.default_modules && hdt_mode.default_modules->modules) {
j = 0;
while (hdt_mode.default_modules->modules[j].name) {
/*
* Any default command that is present in hdt mode but
* not in the current mode is available. A default
* command can be redefined in the current mode though.
* This next call test this use case: if it is
* overwritten, do not print it again.
*/
find_cli_callback_descr(hdt_mode.default_modules->modules[j].name,
current_mode->default_modules,
&associated_module);
if (associated_module == NULL)
printf("%s ", hdt_mode.default_modules->modules[j].name);
j++;
}
printf("\n");
}
/* List secondly the show modules of the mode */
if (current_mode->show_modules && current_mode->show_modules->modules) {
printf("\nshow commands:\n");
j = 0;
while (current_mode->show_modules->modules[j].name) {
printf("%s ", current_mode->show_modules->modules[j].name);
j++;
}
printf("\n");
}
/* List thirdly the set modules of the mode */
if (current_mode->set_modules && current_mode->set_modules->modules) {
printf("\nset commands:\n");
j = 0;
while (current_mode->set_modules->modules[j].name) {
printf("%s ", current_mode->set_modules->modules[j].name);
j++;
}
printf("\n");
}
printf("\n");
main_show_modes(argc, argv, hardware);
}
/**
* show_cli_help - shared helper to show available commands
**/
static void goto_menu(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
char version_string[256];
snprintf(version_string, sizeof version_string, "%s %s (%s)",
PRODUCT_NAME, VERSION, CODENAME);
start_menu_mode(hardware, version_string);
return;
}
/**
* main_show_summary - give an overview of the system
**/
void main_show_summary(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
reset_more_printf();
clear_screen();
main_show_cpu(argc, argv, hardware);
if (hardware->is_dmi_valid) {
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(" Serial : %s\n", hardware->dmi.system.serial);
more_printf("Bios\n");
more_printf(" Version : %s\n", hardware->dmi.bios.version);
more_printf(" Release : %s\n", hardware->dmi.bios.release_date);
more_printf("Memory Size : %lu MB (%lu KB)\n",
(hardware->detected_memory_size + (1 << 9)) >> 10,
hardware->detected_memory_size);
}
main_show_pci(argc, argv, hardware);
if (hardware->is_pxe_valid)
main_show_pxe(argc, argv, hardware);
main_show_kernel(argc, argv, hardware);
}
void main_show_hdt(int argc __unused, char **argv __unused,
struct s_hardware *hardware __unused)
{
reset_more_printf();
more_printf("HDT\n");
more_printf(" Product : %s\n", PRODUCT_NAME);
more_printf(" Version : %s (%s)\n", VERSION, CODENAME);
more_printf(" Website : %s\n", WEBSITE_URL);
more_printf(" IRC Channel : %s\n", IRC_CHANNEL);
more_printf(" Mailing List : %s\n", CONTACT);
more_printf(" Project Leader : %s\n", AUTHOR);
more_printf(" Core Developer : %s\n", CORE_DEVELOPER);
char *contributors[NB_CONTRIBUTORS] = CONTRIBUTORS;
for (int c = 0; c < NB_CONTRIBUTORS; c++) {
more_printf(" Contributor : %s\n", contributors[c]);
}
}
/**
* do_reboot - reboot the system
**/
static void do_reboot(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
(void) hardware;
/* Let's call the internal rebooting call */
syslinux_reboot(1);
}
/**
* do_dump - dump info
**/
static void do_dump(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
dump(hardware);
}
/* Default hdt mode */
struct cli_callback_descr list_hdt_default_modules[] = {
{
.name = CLI_CLEAR,
.exec = cli_clear_screen,
},
{
.name = CLI_EXIT,
.exec = do_exit,
},
{
.name = CLI_HELP,
.exec = show_cli_help,
},
{
.name = CLI_MENU,
.exec = goto_menu,
},
{
.name = CLI_REBOOT,
.exec = do_reboot,
},
{
.name = CLI_HISTORY,
.exec = print_history,
},
{
.name = CLI_DUMP,
.exec = do_dump,
},
{
.name = NULL,
.exec = NULL},
};
struct cli_callback_descr list_hdt_show_modules[] = {
{
.name = CLI_SUMMARY,
.exec = main_show_summary,
},
{
.name = CLI_PCI,
.exec = main_show_pci,
},
{
.name = CLI_DMI,
.exec = main_show_dmi,
},
{
.name = CLI_CPU,
.exec = main_show_cpu,
},
{
.name = CLI_DISK,
.exec = disks_summary,
},
{
.name = CLI_PXE,
.exec = main_show_pxe,
},
{
.name = CLI_SYSLINUX,
.exec = main_show_syslinux,
},
{
.name = CLI_KERNEL,
.exec = main_show_kernel,
},
{
.name = CLI_VESA,
.exec = main_show_vesa,
},
{
.name = CLI_HDT,
.exec = main_show_hdt,
},
{
.name = CLI_VPD,
.exec = main_show_vpd,
},
{
.name = CLI_MEMORY,
.exec = show_dmi_memory_modules,
},
{
.name = CLI_ACPI,
.exec = main_show_acpi,
},
{
.name = "modes",
.exec = main_show_modes,
},
{
.name = NULL,
.exec = NULL,
},
};
struct cli_callback_descr list_hdt_set_modules[] = {
{
.name = CLI_MODE,
.exec = cli_set_mode,
},
{
.name = NULL,
.exec = NULL,
},
};
struct cli_module_descr hdt_default_modules = {
.modules = list_hdt_default_modules,
};
struct cli_module_descr hdt_show_modules = {
.modules = list_hdt_show_modules,
.default_callback = main_show_summary,
};
struct cli_module_descr hdt_set_modules = {
.modules = list_hdt_set_modules,
};
struct cli_mode_descr hdt_mode = {
.mode = HDT_MODE,
.name = CLI_HDT,
.default_modules = &hdt_default_modules,
.show_modules = &hdt_show_modules,
.set_modules = &hdt_set_modules,
};
|