revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / WirelessManager / wpa_supplicant / main_amiga.c
blob5c8492b170f82583550120e0717bbe29a9fa7a31
1 /*
2 * WPA Supplicant / main() function for Amiga-like OSes
3 * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2010-2015, Neil Cafferkey
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
11 * license.
13 * See README and COPYING for more details.
16 #include "includes.h"
18 #include "common.h"
19 #include "wpa_supplicant_i.h"
21 #include <exec/types.h>
22 #include <dos/dos.h>
24 #include <proto/dos.h>
26 #ifdef MUI_GUI
27 #include <proto/exec.h>
28 int start_gui(struct wpa_global *global);
29 void stop_gui(void);
30 VOID MUIGUI(VOID);
32 struct Process *gui_proc;
33 extern struct wpa_global *gui_global;
34 extern struct Task *main_task;
35 #endif
37 #ifndef UPINT
38 #ifdef __AROS__
39 typedef IPTR UPINT;
40 typedef SIPTR PINT;
41 #else
42 typedef ULONG UPINT;
43 typedef LONG PINT;
44 #endif
45 #endif
47 static const TEXT template[] = "DEVICE/A,UNIT/K/N,CONFIG/K,VERBOSE/S,NOGUI/S";
48 const TEXT version_string[] = "$VER: WirelessManager 1.6 (8.3.2015)";
49 static const TEXT config_file_name[] = "ENV:Sys/Wireless.prefs";
52 int main(int argc, char *argv[])
54 struct RDArgs *read_args;
55 LONG error = 0, unit_no = 0;
56 struct
58 const TEXT *device;
59 LONG *unit;
60 const TEXT *config;
61 PINT verbose;
62 PINT no_gui;
64 args = {NULL, &unit_no, config_file_name, FALSE, FALSE};
65 int i;
66 struct wpa_interface *ifaces, *iface;
67 int iface_count, exitcode = RETURN_FAIL;
68 struct wpa_params params;
69 struct wpa_global *global;
70 char *ifname;
72 if (os_program_init())
73 return -1;
75 os_memset(&params, 0, sizeof(params));
76 params.wpa_debug_level = MSG_INFO;
78 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
79 if (ifaces == NULL)
80 return RETURN_FAIL;
81 iface_count = 1;
83 /* Parse arguments */
84 read_args = ReadArgs(template, (PINT *)&args, NULL);
85 if (read_args == NULL)
87 error = IoErr();
88 goto out;
91 iface->ifname = ifname = os_malloc(strlen((const char *)args.device)
92 + 1 + 10 + 1);
93 if (ifname == NULL)
95 error = ERROR_NO_FREE_STORE;
96 goto out;
99 sprintf(ifname, "%s:%ld", args.device, (long int)*args.unit);
101 iface->confname = (char *) args.config;
103 if (args.verbose)
104 params.wpa_debug_level -= 2;
106 exitcode = 0;
107 global = wpa_supplicant_init(&params);
108 if (global == NULL) {
109 wpa_printf(MSG_ERROR, "Failed to initialize WirelessManager");
110 exitcode = RETURN_FAIL;
111 goto out;
114 for (i = 0; exitcode == 0 && i < iface_count; i++) {
115 if ((ifaces[i].confname == NULL &&
116 ifaces[i].ctrl_interface == NULL) ||
117 ifaces[i].ifname == NULL) {
118 if (iface_count == 1 && (params.ctrl_interface ||
119 params.dbus_ctrl_interface))
120 break;
121 error = ERROR_REQUIRED_ARG_MISSING;
122 exitcode = RETURN_FAIL;
123 break;
125 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
126 exitcode = RETURN_FAIL;
129 #ifdef MUI_GUI
130 if (exitcode == 0 && !args.no_gui)
131 exitcode = start_gui(global);
132 #endif
134 if (exitcode == 0)
135 exitcode = wpa_supplicant_run(global);
137 wpa_supplicant_deinit(global);
139 out:
140 os_free(ifaces);
142 // os_program_deinit();
143 #ifdef MUI_GUI
144 stop_gui();
145 #endif
147 FreeArgs(read_args);
149 /* Print error message */
150 SetIoErr(error);
151 PrintFault(error, NULL);
153 if (error != 0)
154 exitcode = RETURN_FAIL;
156 return exitcode;
159 #ifdef MUI_GUI
160 int start_gui(struct wpa_global *global)
162 gui_global = global;
163 main_task = FindTask(NULL);
164 gui_proc = CreateNewProcTags(NP_Entry, MUIGUI,
165 NP_Name, "WirelessManager GUI", TAG_END);
167 return 0;
170 void stop_gui(void)
172 if (gui_proc != NULL)
174 Signal((struct Task *) gui_proc, SIGBREAKF_CTRL_C);
175 Wait(SIGF_SINGLE);
178 #endif