Added WirelessManager, a port of wpa_supplicant.
[AROS.git] / workbench / network / WirelessManager / wpa_supplicant / main_amiga.c
blobf950950b9b0f54fa0cc4046775eda4cb11662e2f
1 /*
2 * WPA Supplicant / main() function for Amiga-like OSes
3 * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2010-2011, 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>
27 #ifndef UPINT
28 #ifdef __AROS__
29 typedef IPTR UPINT;
30 typedef SIPTR PINT;
31 #else
32 typedef ULONG UPINT;
33 typedef LONG PINT;
34 #endif
35 #endif
37 static const TEXT template[] = "DEVICE/A,UNIT/K/N,CONFIG/K,VERBOSE/S";
38 const TEXT version_string[] = "$VER: WirelessManager 1.1 (24.9.2011)";
39 static const TEXT config_file_name[] = "ENV:Wireless.prefs";
42 int main(int argc, char *argv[])
44 struct RDArgs *read_args;
45 LONG error = 0, unit_no = 0;
46 struct
48 const TEXT *device;
49 LONG *unit;
50 const TEXT *config;
51 PINT verbose;
53 args = {NULL, &unit_no, config_file_name, FALSE};
54 int i;
55 struct wpa_interface *ifaces, *iface;
56 int iface_count, exitcode = RETURN_FAIL;
57 struct wpa_params params;
58 struct wpa_global *global;
59 char *ifname;
61 if (os_program_init())
62 return -1;
64 os_memset(&params, 0, sizeof(params));
65 params.wpa_debug_level = MSG_INFO;
67 iface = ifaces = os_zalloc(sizeof(struct wpa_interface));
68 if (ifaces == NULL)
69 return RETURN_FAIL;
70 iface_count = 1;
72 /* Parse arguments */
73 read_args = ReadArgs(template, (UPINT *)&args, NULL);
74 if(read_args == NULL)
76 error = IoErr();
77 goto out;
80 iface->ifname = ifname = os_malloc(strlen((const char *)args.device)
81 + 1 + 10 + 1);
82 if (ifname == NULL)
84 error = ERROR_NO_FREE_STORE;
85 goto out;
88 sprintf(ifname, "%s:%ld", args.device, (long int)*args.unit);
90 iface->confname = (char *) args.config;
92 if (args.verbose)
93 params.wpa_debug_level -= 2;
95 exitcode = 0;
96 global = wpa_supplicant_init(&params);
97 if (global == NULL) {
98 wpa_printf(MSG_ERROR, "Failed to initialize WirelessManager");
99 exitcode = RETURN_FAIL;
100 goto out;
103 for (i = 0; exitcode == 0 && i < iface_count; i++) {
104 if ((ifaces[i].confname == NULL &&
105 ifaces[i].ctrl_interface == NULL) ||
106 ifaces[i].ifname == NULL) {
107 if (iface_count == 1 && (params.ctrl_interface ||
108 params.dbus_ctrl_interface))
109 break;
110 error = ERROR_REQUIRED_ARG_MISSING;
111 exitcode = RETURN_FAIL;
112 break;
114 if (wpa_supplicant_add_iface(global, &ifaces[i]) == NULL)
115 exitcode = RETURN_FAIL;
118 if (exitcode == 0)
119 exitcode = wpa_supplicant_run(global);
121 wpa_supplicant_deinit(global);
123 out:
124 os_free(ifaces);
126 // os_program_deinit();
128 FreeArgs(read_args);
130 /* Print error message */
131 SetIoErr(error);
132 PrintFault(error, NULL);
134 if(error != 0)
135 exitcode = RETURN_FAIL;
139 return exitcode;