[e16e8f2] | 1 | /* ----------------------------------------------------------------------- * |
---|
| 2 | * |
---|
| 3 | * Copyright 2009 Erwan Velu - All Rights Reserved |
---|
| 4 | * |
---|
| 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 |
---|
| 12 | * conditions: |
---|
| 13 | * |
---|
| 14 | * The above copyright notice and this permission notice shall |
---|
| 15 | * be included in all copies or substantial portions of the Software. |
---|
| 16 | * |
---|
| 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. |
---|
| 25 | * |
---|
| 26 | * ----------------------------------------------------------------------- |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef DEFINE_HDT_CLI_H |
---|
| 30 | #define DEFINE_HDT_CLI_H |
---|
| 31 | #include <stdio.h> |
---|
| 32 | #include <getkey.h> |
---|
| 33 | #include <dprintf.h> |
---|
| 34 | |
---|
| 35 | #include "hdt-common.h" |
---|
| 36 | |
---|
| 37 | #define MAX_LINE_SIZE 256 |
---|
| 38 | |
---|
| 39 | #define CLI_SPACE " " |
---|
| 40 | #define CLI_LF "\n" |
---|
| 41 | #define CLI_MENU "menu" |
---|
| 42 | #define CLI_CLEAR "clear" |
---|
| 43 | #define CLI_EXIT "exit" |
---|
| 44 | #define CLI_HELP "help" |
---|
| 45 | #define CLI_REBOOT "reboot" |
---|
| 46 | #define CLI_SHOW "show" |
---|
| 47 | #define CLI_SET "set" |
---|
| 48 | #define CLI_MODE "mode" |
---|
| 49 | #define CLI_HDT "hdt" |
---|
| 50 | #define CLI_PCI "pci" |
---|
| 51 | #define CLI_PXE "pxe" |
---|
| 52 | #define CLI_KERNEL "kernel" |
---|
| 53 | #define CLI_SYSLINUX "syslinux" |
---|
| 54 | #define CLI_VESA "vesa" |
---|
| 55 | #define CLI_SUMMARY "summary" |
---|
| 56 | #define CLI_COMMANDS "commands" |
---|
| 57 | #define CLI_DMI "dmi" |
---|
| 58 | #define CLI_CPU "cpu" |
---|
| 59 | #define CLI_DISK "disk" |
---|
| 60 | #define CLI_SHOW_LIST "list" |
---|
| 61 | #define CLI_IRQ "irq" |
---|
| 62 | #define CLI_MODES "modes" |
---|
| 63 | #define CLI_VPD "vpd" |
---|
| 64 | #define CLI_MEMORY "memory" |
---|
| 65 | #define CLI_ACPI "acpi" |
---|
| 66 | #define CLI_ENABLE "enable" |
---|
| 67 | #define CLI_DISABLE "disable" |
---|
| 68 | #define CLI_DUMP "dump" |
---|
| 69 | #define CLI_SAY "say" |
---|
| 70 | #define CLI_DISPLAY "display" |
---|
| 71 | #define CLI_SLEEP "sleep" |
---|
| 72 | |
---|
| 73 | typedef enum { |
---|
| 74 | INVALID_MODE, |
---|
| 75 | EXIT_MODE, |
---|
| 76 | HDT_MODE, |
---|
| 77 | PCI_MODE, |
---|
| 78 | DMI_MODE, |
---|
| 79 | CPU_MODE, |
---|
| 80 | PXE_MODE, |
---|
| 81 | KERNEL_MODE, |
---|
| 82 | SYSLINUX_MODE, |
---|
| 83 | VESA_MODE, |
---|
| 84 | DISK_MODE, |
---|
| 85 | VPD_MODE, |
---|
| 86 | MEMORY_MODE, |
---|
| 87 | ACPI_MODE |
---|
| 88 | } cli_mode_t; |
---|
| 89 | |
---|
| 90 | #define PROMPT_SIZE 32 |
---|
| 91 | #define MAX_HISTORY_SIZE 32 |
---|
| 92 | #define INPUT hdt_cli.history[hdt_cli.history_pos] |
---|
| 93 | struct s_cli { |
---|
| 94 | cli_mode_t mode; |
---|
| 95 | char prompt[PROMPT_SIZE]; |
---|
| 96 | uint8_t cursor_pos; |
---|
| 97 | char history[MAX_HISTORY_SIZE+1][MAX_LINE_SIZE]; |
---|
| 98 | int history_pos; |
---|
| 99 | int max_history_pos; |
---|
| 100 | }; |
---|
| 101 | struct s_cli hdt_cli; |
---|
| 102 | |
---|
| 103 | /* Describe a cli mode */ |
---|
| 104 | struct cli_mode_descr { |
---|
| 105 | const unsigned int mode; |
---|
| 106 | const char *name; |
---|
| 107 | /* Handle 1-token commands */ |
---|
| 108 | struct cli_module_descr *default_modules; |
---|
| 109 | /* Handle show <module> <args> */ |
---|
| 110 | struct cli_module_descr *show_modules; |
---|
| 111 | /* Handle set <module> <args> */ |
---|
| 112 | struct cli_module_descr *set_modules; |
---|
| 113 | }; |
---|
| 114 | |
---|
| 115 | /* Describe a subset of commands in a module (default, show, set, ...) */ |
---|
| 116 | struct cli_module_descr { |
---|
| 117 | struct cli_callback_descr *modules; |
---|
| 118 | void (*default_callback) (int argc, char **argv, |
---|
| 119 | struct s_hardware * hardware); |
---|
| 120 | }; |
---|
| 121 | |
---|
| 122 | /* Describe a callback (belongs to a mode and a module) */ |
---|
| 123 | struct cli_callback_descr { |
---|
| 124 | const char *name; |
---|
| 125 | void (*exec) (int argc, char **argv, struct s_hardware * hardware); |
---|
| 126 | bool nomodule; |
---|
| 127 | }; |
---|
| 128 | |
---|
| 129 | /* Manage aliases */ |
---|
| 130 | #define MAX_ALIASES 2 |
---|
| 131 | struct cli_alias { |
---|
| 132 | const char *command; /* Original command */ |
---|
| 133 | const int nb_aliases; /* Size of aliases array */ |
---|
| 134 | const char **aliases; /* List of aliases */ |
---|
| 135 | }; |
---|
| 136 | |
---|
| 137 | /* List of implemented modes */ |
---|
| 138 | extern struct cli_mode_descr *list_modes[]; |
---|
| 139 | struct cli_mode_descr hdt_mode; |
---|
| 140 | struct cli_mode_descr dmi_mode; |
---|
| 141 | struct cli_mode_descr syslinux_mode; |
---|
| 142 | struct cli_mode_descr pxe_mode; |
---|
| 143 | struct cli_mode_descr kernel_mode; |
---|
| 144 | struct cli_mode_descr cpu_mode; |
---|
| 145 | struct cli_mode_descr pci_mode; |
---|
| 146 | struct cli_mode_descr vesa_mode; |
---|
| 147 | struct cli_mode_descr disk_mode; |
---|
| 148 | struct cli_mode_descr vpd_mode; |
---|
| 149 | struct cli_mode_descr memory_mode; |
---|
| 150 | struct cli_mode_descr acpi_mode; |
---|
| 151 | |
---|
| 152 | /* cli helpers */ |
---|
| 153 | void find_cli_mode_descr(cli_mode_t mode, struct cli_mode_descr **mode_found); |
---|
| 154 | void find_cli_callback_descr(const char *module_name, |
---|
| 155 | struct cli_module_descr *modules_list, |
---|
| 156 | struct cli_callback_descr **module_found); |
---|
| 157 | cli_mode_t mode_s_to_mode_t(char *name); |
---|
| 158 | |
---|
| 159 | void set_mode(cli_mode_t mode, struct s_hardware *hardware); |
---|
| 160 | void start_cli_mode(struct s_hardware *hardware); |
---|
| 161 | void start_auto_mode(struct s_hardware *hardware); |
---|
| 162 | void main_show(char *item, struct s_hardware *hardware); |
---|
| 163 | |
---|
| 164 | #define CLI_HISTORY "history" |
---|
| 165 | void print_history(int argc, char **argv, struct s_hardware * hardware); |
---|
| 166 | |
---|
| 167 | // DMI STUFF |
---|
| 168 | #define CLI_DMI_BASE_BOARD "base_board" |
---|
| 169 | #define CLI_DMI_BATTERY "battery" |
---|
| 170 | #define CLI_DMI_BIOS "bios" |
---|
| 171 | #define CLI_DMI_CHASSIS "chassis" |
---|
| 172 | #define CLI_DMI_MEMORY "memory" |
---|
| 173 | #define CLI_DMI_MEMORY_BANK "bank" |
---|
| 174 | #define CLI_DMI_PROCESSOR "cpu" |
---|
| 175 | #define CLI_DMI_SYSTEM "system" |
---|
| 176 | #define CLI_DMI_IPMI "ipmi" |
---|
| 177 | #define CLI_DMI_CACHE "cache" |
---|
| 178 | #define CLI_DMI_OEM "oem" |
---|
| 179 | #define CLI_DMI_SECURITY "security" |
---|
| 180 | #define CLI_DMI_LIST CLI_SHOW_LIST |
---|
| 181 | void main_show_dmi(int argc, char **argv, struct s_hardware *hardware); |
---|
| 182 | void show_dmi_memory_modules(int argc, char **argv, |
---|
| 183 | struct s_hardware *hardware); |
---|
| 184 | void show_dmi_memory_bank(int argc, char **argv, struct s_hardware *hardware); |
---|
| 185 | |
---|
| 186 | // PCI STUFF |
---|
| 187 | #define CLI_PCI_DEVICE "device" |
---|
| 188 | void main_show_pci(int argc, char **argv, struct s_hardware *hardware); |
---|
| 189 | |
---|
| 190 | // CPU STUFF |
---|
| 191 | void main_show_cpu(int argc, char **argv, struct s_hardware *hardware); |
---|
| 192 | |
---|
| 193 | // DISK STUFF |
---|
| 194 | void disks_summary(int argc, char **argv, struct s_hardware *hardware); |
---|
| 195 | |
---|
| 196 | // PXE STUFF |
---|
| 197 | void main_show_pxe(int argc, char **argv, struct s_hardware *hardware); |
---|
| 198 | |
---|
| 199 | // KERNEL STUFF |
---|
| 200 | void main_show_kernel(int argc, char **argv, struct s_hardware *hardware); |
---|
| 201 | |
---|
| 202 | // SYSLINUX STUFF |
---|
| 203 | void main_show_syslinux(int argc, char **argv, struct s_hardware *hardware); |
---|
| 204 | |
---|
| 205 | // VESA STUFF |
---|
| 206 | void main_show_vesa(int argc, char **argv, struct s_hardware *hardware); |
---|
| 207 | |
---|
| 208 | // VPD STUFF |
---|
| 209 | void main_show_vpd(int argc __unused, char **argv __unused, |
---|
| 210 | struct s_hardware *hardware); |
---|
| 211 | |
---|
| 212 | // ACPI STUFF |
---|
| 213 | void main_show_acpi(int argc __unused, char **argv __unused, |
---|
| 214 | struct s_hardware *hardware); |
---|
| 215 | |
---|
| 216 | #endif |
---|