nl80211: Fix a typo
[hostap-gosc2009.git] / www / wpa_supplicant / conf / configure.js
blob267982bfa338f71a594631293898604aa485c9e8
1 var conf_ap_scan = -1;
2 var conf_wired = false;
4 function configure_os()
6 var os = document.os_driver.os.value;
7 document.os_driver.driver.disabled = false;
8 document.os_driver.driver[0] = new Option("Select your driver", "select");
9 if (os == "linux") {
10 document.os_driver.driver[1] = new Option("madwifi", "madwifi");
11 document.os_driver.driver[2] = new Option("Host AP (Prism2/2.5/3)", "hostap");
12 document.os_driver.driver[3] = new Option("Intel ipw2100/2200", "ipw");
13 document.os_driver.driver[4] = new Option("Any wired Ethernet driver", "linux_wired");
14 document.os_driver.driver[5] = new Option("Other", "other linux");
15 } else if (os == "windows") {
16 document.os_driver.driver[1] = new Option("Any wireless NDIS driver", "ndis_wireless");
17 document.os_driver.driver[2] = new Option("Any wired (Ethernet) NDIS driver", "ndis_wired");
22 function configure_driver()
24 var drv = document.os_driver.driver.value;
25 var t = document.getElementById("os_desc");
27 t.innerHTML = "";
28 t.style.visibility = "hidden";
30 if (drv == "ndis_wireless") {
31 conf_ap_scan = 2;
32 t.innerHTML = "All wireless Windows NDIS drivers support AP selection " +
33 "and roaming, so in most cases, configuring the driver to take care " +
34 "of this by setting ap_scan=2 is the recommended configuration for " +
35 "Windows.";
36 t.style.visibility = "visible";
37 } else if (drv == "ndis_wired" || drv == "linux_wired") {
38 conf_ap_scan = 0;
39 conf_wired = true;
40 } else
41 conf_ap_scan = 1;
43 update_conf();
47 function update_encr()
49 var auth = document.authmode.auth.value;
50 var t = document.getElementById("encr_desc");
52 for (i = 0; i < 6; i++)
53 document.encrmode.encr[i] = null;
54 if (auth == "open") {
55 document.encrmode.encr[0] = new Option("None (unencrypted open network)", "none");
56 document.encrmode.encr.selectedIndex = 0;
57 t.innerHTML = "Based on the selected authentication mode (open network), only 'None' is an allowed encryption mode.";
58 t.style.visibility = "visible";
59 } else if (auth == "wep") {
60 document.encrmode.encr[0] = new Option("WEP (Wired Equivalent Privacy)", "wep");
61 document.encrmode.encr.selectedIndex = 0;
62 t.innerHTML = "Based on the selected authentication mode (WEP), only 'WEP' is an allowed encryption mode.";
63 t.style.visibility = "visible";
64 } else if (auth == "ieee8021x") {
65 document.encrmode.encr[0] = new Option("None (unencrypted open network)", "none");
66 document.encrmode.encr[1] = new Option("WEP (Wired Equivalent Privacy)", "wep");
67 document.encrmode.encr.selectedIndex = conf_wired ? 0 : 1;
68 t.innerHTML = "Based on the selected authentication mode (IEEE 802.1X), either 'None' or 'WEP' can be selected. In wireless networks, this is most likely going to be 'WEP' and in wired networks, only 'None' is allowed.";
69 t.style.visibility = "visible";
70 } else if (auth == "wpa-psk" || auth == "wpa-eap") {
71 document.encrmode.encr[0] = new Option("TKIP (Temporal Key Integrity Protocol)", "tkip");
72 document.encrmode.encr[1] = new Option("CCMP (AES Counter-Mode/CBC-MAC Protocol)", "ccmp");
73 document.encrmode.encr.selectedIndex = (document.authmode.auth2.value == "wpa1") ? 0 : 1;
74 t.innerHTML = "Based on the selected authentication mode (WPA/WPA2), either 'TKIP' or 'CCMP' can be selected. Most WPA networks are using TKIP whereas WPA2 defaults to CCMP.";
75 t.style.visibility = "visible";
76 } else {
77 t.innerHTML = "";
78 t.style.visibility = "hidden";
83 function update_cred()
85 var auth = document.authmode.auth.value;
86 var t;
88 t = document.getElementById("cred_unknown");
89 t.style.display = "none";
90 t = document.getElementById("cred_open");
91 t.style.display = "none";
92 t = document.getElementById("cred_wep");
93 t.style.display = "none";
94 t = document.getElementById("cred_psk");
95 t.style.display = "none";
96 t = document.getElementById("cred_eap");
97 t.style.display = "none";
99 if (auth == "open") {
100 t = document.getElementById("cred_open");
101 t.style.display = "block";
102 } else if (auth == "wep") {
103 t = document.getElementById("cred_wep");
104 t.style.display = "block";
105 } else if (auth == "wpa-psk") {
106 t = document.getElementById("cred_psk");
107 t.style.display = "block";
108 } else if (auth == "ieee8021x" || auth == "wpa-eap") {
109 t = document.getElementById("cred_eap");
110 t.style.display = "block";
111 } else {
112 t = document.getElementById("cred_unknown");
113 t.style.display = "block";
118 function configure_auth()
120 var auth = document.authmode.auth.value;
122 document.authmode.auth2[0] = null;
123 document.authmode.auth2[1] = null;
124 document.authmode.auth2.disabled = true;
125 if (auth == "wep") {
126 document.authmode.auth2[0] = new Option("Open System authentication", "open");
127 document.authmode.auth2[1] = new Option("Shared Key authentication", "shared");
128 document.authmode.auth2.disabled = false;
129 } else if (auth == "wpa-psk" || auth == "wpa-eap") {
130 document.authmode.auth2[0] = new Option("WPA (version 1)", "wpa1");
131 document.authmode.auth2[1] = new Option("WPA2 (IEEE 802.11i)", "wpa2");
132 document.authmode.auth2.disabled = false;
135 update_encr();
136 update_cred();
137 update_conf();
141 function configure_auth2()
143 update_encr();
144 update_conf();
148 function configure_encr()
150 update_conf();
154 function configure_passphrase()
156 var passphrase = document.cred_psk_form.passphrase.value;
157 var psk = document.cred_psk_form.psk.value;
158 var t = document.getElementById("cred_desc");
160 if (psk.length && (psk.length != 64 || !is_hex(psk))) {
161 t.innerHTML = "<p class=\"error\">Note: Invalid PSK</p>";
162 t.style.visibility = "visible";
163 } else if (psk.length == 0 && passphrase.length &&
164 (passphrase.length < 8 || passphrase.length > 63)) {
165 t.innerHTML = "<p class=\"error\">Note: Invalid passphrase</p>";
166 t.style.visibility = "visible";
167 } else {
168 t.innerHTML = "";
169 t.style.visibility = "hidden";
172 if (psk.length) {
173 document.cred_psk_form.passphrase.disabled = true;
174 document.cred_psk_form.psk.disabled = false;
175 } else if (passphrase.length) {
176 document.cred_psk_form.passphrase.disabled = false;
177 document.cred_psk_form.psk.disabled = true;
178 } else {
179 document.cred_psk_form.passphrase.disabled = false;
180 document.cred_psk_form.psk.disabled = false;
183 update_conf();
187 function is_hex(s)
189 if (s.length % 2)
190 return false;
192 for (i = 0; i < s.length; i++) {
193 if (s[i] >= 'a' && s[i] <= 'f')
194 continue;
195 if (s[i] >= 'A' && s[i] <= 'F')
196 continue;
197 if (s[i] >= '0' && s[i] <= '9')
198 continue;
199 return false;
202 return true;
206 function valid_wep_key(key)
208 if (key.length == 0)
209 return true;
211 if (key[0] == '"') {
212 if (key[key.length - 1] != '"')
213 return false;
214 return (key.length == 5 + 2 || key.length == 13 + 2 ||
215 key.length == 16 + 2);
218 return (is_hex(key) &&
219 (key.length == 10 || key.length == 26 || key.length == 32));
223 function configure_wep()
225 var t = document.getElementById("cred_desc");
226 var txt = "";
227 var wep;
229 wep = document.cred_wep_form.wep0.value;
230 if (!valid_wep_key(wep))
231 txt += "<p class=\"error\">Note: Invalid WEP key: " + wep + "</p>\n";
232 wep = document.cred_wep_form.wep1.value;
233 if (!valid_wep_key(wep))
234 txt += "<p class=\"error\">Note: Invalid WEP key: " + wep + "</p>\n";
235 wep = document.cred_wep_form.wep2.value;
236 if (!valid_wep_key(wep))
237 txt += "<p class=\"error\">Note: Invalid WEP key: " + wep + "</p>\n";
238 wep = document.cred_wep_form.wep3.value;
239 if (!valid_wep_key(wep))
240 txt += "<p class=\"error\">Note: Invalid WEP key: " + wep + "</p>\n";
242 if (txt.length) {
243 t.innerHTML = txt;
244 t.style.visibility = "visible";
245 } else if (t.style.visibility != "hidden")
246 t.style.visibility = "hidden";
248 update_conf();
252 function update_eap()
254 var eap = document.cred_eap_form.eap.value;
255 var n = 0;
257 if (eap == "PEAP" || eap == "TTLS" || eap == "FAST") {
258 document.cred_eap_form.phase2[n++] = new Option("EAP-MSCHAPv2", "MSCHAPV2");
259 document.cred_eap_form.phase2.selectedIndex = n - 1;
260 if (eap != "FAST") {
261 document.cred_eap_form.phase2[n++] = new Option("EAP-GTC", "GTC");
262 document.cred_eap_form.phase2[n++] = new Option("EAP-MD5", "MD5");
263 document.cred_eap_form.phase2[n++] = new Option("EAP-TLS", "TLS");
264 document.cred_eap_form.phase2[n++] = new Option("EAP-OTP", "OTP");
266 if (eap == "TTLS") {
267 document.cred_eap_form.phase2[n++] = new Option("MSCHAPv2", "_MSCHAPV2");
268 document.cred_eap_form.phase2.selectedIndex = n - 1;
269 document.cred_eap_form.phase2[n++] = new Option("MSCHAP", "_MSCHAP");
270 document.cred_eap_form.phase2[n++] = new Option("PAP", "_PAP");
271 document.cred_eap_form.phase2[n++] = new Option("CHAP", "_CHAP");
273 document.cred_eap_form.phase2.disabled = false;
274 } else {
275 document.cred_eap_form.phase2.disabled = true;
278 for (i = 20; i >= n; i--)
279 document.cred_eap_form.phase2[i] = null;
281 update_eap2();
285 function update_eap2()
287 var eap = document.cred_eap_form.eap.value;
288 var password = false;
289 var ca_cert = false;
290 var user_cert = false;
292 if (eap == "PEAP" || eap == "TTLS") {
293 ca_cert = true;
294 if (document.cred_eap_form.phase2.value == "TLS")
295 user_cert = true;
296 else
297 password = true;
298 } else if (eap == "FAST") {
299 password = true;
300 } else if (eap == "GTC") {
301 password = true;
302 } else if (eap == "LEAP" || eap == "MD5" || eap == "MSCHAPV2") {
303 password = true;
304 } else if (eap == "TLS") {
305 ca_cert = true;
306 user_cert = true;
309 if (eap == "TTLS") {
310 document.cred_eap_form.anon_identity.disabled = false;
311 document.cred_eap_form.anon_identity.value = "anonymous";
312 } else if (eap == "FAST") {
313 document.cred_eap_form.anon_identity.disabled = false;
314 document.cred_eap_form.anon_identity.value = "FAST-000000000000";
315 } else {
316 document.cred_eap_form.anon_identity.disabled = true;
318 document.cred_eap_form.password.disabled = !password;
319 if (ca_cert) {
320 document.cred_eap_form.ca_cert.disabled = false;
321 if (document.cred_eap_form.ca_cert.value.length == 0)
322 document.cred_eap_form.ca_cert.value = "/etc/ca.pem";
323 } else {
324 document.cred_eap_form.ca_cert.disabled = true;
326 document.cred_eap_form.client_cert.disabled = !user_cert;
327 document.cred_eap_form.private_key.disabled = !user_cert;
328 document.cred_eap_form.private_key_passwd.disabled = !user_cert;
330 if (eap == "FAST") {
331 document.cred_eap_form.pac_file.disabled = false;
332 if (document.cred_eap_form.pac_file.value.length == 0)
333 document.cred_eap_form.pac_file.value = "/etc/fast.pac";
334 } else {
335 document.cred_eap_form.pac_file.disabled = true;
338 configure_eap();
342 function configure_eap()
344 update_conf();
348 function update_conf()
350 var t = document.getElementById("exampleconf");
351 var txt = "";
352 var indent = "&nbsp;&nbsp;&nbsp;&nbsp;";
353 var ap_scan = conf_ap_scan;
354 var drv = document.os_driver.driver.value;
356 update_cred();
358 if (document.network.hidden_ssid.checked && ap_scan == 1 &&
359 drv != "hostap" && drv != "madwifi") {
360 /* if the selected driver does not support scan_ssid, must use
361 * ap_scan=2 mode with hidden SSIDs */
362 txt += "# this driver requires ap_scan=2 mode when using hidden SSIDs<br>\n";
363 ap_scan = 2;
366 switch (ap_scan) {
367 case -1:
368 txt += "# example configuration will be generated here<br>\n";
369 break;
370 case 0:
371 txt += "# wired drivers do not use scanning<br>\n" +
372 "ap_scan=0<br><br>\n";
373 break;
374 case 1:
375 txt += "# request AP scanning and decide which AP to use<br>\n" +
376 "ap_scan=1<br><br>\n";
377 break;
378 case 2:
379 txt += "# request driver to take care of AP selection and roaming<br>\n" +
380 "ap_scan=2<br><br>\n";
381 break;
384 if (document.os_driver.os.value == "windows") {
385 txt += "# enable control interface using local UDP socket<br>\n" +
386 "ctrl_interface=udp<br>\n";
387 } else {
388 txt += "# enable control interface using UNIX domain sockets<br>\n" +
389 "ctrl_interface=/var/run/wpa_supplicant<br>\n";
392 txt += "<br>\n" +
393 "# you can include one or more network blocks here<br>\n" +
394 "network={<br>\n";
396 if (conf_wired) {
397 txt += indent + "# wired network - must not configure SSID here<br>\n";
398 } else {
399 if (document.network.ssid.value.length == 0)
400 txt += indent + "# must configure SSID here (Step 2)<br>\n";
401 txt += indent + "ssid=\"" + document.network.ssid.value + "\"<br>\n";
402 if (ap_scan == 1 && document.network.hidden_ssid.checked)
403 txt += indent + "scan_ssid=1<br>\n";
406 var auth = document.authmode.auth.value;
407 var auth2 = document.authmode.auth2.value;
409 if (auth == "open" || auth == "wep")
410 txt += indent + "key_mgmt=NONE<br>\n";
411 else if (auth == "ieee8021x")
412 txt += indent + "key_mgmt=IEEE8021X<br>\n";
413 else if (auth == "wpa-psk")
414 txt += indent + "key_mgmt=WPA-PSK<br>\n";
415 else if (auth == "wpa-eap")
416 txt += indent + "key_mgmt=WPA-EAP<br>\n";
417 else
418 txt += indent + "# must set key_mgmt here (Step 3)<br>\n";
420 if (auth == "wep") {
421 if (auth2 == "open")
422 txt += indent + "auth_alg=OPEN<br>\n";
423 else if (auth2 == "shared")
424 txt += indent + "auth_alg=SHARED<br>\n";
425 } else if (auth == "wpa-psk" || auth == "wpa-eap") {
426 if (auth2 == "wpa1")
427 txt += indent + "proto=WPA<br>\n";
428 else if (auth2 == "wpa2")
429 txt += indent + "proto=WPA2<br>\n";
430 else
431 txt += indent + "# WPA proto (v1/v2) should be configured here (Step 3)<br>\n";
435 if (auth == "wpa-psk" || auth == "wpa-eap") {
436 var encr = document.encrmode.encr.value;
437 if (encr == "tkip")
438 txt += indent + "pairwise=TKIP<br>\n";
439 else if (encr == "ccmp")
440 txt += indent + "pairwise=CCMP<br>\n";
441 else
442 txt += indent + "# should configure pairwise encryption cipher (Step 4)<br>\n";
445 if (auth == "wep") {
446 var wep;
447 wep = document.cred_wep_form.wep0.value;
448 if (wep.length)
449 txt += indent + "wep_key0=" + wep + "<br>\n";
450 wep = document.cred_wep_form.wep1.value;
451 if (wep.length)
452 txt += indent + "wep_key1=" + wep + "<br>\n";
453 wep = document.cred_wep_form.wep2.value;
454 if (wep.length)
455 txt += indent + "wep_key2=" + wep + "<br>\n";
456 wep = document.cred_wep_form.wep3.value;
457 if (wep.length)
458 txt += indent + "wep_key3=" + wep + "<br>\n";
459 txt += indent + "wep_tx_keyidx=" + document.cred_wep_form.wep_tx_idx.value + "<br>\n";
460 } else if (auth == "wpa-psk") {
461 var passphrase = document.cred_psk_form.passphrase.value;
462 var psk = document.cred_psk_form.psk.value;
463 if (psk.length) {
464 if (psk.length != 64)
465 txt += indent + "# WPA PSK 64-character hex string<br>\n";
466 txt += indent + "psk=" + psk + "<br>\n";
467 } else {
468 if (passphrase.length < 8)
469 txt += indent + "# WPA passphrase must be at least 8 characters long<br>\n";
470 if (passphrase.length > 63)
471 txt += indent + "# WPA passphrase must be at most 63 characters long<br>\n";
472 txt += indent + "psk=\"" + passphrase + "\"<br>\n";
474 } else if (auth == "ieee8021x" || auth == "wpa-eap") {
475 var eap = document.cred_eap_form.eap.value;
476 if (eap == "select")
477 txt += indent + "# EAP method needs to be selected (Step 5)<br>\n";
478 else
479 txt += indent + "eap=" + eap + "<br>\n";
481 var phase2 = document.cred_eap_form.phase2;
482 var eap2 = phase2.value;
483 if (eap == "PEAP" || eap == "TTLS" || eap == "FAST") {
484 txt += indent + "phase2=\"auth";
485 if (eap == "TTLS") {
486 if (eap2[0] == '_') {
487 eap2 = eap2.substring(1);
488 } else
489 txt += "eap";
491 txt += "=" + eap2 + "\"<br>\n";
494 var identity = document.cred_eap_form.identity.value;
495 if (identity.length)
496 txt += indent + "identity=\"" + identity + "\"<br>\n";
498 var anon = document.cred_eap_form.anon_identity;
499 if (!anon.disabled && anon.value.length)
500 txt += indent + "anonymous_identity=\"" + anon.value + "\"<br>\n";
502 var password = document.cred_eap_form.password;
503 if (!password.disabled && password.value.length)
504 txt += indent + "password=\"" + password.value + "\"<br>\n";
506 var ca_cert = document.cred_eap_form.ca_cert;
507 if (!ca_cert.disabled) {
508 txt += indent + "ca_cert=\"" + ca_cert.value + "\"<br>\n";
509 if (!phase2.disabled && eap2 == "TLS")
510 txt += indent + "ca_cert2=\"" + ca_cert.value + "\"<br>\n";
513 var client_cert = document.cred_eap_form.client_cert;
514 if (!client_cert.disabled) {
515 var e = "";
516 if (!phase2.disabled && eap2 == "TLS")
517 e = "2";
519 if (client_cert.value.length)
520 txt += indent + "client_cert" + e + "=\"" + client_cert.value + "\"<br>\n";
522 var key = document.cred_eap_form.private_key.value;
523 if (key.length)
524 txt += indent + "private_key" + e + "=\"" + key + "\"<br>\n";
526 var passwd = document.cred_eap_form.private_key_passwd.value;
527 if (passwd.length)
528 txt += indent + "private_key_passwd" + e + "=\"" + passwd + "\"<br>\n";
531 var pac = document.cred_eap_form.pac_file;
532 if (!pac.disabled && pac.value.length)
533 txt += indent + "pac_file=\"" + pac.value + "\"<br>\n";
534 if (eap == "FAST")
535 txt += indent + "phase1=\"fast_provisioning=1\"<br>\n";
538 txt += "}<br>\n";
541 txt += "</p>\n";
543 t.innerHTML = txt;