aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas/assoc.c
diff options
context:
space:
mode:
authorHolger Schurig <hs4233@mail.mn-solutions.de>2008-04-02 10:27:42 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-04-08 16:44:40 -0400
commit245bf20f9c159f8d35befbc038997096b759459c (patch)
treeefa49f9090e2933689140d8725d1bbcbcafb7f8c /drivers/net/wireless/libertas/assoc.c
parent697900ac14528e985b66f471ecb81082fc00baa9 (diff)
libertas: move association code from scan.c into assoc.c
Besides code moving, I did the following changes: * made some functions static * removed some unneeded #include's * made patch checkpatch.pl clean Signed-off-by: Holger Schurig <hs4233@mail.mn-solutions.de> Acked-by: Dan Williams <dcbw@redhat.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/libertas/assoc.c')
-rw-r--r--drivers/net/wireless/libertas/assoc.c352
1 files changed, 352 insertions, 0 deletions
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
index e794e93a2297..319b4f931a62 100644
--- a/drivers/net/wireless/libertas/assoc.c
+++ b/drivers/net/wireless/libertas/assoc.c
@@ -5,6 +5,7 @@
5#include "assoc.h" 5#include "assoc.h"
6#include "decl.h" 6#include "decl.h"
7#include "host.h" 7#include "host.h"
8#include "scan.h"
8#include "cmd.h" 9#include "cmd.h"
9 10
10 11
@@ -170,6 +171,272 @@ int lbs_stop_adhoc_network(struct lbs_private *priv)
170 0, CMD_OPTION_WAITFORRSP, 0, NULL); 171 0, CMD_OPTION_WAITFORRSP, 0, NULL);
171} 172}
172 173
174static inline int match_bss_no_security(struct lbs_802_11_security *secinfo,
175 struct bss_descriptor *match_bss)
176{
177 if (!secinfo->wep_enabled && !secinfo->WPAenabled
178 && !secinfo->WPA2enabled
179 && match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC
180 && match_bss->rsn_ie[0] != MFIE_TYPE_RSN
181 && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY))
182 return 1;
183 else
184 return 0;
185}
186
187static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo,
188 struct bss_descriptor *match_bss)
189{
190 if (secinfo->wep_enabled && !secinfo->WPAenabled
191 && !secinfo->WPA2enabled
192 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
193 return 1;
194 else
195 return 0;
196}
197
198static inline int match_bss_wpa(struct lbs_802_11_security *secinfo,
199 struct bss_descriptor *match_bss)
200{
201 if (!secinfo->wep_enabled && secinfo->WPAenabled
202 && (match_bss->wpa_ie[0] == MFIE_TYPE_GENERIC)
203 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
204 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
205 )
206 return 1;
207 else
208 return 0;
209}
210
211static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo,
212 struct bss_descriptor *match_bss)
213{
214 if (!secinfo->wep_enabled && secinfo->WPA2enabled &&
215 (match_bss->rsn_ie[0] == MFIE_TYPE_RSN)
216 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
217 (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */
218 )
219 return 1;
220 else
221 return 0;
222}
223
224static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo,
225 struct bss_descriptor *match_bss)
226{
227 if (!secinfo->wep_enabled && !secinfo->WPAenabled
228 && !secinfo->WPA2enabled
229 && (match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC)
230 && (match_bss->rsn_ie[0] != MFIE_TYPE_RSN)
231 && (match_bss->capability & WLAN_CAPABILITY_PRIVACY))
232 return 1;
233 else
234 return 0;
235}
236
237/**
238 * @brief Check if a scanned network compatible with the driver settings
239 *
240 * WEP WPA WPA2 ad-hoc encrypt Network
241 * enabled enabled enabled AES mode privacy WPA WPA2 Compatible
242 * 0 0 0 0 NONE 0 0 0 yes No security
243 * 1 0 0 0 NONE 1 0 0 yes Static WEP
244 * 0 1 0 0 x 1x 1 x yes WPA
245 * 0 0 1 0 x 1x x 1 yes WPA2
246 * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES
247 * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP
248 *
249 *
250 * @param priv A pointer to struct lbs_private
251 * @param index Index in scantable to check against current driver settings
252 * @param mode Network mode: Infrastructure or IBSS
253 *
254 * @return Index in scantable, or error code if negative
255 */
256static int is_network_compatible(struct lbs_private *priv,
257 struct bss_descriptor *bss, uint8_t mode)
258{
259 int matched = 0;
260
261 lbs_deb_enter(LBS_DEB_SCAN);
262
263 if (bss->mode != mode)
264 goto done;
265
266 matched = match_bss_no_security(&priv->secinfo, bss);
267 if (matched)
268 goto done;
269 matched = match_bss_static_wep(&priv->secinfo, bss);
270 if (matched)
271 goto done;
272 matched = match_bss_wpa(&priv->secinfo, bss);
273 if (matched) {
274 lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x "
275 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
276 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
277 priv->secinfo.wep_enabled ? "e" : "d",
278 priv->secinfo.WPAenabled ? "e" : "d",
279 priv->secinfo.WPA2enabled ? "e" : "d",
280 (bss->capability & WLAN_CAPABILITY_PRIVACY));
281 goto done;
282 }
283 matched = match_bss_wpa2(&priv->secinfo, bss);
284 if (matched) {
285 lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x "
286 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s "
287 "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0],
288 priv->secinfo.wep_enabled ? "e" : "d",
289 priv->secinfo.WPAenabled ? "e" : "d",
290 priv->secinfo.WPA2enabled ? "e" : "d",
291 (bss->capability & WLAN_CAPABILITY_PRIVACY));
292 goto done;
293 }
294 matched = match_bss_dynamic_wep(&priv->secinfo, bss);
295 if (matched) {
296 lbs_deb_scan("is_network_compatible() dynamic WEP: "
297 "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n",
298 bss->wpa_ie[0], bss->rsn_ie[0],
299 (bss->capability & WLAN_CAPABILITY_PRIVACY));
300 goto done;
301 }
302
303 /* bss security settings don't match those configured on card */
304 lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x "
305 "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n",
306 bss->wpa_ie[0], bss->rsn_ie[0],
307 priv->secinfo.wep_enabled ? "e" : "d",
308 priv->secinfo.WPAenabled ? "e" : "d",
309 priv->secinfo.WPA2enabled ? "e" : "d",
310 (bss->capability & WLAN_CAPABILITY_PRIVACY));
311
312done:
313 lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched);
314 return matched;
315}
316
317/**
318 * @brief This function finds a specific compatible BSSID in the scan list
319 *
320 * Used in association code
321 *
322 * @param priv A pointer to struct lbs_private
323 * @param bssid BSSID to find in the scan list
324 * @param mode Network mode: Infrastructure or IBSS
325 *
326 * @return index in BSSID list, or error return code (< 0)
327 */
328static struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv,
329 uint8_t *bssid, uint8_t mode)
330{
331 struct bss_descriptor *iter_bss;
332 struct bss_descriptor *found_bss = NULL;
333
334 lbs_deb_enter(LBS_DEB_SCAN);
335
336 if (!bssid)
337 goto out;
338
339 lbs_deb_hex(LBS_DEB_SCAN, "looking for", bssid, ETH_ALEN);
340
341 /* Look through the scan table for a compatible match. The loop will
342 * continue past a matched bssid that is not compatible in case there
343 * is an AP with multiple SSIDs assigned to the same BSSID
344 */
345 mutex_lock(&priv->lock);
346 list_for_each_entry(iter_bss, &priv->network_list, list) {
347 if (compare_ether_addr(iter_bss->bssid, bssid))
348 continue; /* bssid doesn't match */
349 switch (mode) {
350 case IW_MODE_INFRA:
351 case IW_MODE_ADHOC:
352 if (!is_network_compatible(priv, iter_bss, mode))
353 break;
354 found_bss = iter_bss;
355 break;
356 default:
357 found_bss = iter_bss;
358 break;
359 }
360 }
361 mutex_unlock(&priv->lock);
362
363out:
364 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
365 return found_bss;
366}
367
368/**
369 * @brief This function finds ssid in ssid list.
370 *
371 * Used in association code
372 *
373 * @param priv A pointer to struct lbs_private
374 * @param ssid SSID to find in the list
375 * @param bssid BSSID to qualify the SSID selection (if provided)
376 * @param mode Network mode: Infrastructure or IBSS
377 *
378 * @return index in BSSID list
379 */
380static struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv,
381 uint8_t *ssid, uint8_t ssid_len,
382 uint8_t *bssid, uint8_t mode,
383 int channel)
384{
385 u32 bestrssi = 0;
386 struct bss_descriptor *iter_bss = NULL;
387 struct bss_descriptor *found_bss = NULL;
388 struct bss_descriptor *tmp_oldest = NULL;
389
390 lbs_deb_enter(LBS_DEB_SCAN);
391
392 mutex_lock(&priv->lock);
393
394 list_for_each_entry(iter_bss, &priv->network_list, list) {
395 if (!tmp_oldest ||
396 (iter_bss->last_scanned < tmp_oldest->last_scanned))
397 tmp_oldest = iter_bss;
398
399 if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len,
400 ssid, ssid_len) != 0)
401 continue; /* ssid doesn't match */
402 if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0)
403 continue; /* bssid doesn't match */
404 if ((channel > 0) && (iter_bss->channel != channel))
405 continue; /* channel doesn't match */
406
407 switch (mode) {
408 case IW_MODE_INFRA:
409 case IW_MODE_ADHOC:
410 if (!is_network_compatible(priv, iter_bss, mode))
411 break;
412
413 if (bssid) {
414 /* Found requested BSSID */
415 found_bss = iter_bss;
416 goto out;
417 }
418
419 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
420 bestrssi = SCAN_RSSI(iter_bss->rssi);
421 found_bss = iter_bss;
422 }
423 break;
424 case IW_MODE_AUTO:
425 default:
426 if (SCAN_RSSI(iter_bss->rssi) > bestrssi) {
427 bestrssi = SCAN_RSSI(iter_bss->rssi);
428 found_bss = iter_bss;
429 }
430 break;
431 }
432 }
433
434out:
435 mutex_unlock(&priv->lock);
436 lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss);
437 return found_bss;
438}
439
173static int assoc_helper_essid(struct lbs_private *priv, 440static int assoc_helper_essid(struct lbs_private *priv,
174 struct assoc_request * assoc_req) 441 struct assoc_request * assoc_req)
175{ 442{
@@ -617,6 +884,91 @@ static int should_stop_adhoc(struct lbs_private *priv,
617} 884}
618 885
619 886
887/**
888 * @brief This function finds the best SSID in the Scan List
889 *
890 * Search the scan table for the best SSID that also matches the current
891 * adapter network preference (infrastructure or adhoc)
892 *
893 * @param priv A pointer to struct lbs_private
894 *
895 * @return index in BSSID list
896 */
897static struct bss_descriptor *lbs_find_best_ssid_in_list(
898 struct lbs_private *priv, uint8_t mode)
899{
900 uint8_t bestrssi = 0;
901 struct bss_descriptor *iter_bss;
902 struct bss_descriptor *best_bss = NULL;
903
904 lbs_deb_enter(LBS_DEB_SCAN);
905
906 mutex_lock(&priv->lock);
907
908 list_for_each_entry(iter_bss, &priv->network_list, list) {
909 switch (mode) {
910 case IW_MODE_INFRA:
911 case IW_MODE_ADHOC:
912 if (!is_network_compatible(priv, iter_bss, mode))
913 break;
914 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
915 break;
916 bestrssi = SCAN_RSSI(iter_bss->rssi);
917 best_bss = iter_bss;
918 break;
919 case IW_MODE_AUTO:
920 default:
921 if (SCAN_RSSI(iter_bss->rssi) <= bestrssi)
922 break;
923 bestrssi = SCAN_RSSI(iter_bss->rssi);
924 best_bss = iter_bss;
925 break;
926 }
927 }
928
929 mutex_unlock(&priv->lock);
930 lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss);
931 return best_bss;
932}
933
934/**
935 * @brief Find the best AP
936 *
937 * Used from association worker.
938 *
939 * @param priv A pointer to struct lbs_private structure
940 * @param pSSID A pointer to AP's ssid
941 *
942 * @return 0--success, otherwise--fail
943 */
944static int lbs_find_best_network_ssid(struct lbs_private *priv,
945 uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode,
946 uint8_t *out_mode)
947{
948 int ret = -1;
949 struct bss_descriptor *found;
950
951 lbs_deb_enter(LBS_DEB_SCAN);
952
953 priv->scan_ssid_len = 0;
954 lbs_scan_networks(priv, 1);
955 if (priv->surpriseremoved)
956 goto out;
957
958 found = lbs_find_best_ssid_in_list(priv, preferred_mode);
959 if (found && (found->ssid_len > 0)) {
960 memcpy(out_ssid, &found->ssid, IW_ESSID_MAX_SIZE);
961 *out_ssid_len = found->ssid_len;
962 *out_mode = found->mode;
963 ret = 0;
964 }
965
966out:
967 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
968 return ret;
969}
970
971
620void lbs_association_worker(struct work_struct *work) 972void lbs_association_worker(struct work_struct *work)
621{ 973{
622 struct lbs_private *priv = container_of(work, struct lbs_private, 974 struct lbs_private *priv = container_of(work, struct lbs_private,