Commit | Line | Data |
---|---|---|
876c9d3a MT |
1 | /* Copyright (C) 2006, Red Hat, Inc. */ |
2 | ||
3cf20931 | 3 | #include <linux/etherdevice.h> |
876c9d3a MT |
4 | |
5 | #include "assoc.h" | |
876c9d3a | 6 | #include "decl.h" |
876c9d3a | 7 | #include "host.h" |
245bf20f | 8 | #include "scan.h" |
2dd4b262 | 9 | #include "cmd.h" |
876c9d3a MT |
10 | |
11 | ||
5a6e0434 IH |
12 | static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) = |
13 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; | |
14 | static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) = | |
15 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | |
876c9d3a | 16 | |
697900ac HS |
17 | /* The firmware needs certain bits masked out of the beacon-derviced capability |
18 | * field when associating/joining to BSSs. | |
19 | */ | |
20 | #define CAPINFO_MASK (~(0xda00)) | |
21 | ||
22 | ||
23 | ||
24 | /** | |
25 | * @brief Associate to a specific BSS discovered in a scan | |
26 | * | |
27 | * @param priv A pointer to struct lbs_private structure | |
d5db2dfa | 28 | * @param assoc_req The association request describing the BSS to associate with |
697900ac HS |
29 | * |
30 | * @return 0-success, otherwise fail | |
31 | */ | |
32 | static int lbs_associate(struct lbs_private *priv, | |
33 | struct assoc_request *assoc_req) | |
34 | { | |
35 | int ret; | |
d5db2dfa | 36 | u8 preamble = RADIO_PREAMBLE_LONG; |
697900ac HS |
37 | |
38 | lbs_deb_enter(LBS_DEB_ASSOC); | |
39 | ||
40 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE, | |
41 | 0, CMD_OPTION_WAITFORRSP, | |
42 | 0, assoc_req->bss.bssid); | |
697900ac | 43 | if (ret) |
d5db2dfa | 44 | goto out; |
697900ac | 45 | |
d5db2dfa | 46 | /* Use short preamble only when both the BSS and firmware support it */ |
697900ac HS |
47 | if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && |
48 | (assoc_req->bss.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) | |
d5db2dfa | 49 | preamble = RADIO_PREAMBLE_SHORT; |
697900ac | 50 | |
d5db2dfa DW |
51 | ret = lbs_set_radio(priv, preamble, 1); |
52 | if (ret) | |
53 | goto out; | |
697900ac HS |
54 | |
55 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE, | |
56 | 0, CMD_OPTION_WAITFORRSP, 0, assoc_req); | |
57 | ||
d5db2dfa | 58 | out: |
697900ac HS |
59 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
60 | return ret; | |
61 | } | |
62 | ||
63 | /** | |
64 | * @brief Join an adhoc network found in a previous scan | |
65 | * | |
66 | * @param priv A pointer to struct lbs_private structure | |
d5db2dfa | 67 | * @param assoc_req The association request describing the BSS to join |
697900ac HS |
68 | * |
69 | * @return 0--success, -1--fail | |
70 | */ | |
71 | static int lbs_join_adhoc_network(struct lbs_private *priv, | |
72 | struct assoc_request *assoc_req) | |
73 | { | |
74 | struct bss_descriptor *bss = &assoc_req->bss; | |
75 | int ret = 0; | |
d5db2dfa DW |
76 | u8 preamble = RADIO_PREAMBLE_LONG; |
77 | ||
78 | lbs_deb_enter(LBS_DEB_ASSOC); | |
697900ac HS |
79 | |
80 | lbs_deb_join("current SSID '%s', ssid length %u\n", | |
81 | escape_essid(priv->curbssparams.ssid, | |
82 | priv->curbssparams.ssid_len), | |
83 | priv->curbssparams.ssid_len); | |
84 | lbs_deb_join("requested ssid '%s', ssid length %u\n", | |
85 | escape_essid(bss->ssid, bss->ssid_len), | |
86 | bss->ssid_len); | |
87 | ||
88 | /* check if the requested SSID is already joined */ | |
89 | if (priv->curbssparams.ssid_len && | |
90 | !lbs_ssid_cmp(priv->curbssparams.ssid, | |
91 | priv->curbssparams.ssid_len, | |
92 | bss->ssid, bss->ssid_len) && | |
93 | (priv->mode == IW_MODE_ADHOC) && | |
94 | (priv->connect_status == LBS_CONNECTED)) { | |
95 | union iwreq_data wrqu; | |
96 | ||
97 | lbs_deb_join("ADHOC_J_CMD: New ad-hoc SSID is the same as " | |
98 | "current, not attempting to re-join"); | |
99 | ||
100 | /* Send the re-association event though, because the association | |
101 | * request really was successful, even if just a null-op. | |
102 | */ | |
103 | memset(&wrqu, 0, sizeof(wrqu)); | |
104 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, | |
105 | ETH_ALEN); | |
106 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
107 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); | |
108 | goto out; | |
109 | } | |
110 | ||
d5db2dfa DW |
111 | /* Use short preamble only when both the BSS and firmware support it */ |
112 | if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && | |
113 | (bss->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) { | |
697900ac | 114 | lbs_deb_join("AdhocJoin: Short preamble\n"); |
d5db2dfa | 115 | preamble = RADIO_PREAMBLE_SHORT; |
697900ac HS |
116 | } |
117 | ||
d5db2dfa DW |
118 | ret = lbs_set_radio(priv, preamble, 1); |
119 | if (ret) | |
120 | goto out; | |
697900ac HS |
121 | |
122 | lbs_deb_join("AdhocJoin: channel = %d\n", assoc_req->channel); | |
123 | lbs_deb_join("AdhocJoin: band = %c\n", assoc_req->band); | |
124 | ||
125 | priv->adhoccreate = 0; | |
126 | ||
127 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_JOIN, | |
128 | 0, CMD_OPTION_WAITFORRSP, | |
129 | OID_802_11_SSID, assoc_req); | |
130 | ||
131 | out: | |
d5db2dfa | 132 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
697900ac HS |
133 | return ret; |
134 | } | |
135 | ||
136 | /** | |
137 | * @brief Start an Adhoc Network | |
138 | * | |
139 | * @param priv A pointer to struct lbs_private structure | |
d5db2dfa | 140 | * @param assoc_req The association request describing the BSS to start |
697900ac HS |
141 | * @return 0--success, -1--fail |
142 | */ | |
143 | static int lbs_start_adhoc_network(struct lbs_private *priv, | |
144 | struct assoc_request *assoc_req) | |
145 | { | |
146 | int ret = 0; | |
d5db2dfa DW |
147 | u8 preamble = RADIO_PREAMBLE_LONG; |
148 | ||
149 | lbs_deb_enter(LBS_DEB_ASSOC); | |
697900ac HS |
150 | |
151 | priv->adhoccreate = 1; | |
152 | ||
153 | if (priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) { | |
154 | lbs_deb_join("AdhocStart: Short preamble\n"); | |
d5db2dfa | 155 | preamble = RADIO_PREAMBLE_SHORT; |
697900ac HS |
156 | } |
157 | ||
d5db2dfa DW |
158 | ret = lbs_set_radio(priv, preamble, 1); |
159 | if (ret) | |
160 | goto out; | |
697900ac HS |
161 | |
162 | lbs_deb_join("AdhocStart: channel = %d\n", assoc_req->channel); | |
163 | lbs_deb_join("AdhocStart: band = %d\n", assoc_req->band); | |
164 | ||
165 | ret = lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_START, | |
166 | 0, CMD_OPTION_WAITFORRSP, 0, assoc_req); | |
167 | ||
d5db2dfa DW |
168 | out: |
169 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | |
697900ac HS |
170 | return ret; |
171 | } | |
172 | ||
173 | int lbs_stop_adhoc_network(struct lbs_private *priv) | |
174 | { | |
175 | return lbs_prepare_and_send_command(priv, CMD_802_11_AD_HOC_STOP, | |
176 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); | |
177 | } | |
e76850d6 | 178 | |
245bf20f HS |
179 | static inline int match_bss_no_security(struct lbs_802_11_security *secinfo, |
180 | struct bss_descriptor *match_bss) | |
181 | { | |
182 | if (!secinfo->wep_enabled && !secinfo->WPAenabled | |
183 | && !secinfo->WPA2enabled | |
184 | && match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC | |
185 | && match_bss->rsn_ie[0] != MFIE_TYPE_RSN | |
186 | && !(match_bss->capability & WLAN_CAPABILITY_PRIVACY)) | |
187 | return 1; | |
188 | else | |
189 | return 0; | |
190 | } | |
191 | ||
192 | static inline int match_bss_static_wep(struct lbs_802_11_security *secinfo, | |
193 | struct bss_descriptor *match_bss) | |
194 | { | |
195 | if (secinfo->wep_enabled && !secinfo->WPAenabled | |
196 | && !secinfo->WPA2enabled | |
197 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) | |
198 | return 1; | |
199 | else | |
200 | return 0; | |
201 | } | |
202 | ||
203 | static inline int match_bss_wpa(struct lbs_802_11_security *secinfo, | |
204 | struct bss_descriptor *match_bss) | |
205 | { | |
206 | if (!secinfo->wep_enabled && secinfo->WPAenabled | |
207 | && (match_bss->wpa_ie[0] == MFIE_TYPE_GENERIC) | |
208 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G | |
209 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ | |
210 | ) | |
211 | return 1; | |
212 | else | |
213 | return 0; | |
214 | } | |
215 | ||
216 | static inline int match_bss_wpa2(struct lbs_802_11_security *secinfo, | |
217 | struct bss_descriptor *match_bss) | |
218 | { | |
219 | if (!secinfo->wep_enabled && secinfo->WPA2enabled && | |
220 | (match_bss->rsn_ie[0] == MFIE_TYPE_RSN) | |
221 | /* privacy bit may NOT be set in some APs like LinkSys WRT54G | |
222 | (match_bss->capability & WLAN_CAPABILITY_PRIVACY) */ | |
223 | ) | |
224 | return 1; | |
225 | else | |
226 | return 0; | |
227 | } | |
228 | ||
229 | static inline int match_bss_dynamic_wep(struct lbs_802_11_security *secinfo, | |
230 | struct bss_descriptor *match_bss) | |
231 | { | |
232 | if (!secinfo->wep_enabled && !secinfo->WPAenabled | |
233 | && !secinfo->WPA2enabled | |
234 | && (match_bss->wpa_ie[0] != MFIE_TYPE_GENERIC) | |
235 | && (match_bss->rsn_ie[0] != MFIE_TYPE_RSN) | |
236 | && (match_bss->capability & WLAN_CAPABILITY_PRIVACY)) | |
237 | return 1; | |
238 | else | |
239 | return 0; | |
240 | } | |
241 | ||
242 | /** | |
243 | * @brief Check if a scanned network compatible with the driver settings | |
244 | * | |
245 | * WEP WPA WPA2 ad-hoc encrypt Network | |
246 | * enabled enabled enabled AES mode privacy WPA WPA2 Compatible | |
247 | * 0 0 0 0 NONE 0 0 0 yes No security | |
248 | * 1 0 0 0 NONE 1 0 0 yes Static WEP | |
249 | * 0 1 0 0 x 1x 1 x yes WPA | |
250 | * 0 0 1 0 x 1x x 1 yes WPA2 | |
251 | * 0 0 0 1 NONE 1 0 0 yes Ad-hoc AES | |
252 | * 0 0 0 0 !=NONE 1 0 0 yes Dynamic WEP | |
253 | * | |
254 | * | |
255 | * @param priv A pointer to struct lbs_private | |
256 | * @param index Index in scantable to check against current driver settings | |
257 | * @param mode Network mode: Infrastructure or IBSS | |
258 | * | |
259 | * @return Index in scantable, or error code if negative | |
260 | */ | |
261 | static int is_network_compatible(struct lbs_private *priv, | |
262 | struct bss_descriptor *bss, uint8_t mode) | |
263 | { | |
264 | int matched = 0; | |
265 | ||
266 | lbs_deb_enter(LBS_DEB_SCAN); | |
267 | ||
268 | if (bss->mode != mode) | |
269 | goto done; | |
270 | ||
271 | matched = match_bss_no_security(&priv->secinfo, bss); | |
272 | if (matched) | |
273 | goto done; | |
274 | matched = match_bss_static_wep(&priv->secinfo, bss); | |
275 | if (matched) | |
276 | goto done; | |
277 | matched = match_bss_wpa(&priv->secinfo, bss); | |
278 | if (matched) { | |
279 | lbs_deb_scan("is_network_compatible() WPA: wpa_ie 0x%x " | |
280 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " | |
281 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], | |
282 | priv->secinfo.wep_enabled ? "e" : "d", | |
283 | priv->secinfo.WPAenabled ? "e" : "d", | |
284 | priv->secinfo.WPA2enabled ? "e" : "d", | |
285 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); | |
286 | goto done; | |
287 | } | |
288 | matched = match_bss_wpa2(&priv->secinfo, bss); | |
289 | if (matched) { | |
290 | lbs_deb_scan("is_network_compatible() WPA2: wpa_ie 0x%x " | |
291 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s " | |
292 | "privacy 0x%x\n", bss->wpa_ie[0], bss->rsn_ie[0], | |
293 | priv->secinfo.wep_enabled ? "e" : "d", | |
294 | priv->secinfo.WPAenabled ? "e" : "d", | |
295 | priv->secinfo.WPA2enabled ? "e" : "d", | |
296 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); | |
297 | goto done; | |
298 | } | |
299 | matched = match_bss_dynamic_wep(&priv->secinfo, bss); | |
300 | if (matched) { | |
301 | lbs_deb_scan("is_network_compatible() dynamic WEP: " | |
302 | "wpa_ie 0x%x wpa2_ie 0x%x privacy 0x%x\n", | |
303 | bss->wpa_ie[0], bss->rsn_ie[0], | |
304 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); | |
305 | goto done; | |
306 | } | |
307 | ||
308 | /* bss security settings don't match those configured on card */ | |
309 | lbs_deb_scan("is_network_compatible() FAILED: wpa_ie 0x%x " | |
310 | "wpa2_ie 0x%x WEP %s WPA %s WPA2 %s privacy 0x%x\n", | |
311 | bss->wpa_ie[0], bss->rsn_ie[0], | |
312 | priv->secinfo.wep_enabled ? "e" : "d", | |
313 | priv->secinfo.WPAenabled ? "e" : "d", | |
314 | priv->secinfo.WPA2enabled ? "e" : "d", | |
315 | (bss->capability & WLAN_CAPABILITY_PRIVACY)); | |
316 | ||
317 | done: | |
318 | lbs_deb_leave_args(LBS_DEB_SCAN, "matched: %d", matched); | |
319 | return matched; | |
320 | } | |
321 | ||
322 | /** | |
323 | * @brief This function finds a specific compatible BSSID in the scan list | |
324 | * | |
325 | * Used in association code | |
326 | * | |
327 | * @param priv A pointer to struct lbs_private | |
328 | * @param bssid BSSID to find in the scan list | |
329 | * @param mode Network mode: Infrastructure or IBSS | |
330 | * | |
331 | * @return index in BSSID list, or error return code (< 0) | |
332 | */ | |
333 | static struct bss_descriptor *lbs_find_bssid_in_list(struct lbs_private *priv, | |
334 | uint8_t *bssid, uint8_t mode) | |
335 | { | |
336 | struct bss_descriptor *iter_bss; | |
337 | struct bss_descriptor *found_bss = NULL; | |
338 | ||
339 | lbs_deb_enter(LBS_DEB_SCAN); | |
340 | ||
341 | if (!bssid) | |
342 | goto out; | |
343 | ||
344 | lbs_deb_hex(LBS_DEB_SCAN, "looking for", bssid, ETH_ALEN); | |
345 | ||
346 | /* Look through the scan table for a compatible match. The loop will | |
347 | * continue past a matched bssid that is not compatible in case there | |
348 | * is an AP with multiple SSIDs assigned to the same BSSID | |
349 | */ | |
350 | mutex_lock(&priv->lock); | |
351 | list_for_each_entry(iter_bss, &priv->network_list, list) { | |
352 | if (compare_ether_addr(iter_bss->bssid, bssid)) | |
353 | continue; /* bssid doesn't match */ | |
354 | switch (mode) { | |
355 | case IW_MODE_INFRA: | |
356 | case IW_MODE_ADHOC: | |
357 | if (!is_network_compatible(priv, iter_bss, mode)) | |
358 | break; | |
359 | found_bss = iter_bss; | |
360 | break; | |
361 | default: | |
362 | found_bss = iter_bss; | |
363 | break; | |
364 | } | |
365 | } | |
366 | mutex_unlock(&priv->lock); | |
367 | ||
368 | out: | |
369 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); | |
370 | return found_bss; | |
371 | } | |
372 | ||
373 | /** | |
374 | * @brief This function finds ssid in ssid list. | |
375 | * | |
376 | * Used in association code | |
377 | * | |
378 | * @param priv A pointer to struct lbs_private | |
379 | * @param ssid SSID to find in the list | |
380 | * @param bssid BSSID to qualify the SSID selection (if provided) | |
381 | * @param mode Network mode: Infrastructure or IBSS | |
382 | * | |
383 | * @return index in BSSID list | |
384 | */ | |
385 | static struct bss_descriptor *lbs_find_ssid_in_list(struct lbs_private *priv, | |
386 | uint8_t *ssid, uint8_t ssid_len, | |
387 | uint8_t *bssid, uint8_t mode, | |
388 | int channel) | |
389 | { | |
390 | u32 bestrssi = 0; | |
391 | struct bss_descriptor *iter_bss = NULL; | |
392 | struct bss_descriptor *found_bss = NULL; | |
393 | struct bss_descriptor *tmp_oldest = NULL; | |
394 | ||
395 | lbs_deb_enter(LBS_DEB_SCAN); | |
396 | ||
397 | mutex_lock(&priv->lock); | |
398 | ||
399 | list_for_each_entry(iter_bss, &priv->network_list, list) { | |
400 | if (!tmp_oldest || | |
401 | (iter_bss->last_scanned < tmp_oldest->last_scanned)) | |
402 | tmp_oldest = iter_bss; | |
403 | ||
404 | if (lbs_ssid_cmp(iter_bss->ssid, iter_bss->ssid_len, | |
405 | ssid, ssid_len) != 0) | |
406 | continue; /* ssid doesn't match */ | |
407 | if (bssid && compare_ether_addr(iter_bss->bssid, bssid) != 0) | |
408 | continue; /* bssid doesn't match */ | |
409 | if ((channel > 0) && (iter_bss->channel != channel)) | |
410 | continue; /* channel doesn't match */ | |
411 | ||
412 | switch (mode) { | |
413 | case IW_MODE_INFRA: | |
414 | case IW_MODE_ADHOC: | |
415 | if (!is_network_compatible(priv, iter_bss, mode)) | |
416 | break; | |
417 | ||
418 | if (bssid) { | |
419 | /* Found requested BSSID */ | |
420 | found_bss = iter_bss; | |
421 | goto out; | |
422 | } | |
423 | ||
424 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { | |
425 | bestrssi = SCAN_RSSI(iter_bss->rssi); | |
426 | found_bss = iter_bss; | |
427 | } | |
428 | break; | |
429 | case IW_MODE_AUTO: | |
430 | default: | |
431 | if (SCAN_RSSI(iter_bss->rssi) > bestrssi) { | |
432 | bestrssi = SCAN_RSSI(iter_bss->rssi); | |
433 | found_bss = iter_bss; | |
434 | } | |
435 | break; | |
436 | } | |
437 | } | |
438 | ||
439 | out: | |
440 | mutex_unlock(&priv->lock); | |
441 | lbs_deb_leave_args(LBS_DEB_SCAN, "found_bss %p", found_bss); | |
442 | return found_bss; | |
443 | } | |
444 | ||
69f9032d | 445 | static int assoc_helper_essid(struct lbs_private *priv, |
876c9d3a MT |
446 | struct assoc_request * assoc_req) |
447 | { | |
876c9d3a | 448 | int ret = 0; |
fcdb53db | 449 | struct bss_descriptor * bss; |
aeea0ab4 | 450 | int channel = -1; |
876c9d3a | 451 | |
9012b28a | 452 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a | 453 | |
ef9a264b DW |
454 | /* FIXME: take channel into account when picking SSIDs if a channel |
455 | * is set. | |
456 | */ | |
457 | ||
aeea0ab4 DW |
458 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) |
459 | channel = assoc_req->channel; | |
460 | ||
0765af44 | 461 | lbs_deb_assoc("SSID '%s' requested\n", |
d8efea25 | 462 | escape_essid(assoc_req->ssid, assoc_req->ssid_len)); |
0dc5a290 | 463 | if (assoc_req->mode == IW_MODE_INFRA) { |
10078321 | 464 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
52933d81 | 465 | assoc_req->ssid_len); |
876c9d3a | 466 | |
aa21c004 | 467 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
d8efea25 | 468 | assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel); |
fcdb53db | 469 | if (bss != NULL) { |
e76850d6 | 470 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
10078321 | 471 | ret = lbs_associate(priv, assoc_req); |
876c9d3a | 472 | } else { |
d8efea25 | 473 | lbs_deb_assoc("SSID not found; cannot associate\n"); |
876c9d3a | 474 | } |
0dc5a290 | 475 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
876c9d3a MT |
476 | /* Scan for the network, do not save previous results. Stale |
477 | * scan data will cause us to join a non-existant adhoc network | |
478 | */ | |
10078321 | 479 | lbs_send_specific_ssid_scan(priv, assoc_req->ssid, |
52933d81 | 480 | assoc_req->ssid_len); |
876c9d3a MT |
481 | |
482 | /* Search for the requested SSID in the scan table */ | |
aa21c004 | 483 | bss = lbs_find_ssid_in_list(priv, assoc_req->ssid, |
d8efea25 | 484 | assoc_req->ssid_len, NULL, IW_MODE_ADHOC, channel); |
fcdb53db | 485 | if (bss != NULL) { |
d8efea25 | 486 | lbs_deb_assoc("SSID found, will join\n"); |
e76850d6 | 487 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
10078321 | 488 | lbs_join_adhoc_network(priv, assoc_req); |
876c9d3a MT |
489 | } else { |
490 | /* else send START command */ | |
d8efea25 | 491 | lbs_deb_assoc("SSID not found, creating adhoc network\n"); |
e76850d6 | 492 | memcpy(&assoc_req->bss.ssid, &assoc_req->ssid, |
d8efea25 DW |
493 | IW_ESSID_MAX_SIZE); |
494 | assoc_req->bss.ssid_len = assoc_req->ssid_len; | |
10078321 | 495 | lbs_start_adhoc_network(priv, assoc_req); |
876c9d3a | 496 | } |
876c9d3a MT |
497 | } |
498 | ||
9012b28a | 499 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
876c9d3a MT |
500 | return ret; |
501 | } | |
502 | ||
503 | ||
69f9032d | 504 | static int assoc_helper_bssid(struct lbs_private *priv, |
876c9d3a MT |
505 | struct assoc_request * assoc_req) |
506 | { | |
fcdb53db DW |
507 | int ret = 0; |
508 | struct bss_descriptor * bss; | |
0795af57 | 509 | DECLARE_MAC_BUF(mac); |
876c9d3a | 510 | |
0795af57 JP |
511 | lbs_deb_enter_args(LBS_DEB_ASSOC, "BSSID %s", |
512 | print_mac(mac, assoc_req->bssid)); | |
876c9d3a MT |
513 | |
514 | /* Search for index position in list for requested MAC */ | |
aa21c004 | 515 | bss = lbs_find_bssid_in_list(priv, assoc_req->bssid, |
876c9d3a | 516 | assoc_req->mode); |
fcdb53db | 517 | if (bss == NULL) { |
0795af57 JP |
518 | lbs_deb_assoc("ASSOC: WAP: BSSID %s not found, " |
519 | "cannot associate.\n", print_mac(mac, assoc_req->bssid)); | |
876c9d3a MT |
520 | goto out; |
521 | } | |
522 | ||
e76850d6 | 523 | memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); |
0dc5a290 | 524 | if (assoc_req->mode == IW_MODE_INFRA) { |
10078321 HS |
525 | ret = lbs_associate(priv, assoc_req); |
526 | lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret); | |
0dc5a290 | 527 | } else if (assoc_req->mode == IW_MODE_ADHOC) { |
10078321 | 528 | lbs_join_adhoc_network(priv, assoc_req); |
876c9d3a | 529 | } |
876c9d3a MT |
530 | |
531 | out: | |
9012b28a | 532 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
876c9d3a MT |
533 | return ret; |
534 | } | |
535 | ||
536 | ||
69f9032d | 537 | static int assoc_helper_associate(struct lbs_private *priv, |
876c9d3a MT |
538 | struct assoc_request * assoc_req) |
539 | { | |
540 | int ret = 0, done = 0; | |
541 | ||
0765af44 HS |
542 | lbs_deb_enter(LBS_DEB_ASSOC); |
543 | ||
876c9d3a MT |
544 | /* If we're given and 'any' BSSID, try associating based on SSID */ |
545 | ||
546 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { | |
3cf20931 DW |
547 | if (compare_ether_addr(bssid_any, assoc_req->bssid) |
548 | && compare_ether_addr(bssid_off, assoc_req->bssid)) { | |
876c9d3a MT |
549 | ret = assoc_helper_bssid(priv, assoc_req); |
550 | done = 1; | |
876c9d3a MT |
551 | } |
552 | } | |
553 | ||
554 | if (!done && test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { | |
555 | ret = assoc_helper_essid(priv, assoc_req); | |
876c9d3a MT |
556 | } |
557 | ||
0765af44 | 558 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
876c9d3a MT |
559 | return ret; |
560 | } | |
561 | ||
562 | ||
69f9032d | 563 | static int assoc_helper_mode(struct lbs_private *priv, |
876c9d3a MT |
564 | struct assoc_request * assoc_req) |
565 | { | |
876c9d3a MT |
566 | int ret = 0; |
567 | ||
9012b28a | 568 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a | 569 | |
aa21c004 | 570 | if (assoc_req->mode == priv->mode) |
9012b28a | 571 | goto done; |
876c9d3a | 572 | |
0dc5a290 | 573 | if (assoc_req->mode == IW_MODE_INFRA) { |
aa21c004 | 574 | if (priv->psstate != PS_STATE_FULL_POWER) |
10078321 | 575 | lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
aa21c004 | 576 | priv->psmode = LBS802_11POWERMODECAM; |
876c9d3a MT |
577 | } |
578 | ||
aa21c004 | 579 | priv->mode = assoc_req->mode; |
10078321 | 580 | ret = lbs_prepare_and_send_command(priv, |
0aef64d7 DW |
581 | CMD_802_11_SNMP_MIB, |
582 | 0, CMD_OPTION_WAITFORRSP, | |
876c9d3a | 583 | OID_802_11_INFRASTRUCTURE_MODE, |
981f187b | 584 | /* Shoot me now */ (void *) (size_t) assoc_req->mode); |
876c9d3a | 585 | |
9012b28a HS |
586 | done: |
587 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | |
876c9d3a MT |
588 | return ret; |
589 | } | |
590 | ||
69f9032d | 591 | static int assoc_helper_channel(struct lbs_private *priv, |
ef9a264b DW |
592 | struct assoc_request * assoc_req) |
593 | { | |
ef9a264b DW |
594 | int ret = 0; |
595 | ||
596 | lbs_deb_enter(LBS_DEB_ASSOC); | |
597 | ||
9f462577 | 598 | ret = lbs_update_channel(priv); |
d1a469fd | 599 | if (ret) { |
23d36eec | 600 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
d1a469fd | 601 | goto done; |
ef9a264b DW |
602 | } |
603 | ||
aa21c004 | 604 | if (assoc_req->channel == priv->curbssparams.channel) |
ef9a264b DW |
605 | goto done; |
606 | ||
8642f1f0 | 607 | if (priv->mesh_dev) { |
86062134 DW |
608 | /* Change mesh channel first; 21.p21 firmware won't let |
609 | you change channel otherwise (even though it'll return | |
610 | an error to this */ | |
edaea5ce JC |
611 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP, |
612 | assoc_req->channel); | |
8642f1f0 DW |
613 | } |
614 | ||
ef9a264b | 615 | lbs_deb_assoc("ASSOC: channel: %d -> %d\n", |
86062134 | 616 | priv->curbssparams.channel, assoc_req->channel); |
ef9a264b | 617 | |
2dd4b262 DW |
618 | ret = lbs_set_channel(priv, assoc_req->channel); |
619 | if (ret < 0) | |
23d36eec | 620 | lbs_deb_assoc("ASSOC: channel: error setting channel.\n"); |
ef9a264b | 621 | |
2dd4b262 DW |
622 | /* FIXME: shouldn't need to grab the channel _again_ after setting |
623 | * it since the firmware is supposed to return the new channel, but | |
624 | * whatever... */ | |
9f462577 | 625 | ret = lbs_update_channel(priv); |
d1a469fd | 626 | if (ret) { |
23d36eec | 627 | lbs_deb_assoc("ASSOC: channel: error getting channel.\n"); |
d1a469fd DW |
628 | goto done; |
629 | } | |
ef9a264b | 630 | |
aa21c004 | 631 | if (assoc_req->channel != priv->curbssparams.channel) { |
88ae2915 | 632 | lbs_deb_assoc("ASSOC: channel: failed to update channel to %d\n", |
ef9a264b | 633 | assoc_req->channel); |
8642f1f0 | 634 | goto restore_mesh; |
ef9a264b DW |
635 | } |
636 | ||
637 | if ( assoc_req->secinfo.wep_enabled | |
638 | && (assoc_req->wep_keys[0].len | |
639 | || assoc_req->wep_keys[1].len | |
640 | || assoc_req->wep_keys[2].len | |
641 | || assoc_req->wep_keys[3].len)) { | |
642 | /* Make sure WEP keys are re-sent to firmware */ | |
643 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); | |
644 | } | |
645 | ||
646 | /* Must restart/rejoin adhoc networks after channel change */ | |
23d36eec | 647 | set_bit(ASSOC_FLAG_SSID, &assoc_req->flags); |
ef9a264b | 648 | |
8642f1f0 DW |
649 | restore_mesh: |
650 | if (priv->mesh_dev) | |
edaea5ce JC |
651 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
652 | priv->curbssparams.channel); | |
8642f1f0 DW |
653 | |
654 | done: | |
ef9a264b DW |
655 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
656 | return ret; | |
657 | } | |
658 | ||
659 | ||
69f9032d | 660 | static int assoc_helper_wep_keys(struct lbs_private *priv, |
f70dd451 | 661 | struct assoc_request *assoc_req) |
876c9d3a | 662 | { |
876c9d3a MT |
663 | int i; |
664 | int ret = 0; | |
665 | ||
9012b28a | 666 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a MT |
667 | |
668 | /* Set or remove WEP keys */ | |
f70dd451 DW |
669 | if (assoc_req->wep_keys[0].len || assoc_req->wep_keys[1].len || |
670 | assoc_req->wep_keys[2].len || assoc_req->wep_keys[3].len) | |
671 | ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_ADD, assoc_req); | |
672 | else | |
673 | ret = lbs_cmd_802_11_set_wep(priv, CMD_ACT_REMOVE, assoc_req); | |
876c9d3a MT |
674 | |
675 | if (ret) | |
676 | goto out; | |
677 | ||
678 | /* enable/disable the MAC's WEP packet filter */ | |
889c05bd | 679 | if (assoc_req->secinfo.wep_enabled) |
d9e9778c | 680 | priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE; |
876c9d3a | 681 | else |
d9e9778c | 682 | priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE; |
f70dd451 | 683 | |
c97329e2 | 684 | lbs_set_mac_control(priv); |
876c9d3a | 685 | |
aa21c004 | 686 | mutex_lock(&priv->lock); |
876c9d3a | 687 | |
aa21c004 | 688 | /* Copy WEP keys into priv wep key fields */ |
876c9d3a | 689 | for (i = 0; i < 4; i++) { |
aa21c004 | 690 | memcpy(&priv->wep_keys[i], &assoc_req->wep_keys[i], |
f70dd451 | 691 | sizeof(struct enc_key)); |
876c9d3a | 692 | } |
aa21c004 | 693 | priv->wep_tx_keyidx = assoc_req->wep_tx_keyidx; |
876c9d3a | 694 | |
aa21c004 | 695 | mutex_unlock(&priv->lock); |
876c9d3a MT |
696 | |
697 | out: | |
9012b28a | 698 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
876c9d3a MT |
699 | return ret; |
700 | } | |
701 | ||
69f9032d | 702 | static int assoc_helper_secinfo(struct lbs_private *priv, |
876c9d3a MT |
703 | struct assoc_request * assoc_req) |
704 | { | |
876c9d3a | 705 | int ret = 0; |
4f59abf1 DW |
706 | uint16_t do_wpa; |
707 | uint16_t rsn = 0; | |
876c9d3a | 708 | |
9012b28a | 709 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a | 710 | |
aa21c004 | 711 | memcpy(&priv->secinfo, &assoc_req->secinfo, |
10078321 | 712 | sizeof(struct lbs_802_11_security)); |
876c9d3a | 713 | |
c97329e2 | 714 | lbs_set_mac_control(priv); |
876c9d3a | 715 | |
18c96c34 DW |
716 | /* If RSN is already enabled, don't try to enable it again, since |
717 | * ENABLE_RSN resets internal state machines and will clobber the | |
718 | * 4-way WPA handshake. | |
719 | */ | |
720 | ||
721 | /* Get RSN enabled/disabled */ | |
4f59abf1 | 722 | ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_GET, &rsn); |
18c96c34 | 723 | if (ret) { |
23d36eec | 724 | lbs_deb_assoc("Failed to get RSN status: %d\n", ret); |
18c96c34 DW |
725 | goto out; |
726 | } | |
727 | ||
728 | /* Don't re-enable RSN if it's already enabled */ | |
4f59abf1 | 729 | do_wpa = assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled; |
18c96c34 DW |
730 | if (do_wpa == rsn) |
731 | goto out; | |
732 | ||
733 | /* Set RSN enabled/disabled */ | |
4f59abf1 | 734 | ret = lbs_cmd_802_11_enable_rsn(priv, CMD_ACT_SET, &do_wpa); |
90a42210 DW |
735 | |
736 | out: | |
9012b28a | 737 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
876c9d3a MT |
738 | return ret; |
739 | } | |
740 | ||
741 | ||
69f9032d | 742 | static int assoc_helper_wpa_keys(struct lbs_private *priv, |
876c9d3a MT |
743 | struct assoc_request * assoc_req) |
744 | { | |
745 | int ret = 0; | |
2bcde51d | 746 | unsigned int flags = assoc_req->flags; |
876c9d3a | 747 | |
9012b28a | 748 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a | 749 | |
2bcde51d DW |
750 | /* Work around older firmware bug where WPA unicast and multicast |
751 | * keys must be set independently. Seen in SDIO parts with firmware | |
752 | * version 5.0.11p0. | |
753 | */ | |
876c9d3a | 754 | |
2bcde51d DW |
755 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { |
756 | clear_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); | |
9e1228d0 | 757 | ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req); |
2bcde51d DW |
758 | assoc_req->flags = flags; |
759 | } | |
760 | ||
761 | if (ret) | |
762 | goto out; | |
763 | ||
764 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { | |
765 | clear_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); | |
766 | ||
9e1228d0 | 767 | ret = lbs_cmd_802_11_key_material(priv, CMD_ACT_SET, assoc_req); |
2bcde51d DW |
768 | assoc_req->flags = flags; |
769 | } | |
770 | ||
771 | out: | |
9012b28a | 772 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
876c9d3a MT |
773 | return ret; |
774 | } | |
775 | ||
776 | ||
69f9032d | 777 | static int assoc_helper_wpa_ie(struct lbs_private *priv, |
876c9d3a MT |
778 | struct assoc_request * assoc_req) |
779 | { | |
876c9d3a MT |
780 | int ret = 0; |
781 | ||
9012b28a | 782 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a MT |
783 | |
784 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { | |
aa21c004 DW |
785 | memcpy(&priv->wpa_ie, &assoc_req->wpa_ie, assoc_req->wpa_ie_len); |
786 | priv->wpa_ie_len = assoc_req->wpa_ie_len; | |
876c9d3a | 787 | } else { |
aa21c004 DW |
788 | memset(&priv->wpa_ie, 0, MAX_WPA_IE_LEN); |
789 | priv->wpa_ie_len = 0; | |
876c9d3a MT |
790 | } |
791 | ||
9012b28a | 792 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
876c9d3a MT |
793 | return ret; |
794 | } | |
795 | ||
796 | ||
aa21c004 | 797 | static int should_deauth_infrastructure(struct lbs_private *priv, |
876c9d3a MT |
798 | struct assoc_request * assoc_req) |
799 | { | |
0765af44 HS |
800 | int ret = 0; |
801 | ||
aa21c004 | 802 | if (priv->connect_status != LBS_CONNECTED) |
876c9d3a MT |
803 | return 0; |
804 | ||
52507c20 | 805 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a | 806 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
0765af44 HS |
807 | lbs_deb_assoc("Deauthenticating due to new SSID\n"); |
808 | ret = 1; | |
809 | goto out; | |
876c9d3a MT |
810 | } |
811 | ||
812 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { | |
aa21c004 | 813 | if (priv->secinfo.auth_mode != assoc_req->secinfo.auth_mode) { |
0765af44 HS |
814 | lbs_deb_assoc("Deauthenticating due to new security\n"); |
815 | ret = 1; | |
816 | goto out; | |
876c9d3a MT |
817 | } |
818 | } | |
819 | ||
820 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { | |
0765af44 HS |
821 | lbs_deb_assoc("Deauthenticating due to new BSSID\n"); |
822 | ret = 1; | |
823 | goto out; | |
876c9d3a MT |
824 | } |
825 | ||
fff47f10 | 826 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
0765af44 HS |
827 | lbs_deb_assoc("Deauthenticating due to channel switch\n"); |
828 | ret = 1; | |
829 | goto out; | |
fff47f10 LCCR |
830 | } |
831 | ||
876c9d3a MT |
832 | /* FIXME: deal with 'auto' mode somehow */ |
833 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { | |
0765af44 HS |
834 | if (assoc_req->mode != IW_MODE_INFRA) { |
835 | lbs_deb_assoc("Deauthenticating due to leaving " | |
836 | "infra mode\n"); | |
837 | ret = 1; | |
838 | goto out; | |
839 | } | |
876c9d3a MT |
840 | } |
841 | ||
0765af44 HS |
842 | out: |
843 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | |
52507c20 | 844 | return ret; |
876c9d3a MT |
845 | } |
846 | ||
847 | ||
aa21c004 | 848 | static int should_stop_adhoc(struct lbs_private *priv, |
876c9d3a MT |
849 | struct assoc_request * assoc_req) |
850 | { | |
0765af44 HS |
851 | lbs_deb_enter(LBS_DEB_ASSOC); |
852 | ||
aa21c004 | 853 | if (priv->connect_status != LBS_CONNECTED) |
876c9d3a MT |
854 | return 0; |
855 | ||
aa21c004 DW |
856 | if (lbs_ssid_cmp(priv->curbssparams.ssid, |
857 | priv->curbssparams.ssid_len, | |
d8efea25 | 858 | assoc_req->ssid, assoc_req->ssid_len) != 0) |
876c9d3a MT |
859 | return 1; |
860 | ||
861 | /* FIXME: deal with 'auto' mode somehow */ | |
862 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { | |
0dc5a290 | 863 | if (assoc_req->mode != IW_MODE_ADHOC) |
876c9d3a MT |
864 | return 1; |
865 | } | |
866 | ||
ef9a264b | 867 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
aa21c004 | 868 | if (assoc_req->channel != priv->curbssparams.channel) |
ef9a264b DW |
869 | return 1; |
870 | } | |
871 | ||
0765af44 | 872 | lbs_deb_leave(LBS_DEB_ASSOC); |
876c9d3a MT |
873 | return 0; |
874 | } | |
875 | ||
876 | ||
245bf20f HS |
877 | /** |
878 | * @brief This function finds the best SSID in the Scan List | |
879 | * | |
880 | * Search the scan table for the best SSID that also matches the current | |
881 | * adapter network preference (infrastructure or adhoc) | |
882 | * | |
883 | * @param priv A pointer to struct lbs_private | |
884 | * | |
885 | * @return index in BSSID list | |
886 | */ | |
887 | static struct bss_descriptor *lbs_find_best_ssid_in_list( | |
888 | struct lbs_private *priv, uint8_t mode) | |
889 | { | |
890 | uint8_t bestrssi = 0; | |
891 | struct bss_descriptor *iter_bss; | |
892 | struct bss_descriptor *best_bss = NULL; | |
893 | ||
894 | lbs_deb_enter(LBS_DEB_SCAN); | |
895 | ||
896 | mutex_lock(&priv->lock); | |
897 | ||
898 | list_for_each_entry(iter_bss, &priv->network_list, list) { | |
899 | switch (mode) { | |
900 | case IW_MODE_INFRA: | |
901 | case IW_MODE_ADHOC: | |
902 | if (!is_network_compatible(priv, iter_bss, mode)) | |
903 | break; | |
904 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) | |
905 | break; | |
906 | bestrssi = SCAN_RSSI(iter_bss->rssi); | |
907 | best_bss = iter_bss; | |
908 | break; | |
909 | case IW_MODE_AUTO: | |
910 | default: | |
911 | if (SCAN_RSSI(iter_bss->rssi) <= bestrssi) | |
912 | break; | |
913 | bestrssi = SCAN_RSSI(iter_bss->rssi); | |
914 | best_bss = iter_bss; | |
915 | break; | |
916 | } | |
917 | } | |
918 | ||
919 | mutex_unlock(&priv->lock); | |
920 | lbs_deb_leave_args(LBS_DEB_SCAN, "best_bss %p", best_bss); | |
921 | return best_bss; | |
922 | } | |
923 | ||
924 | /** | |
925 | * @brief Find the best AP | |
926 | * | |
927 | * Used from association worker. | |
928 | * | |
929 | * @param priv A pointer to struct lbs_private structure | |
930 | * @param pSSID A pointer to AP's ssid | |
931 | * | |
932 | * @return 0--success, otherwise--fail | |
933 | */ | |
934 | static int lbs_find_best_network_ssid(struct lbs_private *priv, | |
935 | uint8_t *out_ssid, uint8_t *out_ssid_len, uint8_t preferred_mode, | |
936 | uint8_t *out_mode) | |
937 | { | |
938 | int ret = -1; | |
939 | struct bss_descriptor *found; | |
940 | ||
941 | lbs_deb_enter(LBS_DEB_SCAN); | |
942 | ||
943 | priv->scan_ssid_len = 0; | |
944 | lbs_scan_networks(priv, 1); | |
945 | if (priv->surpriseremoved) | |
946 | goto out; | |
947 | ||
948 | found = lbs_find_best_ssid_in_list(priv, preferred_mode); | |
949 | if (found && (found->ssid_len > 0)) { | |
950 | memcpy(out_ssid, &found->ssid, IW_ESSID_MAX_SIZE); | |
951 | *out_ssid_len = found->ssid_len; | |
952 | *out_mode = found->mode; | |
953 | ret = 0; | |
954 | } | |
955 | ||
956 | out: | |
957 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); | |
958 | return ret; | |
959 | } | |
960 | ||
961 | ||
10078321 | 962 | void lbs_association_worker(struct work_struct *work) |
876c9d3a | 963 | { |
69f9032d HS |
964 | struct lbs_private *priv = container_of(work, struct lbs_private, |
965 | assoc_work.work); | |
876c9d3a MT |
966 | struct assoc_request * assoc_req = NULL; |
967 | int ret = 0; | |
968 | int find_any_ssid = 0; | |
0795af57 | 969 | DECLARE_MAC_BUF(mac); |
876c9d3a | 970 | |
9012b28a | 971 | lbs_deb_enter(LBS_DEB_ASSOC); |
876c9d3a | 972 | |
aa21c004 DW |
973 | mutex_lock(&priv->lock); |
974 | assoc_req = priv->pending_assoc_req; | |
975 | priv->pending_assoc_req = NULL; | |
976 | priv->in_progress_assoc_req = assoc_req; | |
977 | mutex_unlock(&priv->lock); | |
876c9d3a | 978 | |
9012b28a HS |
979 | if (!assoc_req) |
980 | goto done; | |
876c9d3a | 981 | |
0765af44 HS |
982 | lbs_deb_assoc( |
983 | "Association Request:\n" | |
984 | " flags: 0x%08lx\n" | |
985 | " SSID: '%s'\n" | |
986 | " chann: %d\n" | |
987 | " band: %d\n" | |
988 | " mode: %d\n" | |
989 | " BSSID: %s\n" | |
990 | " secinfo: %s%s%s\n" | |
991 | " auth_mode: %d\n", | |
992 | assoc_req->flags, | |
993 | escape_essid(assoc_req->ssid, assoc_req->ssid_len), | |
994 | assoc_req->channel, assoc_req->band, assoc_req->mode, | |
995 | print_mac(mac, assoc_req->bssid), | |
996 | assoc_req->secinfo.WPAenabled ? " WPA" : "", | |
997 | assoc_req->secinfo.WPA2enabled ? " WPA2" : "", | |
998 | assoc_req->secinfo.wep_enabled ? " WEP" : "", | |
999 | assoc_req->secinfo.auth_mode); | |
876c9d3a MT |
1000 | |
1001 | /* If 'any' SSID was specified, find an SSID to associate with */ | |
1002 | if (test_bit(ASSOC_FLAG_SSID, &assoc_req->flags) | |
d8efea25 | 1003 | && !assoc_req->ssid_len) |
876c9d3a MT |
1004 | find_any_ssid = 1; |
1005 | ||
1006 | /* But don't use 'any' SSID if there's a valid locked BSSID to use */ | |
1007 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { | |
3cf20931 DW |
1008 | if (compare_ether_addr(assoc_req->bssid, bssid_any) |
1009 | && compare_ether_addr(assoc_req->bssid, bssid_off)) | |
876c9d3a MT |
1010 | find_any_ssid = 0; |
1011 | } | |
1012 | ||
1013 | if (find_any_ssid) { | |
877cb0d4 | 1014 | u8 new_mode = assoc_req->mode; |
876c9d3a | 1015 | |
10078321 | 1016 | ret = lbs_find_best_network_ssid(priv, assoc_req->ssid, |
d8efea25 | 1017 | &assoc_req->ssid_len, assoc_req->mode, &new_mode); |
876c9d3a | 1018 | if (ret) { |
9012b28a | 1019 | lbs_deb_assoc("Could not find best network\n"); |
876c9d3a MT |
1020 | ret = -ENETUNREACH; |
1021 | goto out; | |
1022 | } | |
1023 | ||
1024 | /* Ensure we switch to the mode of the AP */ | |
0dc5a290 | 1025 | if (assoc_req->mode == IW_MODE_AUTO) { |
876c9d3a MT |
1026 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
1027 | assoc_req->mode = new_mode; | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | /* | |
1032 | * Check if the attributes being changing require deauthentication | |
1033 | * from the currently associated infrastructure access point. | |
1034 | */ | |
aa21c004 DW |
1035 | if (priv->mode == IW_MODE_INFRA) { |
1036 | if (should_deauth_infrastructure(priv, assoc_req)) { | |
191bb40e DW |
1037 | ret = lbs_cmd_80211_deauthenticate(priv, |
1038 | priv->curbssparams.bssid, | |
1039 | WLAN_REASON_DEAUTH_LEAVING); | |
876c9d3a | 1040 | if (ret) { |
9012b28a | 1041 | lbs_deb_assoc("Deauthentication due to new " |
876c9d3a MT |
1042 | "configuration request failed: %d\n", |
1043 | ret); | |
1044 | } | |
1045 | } | |
aa21c004 DW |
1046 | } else if (priv->mode == IW_MODE_ADHOC) { |
1047 | if (should_stop_adhoc(priv, assoc_req)) { | |
10078321 | 1048 | ret = lbs_stop_adhoc_network(priv); |
876c9d3a | 1049 | if (ret) { |
9012b28a | 1050 | lbs_deb_assoc("Teardown of AdHoc network due to " |
876c9d3a MT |
1051 | "new configuration request failed: %d\n", |
1052 | ret); | |
1053 | } | |
1054 | ||
1055 | } | |
1056 | } | |
1057 | ||
1058 | /* Send the various configuration bits to the firmware */ | |
1059 | if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { | |
1060 | ret = assoc_helper_mode(priv, assoc_req); | |
0765af44 | 1061 | if (ret) |
876c9d3a | 1062 | goto out; |
876c9d3a MT |
1063 | } |
1064 | ||
ef9a264b DW |
1065 | if (test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) { |
1066 | ret = assoc_helper_channel(priv, assoc_req); | |
0765af44 | 1067 | if (ret) |
ef9a264b | 1068 | goto out; |
ef9a264b DW |
1069 | } |
1070 | ||
876c9d3a MT |
1071 | if ( test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags) |
1072 | || test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) { | |
1073 | ret = assoc_helper_wep_keys(priv, assoc_req); | |
0765af44 | 1074 | if (ret) |
876c9d3a | 1075 | goto out; |
876c9d3a MT |
1076 | } |
1077 | ||
1078 | if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { | |
1079 | ret = assoc_helper_secinfo(priv, assoc_req); | |
0765af44 | 1080 | if (ret) |
876c9d3a | 1081 | goto out; |
876c9d3a MT |
1082 | } |
1083 | ||
1084 | if (test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { | |
1085 | ret = assoc_helper_wpa_ie(priv, assoc_req); | |
0765af44 | 1086 | if (ret) |
876c9d3a | 1087 | goto out; |
876c9d3a MT |
1088 | } |
1089 | ||
1090 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags) | |
1091 | || test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { | |
1092 | ret = assoc_helper_wpa_keys(priv, assoc_req); | |
0765af44 | 1093 | if (ret) |
876c9d3a | 1094 | goto out; |
876c9d3a MT |
1095 | } |
1096 | ||
1097 | /* SSID/BSSID should be the _last_ config option set, because they | |
1098 | * trigger the association attempt. | |
1099 | */ | |
1100 | if (test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags) | |
1101 | || test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { | |
1102 | int success = 1; | |
1103 | ||
1104 | ret = assoc_helper_associate(priv, assoc_req); | |
1105 | if (ret) { | |
91843463 | 1106 | lbs_deb_assoc("ASSOC: association unsuccessful: %d\n", |
876c9d3a MT |
1107 | ret); |
1108 | success = 0; | |
1109 | } | |
1110 | ||
aa21c004 | 1111 | if (priv->connect_status != LBS_CONNECTED) { |
91843463 HS |
1112 | lbs_deb_assoc("ASSOC: association unsuccessful, " |
1113 | "not connected\n"); | |
876c9d3a MT |
1114 | success = 0; |
1115 | } | |
1116 | ||
1117 | if (success) { | |
52507c20 | 1118 | lbs_deb_assoc("associated to %s\n", |
aa21c004 | 1119 | print_mac(mac, priv->curbssparams.bssid)); |
10078321 | 1120 | lbs_prepare_and_send_command(priv, |
0aef64d7 DW |
1121 | CMD_802_11_RSSI, |
1122 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); | |
876c9d3a | 1123 | } else { |
876c9d3a MT |
1124 | ret = -1; |
1125 | } | |
1126 | } | |
1127 | ||
1128 | out: | |
1129 | if (ret) { | |
9012b28a | 1130 | lbs_deb_assoc("ASSOC: reconfiguration attempt unsuccessful: %d\n", |
876c9d3a MT |
1131 | ret); |
1132 | } | |
e76850d6 | 1133 | |
aa21c004 DW |
1134 | mutex_lock(&priv->lock); |
1135 | priv->in_progress_assoc_req = NULL; | |
1136 | mutex_unlock(&priv->lock); | |
876c9d3a | 1137 | kfree(assoc_req); |
9012b28a HS |
1138 | |
1139 | done: | |
1140 | lbs_deb_leave(LBS_DEB_ASSOC); | |
876c9d3a MT |
1141 | } |
1142 | ||
1143 | ||
1144 | /* | |
1145 | * Caller MUST hold any necessary locks | |
1146 | */ | |
aa21c004 | 1147 | struct assoc_request *lbs_get_association_request(struct lbs_private *priv) |
876c9d3a MT |
1148 | { |
1149 | struct assoc_request * assoc_req; | |
1150 | ||
0765af44 | 1151 | lbs_deb_enter(LBS_DEB_ASSOC); |
aa21c004 DW |
1152 | if (!priv->pending_assoc_req) { |
1153 | priv->pending_assoc_req = kzalloc(sizeof(struct assoc_request), | |
e76850d6 | 1154 | GFP_KERNEL); |
aa21c004 | 1155 | if (!priv->pending_assoc_req) { |
876c9d3a MT |
1156 | lbs_pr_info("Not enough memory to allocate association" |
1157 | " request!\n"); | |
1158 | return NULL; | |
1159 | } | |
1160 | } | |
1161 | ||
1162 | /* Copy current configuration attributes to the association request, | |
1163 | * but don't overwrite any that are already set. | |
1164 | */ | |
aa21c004 | 1165 | assoc_req = priv->pending_assoc_req; |
876c9d3a | 1166 | if (!test_bit(ASSOC_FLAG_SSID, &assoc_req->flags)) { |
aa21c004 | 1167 | memcpy(&assoc_req->ssid, &priv->curbssparams.ssid, |
d8efea25 | 1168 | IW_ESSID_MAX_SIZE); |
aa21c004 | 1169 | assoc_req->ssid_len = priv->curbssparams.ssid_len; |
876c9d3a MT |
1170 | } |
1171 | ||
1172 | if (!test_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags)) | |
aa21c004 | 1173 | assoc_req->channel = priv->curbssparams.channel; |
876c9d3a | 1174 | |
e76850d6 | 1175 | if (!test_bit(ASSOC_FLAG_BAND, &assoc_req->flags)) |
aa21c004 | 1176 | assoc_req->band = priv->curbssparams.band; |
e76850d6 | 1177 | |
876c9d3a | 1178 | if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) |
aa21c004 | 1179 | assoc_req->mode = priv->mode; |
876c9d3a MT |
1180 | |
1181 | if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { | |
aa21c004 | 1182 | memcpy(&assoc_req->bssid, priv->curbssparams.bssid, |
876c9d3a MT |
1183 | ETH_ALEN); |
1184 | } | |
1185 | ||
1186 | if (!test_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags)) { | |
1187 | int i; | |
1188 | for (i = 0; i < 4; i++) { | |
aa21c004 | 1189 | memcpy(&assoc_req->wep_keys[i], &priv->wep_keys[i], |
1443b653 | 1190 | sizeof(struct enc_key)); |
876c9d3a MT |
1191 | } |
1192 | } | |
1193 | ||
1194 | if (!test_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags)) | |
aa21c004 | 1195 | assoc_req->wep_tx_keyidx = priv->wep_tx_keyidx; |
876c9d3a MT |
1196 | |
1197 | if (!test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) { | |
aa21c004 | 1198 | memcpy(&assoc_req->wpa_mcast_key, &priv->wpa_mcast_key, |
1443b653 | 1199 | sizeof(struct enc_key)); |
876c9d3a MT |
1200 | } |
1201 | ||
1202 | if (!test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) { | |
aa21c004 | 1203 | memcpy(&assoc_req->wpa_unicast_key, &priv->wpa_unicast_key, |
1443b653 | 1204 | sizeof(struct enc_key)); |
876c9d3a MT |
1205 | } |
1206 | ||
1207 | if (!test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { | |
aa21c004 | 1208 | memcpy(&assoc_req->secinfo, &priv->secinfo, |
10078321 | 1209 | sizeof(struct lbs_802_11_security)); |
876c9d3a MT |
1210 | } |
1211 | ||
1212 | if (!test_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags)) { | |
aa21c004 | 1213 | memcpy(&assoc_req->wpa_ie, &priv->wpa_ie, |
876c9d3a | 1214 | MAX_WPA_IE_LEN); |
aa21c004 | 1215 | assoc_req->wpa_ie_len = priv->wpa_ie_len; |
876c9d3a MT |
1216 | } |
1217 | ||
0765af44 | 1218 | lbs_deb_leave(LBS_DEB_ASSOC); |
876c9d3a MT |
1219 | return assoc_req; |
1220 | } | |
697900ac HS |
1221 | |
1222 | ||
1223 | /** | |
1224 | * @brief This function finds common rates between rate1 and card rates. | |
1225 | * | |
1226 | * It will fill common rates in rate1 as output if found. | |
1227 | * | |
1228 | * NOTE: Setting the MSB of the basic rates need to be taken | |
1229 | * care, either before or after calling this function | |
1230 | * | |
1231 | * @param priv A pointer to struct lbs_private structure | |
1232 | * @param rate1 the buffer which keeps input and output | |
1233 | * @param rate1_size the size of rate1 buffer; new size of buffer on return | |
1234 | * | |
1235 | * @return 0 or -1 | |
1236 | */ | |
1237 | static int get_common_rates(struct lbs_private *priv, | |
1238 | u8 *rates, | |
1239 | u16 *rates_size) | |
1240 | { | |
1241 | u8 *card_rates = lbs_bg_rates; | |
1242 | size_t num_card_rates = sizeof(lbs_bg_rates); | |
1243 | int ret = 0, i, j; | |
1244 | u8 tmp[30]; | |
1245 | size_t tmp_size = 0; | |
1246 | ||
1247 | /* For each rate in card_rates that exists in rate1, copy to tmp */ | |
1248 | for (i = 0; card_rates[i] && (i < num_card_rates); i++) { | |
1249 | for (j = 0; rates[j] && (j < *rates_size); j++) { | |
1250 | if (rates[j] == card_rates[i]) | |
1251 | tmp[tmp_size++] = card_rates[i]; | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); | |
1256 | lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates); | |
1257 | lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); | |
1258 | lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); | |
1259 | ||
85319f93 | 1260 | if (!priv->enablehwauto) { |
697900ac HS |
1261 | for (i = 0; i < tmp_size; i++) { |
1262 | if (tmp[i] == priv->cur_rate) | |
1263 | goto done; | |
1264 | } | |
1265 | lbs_pr_alert("Previously set fixed data rate %#x isn't " | |
1266 | "compatible with the network.\n", priv->cur_rate); | |
1267 | ret = -1; | |
1268 | goto done; | |
1269 | } | |
1270 | ret = 0; | |
1271 | ||
1272 | done: | |
1273 | memset(rates, 0, *rates_size); | |
1274 | *rates_size = min_t(int, tmp_size, *rates_size); | |
1275 | memcpy(rates, tmp, *rates_size); | |
1276 | return ret; | |
1277 | } | |
1278 | ||
1279 | ||
1280 | /** | |
1281 | * @brief Sets the MSB on basic rates as the firmware requires | |
1282 | * | |
1283 | * Scan through an array and set the MSB for basic data rates. | |
1284 | * | |
1285 | * @param rates buffer of data rates | |
1286 | * @param len size of buffer | |
1287 | */ | |
1288 | static void lbs_set_basic_rate_flags(u8 *rates, size_t len) | |
1289 | { | |
1290 | int i; | |
1291 | ||
1292 | for (i = 0; i < len; i++) { | |
1293 | if (rates[i] == 0x02 || rates[i] == 0x04 || | |
1294 | rates[i] == 0x0b || rates[i] == 0x16) | |
1295 | rates[i] |= 0x80; | |
1296 | } | |
1297 | } | |
1298 | ||
697900ac HS |
1299 | /** |
1300 | * @brief This function prepares command of authenticate. | |
1301 | * | |
1302 | * @param priv A pointer to struct lbs_private structure | |
1303 | * @param cmd A pointer to cmd_ds_command structure | |
1304 | * @param pdata_buf Void cast of pointer to a BSSID to authenticate with | |
1305 | * | |
1306 | * @return 0 or -1 | |
1307 | */ | |
1308 | int lbs_cmd_80211_authenticate(struct lbs_private *priv, | |
1309 | struct cmd_ds_command *cmd, | |
1310 | void *pdata_buf) | |
1311 | { | |
1312 | struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth; | |
1313 | int ret = -1; | |
1314 | u8 *bssid = pdata_buf; | |
1315 | DECLARE_MAC_BUF(mac); | |
1316 | ||
1317 | lbs_deb_enter(LBS_DEB_JOIN); | |
1318 | ||
1319 | cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE); | |
1320 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate) | |
1321 | + S_DS_GEN); | |
1322 | ||
1323 | /* translate auth mode to 802.11 defined wire value */ | |
1324 | switch (priv->secinfo.auth_mode) { | |
1325 | case IW_AUTH_ALG_OPEN_SYSTEM: | |
1326 | pauthenticate->authtype = 0x00; | |
1327 | break; | |
1328 | case IW_AUTH_ALG_SHARED_KEY: | |
1329 | pauthenticate->authtype = 0x01; | |
1330 | break; | |
1331 | case IW_AUTH_ALG_LEAP: | |
1332 | pauthenticate->authtype = 0x80; | |
1333 | break; | |
1334 | default: | |
1335 | lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n", | |
1336 | priv->secinfo.auth_mode); | |
1337 | goto out; | |
1338 | } | |
1339 | ||
1340 | memcpy(pauthenticate->macaddr, bssid, ETH_ALEN); | |
1341 | ||
1342 | lbs_deb_join("AUTH_CMD: BSSID %s, auth 0x%x\n", | |
1343 | print_mac(mac, bssid), pauthenticate->authtype); | |
1344 | ret = 0; | |
1345 | ||
1346 | out: | |
1347 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); | |
1348 | return ret; | |
1349 | } | |
1350 | ||
191bb40e DW |
1351 | /** |
1352 | * @brief Deauthenticate from a specific BSS | |
1353 | * | |
1354 | * @param priv A pointer to struct lbs_private structure | |
1355 | * @param bssid The specific BSS to deauthenticate from | |
1356 | * @param reason The 802.11 sec. 7.3.1.7 Reason Code for deauthenticating | |
1357 | * | |
1358 | * @return 0 on success, error on failure | |
1359 | */ | |
1360 | int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, u8 bssid[ETH_ALEN], | |
1361 | u16 reason) | |
697900ac | 1362 | { |
191bb40e DW |
1363 | struct cmd_ds_802_11_deauthenticate cmd; |
1364 | int ret; | |
697900ac HS |
1365 | |
1366 | lbs_deb_enter(LBS_DEB_JOIN); | |
1367 | ||
191bb40e DW |
1368 | memset(&cmd, 0, sizeof(cmd)); |
1369 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1370 | memcpy(cmd.macaddr, &bssid[0], ETH_ALEN); | |
1371 | cmd.reasoncode = cpu_to_le16(reason); | |
697900ac | 1372 | |
191bb40e | 1373 | ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd); |
697900ac | 1374 | |
191bb40e DW |
1375 | /* Clean up everything even if there was an error; can't assume that |
1376 | * we're still authenticated to the AP after trying to deauth. | |
1377 | */ | |
1378 | lbs_mac_event_disconnected(priv); | |
697900ac HS |
1379 | |
1380 | lbs_deb_leave(LBS_DEB_JOIN); | |
191bb40e | 1381 | return ret; |
697900ac HS |
1382 | } |
1383 | ||
1384 | int lbs_cmd_80211_associate(struct lbs_private *priv, | |
1385 | struct cmd_ds_command *cmd, void *pdata_buf) | |
1386 | { | |
1387 | struct cmd_ds_802_11_associate *passo = &cmd->params.associate; | |
1388 | int ret = 0; | |
1389 | struct assoc_request *assoc_req = pdata_buf; | |
1390 | struct bss_descriptor *bss = &assoc_req->bss; | |
1391 | u8 *pos; | |
1392 | u16 tmpcap, tmplen; | |
1393 | struct mrvlietypes_ssidparamset *ssid; | |
1394 | struct mrvlietypes_phyparamset *phy; | |
1395 | struct mrvlietypes_ssparamset *ss; | |
1396 | struct mrvlietypes_ratesparamset *rates; | |
1397 | struct mrvlietypes_rsnparamset *rsn; | |
1398 | ||
1399 | lbs_deb_enter(LBS_DEB_ASSOC); | |
1400 | ||
1401 | pos = (u8 *) passo; | |
1402 | ||
1403 | if (!priv) { | |
1404 | ret = -1; | |
1405 | goto done; | |
1406 | } | |
1407 | ||
1408 | cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE); | |
1409 | ||
1410 | memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr)); | |
1411 | pos += sizeof(passo->peerstaaddr); | |
1412 | ||
1413 | /* set the listen interval */ | |
1414 | passo->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL); | |
1415 | ||
1416 | pos += sizeof(passo->capability); | |
1417 | pos += sizeof(passo->listeninterval); | |
1418 | pos += sizeof(passo->bcnperiod); | |
1419 | pos += sizeof(passo->dtimperiod); | |
1420 | ||
1421 | ssid = (struct mrvlietypes_ssidparamset *) pos; | |
1422 | ssid->header.type = cpu_to_le16(TLV_TYPE_SSID); | |
1423 | tmplen = bss->ssid_len; | |
1424 | ssid->header.len = cpu_to_le16(tmplen); | |
1425 | memcpy(ssid->ssid, bss->ssid, tmplen); | |
1426 | pos += sizeof(ssid->header) + tmplen; | |
1427 | ||
1428 | phy = (struct mrvlietypes_phyparamset *) pos; | |
1429 | phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS); | |
1430 | tmplen = sizeof(phy->fh_ds.dsparamset); | |
1431 | phy->header.len = cpu_to_le16(tmplen); | |
1432 | memcpy(&phy->fh_ds.dsparamset, | |
1433 | &bss->phyparamset.dsparamset.currentchan, | |
1434 | tmplen); | |
1435 | pos += sizeof(phy->header) + tmplen; | |
1436 | ||
1437 | ss = (struct mrvlietypes_ssparamset *) pos; | |
1438 | ss->header.type = cpu_to_le16(TLV_TYPE_CF); | |
1439 | tmplen = sizeof(ss->cf_ibss.cfparamset); | |
1440 | ss->header.len = cpu_to_le16(tmplen); | |
1441 | pos += sizeof(ss->header) + tmplen; | |
1442 | ||
1443 | rates = (struct mrvlietypes_ratesparamset *) pos; | |
1444 | rates->header.type = cpu_to_le16(TLV_TYPE_RATES); | |
1445 | memcpy(&rates->rates, &bss->rates, MAX_RATES); | |
1446 | tmplen = MAX_RATES; | |
1447 | if (get_common_rates(priv, rates->rates, &tmplen)) { | |
1448 | ret = -1; | |
1449 | goto done; | |
1450 | } | |
1451 | pos += sizeof(rates->header) + tmplen; | |
1452 | rates->header.len = cpu_to_le16(tmplen); | |
1453 | lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen); | |
1454 | ||
1455 | /* Copy the infra. association rates into Current BSS state structure */ | |
1456 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); | |
1457 | memcpy(&priv->curbssparams.rates, &rates->rates, tmplen); | |
1458 | ||
1459 | /* Set MSB on basic rates as the firmware requires, but _after_ | |
1460 | * copying to current bss rates. | |
1461 | */ | |
1462 | lbs_set_basic_rate_flags(rates->rates, tmplen); | |
1463 | ||
1464 | if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { | |
1465 | rsn = (struct mrvlietypes_rsnparamset *) pos; | |
1466 | /* WPA_IE or WPA2_IE */ | |
1467 | rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]); | |
1468 | tmplen = (u16) assoc_req->wpa_ie[1]; | |
1469 | rsn->header.len = cpu_to_le16(tmplen); | |
1470 | memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen); | |
1471 | lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn, | |
1472 | sizeof(rsn->header) + tmplen); | |
1473 | pos += sizeof(rsn->header) + tmplen; | |
1474 | } | |
1475 | ||
1476 | /* update curbssparams */ | |
1477 | priv->curbssparams.channel = bss->phyparamset.dsparamset.currentchan; | |
1478 | ||
1479 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { | |
1480 | ret = -1; | |
1481 | goto done; | |
1482 | } | |
1483 | ||
1484 | cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN); | |
1485 | ||
1486 | /* set the capability info */ | |
1487 | tmpcap = (bss->capability & CAPINFO_MASK); | |
1488 | if (bss->mode == IW_MODE_INFRA) | |
1489 | tmpcap |= WLAN_CAPABILITY_ESS; | |
1490 | passo->capability = cpu_to_le16(tmpcap); | |
1491 | lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap); | |
1492 | ||
1493 | done: | |
1494 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | |
1495 | return ret; | |
1496 | } | |
1497 | ||
1498 | int lbs_cmd_80211_ad_hoc_start(struct lbs_private *priv, | |
1499 | struct cmd_ds_command *cmd, void *pdata_buf) | |
1500 | { | |
1501 | struct cmd_ds_802_11_ad_hoc_start *adhs = &cmd->params.ads; | |
1502 | int ret = 0; | |
1503 | int cmdappendsize = 0; | |
1504 | struct assoc_request *assoc_req = pdata_buf; | |
1505 | u16 tmpcap = 0; | |
1506 | size_t ratesize = 0; | |
1507 | ||
1508 | lbs_deb_enter(LBS_DEB_JOIN); | |
1509 | ||
1510 | if (!priv) { | |
1511 | ret = -1; | |
1512 | goto done; | |
1513 | } | |
1514 | ||
1515 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_START); | |
1516 | ||
1517 | /* | |
1518 | * Fill in the parameters for 2 data structures: | |
1519 | * 1. cmd_ds_802_11_ad_hoc_start command | |
1520 | * 2. priv->scantable[i] | |
1521 | * | |
1522 | * Driver will fill up SSID, bsstype,IBSS param, Physical Param, | |
1523 | * probe delay, and cap info. | |
1524 | * | |
1525 | * Firmware will fill up beacon period, DTIM, Basic rates | |
1526 | * and operational rates. | |
1527 | */ | |
1528 | ||
1529 | memset(adhs->ssid, 0, IW_ESSID_MAX_SIZE); | |
1530 | memcpy(adhs->ssid, assoc_req->ssid, assoc_req->ssid_len); | |
1531 | ||
1532 | lbs_deb_join("ADHOC_S_CMD: SSID '%s', ssid length %u\n", | |
1533 | escape_essid(assoc_req->ssid, assoc_req->ssid_len), | |
1534 | assoc_req->ssid_len); | |
1535 | ||
1536 | /* set the BSS type */ | |
1537 | adhs->bsstype = CMD_BSS_TYPE_IBSS; | |
1538 | priv->mode = IW_MODE_ADHOC; | |
1539 | if (priv->beacon_period == 0) | |
1540 | priv->beacon_period = MRVDRV_BEACON_INTERVAL; | |
1541 | adhs->beaconperiod = cpu_to_le16(priv->beacon_period); | |
1542 | ||
1543 | /* set Physical param set */ | |
1544 | #define DS_PARA_IE_ID 3 | |
1545 | #define DS_PARA_IE_LEN 1 | |
1546 | ||
1547 | adhs->phyparamset.dsparamset.elementid = DS_PARA_IE_ID; | |
1548 | adhs->phyparamset.dsparamset.len = DS_PARA_IE_LEN; | |
1549 | ||
1550 | WARN_ON(!assoc_req->channel); | |
1551 | ||
1552 | lbs_deb_join("ADHOC_S_CMD: Creating ADHOC on channel %d\n", | |
1553 | assoc_req->channel); | |
1554 | ||
1555 | adhs->phyparamset.dsparamset.currentchan = assoc_req->channel; | |
1556 | ||
1557 | /* set IBSS param set */ | |
1558 | #define IBSS_PARA_IE_ID 6 | |
1559 | #define IBSS_PARA_IE_LEN 2 | |
1560 | ||
1561 | adhs->ssparamset.ibssparamset.elementid = IBSS_PARA_IE_ID; | |
1562 | adhs->ssparamset.ibssparamset.len = IBSS_PARA_IE_LEN; | |
1563 | adhs->ssparamset.ibssparamset.atimwindow = 0; | |
1564 | ||
1565 | /* set capability info */ | |
1566 | tmpcap = WLAN_CAPABILITY_IBSS; | |
1567 | if (assoc_req->secinfo.wep_enabled) { | |
1568 | lbs_deb_join("ADHOC_S_CMD: WEP enabled, " | |
1569 | "setting privacy on\n"); | |
1570 | tmpcap |= WLAN_CAPABILITY_PRIVACY; | |
1571 | } else { | |
1572 | lbs_deb_join("ADHOC_S_CMD: WEP disabled, " | |
1573 | "setting privacy off\n"); | |
1574 | } | |
1575 | adhs->capability = cpu_to_le16(tmpcap); | |
1576 | ||
1577 | /* probedelay */ | |
1578 | adhs->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | |
1579 | ||
1580 | memset(adhs->rates, 0, sizeof(adhs->rates)); | |
1581 | ratesize = min(sizeof(adhs->rates), sizeof(lbs_bg_rates)); | |
1582 | memcpy(adhs->rates, lbs_bg_rates, ratesize); | |
1583 | ||
1584 | /* Copy the ad-hoc creating rates into Current BSS state structure */ | |
1585 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); | |
1586 | memcpy(&priv->curbssparams.rates, &adhs->rates, ratesize); | |
1587 | ||
1588 | /* Set MSB on basic rates as the firmware requires, but _after_ | |
1589 | * copying to current bss rates. | |
1590 | */ | |
1591 | lbs_set_basic_rate_flags(adhs->rates, ratesize); | |
1592 | ||
1593 | lbs_deb_join("ADHOC_S_CMD: rates=%02x %02x %02x %02x \n", | |
1594 | adhs->rates[0], adhs->rates[1], adhs->rates[2], adhs->rates[3]); | |
1595 | ||
1596 | lbs_deb_join("ADHOC_S_CMD: AD HOC Start command is ready\n"); | |
1597 | ||
1598 | if (lbs_create_dnld_countryinfo_11d(priv)) { | |
1599 | lbs_deb_join("ADHOC_S_CMD: dnld_countryinfo_11d failed\n"); | |
1600 | ret = -1; | |
1601 | goto done; | |
1602 | } | |
1603 | ||
1604 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_start) + | |
1605 | S_DS_GEN + cmdappendsize); | |
1606 | ||
1607 | ret = 0; | |
1608 | done: | |
1609 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); | |
1610 | return ret; | |
1611 | } | |
1612 | ||
1613 | int lbs_cmd_80211_ad_hoc_stop(struct cmd_ds_command *cmd) | |
1614 | { | |
1615 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_STOP); | |
1616 | cmd->size = cpu_to_le16(S_DS_GEN); | |
1617 | ||
1618 | return 0; | |
1619 | } | |
1620 | ||
1621 | int lbs_cmd_80211_ad_hoc_join(struct lbs_private *priv, | |
1622 | struct cmd_ds_command *cmd, void *pdata_buf) | |
1623 | { | |
1624 | struct cmd_ds_802_11_ad_hoc_join *join_cmd = &cmd->params.adj; | |
1625 | struct assoc_request *assoc_req = pdata_buf; | |
1626 | struct bss_descriptor *bss = &assoc_req->bss; | |
1627 | int cmdappendsize = 0; | |
1628 | int ret = 0; | |
1629 | u16 ratesize = 0; | |
1630 | DECLARE_MAC_BUF(mac); | |
1631 | ||
1632 | lbs_deb_enter(LBS_DEB_JOIN); | |
1633 | ||
1634 | cmd->command = cpu_to_le16(CMD_802_11_AD_HOC_JOIN); | |
1635 | ||
1636 | join_cmd->bss.type = CMD_BSS_TYPE_IBSS; | |
1637 | join_cmd->bss.beaconperiod = cpu_to_le16(bss->beaconperiod); | |
1638 | ||
1639 | memcpy(&join_cmd->bss.bssid, &bss->bssid, ETH_ALEN); | |
1640 | memcpy(&join_cmd->bss.ssid, &bss->ssid, bss->ssid_len); | |
1641 | ||
1642 | memcpy(&join_cmd->bss.phyparamset, &bss->phyparamset, | |
1643 | sizeof(union ieeetypes_phyparamset)); | |
1644 | ||
1645 | memcpy(&join_cmd->bss.ssparamset, &bss->ssparamset, | |
1646 | sizeof(union IEEEtypes_ssparamset)); | |
1647 | ||
1648 | join_cmd->bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); | |
1649 | lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n", | |
1650 | bss->capability, CAPINFO_MASK); | |
1651 | ||
1652 | /* information on BSSID descriptor passed to FW */ | |
1653 | lbs_deb_join( | |
1654 | "ADHOC_J_CMD: BSSID = %s, SSID = '%s'\n", | |
1655 | print_mac(mac, join_cmd->bss.bssid), | |
1656 | join_cmd->bss.ssid); | |
1657 | ||
1658 | /* failtimeout */ | |
1659 | join_cmd->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); | |
1660 | ||
1661 | /* probedelay */ | |
1662 | join_cmd->probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | |
1663 | ||
1664 | priv->curbssparams.channel = bss->channel; | |
1665 | ||
1666 | /* Copy Data rates from the rates recorded in scan response */ | |
1667 | memset(join_cmd->bss.rates, 0, sizeof(join_cmd->bss.rates)); | |
1668 | ratesize = min_t(u16, sizeof(join_cmd->bss.rates), MAX_RATES); | |
1669 | memcpy(join_cmd->bss.rates, bss->rates, ratesize); | |
1670 | if (get_common_rates(priv, join_cmd->bss.rates, &ratesize)) { | |
1671 | lbs_deb_join("ADHOC_J_CMD: get_common_rates returns error.\n"); | |
1672 | ret = -1; | |
1673 | goto done; | |
1674 | } | |
1675 | ||
1676 | /* Copy the ad-hoc creating rates into Current BSS state structure */ | |
1677 | memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); | |
1678 | memcpy(&priv->curbssparams.rates, join_cmd->bss.rates, ratesize); | |
1679 | ||
1680 | /* Set MSB on basic rates as the firmware requires, but _after_ | |
1681 | * copying to current bss rates. | |
1682 | */ | |
1683 | lbs_set_basic_rate_flags(join_cmd->bss.rates, ratesize); | |
1684 | ||
1685 | join_cmd->bss.ssparamset.ibssparamset.atimwindow = | |
1686 | cpu_to_le16(bss->atimwindow); | |
1687 | ||
1688 | if (assoc_req->secinfo.wep_enabled) { | |
1689 | u16 tmp = le16_to_cpu(join_cmd->bss.capability); | |
1690 | tmp |= WLAN_CAPABILITY_PRIVACY; | |
1691 | join_cmd->bss.capability = cpu_to_le16(tmp); | |
1692 | } | |
1693 | ||
1694 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { | |
1695 | /* wake up first */ | |
1696 | __le32 Localpsmode; | |
1697 | ||
1698 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); | |
1699 | ret = lbs_prepare_and_send_command(priv, | |
1700 | CMD_802_11_PS_MODE, | |
1701 | CMD_ACT_SET, | |
1702 | 0, 0, &Localpsmode); | |
1703 | ||
1704 | if (ret) { | |
1705 | ret = -1; | |
1706 | goto done; | |
1707 | } | |
1708 | } | |
1709 | ||
1710 | if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { | |
1711 | ret = -1; | |
1712 | goto done; | |
1713 | } | |
1714 | ||
1715 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ad_hoc_join) + | |
1716 | S_DS_GEN + cmdappendsize); | |
1717 | ||
1718 | done: | |
1719 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); | |
1720 | return ret; | |
1721 | } | |
1722 | ||
1723 | int lbs_ret_80211_associate(struct lbs_private *priv, | |
1724 | struct cmd_ds_command *resp) | |
1725 | { | |
1726 | int ret = 0; | |
1727 | union iwreq_data wrqu; | |
1728 | struct ieeetypes_assocrsp *passocrsp; | |
1729 | struct bss_descriptor *bss; | |
1730 | u16 status_code; | |
1731 | ||
1732 | lbs_deb_enter(LBS_DEB_ASSOC); | |
1733 | ||
1734 | if (!priv->in_progress_assoc_req) { | |
1735 | lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n"); | |
1736 | ret = -1; | |
1737 | goto done; | |
1738 | } | |
1739 | bss = &priv->in_progress_assoc_req->bss; | |
1740 | ||
1741 | passocrsp = (struct ieeetypes_assocrsp *) &resp->params; | |
1742 | ||
1743 | /* | |
1744 | * Older FW versions map the IEEE 802.11 Status Code in the association | |
1745 | * response to the following values returned in passocrsp->statuscode: | |
1746 | * | |
1747 | * IEEE Status Code Marvell Status Code | |
1748 | * 0 -> 0x0000 ASSOC_RESULT_SUCCESS | |
1749 | * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED | |
1750 | * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED | |
1751 | * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED | |
1752 | * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED | |
1753 | * others -> 0x0003 ASSOC_RESULT_REFUSED | |
1754 | * | |
1755 | * Other response codes: | |
1756 | * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused) | |
1757 | * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for | |
1758 | * association response from the AP) | |
1759 | */ | |
1760 | ||
1761 | status_code = le16_to_cpu(passocrsp->statuscode); | |
1762 | switch (status_code) { | |
1763 | case 0x00: | |
1764 | break; | |
1765 | case 0x01: | |
1766 | lbs_deb_assoc("ASSOC_RESP: invalid parameters\n"); | |
1767 | break; | |
1768 | case 0x02: | |
1769 | lbs_deb_assoc("ASSOC_RESP: internal timer " | |
1770 | "expired while waiting for the AP\n"); | |
1771 | break; | |
1772 | case 0x03: | |
1773 | lbs_deb_assoc("ASSOC_RESP: association " | |
1774 | "refused by AP\n"); | |
1775 | break; | |
1776 | case 0x04: | |
1777 | lbs_deb_assoc("ASSOC_RESP: authentication " | |
1778 | "refused by AP\n"); | |
1779 | break; | |
1780 | default: | |
1781 | lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x " | |
1782 | " unknown\n", status_code); | |
1783 | break; | |
1784 | } | |
1785 | ||
1786 | if (status_code) { | |
1787 | lbs_mac_event_disconnected(priv); | |
1788 | ret = -1; | |
1789 | goto done; | |
1790 | } | |
1791 | ||
1792 | lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", (void *)&resp->params, | |
1793 | le16_to_cpu(resp->size) - S_DS_GEN); | |
1794 | ||
1795 | /* Send a Media Connected event, according to the Spec */ | |
1796 | priv->connect_status = LBS_CONNECTED; | |
1797 | ||
1798 | /* Update current SSID and BSSID */ | |
1799 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); | |
1800 | priv->curbssparams.ssid_len = bss->ssid_len; | |
1801 | memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN); | |
1802 | ||
1803 | priv->SNR[TYPE_RXPD][TYPE_AVG] = 0; | |
1804 | priv->NF[TYPE_RXPD][TYPE_AVG] = 0; | |
1805 | ||
1806 | memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR)); | |
1807 | memset(priv->rawNF, 0x00, sizeof(priv->rawNF)); | |
1808 | priv->nextSNRNF = 0; | |
1809 | priv->numSNRNF = 0; | |
1810 | ||
1811 | netif_carrier_on(priv->dev); | |
1812 | if (!priv->tx_pending_len) | |
1813 | netif_wake_queue(priv->dev); | |
1814 | ||
1815 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); | |
1816 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1817 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); | |
1818 | ||
1819 | done: | |
1820 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | |
1821 | return ret; | |
1822 | } | |
1823 | ||
697900ac HS |
1824 | int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv, |
1825 | struct cmd_ds_command *resp) | |
1826 | { | |
1827 | int ret = 0; | |
1828 | u16 command = le16_to_cpu(resp->command); | |
1829 | u16 result = le16_to_cpu(resp->result); | |
1830 | struct cmd_ds_802_11_ad_hoc_result *padhocresult; | |
1831 | union iwreq_data wrqu; | |
1832 | struct bss_descriptor *bss; | |
1833 | DECLARE_MAC_BUF(mac); | |
1834 | ||
1835 | lbs_deb_enter(LBS_DEB_JOIN); | |
1836 | ||
1837 | padhocresult = &resp->params.result; | |
1838 | ||
1839 | lbs_deb_join("ADHOC_RESP: size = %d\n", le16_to_cpu(resp->size)); | |
1840 | lbs_deb_join("ADHOC_RESP: command = %x\n", command); | |
1841 | lbs_deb_join("ADHOC_RESP: result = %x\n", result); | |
1842 | ||
1843 | if (!priv->in_progress_assoc_req) { | |
1844 | lbs_deb_join("ADHOC_RESP: no in-progress association " | |
1845 | "request\n"); | |
1846 | ret = -1; | |
1847 | goto done; | |
1848 | } | |
1849 | bss = &priv->in_progress_assoc_req->bss; | |
1850 | ||
1851 | /* | |
1852 | * Join result code 0 --> SUCCESS | |
1853 | */ | |
1854 | if (result) { | |
1855 | lbs_deb_join("ADHOC_RESP: failed\n"); | |
1856 | if (priv->connect_status == LBS_CONNECTED) | |
1857 | lbs_mac_event_disconnected(priv); | |
1858 | ret = -1; | |
1859 | goto done; | |
1860 | } | |
1861 | ||
1862 | /* | |
1863 | * Now the join cmd should be successful | |
1864 | * If BSSID has changed use SSID to compare instead of BSSID | |
1865 | */ | |
1866 | lbs_deb_join("ADHOC_RESP: associated to '%s'\n", | |
1867 | escape_essid(bss->ssid, bss->ssid_len)); | |
1868 | ||
1869 | /* Send a Media Connected event, according to the Spec */ | |
1870 | priv->connect_status = LBS_CONNECTED; | |
1871 | ||
1872 | if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { | |
1873 | /* Update the created network descriptor with the new BSSID */ | |
1874 | memcpy(bss->bssid, padhocresult->bssid, ETH_ALEN); | |
1875 | } | |
1876 | ||
1877 | /* Set the BSSID from the joined/started descriptor */ | |
1878 | memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN); | |
1879 | ||
1880 | /* Set the new SSID to current SSID */ | |
1881 | memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); | |
1882 | priv->curbssparams.ssid_len = bss->ssid_len; | |
1883 | ||
1884 | netif_carrier_on(priv->dev); | |
1885 | if (!priv->tx_pending_len) | |
1886 | netif_wake_queue(priv->dev); | |
1887 | ||
1888 | memset(&wrqu, 0, sizeof(wrqu)); | |
1889 | memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); | |
1890 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1891 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); | |
1892 | ||
1893 | lbs_deb_join("ADHOC_RESP: - Joined/Started Ad Hoc\n"); | |
1894 | lbs_deb_join("ADHOC_RESP: channel = %d\n", priv->curbssparams.channel); | |
1895 | lbs_deb_join("ADHOC_RESP: BSSID = %s\n", | |
1896 | print_mac(mac, padhocresult->bssid)); | |
1897 | ||
1898 | done: | |
1899 | lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); | |
1900 | return ret; | |
1901 | } | |
1902 | ||
1903 | int lbs_ret_80211_ad_hoc_stop(struct lbs_private *priv) | |
1904 | { | |
1905 | lbs_deb_enter(LBS_DEB_JOIN); | |
1906 | ||
1907 | lbs_mac_event_disconnected(priv); | |
1908 | ||
1909 | lbs_deb_leave(LBS_DEB_JOIN); | |
1910 | return 0; | |
1911 | } |