[c88644c] | 1 | /* Init |
---|
| 2 | * |
---|
| 3 | * This routine is the initialization task for this test program. |
---|
| 4 | * |
---|
| 5 | * Don't forget to change the IP addresses |
---|
| 6 | */ |
---|
| 7 | |
---|
[84b2a48] | 8 | #define USE_RTEMS_SHELL |
---|
| 9 | |
---|
[52ce8e2] | 10 | /* |
---|
| 11 | * Configuration parameters |
---|
| 12 | */ |
---|
| 13 | |
---|
[c88644c] | 14 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 15 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
[be2fc3e] | 16 | #ifdef RTEMS_BSP_HAS_IDE_DRIVER |
---|
| 17 | #define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER |
---|
| 18 | #endif |
---|
| 19 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK |
---|
| 20 | |
---|
[c88644c] | 21 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
[52ce8e2] | 22 | |
---|
[c88644c] | 23 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20 |
---|
[84b2a48] | 24 | #define CONFIGURE_MAXIMUM_PTYS 8 |
---|
[52ce8e2] | 25 | |
---|
| 26 | #if defined(USE_RTEMS_SHELL) |
---|
| 27 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK |
---|
| 28 | #endif |
---|
[c88644c] | 29 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
| 30 | |
---|
[09fc233] | 31 | #define CONFIGURE_STACK_CHECKER_ENABLED |
---|
[52ce8e2] | 32 | |
---|
| 33 | #define CONFIGURE_MEMORY_OVERHEAD 256 |
---|
| 34 | #define CONFIGURE_MESSAGE_BUFFER_MEMORY (32 * 1024) |
---|
| 35 | #define CONFIGURE_MAXIMUM_SEMAPHORES 40 |
---|
| 36 | #define CONFIGURE_MAXIMUM_TASKS 20 |
---|
| 37 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 20 |
---|
[c88644c] | 38 | |
---|
| 39 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
| 40 | |
---|
| 41 | #define CONFIGURE_INIT_TASK_STACK_SIZE (64*1024) |
---|
| 42 | #define CONFIGURE_INIT_TASK_PRIORITY 120 |
---|
| 43 | #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT |
---|
| 44 | #define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \ |
---|
| 45 | RTEMS_NO_TIMESLICE | \ |
---|
| 46 | RTEMS_NO_ASR | \ |
---|
| 47 | RTEMS_INTERRUPT_LEVEL(0)) |
---|
| 48 | |
---|
| 49 | #define CONFIGURE_MAXIMUM_DRIVERS 10 |
---|
| 50 | #define CONFIGURE_INIT |
---|
| 51 | |
---|
| 52 | #include <stdlib.h> |
---|
| 53 | #include <rtems.h> |
---|
| 54 | #include <rtems/telnetd.h> |
---|
| 55 | |
---|
| 56 | /* functions */ |
---|
| 57 | |
---|
| 58 | rtems_task Init( |
---|
| 59 | rtems_task_argument argument |
---|
| 60 | ); |
---|
| 61 | |
---|
| 62 | /* configuration information */ |
---|
| 63 | |
---|
| 64 | #include <rtems/confdefs.h> |
---|
| 65 | #include <bsp.h> |
---|
| 66 | |
---|
| 67 | #include <errno.h> |
---|
| 68 | #include <time.h> |
---|
| 69 | |
---|
| 70 | #include <rtems/confdefs.h> |
---|
| 71 | #include <stdio.h> |
---|
| 72 | #include <rtems/rtems_bsdnet.h> |
---|
| 73 | #include <rtems/telnetd.h> |
---|
| 74 | #include <rtems/shell.h> |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | #include <rtems/error.h> |
---|
| 78 | #include <rpc/rpc.h> |
---|
| 79 | #include <netinet/in.h> |
---|
| 80 | #include <time.h> |
---|
| 81 | |
---|
| 82 | #include <arpa/inet.h> |
---|
| 83 | #include <sys/socket.h> |
---|
| 84 | #include "../networkconfig.h" |
---|
| 85 | |
---|
[236963f] | 86 | /* |
---|
| 87 | * If true, listen on socket(s). |
---|
| 88 | * If false, remain on console. |
---|
| 89 | */ |
---|
| 90 | /* #define REMAIN_ON_CONSOLE */ |
---|
| 91 | bool remain_on_console = false; |
---|
| 92 | |
---|
[84b2a48] | 93 | #if defined(USE_ECHO_SHELL) |
---|
| 94 | |
---|
| 95 | #define SHELL_HELP_MSG \ |
---|
| 96 | "Starting echoShell via telnetd -- default password is rtems\n" |
---|
| 97 | |
---|
[c88644c] | 98 | /* |
---|
| 99 | * Number of sessions |
---|
| 100 | */ |
---|
| 101 | int session = 0; |
---|
| 102 | |
---|
| 103 | /* |
---|
| 104 | * Macro to printf and printk the same arguments |
---|
| 105 | */ |
---|
| 106 | |
---|
| 107 | #define printKF( ... ) \ |
---|
| 108 | do { \ |
---|
| 109 | printf( __VA_ARGS__ ); \ |
---|
| 110 | printk( __VA_ARGS__ ); \ |
---|
| 111 | } while (0) |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | /* |
---|
| 115 | * echo shell |
---|
| 116 | */ |
---|
| 117 | void echoShell( |
---|
| 118 | char *pty_name, |
---|
| 119 | void *cmd_arg |
---|
| 120 | ) |
---|
| 121 | { |
---|
| 122 | int cmds = 0; |
---|
| 123 | char line[256]; |
---|
| 124 | char *c; |
---|
| 125 | int l; |
---|
| 126 | |
---|
| 127 | ++session; |
---|
| 128 | printKF( "Connected to %s with argument %p for session %d\n", |
---|
| 129 | pty_name, cmd_arg, session ); |
---|
| 130 | |
---|
| 131 | while (1) { |
---|
| 132 | cmds++; |
---|
| 133 | printf( "> " ); |
---|
| 134 | c = fgets( line, 256, stdin ); |
---|
| 135 | if ( !c ) { |
---|
| 136 | printKF( "Connection terminated\n"); |
---|
| 137 | return; |
---|
| 138 | } |
---|
| 139 | l = strlen( line ); |
---|
| 140 | if ( line[l-1] == '\n' ) { |
---|
| 141 | line[l-1] = '\0'; |
---|
| 142 | } |
---|
| 143 | if ( !strcmp( line, "bye" ) ) { |
---|
| 144 | printKF( "%s", "Terminating connection\n"); |
---|
| 145 | return; |
---|
| 146 | } |
---|
| 147 | if ( !strcmp( line, "exit" ) ) { |
---|
| 148 | printKF("\n\n*** End of Telnetd Server Test ***\n\r" ); |
---|
| 149 | exit(0); |
---|
| 150 | } |
---|
| 151 | printKF( "echo %d-%d> %s\n", session, cmds, line ); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
[84b2a48] | 155 | #define SHELL_ENTRY echoShell |
---|
| 156 | |
---|
| 157 | #endif |
---|
| 158 | |
---|
| 159 | #if defined(USE_RTEMS_SHELL) |
---|
| 160 | |
---|
| 161 | #include <rtems/shell.h> |
---|
| 162 | |
---|
| 163 | #define SHELL_HELP_MSG \ |
---|
| 164 | "Starting rtemsShell via telnetd -- default account is rtems w/no password\n" |
---|
| 165 | |
---|
[362583c] | 166 | #define CONFIGURE_SHELL_COMMANDS_ALL_NETWORKING |
---|
| 167 | #define CONFIGURE_SHELL_COMMANDS_ALL |
---|
| 168 | |
---|
| 169 | #define CONFIGURE_SHELL_COMMANDS_INIT |
---|
| 170 | #include <rtems/shellconfig.h> |
---|
| 171 | |
---|
| 172 | |
---|
[84b2a48] | 173 | void rtemsShell( |
---|
| 174 | char *pty_name, |
---|
| 175 | void *cmd_arg |
---|
| 176 | ) |
---|
| 177 | { |
---|
[236963f] | 178 | if ( !remain_on_console ) |
---|
| 179 | printk("============== Starting Shell ==============\n"); |
---|
| 180 | |
---|
[52ce8e2] | 181 | rtems_shell_main_loop( NULL ); |
---|
[236963f] | 182 | |
---|
| 183 | if ( !remain_on_console ) |
---|
| 184 | printk("============== Exiting Shell ==============\n"); |
---|
[84b2a48] | 185 | } |
---|
| 186 | |
---|
| 187 | #define SHELL_ENTRY rtemsShell |
---|
| 188 | |
---|
| 189 | #endif |
---|
| 190 | |
---|
[c88644c] | 191 | /* |
---|
| 192 | * Init task |
---|
| 193 | */ |
---|
| 194 | rtems_task Init( |
---|
| 195 | rtems_task_argument argument |
---|
| 196 | ) |
---|
| 197 | { |
---|
[236963f] | 198 | fprintf(stderr, "\n\n*** Telnetd Server Test ***\n\r" ); |
---|
[c88644c] | 199 | |
---|
[236963f] | 200 | fprintf(stderr, "============== Initializing Network ==============\n"); |
---|
[c88644c] | 201 | rtems_bsdnet_initialize_network (); |
---|
| 202 | |
---|
[236963f] | 203 | fprintf(stderr, "============== Add Route ==============\n"); |
---|
[c88644c] | 204 | rtems_bsdnet_show_inet_routes (); |
---|
| 205 | |
---|
[236963f] | 206 | fprintf(stderr, "============== Start Telnetd ==============\n"); |
---|
[84b2a48] | 207 | |
---|
| 208 | printk( SHELL_HELP_MSG ); |
---|
| 209 | |
---|
[236963f] | 210 | #if defined(REMAIN_ON_CONSOLE) |
---|
| 211 | remain_on_console = true; |
---|
| 212 | #endif |
---|
| 213 | |
---|
[c88644c] | 214 | rtems_telnetd_initialize( |
---|
[236963f] | 215 | SHELL_ENTRY, /* "shell" function */ |
---|
| 216 | NULL, /* no context necessary for echoShell */ |
---|
| 217 | remain_on_console, /* true == remain on console */ |
---|
| 218 | /* false == listen on sockets */ |
---|
[be2fc3e] | 219 | RTEMS_MINIMUM_STACK_SIZE * 20, /* shell needs a large stack */ |
---|
[236963f] | 220 | 1, /* priority .. we feel important today */ |
---|
| 221 | false /* false = telnetd does NOT ask for password */ |
---|
| 222 | /* true = telnetd asks for password */ |
---|
| 223 | /* RTEMS Shell always asks for user/passwd */ |
---|
[c88644c] | 224 | ); |
---|
| 225 | |
---|
[236963f] | 226 | if ( !remain_on_console ) |
---|
| 227 | fprintf(stderr, "============== Deleting Init Task ==============\n"); |
---|
[c88644c] | 228 | rtems_task_delete(RTEMS_SELF); |
---|
| 229 | } |
---|
| 230 | |
---|