summaryrefslogtreecommitdiff
path: root/include/console.h
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2016-08-25 13:07:54 -0700
committerBill Richardson <wfrichar@chromium.org>2016-08-31 16:02:36 +0000
commit6d805476ba032b33e440330469a873e6a444fddb (patch)
tree07a9524ffbba605a1615b74f7f2f681afd32f8e7 /include/console.h
parent12b958dd8ad1e8d75308f924a0794448439d9b31 (diff)
downloadchrome-ec-6d805476ba032b33e440330469a873e6a444fddb.tar.gz
Add configs to add flags to console commands
If we add a .flags field to the console commands data structure, we can use it to distinguish some commands from others, for example to mark some commands as safe and others as dangerous. This just adds the undefined CONFIG_ options. They aren't used anywhere, so there's no behavioral difference yet. BUG=chrome-os-partner:55322 BRANCH=none TEST=make buildall Change-Id: I17fdf177dcb4324c77565bd95344da1405ea15ed Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/376185 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'include/console.h')
-rw-r--r--include/console.h44
1 files changed, 32 insertions, 12 deletions
diff --git a/include/console.h b/include/console.h
index f0c96a167f..e82cd128cb 100644
--- a/include/console.h
+++ b/include/console.h
@@ -20,10 +20,29 @@ struct console_command {
/* Description of args */
const char *argdesc;
/* Short help for command */
- const char *shorthelp;
+ const char *help;
+#endif
+#ifdef CONFIG_CONSOLE_COMMAND_FLAGS
+ const uint32_t flags;
#endif
};
+/* Flag bits for when CONFIG_CONSOLE_COMMAND_FLAGS is enabled */
+#define CMD_FLAG_RESTRICTED 0x00000001
+
+/* The default .flags value can be overridden in board.h */
+#ifndef CONFIG_CONSOLE_COMMAND_FLAGS_DEFAULT
+#define CONFIG_CONSOLE_COMMAND_FLAGS_DEFAULT 0
+#endif
+
+#ifdef CONFIG_RESTRICTED_CONSOLE_COMMANDS
+/*
+ * This must be implemented somewhere. A true return value means that all
+ * CMD_FLAG_RESTRICTED commands are disabled.
+ */
+int console_is_restricted(void);
+#endif
+
/* Console channels */
enum console_channel {
#define CONSOLE_CHANNEL(enumeration, string) enumeration,
@@ -94,19 +113,20 @@ void console_has_input(void);
/**
* Register a console command handler.
*
- * @param name Command name; must not be the beginning of another
- * existing command name. Note this is NOT in quotes
- * so it can be concatenated to form a struct name.
- * @param routine Command handling routine, of the form
- * int handler(int argc, char **argv)
- * @param argdesc String describing arguments to command; NULL if none.
- * @param shorthelp String with one-line description of command.
+ * @param name Command name; must not be the beginning of another
+ * existing command name. Note this is NOT in quotes
+ * so it can be concatenated to form a struct name.
+ * @param routine Command handling routine, of the form
+ * int handler(int argc, char **argv)
+ * @param argdesc String describing arguments to command; NULL if none.
+ * @param help String with one-line description of command, or NULL.
+ * @param flags Per-command flags, if needed.
*/
#ifndef HAS_TASK_CONSOLE
-#define DECLARE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, SHORTHELP) \
+#define DECLARE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, HELP) \
int (ROUTINE)(int argc, char **argv) __attribute__((unused))
#elif defined(CONFIG_CONSOLE_CMDHELP)
-#define DECLARE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, SHORTHELP) \
+#define DECLARE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, HELP) \
static const char __con_cmd_label_##NAME[] = #NAME; \
struct size_check##NAME { \
int field[2 * (sizeof(__con_cmd_label_##NAME) < 16) - 1]; }; \
@@ -115,10 +135,10 @@ void console_has_input(void);
{ .name = __con_cmd_label_##NAME, \
.handler = ROUTINE, \
.argdesc = ARGDESC, \
- .shorthelp = SHORTHELP \
+ .help = HELP \
}
#else
-#define DECLARE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, SHORTHELP) \
+#define DECLARE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, HELP) \
static const char __con_cmd_label_##NAME[] = #NAME; \
struct size_check##NAME { \
int field[2 * (sizeof(__con_cmd_label_##NAME) < 16) - 1]; }; \