/* * This is a derived from the init.c file in the telnetd demo. * * $Id$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../networkconfig.h" // I'm not sure why this is necessary #include 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 #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 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 #include #include /* Helper for Ada */ void invoke_rtems_shell(void) { rtemsShell("console", NULL); }