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