www.usr.com/support/gpl/USR9113_release1.0.tar.gz
[bcm963xx.git] / userapps / broadcom / cfm / html / usr_91xx.js
1 /* -------------------------------------------------------------------------- */
2 /*
3         (c) 2005-2006 U.S. Robotics Corporation
4 */
5 /* -------------------------------------------------------------------------- */
6
7 /* --------------------------------------------------------------------------
8
9         Wireless info functions
10
11 */
12
13 /*
14         This is called to set the visibility of fields on
15         the Status and Tutorial pages.
16 */
17 // initializeSecurity("<%ejGetWl(wlAuthMode)%>", "<%ejGetWl(wlWep)%>")
18 function initializeSecurity(strAuthMode, strWEPmode)
19 {
20         var method = getSecurityMethod(strAuthMode, strWEPmode);
21         if (method.indexOf("RADIUS") != -1)
22         {
23                 // only show Encryption if also WPA
24                 if (method.indexOf("WPA") != -1)
25                         setVisibility("idEncrypt", true);
26
27                 setVisibility("idRADIUSkey", true);
28
29                 // Tutorial
30                 setVisibility("idKey8021x1", true);
31                 setVisibility("idKey8021x2", true);
32                 setVisibility("idKey8021x3", true);
33         }
34         else if (method.indexOf("WPA") != -1)
35         {
36                 setVisibility("idEncrypt", true);
37                 setVisibility("idKeyWPA", true);
38         }
39         else if (method.indexOf("WEP") != -1)
40         {
41                 setVisibility("idKeyWEP", true);
42         }
43 }
44
45 // getSecurityMethod("<%ejGetWl(wlAuthMode)%>", "<%ejGetWl(wlWep)%>")
46 function getSecurityMethod(strAuthMode, strWEPmode)
47 {
48         switch (strAuthMode)
49         {
50                 case "open":
51                         if (strWEPmode == "enabled")
52                                 return "WEP open";
53                         return "None";
54
55                 case "shared":                  return "WEP shared";
56
57                 case "psk":                             return "WPA";
58                 case "psk2":                    return "WPA2";
59                 case "psk2mix":         return "WPA2 and WPA";
60
61                 case "wpa":                             return "WPA with 802.1x (RADIUS)";
62                 case "wpa2":                    return "WPA2 with 802.1x (RADIUS)";
63                 case "wpa2mix":         return "WPA2 and WPA with 802.1x (RADIUS)";
64                 case "radius":                  return "802.1x (RADIUS)";
65
66                 default:                                        return "None";
67         }
68
69         return "";
70 }
71
72
73 /*
74         Return encryption method used for WPA or WEP
75 */
76 function getEncryption(strEncrypt)
77 {
78         switch (strEncrypt)
79         {
80                 case "aes":                             return "AES";
81                 case "tkip":                    return "TKIP";
82                 case "tkip+aes":                return "AES and TKIP";
83                 default:                                        return "";
84         }
85 }
86
87
88 /*
89         Return the WEP key specified by the current index.
90 */
91 function getWEPkey(strWEPkeyIx, strKey1, strKey2, strKey3, strKey4)
92 {
93         if (strWEPkeyIx == "")
94                 return "";
95
96         var ixKey = parseInt(strWEPkeyIx);
97         if ((ixKey >= 1) && (ixKey <= 4))
98         {
99                 var keys = new Array(strKey1, strKey2, strKey3, strKey4);
100                 return keys[ixKey - 1];
101         }
102
103         return "";
104 }
105
106 function getWEPkeyType(strKey)
107 {
108         return getKeySize(strKey) + "-" + (isKeyASCII(strKey) ? "ASCII" : "hex");
109 }
110
111
112
113 /*
114         Only call if WEP.
115
116         This is called when the user changes a sub-type of
117         encryption (WEP ASCII 128-bit, WEP hex 64-bit, ...).
118
119         Type values:
120                 type128ASCII
121                 type128hex
122                 type64ASCII
123                 type64hex
124 */
125 function setMaxLength(bClearValues, strType, eltKeys)
126 {
127         var bHex = ((strType == "type128hex") || (strType == "type64hex"));
128
129         var iBits = 128;
130         if ((strType == "type64ASCII") || (strType == "type64hex"))
131                 iBits = 64;
132
133         var iMaxLength = getKeyLength(iBits, bHex);
134
135         document.getElementById("idKeyNumChars").innerHTML = iMaxLength;
136
137         /*
138                 some page(s) might have only one key field,
139                 instead of an array of them, so check for that
140         */
141         if (eltKeys.length == null)
142         {
143                 eltKeys.maxLength = iMaxLength;
144                 if (bClearValues)
145                         eltKeys.value = "";
146         }
147         else
148         {
149                 for (var i = 0; i < eltKeys.length; ++i)
150                 {
151                         eltKeys[i].maxLength = iMaxLength;
152                         if (bClearValues)
153                                 eltKeys[i].value = "";
154                 }
155         }
156 }
157
158
159
160 /* --------------------------------------------------------------------------
161
162         General helper functions
163
164 */
165
166 /*
167         This function tests the passed element's value for being inside
168         the passed range--inclusive. If it's not, it displays an error
169         and sets focus to the field...and returns false.
170 */
171 function inRange(strName, elt, min, max)
172 {
173         if ((elt.value == "") || (elt.value < min) || (elt.value > max))
174         {
175                 alert("The " + strName + " setting must be between " + min + " and " + max + ", inclusive.");
176                 elt.focus();
177                 return false;
178         }
179         return true;
180 }
181
182 /*
183         This function tests the passed element's length for being at least the
184         passed number of characters. If it's not, it displays an error and sets
185         focus to the field...and returns false.
186 */
187 function minLength(strName, elt, min)
188 {
189         if (elt.value.length < min)
190         {
191                 alert("The " + strName + " field must have at least " + min + " characters.");
192                 elt.focus();
193                 return false;
194         }
195
196         return true;
197 }