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
12 * See README and COPYING for more details.
18 #include "rsn_supp/wpa.h"
20 #include "wpa_supplicant_i.h"
22 #include "common/ieee802_11_defs.h"
26 #include <exec/types.h>
27 #include <utility/hooks.h>
28 #include <libraries/mui.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
[] =
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
;
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
)
71 else if (wpa_scan_get_ie(bss
, (u8
) WPA_IE_VENDOR_TYPE
) != NULL
)
73 else if ((bss
->caps
& IEEE80211_CAP_PRIVACY
) != 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]);
85 item
[1] = enc_names
[enc
];
87 DoMethod(list
, MUIM_List_InsertSingle
, item
,
88 MUIV_List_Insert_Top
);
94 static IPTR
DisplayFunc(struct Hook
*hook
, STRPTR
*columns
, STRPTR
*entry
)
99 columns
[1] = "Encryption";
103 columns
[0] = entry
[0];
104 columns
[1] = entry
[1];
110 static IPTR
ScanFunc(struct Hook
*hook
, Object
* caller
, void *data
)
112 wpa_supplicant_req_scan(wpa_sup
, 0, 0);
118 static IPTR
ConnectFunc(struct Hook
*hook
, Object
* caller
, void *data
)
124 get(list
, MUIA_List_Active
, &active
);
125 if (active
== MUIV_List_Active_Off
)
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
;
133 && os_strncmp(ssid
->ssid
, entry
[0], ssid
->ssid_len
) != 0)
138 /* If not found, create a new configuration for this network */
141 passphrase
= (STRPTR
) XGET(str1
, MUIA_String_Contents
);
142 ssid
= wpa_config_add_network(wpa_sup
->conf
);
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 */
161 wpa_supplicant_select_network(wpa_sup
, ssid
);
163 DoMethod(list
, MUIM_List_Redraw
, MUIV_List_Redraw_Active
);
171 struct Hook scan_hook
, display_hook
, connect_hook
;
172 struct DiskObject
*dobj
;
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
,
201 Child
, (IPTR
) Label2("Passphrase"),
202 Child
, (str1
= StringObject
, StringFrame
, End
),
205 Child
, button1
= SimpleButton("Scan"),
206 Child
, button2
= SimpleButton("Connect"),
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
)
228 sigs
= Wait(sigs
| SIGBREAKF_CTRL_C
);
231 MUI_DisposeObject(app
);
232 FreeDiskObject(dobj
);
235 Signal(main_task
, SIGF_SINGLE
);