source: rtems-libbsd/testsuite/media01/test_main.c @ ce2262e

55-freebsd-126-freebsd-12
Last change on this file since ce2262e was ce2262e, checked in by Sichen Zhao <1473996754@…>, on 10/12/17 at 12:16:09

Add wpa_supplicant_fork command.

Add fork command for wpa supplicant to start a new task.

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * Copyright (c) 2010-2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/param.h>
33
34#include <assert.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38
39#include <rtems/bdbuf.h>
40#include <rtems/console.h>
41#include <rtems/ftpd.h>
42#include <rtems/media.h>
43#include <rtems/shell.h>
44#include <rtems/telnetd.h>
45
46#define TEST_NAME "LIBBSD MEDIA 1"
47
48struct rtems_ftpd_configuration rtems_ftpd_configuration = {
49        /* FTPD task priority */
50        .priority = 100,
51
52        /* Maximum buffersize for hooks */
53        .max_hook_filesize = 0,
54
55        /* Well-known port */
56        .port = 21,
57
58        /* List of hooks */
59        .hooks = NULL,
60
61        /* Root for FTPD or NULL for "/" */
62        .root = NULL,
63
64        /* Max. connections depending on processor count */
65        .tasks_count = 0,
66
67        /* Idle timeout in seconds  or 0 for no (infinite) timeout */
68        .idle = 5 * 60,
69
70        /* Access: 0 - r/w, 1 - read-only, 2 - write-only, 3 - browse-only */
71        .access = 0
72};
73
74static rtems_status_code
75media_listener(rtems_media_event event, rtems_media_state state,
76    const char *src, const char *dest, void *arg)
77{
78        printf(
79                "media listener: event = %s, state = %s, src = %s",
80                rtems_media_event_description(event),
81                rtems_media_state_description(state),
82                src
83        );
84
85        if (dest != NULL) {
86                printf(", dest = %s", dest);
87        }
88
89        if (arg != NULL) {
90                printf(", arg = %p\n", arg);
91        }
92
93        printf("\n");
94
95        if (event == RTEMS_MEDIA_EVENT_MOUNT && state == RTEMS_MEDIA_STATE_SUCCESS) {
96                char name[256];
97                int n = snprintf(&name[0], sizeof(name), "%s/test.txt", dest);
98                FILE *file;
99
100                assert(n < (int) sizeof(name));
101
102                printf("write file %s\n", &name[0]);
103                file = fopen(&name[0], "w");
104                if (file != NULL) {
105                        const char hello[] = "Hello, world!\n";
106
107                        fwrite(&hello[0], sizeof(hello) - 1, 1, file);
108                        fclose(file);
109                }
110        }
111
112        return RTEMS_SUCCESSFUL;
113}
114
115static void
116telnet_shell(char *name, void *arg)
117{
118        rtems_shell_env_t env;
119
120        memset(&env, 0, sizeof(env));
121
122        env.devname = name;
123        env.taskname = "TLNT";
124        env.login_check = NULL;
125        env.forever = false;
126
127        rtems_shell_main_loop(&env);
128}
129
130rtems_telnetd_config_table rtems_telnetd_config = {
131        .command = telnet_shell,
132        .arg = NULL,
133        .priority = 0,
134        .stack_size = 0,
135        .login_check = NULL,
136        .keep_stdio = false
137};
138
139static void
140test_main(void)
141{
142        int rv;
143        rtems_status_code sc;
144
145        rtems_ftpd_configuration.tasks_count = MAX(4,
146            rtems_get_processor_count());
147        rv = rtems_initialize_ftpd();
148        assert(rv == 0);
149
150        sc = rtems_telnetd_initialize();
151        assert(sc == RTEMS_SUCCESSFUL);
152
153        sc = rtems_shell_init("SHLL", 16 * 1024, 1, CONSOLE_DEVICE_NAME,
154            false, true, NULL);
155        assert(sc == RTEMS_SUCCESSFUL);
156
157        exit(0);
158}
159
160#define DEFAULT_EARLY_INITIALIZATION
161
162static void
163early_initialization(void)
164{
165        rtems_status_code sc;
166
167        sc = rtems_bdbuf_init();
168        assert(sc == RTEMS_SUCCESSFUL);
169
170        sc = rtems_media_initialize();
171        assert(sc == RTEMS_SUCCESSFUL);
172
173        sc = rtems_media_listener_add(media_listener, NULL);
174        assert(sc == RTEMS_SUCCESSFUL);
175
176        sc = rtems_media_server_initialize(
177                200,
178                32 * 1024,
179                RTEMS_DEFAULT_MODES,
180                RTEMS_DEFAULT_ATTRIBUTES
181        );
182        assert(sc == RTEMS_SUCCESSFUL);
183}
184
185#define DEFAULT_NETWORK_DHCPCD_ENABLE
186
187#define CONFIGURE_MICROSECONDS_PER_TICK 1000
188
189#define CONFIGURE_MAXIMUM_DRIVERS 32
190
191#define CONFIGURE_FILESYSTEM_DOSFS
192
193#define CONFIGURE_MAXIMUM_PROCESSORS 32
194
195#include <rtems/bsd/test/default-network-init.h>
196
197#define CONFIGURE_SHELL_COMMANDS_INIT
198
199#include <bsp/irq-info.h>
200
201#include <rtems/netcmds-config.h>
202
203#define CONFIGURE_SHELL_USER_COMMANDS \
204  &bsp_interrupt_shell_command, \
205  &rtems_shell_ARP_Command, \
206  &rtems_shell_HOSTNAME_Command, \
207  &rtems_shell_PING_Command, \
208  &rtems_shell_ROUTE_Command, \
209  &rtems_shell_NETSTAT_Command, \
210  &rtems_shell_SYSCTL_Command, \
211  &rtems_shell_IFCONFIG_Command, \
212  &rtems_shell_VMSTAT_Command, \
213  &rtems_shell_WPA_SUPPLICANT_Command, \
214  &rtems_shell_WPA_SUPPLICANT_FORK_Command
215
216#define CONFIGURE_SHELL_COMMAND_CPUINFO
217#define CONFIGURE_SHELL_COMMAND_CPUUSE
218#define CONFIGURE_SHELL_COMMAND_PERIODUSE
219#define CONFIGURE_SHELL_COMMAND_STACKUSE
220#define CONFIGURE_SHELL_COMMAND_PROFREPORT
221
222#define CONFIGURE_SHELL_COMMAND_CP
223#define CONFIGURE_SHELL_COMMAND_PWD
224#define CONFIGURE_SHELL_COMMAND_LS
225#define CONFIGURE_SHELL_COMMAND_LN
226#define CONFIGURE_SHELL_COMMAND_LSOF
227#define CONFIGURE_SHELL_COMMAND_CHDIR
228#define CONFIGURE_SHELL_COMMAND_CD
229#define CONFIGURE_SHELL_COMMAND_MKDIR
230#define CONFIGURE_SHELL_COMMAND_RMDIR
231#define CONFIGURE_SHELL_COMMAND_CAT
232#define CONFIGURE_SHELL_COMMAND_MV
233#define CONFIGURE_SHELL_COMMAND_RM
234#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
235
236#define CONFIGURE_SHELL_COMMAND_FDISK
237#define CONFIGURE_SHELL_COMMAND_BLKSTATS
238#define CONFIGURE_SHELL_COMMAND_BLKSYNC
239#define CONFIGURE_SHELL_COMMAND_MSDOSFMT
240#define CONFIGURE_SHELL_COMMAND_DF
241#define CONFIGURE_SHELL_COMMAND_MOUNT
242#define CONFIGURE_SHELL_COMMAND_UNMOUNT
243#define CONFIGURE_SHELL_COMMAND_MSDOSFMT
244
245#include <rtems/shellconfig.h>
Note: See TracBrowser for help on using the repository browser.