Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / WirelessManager / wpa_supplicant / wpa_gui_amiga.c
blob48f0ab0231316721bcd2cfdc0d74bb787a6af4dd
1 /*
2 * WPA Supplicant - MUI GUI
3 * Copyright (c) 2012-2016, Neil Cafferkey
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
17 #include "common.h"
18 #include "rsn_supp/wpa.h"
19 #include "config.h"
20 #include "wpa_supplicant_i.h"
21 #include "driver_i.h"
22 #include "common/ieee802_11_defs.h"
23 #include "ibss_rsn.h"
24 #include "scan.h"
26 #include <exec/types.h>
27 #include <utility/hooks.h>
28 #include <libraries/mui.h>
29 #include <dos/dos.h>
30 #include <intuition/gadgetclass.h>
31 #include <intuition/icclass.h>
33 #include <proto/exec.h>
34 #include <proto/icon.h>
35 #include <proto/intuition.h>
36 #include <proto/muimaster.h>
37 #include <clib/alib_protos.h>
40 struct wpa_global *gui_global;
41 struct Task *main_task;
42 static struct wpa_supplicant *wpa_sup;
43 static Object *app, *window, *str1, *button1, *button2, *list;
45 static CONST_STRPTR enc_names[] =
47 (STRPTR) "None",
48 (STRPTR) "WEP",
49 (STRPTR) "WPA",
50 (STRPTR) "WPA2"
53 void wpa_gui_amiga_inspect_scan_results(struct wpa_supplicant *wpa_s,
54 struct wpa_scan_results *scan_res)
56 struct wpa_scan_res *bss;
57 size_t i;
58 const u8 *ie;
59 UWORD enc;
61 DoMethod(list, MUIM_List_Clear);
63 for (i = 0; i < scan_res->num; i++)
65 bss = scan_res->res[i];
67 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
69 if (wpa_scan_get_ie(bss, WLAN_EID_RSN) != NULL)
70 enc = 3;
71 else if (wpa_scan_get_ie(bss, (u8) WPA_IE_VENDOR_TYPE) != NULL)
72 enc = 2;
73 else if ((bss->caps & IEEE80211_CAP_PRIVACY) != 0)
74 enc = 1;
75 else
76 enc = 0;
78 STRPTR name = AllocVec(ie[1] + 1, MEMF_CLEAR);
79 CONST_STRPTR *item = AllocMem(sizeof(STRPTR) * 3, MEMF_ANY);
81 if (name != NULL && item != NULL)
83 CopyMem(ie + 2, name, ie[1]);
84 item[0] = name;
85 item[1] = enc_names[enc];
86 item[2] = NULL;
87 DoMethod(list, MUIM_List_InsertSingle, item,
88 MUIV_List_Insert_Top);
94 static IPTR DisplayFunc(struct Hook *hook, STRPTR *columns, STRPTR *entry)
96 if (entry == NULL)
98 columns[0] = "Name";
99 columns[1] = "Encryption";
101 else
103 columns[0] = entry[0];
104 columns[1] = entry[1];
106 return TRUE;
110 static IPTR ScanFunc(struct Hook *hook, Object * caller, void *data)
112 wpa_supplicant_req_scan(wpa_sup, 0, 0);
114 return TRUE;
118 static IPTR ConnectFunc(struct Hook *hook, Object * caller, void *data)
120 LONG active = 0;
121 STRPTR *entry;
122 STRPTR passphrase;
124 get(list, MUIA_List_Active, &active);
125 if (active == MUIV_List_Active_Off)
126 return FALSE;
128 DoMethod(list, MUIM_List_GetEntry, active, &entry);
130 /* Look for an existing configuration for this network */
131 struct wpa_ssid *ssid = wpa_sup->conf->ssid;
132 while (ssid != NULL
133 && os_strncmp(ssid->ssid, entry[0], ssid->ssid_len) != 0)
135 ssid = ssid->next;
138 /* If not found, create a new configuration for this network */
139 if (ssid == NULL)
141 passphrase = (STRPTR) XGET(str1, MUIA_String_Contents);
142 ssid = wpa_config_add_network(wpa_sup->conf);
143 if (ssid != NULL)
145 wpa_config_set_network_defaults(ssid);
146 ssid->ssid = os_strdup(entry[0]);
147 ssid->ssid_len = strlen(entry[0]);
148 if (entry[1] == enc_names[2] || entry[1] == enc_names[3])
150 ssid->passphrase = os_strdup(passphrase);
151 wpa_config_update_psk(ssid);
153 else if (entry[1] == enc_names[1])
159 /* Connect to network */
160 if (ssid != NULL)
161 wpa_supplicant_select_network(wpa_sup, ssid);
163 DoMethod(list, MUIM_List_Redraw, MUIV_List_Redraw_Active);
165 return TRUE;
169 VOID MUIGUI(VOID)
171 struct Hook scan_hook, display_hook, connect_hook;
172 struct DiskObject *dobj;
173 ULONG sigs = 0;
175 wpa_sup = &gui_global->ifaces[0];
177 scan_hook.h_Entry = HookEntry;
178 scan_hook.h_SubEntry = (HOOKFUNC) ScanFunc;
179 display_hook.h_Entry = HookEntry;
180 display_hook.h_SubEntry = (HOOKFUNC) DisplayFunc;
181 connect_hook.h_Entry = HookEntry;
182 connect_hook.h_SubEntry = (HOOKFUNC) ConnectFunc;
184 app = ApplicationObject,
185 MUIA_Application_Title, "Wireless Manager",
186 MUIA_Application_DiskObject,
187 (IPTR) (dobj = GetDiskObject("ENVARC:SYS/def_Wireless")),
188 SubWindow, window = WindowObject,
189 MUIA_Window_Title, "Wireless Manager",
190 MUIA_Window_Activate, TRUE,
191 MUIA_Window_CloseGadget, FALSE,
192 MUIA_Window_Width, 256,
193 WindowContents, VGroup,
194 Child, ListviewObject, MUIA_Listview_List,
195 (list = ListObject, MUIA_List_DisplayHook, &display_hook,
196 MUIA_List_Format, "WEIGHT=500 BAR, ",
197 MUIA_List_Title, TRUE,
198 End),
199 End,
200 Child, HGroup,
201 Child, (IPTR) Label2("Passphrase"),
202 Child, (str1 = StringObject, StringFrame, End),
203 End,
204 Child, HGroup,
205 Child, button1 = SimpleButton("Scan"),
206 Child, button2 = SimpleButton("Connect"),
207 End,
208 End,
209 End,
210 End;
212 if (app != NULL)
214 DoMethod(button1, MUIM_Notify, MUIA_Pressed, FALSE,
215 (IPTR) button1, 3, MUIM_CallHook, &scan_hook, list);
217 DoMethod(button2, MUIM_Notify, MUIA_Pressed, FALSE,
218 (IPTR) list, 3, MUIM_CallHook, &connect_hook, NULL);
220 set(app, MUIA_Application_Iconified, TRUE);
221 set(window, MUIA_Window_Open, TRUE);
223 while ((sigs & SIGBREAKF_CTRL_C) == 0
224 && DoMethod(app, MUIM_Application_NewInput,
225 (IPTR) &sigs) != MUIV_Application_ReturnID_Quit)
227 if (sigs != 0)
228 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
231 MUI_DisposeObject(app);
232 FreeDiskObject(dobj);
235 Signal(main_task, SIGF_SINGLE);