diff options
Diffstat (limited to 'shell/shell_init.c')
-rw-r--r-- | shell/shell_init.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/shell/shell_init.c b/shell/shell_init.c new file mode 100644 index 0000000..32d7bbe --- /dev/null +++ b/shell/shell_init.c @@ -0,0 +1,152 @@ +/* + * This is a derived from the init.c file in the telnetd demo. + * + * $Id$ + */ + +#include <bsp.h> + +#include <errno.h> +#include <time.h> + +#include <stdio.h> +#include <rtems/rtems_bsdnet.h> +#include <rtems/telnetd.h> +#include <rtems/shell.h> + +#include <rtems/error.h> +#include <rpc/rpc.h> +#include <netinet/in.h> +#include <time.h> + +#include <arpa/inet.h> +#include <sys/socket.h> +#include "../networkconfig.h" + +// I'm not sure why this is necessary +#include <rtems/bdbuf.h> +const rtems_bdbuf_config rtems_bdbuf_configuration; + +typedef char * (* prompt_function_t)(void); + +static prompt_function_t prompt_function = NULL; + +extern void set_prompt_function(prompt_function_t f) +{ + prompt_function = f; +} + +extern char * get_prompt(void); +void rtems_shell_get_prompt( + rtems_shell_env_t *shell_env, + char *prompt, + size_t size +) +{ + char curdir[256]; + + if (prompt_function == NULL) + { + getcwd(curdir,sizeof(curdir)); + snprintf(prompt, size - 1, "%s%s[%s] %c ", + ((shell_env->taskname) ? shell_env->taskname : ""), + ((shell_env->taskname) ? " " : ""), + curdir, + geteuid()?'$':'#'); + + } + else + snprintf(prompt, size - 1, prompt_function()); +} + +/* + * If true, listen on socket(s). + * If false, remain on console. + */ +/* #define REMAIN_ON_CONSOLE */ +bool remain_on_console = false; + +#include <rtems/shell.h> + +#define SHELL_HELP_MSG \ + "Starting rtemsShell via telnetd -- default account is rtems w/no password\n" + +#define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING +#define CONFIGURE_SHELL_COMMANDS_ALL + +#define CONFIGURE_SHELL_COMMANDS_INIT +#include <rtems/shellconfig.h> + + +static void rtemsShell( + char *pty_name, + void *cmd_arg +) +{ + rtems_shell_env_t env = rtems_global_shell_env; + + env.devname = pty_name; + env.taskname = "TLNT"; + env.login_check = rtems_shell_login_check; + + if ( !remain_on_console ) + printk("============== Starting Shell ==============\n"); + + rtems_shell_main_loop( &env ); + + if ( !remain_on_console ) + printk("============== Exiting Shell ==============\n"); +} + +#define SHELL_ENTRY rtemsShell + +/* + * Telnet demon configuration + */ +rtems_telnetd_config_table rtems_telnetd_config = { + .command = SHELL_ENTRY, + .arg = NULL, + .priority = 1, /* We feel important today */ + .stack_size = 20 * RTEMS_MINIMUM_STACK_SIZE, /* Shell needs a large stack */ + .login_check = NULL, /* Shell asks for user and password */ + .keep_stdio = false +}; + +/* + * Initialization Aid + */ +void init_telnet_daemon(void) +{ + fprintf(stderr, "\n\n*** Telnetd Server Test ***\n\r" ); + + fprintf(stderr, "============== Initializing Network ==============\n"); + rtems_bsdnet_initialize_network (); + + fprintf(stderr, "============== Add Route ==============\n"); + rtems_bsdnet_show_inet_routes (); + + fprintf(stderr, "============== Start Telnetd ==============\n"); + + printk( SHELL_HELP_MSG ); + + #if defined(REMAIN_ON_CONSOLE) + remain_on_console = true; + #endif + + rtems_global_shell_env.login_check = rtems_shell_login_check; + rtems_telnetd_config.keep_stdio = remain_on_console; + + rtems_telnetd_initialize(); +} + + +#include <stdlib.h> +#include <rtems.h> +#include <rtems/telnetd.h> + +/* Helper for Ada */ +void invoke_rtems_shell(void) +{ + rtemsShell("console", NULL); +} + |