1 | /* |
---|
2 | * Copyright (c) 2017 Sichen Zhao. All rights reserved. |
---|
3 | * |
---|
4 | * <zsc19940506@gmail.com> |
---|
5 | * |
---|
6 | * Redistribution and use in source and binary forms, with or without |
---|
7 | * modification, are permitted provided that the following conditions |
---|
8 | * are met: |
---|
9 | * 1. Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
25 | * SUCH DAMAGE. |
---|
26 | */ |
---|
27 | |
---|
28 | #include <rtems/netcmds-config.h> |
---|
29 | #include <machine/rtems-bsd-commands.h> |
---|
30 | #include <assert.h> |
---|
31 | |
---|
32 | struct myparams { |
---|
33 | int argc; |
---|
34 | char ** argv; |
---|
35 | }; |
---|
36 | |
---|
37 | static void |
---|
38 | new_wpa_supplicant_task(rtems_task_argument arg) |
---|
39 | { |
---|
40 | int argc; |
---|
41 | char ** argv; |
---|
42 | int i; |
---|
43 | |
---|
44 | struct myparams *params = (struct myparams *)arg; |
---|
45 | argc = params->argc; |
---|
46 | argv = params->argv; |
---|
47 | |
---|
48 | rtems_bsd_command_wpa_supplicant(argc, argv); |
---|
49 | |
---|
50 | for (i = 0; i < params->argc; i++) { |
---|
51 | free(params->argv[i]); |
---|
52 | } |
---|
53 | free(params->argv); |
---|
54 | free(params); |
---|
55 | |
---|
56 | rtems_task_delete( RTEMS_SELF ); |
---|
57 | } |
---|
58 | |
---|
59 | int rtems_bsd_command_wpa_supplicant_fork(int argc, char **argv) |
---|
60 | { |
---|
61 | rtems_status_code sc; |
---|
62 | rtems_id id; |
---|
63 | int i; |
---|
64 | |
---|
65 | struct myparams *params = malloc(sizeof(struct myparams)); |
---|
66 | if (params == NULL) |
---|
67 | return NULL; |
---|
68 | |
---|
69 | params->argc = argc; |
---|
70 | params->argv = malloc((argc + 1) * sizeof(argv[0])); |
---|
71 | if (params->argv == NULL) |
---|
72 | return NULL; |
---|
73 | |
---|
74 | for (i = 0; i < argc; i++) { |
---|
75 | params->argv[i] = strdup(argv[i]); |
---|
76 | if (params->argv[i] == NULL) |
---|
77 | return NULL; |
---|
78 | } |
---|
79 | params->argv[argc] = NULL; |
---|
80 | |
---|
81 | sc = rtems_task_create( |
---|
82 | rtems_build_name('W', 'P', 'A', 'S'), |
---|
83 | RTEMS_MAXIMUM_PRIORITY - 1, |
---|
84 | 8 * RTEMS_MINIMUM_STACK_SIZE, |
---|
85 | RTEMS_DEFAULT_MODES, |
---|
86 | RTEMS_FLOATING_POINT, |
---|
87 | &id |
---|
88 | ); |
---|
89 | assert(sc == RTEMS_SUCCESSFUL); |
---|
90 | |
---|
91 | sc = rtems_task_start(id, new_wpa_supplicant_task, params); |
---|
92 | assert(sc == RTEMS_SUCCESSFUL); |
---|
93 | } |
---|
94 | |
---|
95 | rtems_shell_cmd_t rtems_shell_WPA_SUPPLICANT_FORK_Command = { |
---|
96 | .name = "wpa_supplicant_fork", |
---|
97 | .usage = "wpa_supplicant_fork [args]", |
---|
98 | .topic = "net", |
---|
99 | .command = rtems_bsd_command_wpa_supplicant_fork |
---|
100 | }; |
---|