]>
Commit | Line | Data |
---|---|---|
ff9fc791 HS |
1 | /* |
2 | * Implement cfg80211 ("iw") support. | |
3 | * | |
4 | * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany | |
5 | * Holger Schurig <hs4233@mail.mn-solutions.de> | |
6 | * | |
7 | */ | |
8 | ||
5a0e3ad6 | 9 | #include <linux/slab.h> |
a9fda88b | 10 | #include <linux/sched.h> |
1047d5ed | 11 | #include <linux/ieee80211.h> |
ff9fc791 | 12 | #include <net/cfg80211.h> |
e86dc1ca | 13 | #include <asm/unaligned.h> |
ff9fc791 | 14 | |
e86dc1ca | 15 | #include "decl.h" |
ff9fc791 HS |
16 | #include "cfg.h" |
17 | #include "cmd.h" | |
18 | ||
19 | ||
20 | #define CHAN2G(_channel, _freq, _flags) { \ | |
21 | .band = IEEE80211_BAND_2GHZ, \ | |
22 | .center_freq = (_freq), \ | |
23 | .hw_value = (_channel), \ | |
24 | .flags = (_flags), \ | |
25 | .max_antenna_gain = 0, \ | |
26 | .max_power = 30, \ | |
27 | } | |
28 | ||
29 | static struct ieee80211_channel lbs_2ghz_channels[] = { | |
30 | CHAN2G(1, 2412, 0), | |
31 | CHAN2G(2, 2417, 0), | |
32 | CHAN2G(3, 2422, 0), | |
33 | CHAN2G(4, 2427, 0), | |
34 | CHAN2G(5, 2432, 0), | |
35 | CHAN2G(6, 2437, 0), | |
36 | CHAN2G(7, 2442, 0), | |
37 | CHAN2G(8, 2447, 0), | |
38 | CHAN2G(9, 2452, 0), | |
39 | CHAN2G(10, 2457, 0), | |
40 | CHAN2G(11, 2462, 0), | |
41 | CHAN2G(12, 2467, 0), | |
42 | CHAN2G(13, 2472, 0), | |
43 | CHAN2G(14, 2484, 0), | |
44 | }; | |
45 | ||
e86dc1ca KD |
46 | #define RATETAB_ENT(_rate, _hw_value, _flags) { \ |
47 | .bitrate = (_rate), \ | |
48 | .hw_value = (_hw_value), \ | |
49 | .flags = (_flags), \ | |
ff9fc791 HS |
50 | } |
51 | ||
52 | ||
e86dc1ca | 53 | /* Table 6 in section 3.2.1.1 */ |
ff9fc791 | 54 | static struct ieee80211_rate lbs_rates[] = { |
e86dc1ca KD |
55 | RATETAB_ENT(10, 0, 0), |
56 | RATETAB_ENT(20, 1, 0), | |
57 | RATETAB_ENT(55, 2, 0), | |
58 | RATETAB_ENT(110, 3, 0), | |
59 | RATETAB_ENT(60, 9, 0), | |
60 | RATETAB_ENT(90, 6, 0), | |
61 | RATETAB_ENT(120, 7, 0), | |
62 | RATETAB_ENT(180, 8, 0), | |
63 | RATETAB_ENT(240, 9, 0), | |
64 | RATETAB_ENT(360, 10, 0), | |
65 | RATETAB_ENT(480, 11, 0), | |
66 | RATETAB_ENT(540, 12, 0), | |
ff9fc791 HS |
67 | }; |
68 | ||
69 | static struct ieee80211_supported_band lbs_band_2ghz = { | |
70 | .channels = lbs_2ghz_channels, | |
71 | .n_channels = ARRAY_SIZE(lbs_2ghz_channels), | |
72 | .bitrates = lbs_rates, | |
73 | .n_bitrates = ARRAY_SIZE(lbs_rates), | |
74 | }; | |
75 | ||
76 | ||
77 | static const u32 cipher_suites[] = { | |
78 | WLAN_CIPHER_SUITE_WEP40, | |
79 | WLAN_CIPHER_SUITE_WEP104, | |
80 | WLAN_CIPHER_SUITE_TKIP, | |
81 | WLAN_CIPHER_SUITE_CCMP, | |
82 | }; | |
83 | ||
e86dc1ca KD |
84 | /* Time to stay on the channel */ |
85 | #define LBS_DWELL_PASSIVE 100 | |
86 | #define LBS_DWELL_ACTIVE 40 | |
ff9fc791 HS |
87 | |
88 | ||
e86dc1ca KD |
89 | /*************************************************************************** |
90 | * Misc utility functions | |
91 | * | |
92 | * TLVs are Marvell specific. They are very similar to IEs, they have the | |
93 | * same structure: type, length, data*. The only difference: for IEs, the | |
94 | * type and length are u8, but for TLVs they're __le16. | |
95 | */ | |
96 | ||
97 | /* | |
98 | * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1 | |
99 | * in the firmware spec | |
100 | */ | |
101 | static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type) | |
102 | { | |
103 | int ret = -ENOTSUPP; | |
104 | ||
105 | switch (auth_type) { | |
106 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
107 | case NL80211_AUTHTYPE_SHARED_KEY: | |
108 | ret = auth_type; | |
109 | break; | |
110 | case NL80211_AUTHTYPE_AUTOMATIC: | |
111 | ret = NL80211_AUTHTYPE_OPEN_SYSTEM; | |
112 | break; | |
113 | case NL80211_AUTHTYPE_NETWORK_EAP: | |
114 | ret = 0x80; | |
115 | break; | |
116 | default: | |
117 | /* silence compiler */ | |
118 | break; | |
119 | } | |
120 | return ret; | |
121 | } | |
122 | ||
123 | ||
124 | /* Various firmware commands need the list of supported rates, but with | |
125 | the hight-bit set for basic rates */ | |
126 | static int lbs_add_rates(u8 *rates) | |
127 | { | |
128 | size_t i; | |
129 | ||
130 | for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) { | |
131 | u8 rate = lbs_rates[i].bitrate / 5; | |
132 | if (rate == 0x02 || rate == 0x04 || | |
133 | rate == 0x0b || rate == 0x16) | |
134 | rate |= 0x80; | |
135 | rates[i] = rate; | |
136 | } | |
137 | return ARRAY_SIZE(lbs_rates); | |
138 | } | |
139 | ||
140 | ||
141 | /*************************************************************************** | |
142 | * TLV utility functions | |
143 | * | |
144 | * TLVs are Marvell specific. They are very similar to IEs, they have the | |
145 | * same structure: type, length, data*. The only difference: for IEs, the | |
146 | * type and length are u8, but for TLVs they're __le16. | |
147 | */ | |
148 | ||
149 | ||
150 | /* | |
151 | * Add ssid TLV | |
152 | */ | |
153 | #define LBS_MAX_SSID_TLV_SIZE \ | |
154 | (sizeof(struct mrvl_ie_header) \ | |
155 | + IEEE80211_MAX_SSID_LEN) | |
156 | ||
157 | static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len) | |
158 | { | |
159 | struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv; | |
160 | ||
161 | /* | |
162 | * TLV-ID SSID 00 00 | |
163 | * length 06 00 | |
164 | * ssid 4d 4e 54 45 53 54 | |
165 | */ | |
166 | ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID); | |
167 | ssid_tlv->header.len = cpu_to_le16(ssid_len); | |
168 | memcpy(ssid_tlv->ssid, ssid, ssid_len); | |
169 | return sizeof(ssid_tlv->header) + ssid_len; | |
170 | } | |
171 | ||
172 | ||
173 | /* | |
174 | * Add channel list TLV (section 8.4.2) | |
175 | * | |
176 | * Actual channel data comes from priv->wdev->wiphy->channels. | |
177 | */ | |
178 | #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \ | |
179 | (sizeof(struct mrvl_ie_header) \ | |
180 | + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset))) | |
181 | ||
182 | static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv, | |
183 | int last_channel, int active_scan) | |
184 | { | |
185 | int chanscanparamsize = sizeof(struct chanscanparamset) * | |
186 | (last_channel - priv->scan_channel); | |
187 | ||
188 | struct mrvl_ie_header *header = (void *) tlv; | |
189 | ||
190 | /* | |
191 | * TLV-ID CHANLIST 01 01 | |
192 | * length 0e 00 | |
193 | * channel 00 01 00 00 00 64 00 | |
194 | * radio type 00 | |
195 | * channel 01 | |
196 | * scan type 00 | |
197 | * min scan time 00 00 | |
198 | * max scan time 64 00 | |
199 | * channel 2 00 02 00 00 00 64 00 | |
200 | * | |
201 | */ | |
202 | ||
203 | header->type = cpu_to_le16(TLV_TYPE_CHANLIST); | |
204 | header->len = cpu_to_le16(chanscanparamsize); | |
205 | tlv += sizeof(struct mrvl_ie_header); | |
206 | ||
207 | /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel, | |
208 | last_channel); */ | |
209 | memset(tlv, 0, chanscanparamsize); | |
210 | ||
211 | while (priv->scan_channel < last_channel) { | |
212 | struct chanscanparamset *param = (void *) tlv; | |
213 | ||
214 | param->radiotype = CMD_SCAN_RADIO_TYPE_BG; | |
215 | param->channumber = | |
216 | priv->scan_req->channels[priv->scan_channel]->hw_value; | |
217 | if (active_scan) { | |
218 | param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE); | |
219 | } else { | |
220 | param->chanscanmode.passivescan = 1; | |
221 | param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE); | |
222 | } | |
223 | tlv += sizeof(struct chanscanparamset); | |
224 | priv->scan_channel++; | |
225 | } | |
226 | return sizeof(struct mrvl_ie_header) + chanscanparamsize; | |
227 | } | |
228 | ||
229 | ||
230 | /* | |
231 | * Add rates TLV | |
232 | * | |
233 | * The rates are in lbs_bg_rates[], but for the 802.11b | |
234 | * rates the high bit is set. We add this TLV only because | |
235 | * there's a firmware which otherwise doesn't report all | |
236 | * APs in range. | |
237 | */ | |
238 | #define LBS_MAX_RATES_TLV_SIZE \ | |
239 | (sizeof(struct mrvl_ie_header) \ | |
240 | + (ARRAY_SIZE(lbs_rates))) | |
241 | ||
242 | /* Adds a TLV with all rates the hardware supports */ | |
243 | static int lbs_add_supported_rates_tlv(u8 *tlv) | |
244 | { | |
245 | size_t i; | |
246 | struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv; | |
247 | ||
248 | /* | |
249 | * TLV-ID RATES 01 00 | |
250 | * length 0e 00 | |
251 | * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c | |
252 | */ | |
253 | rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES); | |
254 | tlv += sizeof(rate_tlv->header); | |
255 | i = lbs_add_rates(tlv); | |
256 | tlv += i; | |
257 | rate_tlv->header.len = cpu_to_le16(i); | |
258 | return sizeof(rate_tlv->header) + i; | |
259 | } | |
260 | ||
19757539 DW |
261 | /* Add common rates from a TLV and return the new end of the TLV */ |
262 | static u8 * | |
263 | add_ie_rates(u8 *tlv, const u8 *ie, int *nrates) | |
264 | { | |
265 | int hw, ap, ap_max = ie[1]; | |
266 | u8 hw_rate; | |
267 | ||
268 | /* Advance past IE header */ | |
269 | ie += 2; | |
270 | ||
271 | lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max); | |
272 | ||
273 | for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) { | |
274 | hw_rate = lbs_rates[hw].bitrate / 5; | |
275 | for (ap = 0; ap < ap_max; ap++) { | |
276 | if (hw_rate == (ie[ap] & 0x7f)) { | |
277 | *tlv++ = ie[ap]; | |
278 | *nrates = *nrates + 1; | |
279 | } | |
280 | } | |
281 | } | |
282 | return tlv; | |
283 | } | |
e86dc1ca KD |
284 | |
285 | /* | |
286 | * Adds a TLV with all rates the hardware *and* BSS supports. | |
287 | */ | |
288 | static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss) | |
289 | { | |
290 | struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv; | |
19757539 DW |
291 | const u8 *rates_eid, *ext_rates_eid; |
292 | int n = 0; | |
293 | ||
294 | rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES); | |
295 | ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES); | |
e86dc1ca KD |
296 | |
297 | /* | |
298 | * 01 00 TLV_TYPE_RATES | |
299 | * 04 00 len | |
300 | * 82 84 8b 96 rates | |
301 | */ | |
302 | rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES); | |
303 | tlv += sizeof(rate_tlv->header); | |
304 | ||
19757539 DW |
305 | /* Add basic rates */ |
306 | if (rates_eid) { | |
307 | tlv = add_ie_rates(tlv, rates_eid, &n); | |
308 | ||
309 | /* Add extended rates, if any */ | |
310 | if (ext_rates_eid) | |
311 | tlv = add_ie_rates(tlv, ext_rates_eid, &n); | |
312 | } else { | |
313 | lbs_deb_assoc("assoc: bss had no basic rate IE\n"); | |
e86dc1ca KD |
314 | /* Fallback: add basic 802.11b rates */ |
315 | *tlv++ = 0x82; | |
316 | *tlv++ = 0x84; | |
317 | *tlv++ = 0x8b; | |
318 | *tlv++ = 0x96; | |
319 | n = 4; | |
e86dc1ca KD |
320 | } |
321 | ||
322 | rate_tlv->header.len = cpu_to_le16(n); | |
323 | return sizeof(rate_tlv->header) + n; | |
324 | } | |
325 | ||
326 | ||
327 | /* | |
328 | * Add auth type TLV. | |
329 | * | |
330 | * This is only needed for newer firmware (V9 and up). | |
331 | */ | |
332 | #define LBS_MAX_AUTH_TYPE_TLV_SIZE \ | |
333 | sizeof(struct mrvl_ie_auth_type) | |
334 | ||
335 | static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type) | |
336 | { | |
337 | struct mrvl_ie_auth_type *auth = (void *) tlv; | |
338 | ||
339 | /* | |
340 | * 1f 01 TLV_TYPE_AUTH_TYPE | |
341 | * 01 00 len | |
342 | * 01 auth type | |
343 | */ | |
344 | auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE); | |
345 | auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header)); | |
346 | auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type)); | |
347 | return sizeof(*auth); | |
348 | } | |
349 | ||
350 | ||
351 | /* | |
352 | * Add channel (phy ds) TLV | |
353 | */ | |
354 | #define LBS_MAX_CHANNEL_TLV_SIZE \ | |
355 | sizeof(struct mrvl_ie_header) | |
356 | ||
357 | static int lbs_add_channel_tlv(u8 *tlv, u8 channel) | |
358 | { | |
359 | struct mrvl_ie_ds_param_set *ds = (void *) tlv; | |
360 | ||
361 | /* | |
362 | * 03 00 TLV_TYPE_PHY_DS | |
363 | * 01 00 len | |
364 | * 06 channel | |
365 | */ | |
366 | ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS); | |
367 | ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header)); | |
368 | ds->channel = channel; | |
369 | return sizeof(*ds); | |
370 | } | |
371 | ||
372 | ||
373 | /* | |
374 | * Add (empty) CF param TLV of the form: | |
375 | */ | |
376 | #define LBS_MAX_CF_PARAM_TLV_SIZE \ | |
377 | sizeof(struct mrvl_ie_header) | |
378 | ||
379 | static int lbs_add_cf_param_tlv(u8 *tlv) | |
380 | { | |
381 | struct mrvl_ie_cf_param_set *cf = (void *)tlv; | |
382 | ||
383 | /* | |
384 | * 04 00 TLV_TYPE_CF | |
385 | * 06 00 len | |
386 | * 00 cfpcnt | |
387 | * 00 cfpperiod | |
388 | * 00 00 cfpmaxduration | |
389 | * 00 00 cfpdurationremaining | |
390 | */ | |
391 | cf->header.type = cpu_to_le16(TLV_TYPE_CF); | |
392 | cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header)); | |
393 | return sizeof(*cf); | |
394 | } | |
395 | ||
396 | /* | |
397 | * Add WPA TLV | |
398 | */ | |
399 | #define LBS_MAX_WPA_TLV_SIZE \ | |
400 | (sizeof(struct mrvl_ie_header) \ | |
401 | + 128 /* TODO: I guessed the size */) | |
402 | ||
403 | static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len) | |
404 | { | |
405 | size_t tlv_len; | |
406 | ||
407 | /* | |
408 | * We need just convert an IE to an TLV. IEs use u8 for the header, | |
409 | * u8 type | |
410 | * u8 len | |
411 | * u8[] data | |
412 | * but TLVs use __le16 instead: | |
413 | * __le16 type | |
414 | * __le16 len | |
415 | * u8[] data | |
416 | */ | |
417 | *tlv++ = *ie++; | |
418 | *tlv++ = 0; | |
419 | tlv_len = *tlv++ = *ie++; | |
420 | *tlv++ = 0; | |
421 | while (tlv_len--) | |
422 | *tlv++ = *ie++; | |
423 | /* the TLV is two bytes larger than the IE */ | |
424 | return ie_len + 2; | |
425 | } | |
426 | ||
427 | /*************************************************************************** | |
428 | * Set Channel | |
429 | */ | |
430 | ||
ff9fc791 | 431 | static int lbs_cfg_set_channel(struct wiphy *wiphy, |
f444de05 | 432 | struct net_device *netdev, |
e86dc1ca | 433 | struct ieee80211_channel *channel, |
ff9fc791 HS |
434 | enum nl80211_channel_type channel_type) |
435 | { | |
436 | struct lbs_private *priv = wiphy_priv(wiphy); | |
e86dc1ca KD |
437 | int ret = -ENOTSUPP; |
438 | ||
439 | lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d", | |
440 | channel->center_freq, channel_type); | |
441 | ||
442 | if (channel_type != NL80211_CHAN_NO_HT) | |
443 | goto out; | |
444 | ||
445 | ret = lbs_set_channel(priv, channel->hw_value); | |
446 | ||
447 | out: | |
448 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
449 | return ret; | |
450 | } | |
451 | ||
452 | ||
453 | ||
454 | /*************************************************************************** | |
455 | * Scanning | |
456 | */ | |
457 | ||
458 | /* | |
459 | * When scanning, the firmware doesn't send a nul packet with the power-safe | |
460 | * bit to the AP. So we cannot stay away from our current channel too long, | |
461 | * otherwise we loose data. So take a "nap" while scanning every other | |
462 | * while. | |
463 | */ | |
464 | #define LBS_SCAN_BEFORE_NAP 4 | |
465 | ||
466 | ||
467 | /* | |
468 | * When the firmware reports back a scan-result, it gives us an "u8 rssi", | |
469 | * which isn't really an RSSI, as it becomes larger when moving away from | |
470 | * the AP. Anyway, we need to convert that into mBm. | |
471 | */ | |
472 | #define LBS_SCAN_RSSI_TO_MBM(rssi) \ | |
473 | ((-(int)rssi + 3)*100) | |
474 | ||
475 | static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy, | |
476 | struct cmd_header *resp) | |
477 | { | |
478 | struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp; | |
479 | int bsssize; | |
480 | const u8 *pos; | |
481 | u16 nr_sets; | |
482 | const u8 *tsfdesc; | |
483 | int tsfsize; | |
484 | int i; | |
485 | int ret = -EILSEQ; | |
486 | ||
487 | lbs_deb_enter(LBS_DEB_CFG80211); | |
488 | ||
489 | bsssize = get_unaligned_le16(&scanresp->bssdescriptsize); | |
aebb628f DW |
490 | nr_sets = le16_to_cpu(scanresp->nr_sets); |
491 | ||
492 | lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n", | |
493 | nr_sets, bsssize, le16_to_cpu(resp->size)); | |
494 | ||
495 | if (nr_sets == 0) { | |
496 | ret = 0; | |
497 | goto done; | |
498 | } | |
e86dc1ca KD |
499 | |
500 | /* | |
501 | * The general layout of the scan response is described in chapter | |
502 | * 5.7.1. Basically we have a common part, then any number of BSS | |
503 | * descriptor sections. Finally we have section with the same number | |
504 | * of TSFs. | |
505 | * | |
506 | * cmd_ds_802_11_scan_rsp | |
507 | * cmd_header | |
508 | * pos_size | |
509 | * nr_sets | |
510 | * bssdesc 1 | |
511 | * bssid | |
512 | * rssi | |
513 | * timestamp | |
514 | * intvl | |
515 | * capa | |
516 | * IEs | |
517 | * bssdesc 2 | |
518 | * bssdesc n | |
519 | * MrvlIEtypes_TsfFimestamp_t | |
520 | * TSF for BSS 1 | |
521 | * TSF for BSS 2 | |
522 | * TSF for BSS n | |
523 | */ | |
524 | ||
525 | pos = scanresp->bssdesc_and_tlvbuffer; | |
526 | ||
4083858c DW |
527 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_RSP", scanresp->bssdesc_and_tlvbuffer, |
528 | scanresp->bssdescriptsize); | |
529 | ||
e86dc1ca KD |
530 | tsfdesc = pos + bsssize; |
531 | tsfsize = 4 + 8 * scanresp->nr_sets; | |
4083858c | 532 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TSF", (u8 *) tsfdesc, tsfsize); |
e86dc1ca KD |
533 | |
534 | /* Validity check: we expect a Marvell-Local TLV */ | |
535 | i = get_unaligned_le16(tsfdesc); | |
536 | tsfdesc += 2; | |
4083858c DW |
537 | if (i != TLV_TYPE_TSFTIMESTAMP) { |
538 | lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i); | |
e86dc1ca | 539 | goto done; |
4083858c DW |
540 | } |
541 | ||
e86dc1ca KD |
542 | /* Validity check: the TLV holds TSF values with 8 bytes each, so |
543 | * the size in the TLV must match the nr_sets value */ | |
544 | i = get_unaligned_le16(tsfdesc); | |
545 | tsfdesc += 2; | |
4083858c DW |
546 | if (i / 8 != scanresp->nr_sets) { |
547 | lbs_deb_scan("scan response: invalid number of TSF timestamp " | |
548 | "sets (expected %d got %d)\n", scanresp->nr_sets, | |
549 | i / 8); | |
e86dc1ca | 550 | goto done; |
4083858c | 551 | } |
e86dc1ca KD |
552 | |
553 | for (i = 0; i < scanresp->nr_sets; i++) { | |
554 | const u8 *bssid; | |
555 | const u8 *ie; | |
556 | int left; | |
557 | int ielen; | |
558 | int rssi; | |
559 | u16 intvl; | |
560 | u16 capa; | |
561 | int chan_no = -1; | |
562 | const u8 *ssid = NULL; | |
563 | u8 ssid_len = 0; | |
564 | DECLARE_SSID_BUF(ssid_buf); | |
565 | ||
566 | int len = get_unaligned_le16(pos); | |
567 | pos += 2; | |
568 | ||
569 | /* BSSID */ | |
570 | bssid = pos; | |
571 | pos += ETH_ALEN; | |
572 | /* RSSI */ | |
573 | rssi = *pos++; | |
574 | /* Packet time stamp */ | |
575 | pos += 8; | |
576 | /* Beacon interval */ | |
577 | intvl = get_unaligned_le16(pos); | |
578 | pos += 2; | |
579 | /* Capabilities */ | |
580 | capa = get_unaligned_le16(pos); | |
581 | pos += 2; | |
582 | ||
583 | /* To find out the channel, we must parse the IEs */ | |
584 | ie = pos; | |
585 | /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon | |
586 | interval, capabilities */ | |
587 | ielen = left = len - (6 + 1 + 8 + 2 + 2); | |
588 | while (left >= 2) { | |
589 | u8 id, elen; | |
590 | id = *pos++; | |
591 | elen = *pos++; | |
592 | left -= 2; | |
4083858c DW |
593 | if (elen > left || elen == 0) { |
594 | lbs_deb_scan("scan response: invalid IE fmt\n"); | |
e86dc1ca | 595 | goto done; |
4083858c DW |
596 | } |
597 | ||
e86dc1ca KD |
598 | if (id == WLAN_EID_DS_PARAMS) |
599 | chan_no = *pos; | |
600 | if (id == WLAN_EID_SSID) { | |
601 | ssid = pos; | |
602 | ssid_len = elen; | |
603 | } | |
604 | left -= elen; | |
605 | pos += elen; | |
606 | } | |
607 | ||
608 | /* No channel, no luck */ | |
609 | if (chan_no != -1) { | |
610 | struct wiphy *wiphy = priv->wdev->wiphy; | |
611 | int freq = ieee80211_channel_to_frequency(chan_no); | |
612 | struct ieee80211_channel *channel = | |
613 | ieee80211_get_channel(wiphy, freq); | |
614 | ||
615 | lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, " | |
616 | "%d dBm\n", | |
617 | bssid, capa, chan_no, | |
618 | print_ssid(ssid_buf, ssid, ssid_len), | |
619 | LBS_SCAN_RSSI_TO_MBM(rssi)/100); | |
620 | ||
621 | if (channel || | |
622 | !(channel->flags & IEEE80211_CHAN_DISABLED)) | |
623 | cfg80211_inform_bss(wiphy, channel, | |
624 | bssid, le64_to_cpu(*(__le64 *)tsfdesc), | |
625 | capa, intvl, ie, ielen, | |
626 | LBS_SCAN_RSSI_TO_MBM(rssi), | |
627 | GFP_KERNEL); | |
4083858c DW |
628 | } else |
629 | lbs_deb_scan("scan response: missing BSS channel IE\n"); | |
630 | ||
e86dc1ca KD |
631 | tsfdesc += 8; |
632 | } | |
633 | ret = 0; | |
634 | ||
635 | done: | |
636 | lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret); | |
637 | return ret; | |
638 | } | |
639 | ||
640 | ||
641 | /* | |
642 | * Our scan command contains a TLV, consting of a SSID TLV, a channel list | |
643 | * TLV and a rates TLV. Determine the maximum size of them: | |
644 | */ | |
645 | #define LBS_SCAN_MAX_CMD_SIZE \ | |
646 | (sizeof(struct cmd_ds_802_11_scan) \ | |
647 | + LBS_MAX_SSID_TLV_SIZE \ | |
648 | + LBS_MAX_CHANNEL_LIST_TLV_SIZE \ | |
649 | + LBS_MAX_RATES_TLV_SIZE) | |
650 | ||
651 | /* | |
652 | * Assumes priv->scan_req is initialized and valid | |
653 | * Assumes priv->scan_channel is initialized | |
654 | */ | |
655 | static void lbs_scan_worker(struct work_struct *work) | |
656 | { | |
657 | struct lbs_private *priv = | |
658 | container_of(work, struct lbs_private, scan_work.work); | |
659 | struct cmd_ds_802_11_scan *scan_cmd; | |
660 | u8 *tlv; /* pointer into our current, growing TLV storage area */ | |
661 | int last_channel; | |
662 | int running, carrier; | |
663 | ||
664 | lbs_deb_enter(LBS_DEB_SCAN); | |
665 | ||
666 | scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL); | |
667 | if (scan_cmd == NULL) | |
668 | goto out_no_scan_cmd; | |
669 | ||
670 | /* prepare fixed part of scan command */ | |
671 | scan_cmd->bsstype = CMD_BSS_TYPE_ANY; | |
672 | ||
673 | /* stop network while we're away from our main channel */ | |
674 | running = !netif_queue_stopped(priv->dev); | |
675 | carrier = netif_carrier_ok(priv->dev); | |
676 | if (running) | |
677 | netif_stop_queue(priv->dev); | |
678 | if (carrier) | |
679 | netif_carrier_off(priv->dev); | |
680 | ||
681 | /* prepare fixed part of scan command */ | |
682 | tlv = scan_cmd->tlvbuffer; | |
683 | ||
684 | /* add SSID TLV */ | |
685 | if (priv->scan_req->n_ssids) | |
686 | tlv += lbs_add_ssid_tlv(tlv, | |
687 | priv->scan_req->ssids[0].ssid, | |
688 | priv->scan_req->ssids[0].ssid_len); | |
689 | ||
690 | /* add channel TLVs */ | |
691 | last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP; | |
692 | if (last_channel > priv->scan_req->n_channels) | |
693 | last_channel = priv->scan_req->n_channels; | |
694 | tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel, | |
695 | priv->scan_req->n_ssids); | |
696 | ||
697 | /* add rates TLV */ | |
698 | tlv += lbs_add_supported_rates_tlv(tlv); | |
699 | ||
700 | if (priv->scan_channel < priv->scan_req->n_channels) { | |
701 | cancel_delayed_work(&priv->scan_work); | |
702 | queue_delayed_work(priv->work_thread, &priv->scan_work, | |
703 | msecs_to_jiffies(300)); | |
704 | } | |
705 | ||
706 | /* This is the final data we are about to send */ | |
707 | scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd); | |
708 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd, | |
709 | sizeof(*scan_cmd)); | |
710 | lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer, | |
711 | tlv - scan_cmd->tlvbuffer); | |
712 | ||
713 | __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr, | |
714 | le16_to_cpu(scan_cmd->hdr.size), | |
715 | lbs_ret_scan, 0); | |
716 | ||
717 | if (priv->scan_channel >= priv->scan_req->n_channels) { | |
718 | /* Mark scan done */ | |
cc026819 DW |
719 | if (priv->internal_scan) |
720 | kfree(priv->scan_req); | |
721 | else | |
722 | cfg80211_scan_done(priv->scan_req, false); | |
723 | ||
e86dc1ca | 724 | priv->scan_req = NULL; |
cc026819 | 725 | priv->last_scan = jiffies; |
e86dc1ca KD |
726 | } |
727 | ||
728 | /* Restart network */ | |
729 | if (carrier) | |
730 | netif_carrier_on(priv->dev); | |
731 | if (running && !priv->tx_pending_len) | |
732 | netif_wake_queue(priv->dev); | |
733 | ||
734 | kfree(scan_cmd); | |
735 | ||
cc026819 DW |
736 | /* Wake up anything waiting on scan completion */ |
737 | if (priv->scan_req == NULL) { | |
738 | lbs_deb_scan("scan: waking up waiters\n"); | |
739 | wake_up_all(&priv->scan_q); | |
740 | } | |
741 | ||
e86dc1ca KD |
742 | out_no_scan_cmd: |
743 | lbs_deb_leave(LBS_DEB_SCAN); | |
744 | } | |
745 | ||
cc026819 DW |
746 | static void _internal_start_scan(struct lbs_private *priv, bool internal, |
747 | struct cfg80211_scan_request *request) | |
748 | { | |
749 | lbs_deb_enter(LBS_DEB_CFG80211); | |
750 | ||
751 | lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n", | |
752 | request->n_ssids, request->n_channels, request->ie_len); | |
753 | ||
754 | priv->scan_channel = 0; | |
755 | queue_delayed_work(priv->work_thread, &priv->scan_work, | |
756 | msecs_to_jiffies(50)); | |
757 | ||
758 | priv->scan_req = request; | |
759 | priv->internal_scan = internal; | |
760 | ||
761 | lbs_deb_leave(LBS_DEB_CFG80211); | |
762 | } | |
e86dc1ca KD |
763 | |
764 | static int lbs_cfg_scan(struct wiphy *wiphy, | |
765 | struct net_device *dev, | |
766 | struct cfg80211_scan_request *request) | |
767 | { | |
768 | struct lbs_private *priv = wiphy_priv(wiphy); | |
769 | int ret = 0; | |
770 | ||
771 | lbs_deb_enter(LBS_DEB_CFG80211); | |
772 | ||
773 | if (priv->scan_req || delayed_work_pending(&priv->scan_work)) { | |
774 | /* old scan request not yet processed */ | |
775 | ret = -EAGAIN; | |
776 | goto out; | |
777 | } | |
778 | ||
cc026819 | 779 | _internal_start_scan(priv, false, request); |
e86dc1ca KD |
780 | |
781 | if (priv->surpriseremoved) | |
782 | ret = -EIO; | |
783 | ||
e86dc1ca KD |
784 | out: |
785 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
786 | return ret; | |
787 | } | |
788 | ||
789 | ||
790 | ||
791 | ||
792 | /*************************************************************************** | |
793 | * Events | |
794 | */ | |
795 | ||
796 | void lbs_send_disconnect_notification(struct lbs_private *priv) | |
797 | { | |
798 | lbs_deb_enter(LBS_DEB_CFG80211); | |
799 | ||
800 | cfg80211_disconnected(priv->dev, | |
801 | 0, | |
802 | NULL, 0, | |
803 | GFP_KERNEL); | |
804 | ||
805 | lbs_deb_leave(LBS_DEB_CFG80211); | |
806 | } | |
807 | ||
808 | void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event) | |
809 | { | |
810 | lbs_deb_enter(LBS_DEB_CFG80211); | |
811 | ||
812 | cfg80211_michael_mic_failure(priv->dev, | |
813 | priv->assoc_bss, | |
814 | event == MACREG_INT_CODE_MIC_ERR_MULTICAST ? | |
815 | NL80211_KEYTYPE_GROUP : | |
816 | NL80211_KEYTYPE_PAIRWISE, | |
817 | -1, | |
818 | NULL, | |
819 | GFP_KERNEL); | |
820 | ||
821 | lbs_deb_leave(LBS_DEB_CFG80211); | |
822 | } | |
823 | ||
824 | ||
825 | ||
826 | ||
827 | /*************************************************************************** | |
828 | * Connect/disconnect | |
829 | */ | |
830 | ||
831 | ||
832 | /* | |
833 | * This removes all WEP keys | |
834 | */ | |
835 | static int lbs_remove_wep_keys(struct lbs_private *priv) | |
836 | { | |
837 | struct cmd_ds_802_11_set_wep cmd; | |
838 | int ret; | |
839 | ||
840 | lbs_deb_enter(LBS_DEB_CFG80211); | |
841 | ||
842 | memset(&cmd, 0, sizeof(cmd)); | |
843 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
844 | cmd.keyindex = cpu_to_le16(priv->wep_tx_key); | |
845 | cmd.action = cpu_to_le16(CMD_ACT_REMOVE); | |
846 | ||
847 | ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd); | |
848 | ||
849 | lbs_deb_leave(LBS_DEB_CFG80211); | |
850 | return ret; | |
851 | } | |
852 | ||
853 | /* | |
854 | * Set WEP keys | |
855 | */ | |
856 | static int lbs_set_wep_keys(struct lbs_private *priv) | |
857 | { | |
858 | struct cmd_ds_802_11_set_wep cmd; | |
859 | int i; | |
860 | int ret; | |
861 | ||
862 | lbs_deb_enter(LBS_DEB_CFG80211); | |
863 | ||
864 | /* | |
865 | * command 13 00 | |
866 | * size 50 00 | |
867 | * sequence xx xx | |
868 | * result 00 00 | |
869 | * action 02 00 ACT_ADD | |
870 | * transmit key 00 00 | |
871 | * type for key 1 01 WEP40 | |
872 | * type for key 2 00 | |
873 | * type for key 3 00 | |
874 | * type for key 4 00 | |
875 | * key 1 39 39 39 39 39 00 00 00 | |
876 | * 00 00 00 00 00 00 00 00 | |
877 | * key 2 00 00 00 00 00 00 00 00 | |
878 | * 00 00 00 00 00 00 00 00 | |
879 | * key 3 00 00 00 00 00 00 00 00 | |
880 | * 00 00 00 00 00 00 00 00 | |
881 | * key 4 00 00 00 00 00 00 00 00 | |
882 | */ | |
883 | if (priv->wep_key_len[0] || priv->wep_key_len[1] || | |
884 | priv->wep_key_len[2] || priv->wep_key_len[3]) { | |
885 | /* Only set wep keys if we have at least one of them */ | |
886 | memset(&cmd, 0, sizeof(cmd)); | |
887 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
888 | cmd.keyindex = cpu_to_le16(priv->wep_tx_key); | |
889 | cmd.action = cpu_to_le16(CMD_ACT_ADD); | |
890 | ||
891 | for (i = 0; i < 4; i++) { | |
892 | switch (priv->wep_key_len[i]) { | |
893 | case WLAN_KEY_LEN_WEP40: | |
894 | cmd.keytype[i] = CMD_TYPE_WEP_40_BIT; | |
895 | break; | |
896 | case WLAN_KEY_LEN_WEP104: | |
897 | cmd.keytype[i] = CMD_TYPE_WEP_104_BIT; | |
898 | break; | |
899 | default: | |
900 | cmd.keytype[i] = 0; | |
901 | break; | |
902 | } | |
903 | memcpy(cmd.keymaterial[i], priv->wep_key[i], | |
904 | priv->wep_key_len[i]); | |
905 | } | |
906 | ||
907 | ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd); | |
908 | } else { | |
909 | /* Otherwise remove all wep keys */ | |
910 | ret = lbs_remove_wep_keys(priv); | |
911 | } | |
912 | ||
913 | lbs_deb_leave(LBS_DEB_CFG80211); | |
914 | return ret; | |
915 | } | |
916 | ||
917 | ||
918 | /* | |
919 | * Enable/Disable RSN status | |
920 | */ | |
921 | static int lbs_enable_rsn(struct lbs_private *priv, int enable) | |
922 | { | |
923 | struct cmd_ds_802_11_enable_rsn cmd; | |
924 | int ret; | |
925 | ||
926 | lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable); | |
927 | ||
928 | /* | |
929 | * cmd 2f 00 | |
930 | * size 0c 00 | |
931 | * sequence xx xx | |
932 | * result 00 00 | |
933 | * action 01 00 ACT_SET | |
934 | * enable 01 00 | |
935 | */ | |
936 | memset(&cmd, 0, sizeof(cmd)); | |
937 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
938 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
939 | cmd.enable = cpu_to_le16(enable); | |
940 | ||
941 | ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd); | |
942 | ||
943 | lbs_deb_leave(LBS_DEB_CFG80211); | |
944 | return ret; | |
945 | } | |
946 | ||
947 | ||
948 | /* | |
949 | * Set WPA/WPA key material | |
950 | */ | |
951 | ||
952 | /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we | |
953 | * get rid of WEXT, this should go into host.h */ | |
954 | ||
955 | struct cmd_key_material { | |
956 | struct cmd_header hdr; | |
957 | ||
958 | __le16 action; | |
959 | struct MrvlIEtype_keyParamSet param; | |
beabe914 | 960 | } __packed; |
e86dc1ca KD |
961 | |
962 | static int lbs_set_key_material(struct lbs_private *priv, | |
963 | int key_type, | |
964 | int key_info, | |
965 | u8 *key, u16 key_len) | |
966 | { | |
967 | struct cmd_key_material cmd; | |
968 | int ret; | |
969 | ||
970 | lbs_deb_enter(LBS_DEB_CFG80211); | |
971 | ||
972 | /* | |
973 | * Example for WPA (TKIP): | |
974 | * | |
975 | * cmd 5e 00 | |
976 | * size 34 00 | |
977 | * sequence xx xx | |
978 | * result 00 00 | |
979 | * action 01 00 | |
980 | * TLV type 00 01 key param | |
981 | * length 00 26 | |
982 | * key type 01 00 TKIP | |
983 | * key info 06 00 UNICAST | ENABLED | |
984 | * key len 20 00 | |
985 | * key 32 bytes | |
986 | */ | |
987 | memset(&cmd, 0, sizeof(cmd)); | |
988 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
989 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
990 | cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL); | |
991 | cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4); | |
992 | cmd.param.keytypeid = cpu_to_le16(key_type); | |
993 | cmd.param.keyinfo = cpu_to_le16(key_info); | |
994 | cmd.param.keylen = cpu_to_le16(key_len); | |
995 | if (key && key_len) | |
996 | memcpy(cmd.param.key, key, key_len); | |
997 | ||
998 | ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd); | |
999 | ||
1000 | lbs_deb_leave(LBS_DEB_CFG80211); | |
1001 | return ret; | |
1002 | } | |
1003 | ||
1004 | ||
1005 | /* | |
1006 | * Sets the auth type (open, shared, etc) in the firmware. That | |
1007 | * we use CMD_802_11_AUTHENTICATE is misleading, this firmware | |
1008 | * command doesn't send an authentication frame at all, it just | |
1009 | * stores the auth_type. | |
1010 | */ | |
1011 | static int lbs_set_authtype(struct lbs_private *priv, | |
1012 | struct cfg80211_connect_params *sme) | |
1013 | { | |
1014 | struct cmd_ds_802_11_authenticate cmd; | |
1015 | int ret; | |
1016 | ||
1017 | lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type); | |
1018 | ||
1019 | /* | |
1020 | * cmd 11 00 | |
1021 | * size 19 00 | |
1022 | * sequence xx xx | |
1023 | * result 00 00 | |
1024 | * BSS id 00 13 19 80 da 30 | |
1025 | * auth type 00 | |
1026 | * reserved 00 00 00 00 00 00 00 00 00 00 | |
1027 | */ | |
1028 | memset(&cmd, 0, sizeof(cmd)); | |
1029 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1030 | if (sme->bssid) | |
1031 | memcpy(cmd.bssid, sme->bssid, ETH_ALEN); | |
1032 | /* convert auth_type */ | |
1033 | ret = lbs_auth_to_authtype(sme->auth_type); | |
1034 | if (ret < 0) | |
1035 | goto done; | |
1036 | ||
1037 | cmd.authtype = ret; | |
1038 | ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd); | |
1039 | ||
1040 | done: | |
1041 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1042 | return ret; | |
1043 | } | |
1044 | ||
1045 | ||
1046 | /* | |
1047 | * Create association request | |
1048 | */ | |
1049 | #define LBS_ASSOC_MAX_CMD_SIZE \ | |
1050 | (sizeof(struct cmd_ds_802_11_associate) \ | |
1051 | - 512 /* cmd_ds_802_11_associate.iebuf */ \ | |
1052 | + LBS_MAX_SSID_TLV_SIZE \ | |
1053 | + LBS_MAX_CHANNEL_TLV_SIZE \ | |
1054 | + LBS_MAX_CF_PARAM_TLV_SIZE \ | |
1055 | + LBS_MAX_AUTH_TYPE_TLV_SIZE \ | |
1056 | + LBS_MAX_WPA_TLV_SIZE) | |
1057 | ||
1058 | static int lbs_associate(struct lbs_private *priv, | |
1059 | struct cfg80211_bss *bss, | |
1060 | struct cfg80211_connect_params *sme) | |
1061 | { | |
1062 | struct cmd_ds_802_11_associate_response *resp; | |
1063 | struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE, | |
1064 | GFP_KERNEL); | |
1065 | const u8 *ssid_eid; | |
1066 | size_t len, resp_ie_len; | |
1067 | int status; | |
1068 | int ret; | |
1069 | u8 *pos = &(cmd->iebuf[0]); | |
19757539 | 1070 | u8 *tmp; |
e86dc1ca KD |
1071 | |
1072 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1073 | ||
1074 | if (!cmd) { | |
1075 | ret = -ENOMEM; | |
1076 | goto done; | |
1077 | } | |
1078 | ||
1079 | /* | |
1080 | * cmd 50 00 | |
1081 | * length 34 00 | |
1082 | * sequence xx xx | |
1083 | * result 00 00 | |
1084 | * BSS id 00 13 19 80 da 30 | |
1085 | * capabilities 11 00 | |
1086 | * listen interval 0a 00 | |
1087 | * beacon interval 00 00 | |
1088 | * DTIM period 00 | |
1089 | * TLVs xx (up to 512 bytes) | |
1090 | */ | |
1091 | cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE); | |
1092 | ||
1093 | /* Fill in static fields */ | |
1094 | memcpy(cmd->bssid, bss->bssid, ETH_ALEN); | |
1095 | cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL); | |
1096 | cmd->capability = cpu_to_le16(bss->capability); | |
1097 | ||
1098 | /* add SSID TLV */ | |
1099 | ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID); | |
1100 | if (ssid_eid) | |
1101 | pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]); | |
1102 | else | |
1103 | lbs_deb_assoc("no SSID\n"); | |
1104 | ||
1105 | /* add DS param TLV */ | |
1106 | if (bss->channel) | |
1107 | pos += lbs_add_channel_tlv(pos, bss->channel->hw_value); | |
1108 | else | |
1109 | lbs_deb_assoc("no channel\n"); | |
1110 | ||
1111 | /* add (empty) CF param TLV */ | |
1112 | pos += lbs_add_cf_param_tlv(pos); | |
1113 | ||
1114 | /* add rates TLV */ | |
19757539 | 1115 | tmp = pos + 4; /* skip Marvell IE header */ |
e86dc1ca | 1116 | pos += lbs_add_common_rates_tlv(pos, bss); |
19757539 | 1117 | lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp); |
e86dc1ca KD |
1118 | |
1119 | /* add auth type TLV */ | |
1120 | if (priv->fwrelease >= 0x09000000) | |
1121 | pos += lbs_add_auth_type_tlv(pos, sme->auth_type); | |
1122 | ||
1123 | /* add WPA/WPA2 TLV */ | |
1124 | if (sme->ie && sme->ie_len) | |
1125 | pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len); | |
1126 | ||
1127 | len = (sizeof(*cmd) - sizeof(cmd->iebuf)) + | |
1128 | (u16)(pos - (u8 *) &cmd->iebuf); | |
1129 | cmd->hdr.size = cpu_to_le16(len); | |
1130 | ||
1131 | /* store for later use */ | |
1132 | memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN); | |
1133 | ||
1134 | ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd); | |
1135 | if (ret) | |
1136 | goto done; | |
1137 | ||
1138 | ||
1139 | /* generate connect message to cfg80211 */ | |
1140 | ||
1141 | resp = (void *) cmd; /* recast for easier field access */ | |
1142 | status = le16_to_cpu(resp->statuscode); | |
1143 | ||
1144 | /* Convert statis code of old firmware */ | |
1145 | if (priv->fwrelease < 0x09000000) | |
1146 | switch (status) { | |
1147 | case 0: | |
1148 | break; | |
1149 | case 1: | |
1150 | lbs_deb_assoc("invalid association parameters\n"); | |
1151 | status = WLAN_STATUS_CAPS_UNSUPPORTED; | |
1152 | break; | |
1153 | case 2: | |
1154 | lbs_deb_assoc("timer expired while waiting for AP\n"); | |
1155 | status = WLAN_STATUS_AUTH_TIMEOUT; | |
1156 | break; | |
1157 | case 3: | |
1158 | lbs_deb_assoc("association refused by AP\n"); | |
1159 | status = WLAN_STATUS_ASSOC_DENIED_UNSPEC; | |
1160 | break; | |
1161 | case 4: | |
1162 | lbs_deb_assoc("authentication refused by AP\n"); | |
1163 | status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; | |
1164 | break; | |
1165 | default: | |
1166 | lbs_deb_assoc("association failure %d\n", status); | |
1167 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; | |
1168 | } | |
1169 | ||
1170 | lbs_deb_assoc("status %d, capability 0x%04x\n", status, | |
1171 | le16_to_cpu(resp->capability)); | |
1172 | ||
1173 | resp_ie_len = le16_to_cpu(resp->hdr.size) | |
1174 | - sizeof(resp->hdr) | |
1175 | - 6; | |
1176 | cfg80211_connect_result(priv->dev, | |
1177 | priv->assoc_bss, | |
1178 | sme->ie, sme->ie_len, | |
1179 | resp->iebuf, resp_ie_len, | |
1180 | status, | |
1181 | GFP_KERNEL); | |
1182 | ||
1183 | if (status == 0) { | |
1184 | /* TODO: get rid of priv->connect_status */ | |
1185 | priv->connect_status = LBS_CONNECTED; | |
1186 | netif_carrier_on(priv->dev); | |
1187 | if (!priv->tx_pending_len) | |
1188 | netif_tx_wake_all_queues(priv->dev); | |
1189 | } | |
1190 | ||
1191 | ||
1192 | done: | |
1193 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1194 | return ret; | |
1195 | } | |
1196 | ||
cc026819 DW |
1197 | static struct cfg80211_scan_request * |
1198 | _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme) | |
1199 | { | |
1200 | struct cfg80211_scan_request *creq = NULL; | |
1201 | int i, n_channels = 0; | |
1202 | enum ieee80211_band band; | |
1203 | ||
1204 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
1205 | if (wiphy->bands[band]) | |
1206 | n_channels += wiphy->bands[band]->n_channels; | |
1207 | } | |
1208 | ||
1209 | creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) + | |
1210 | n_channels * sizeof(void *), | |
1211 | GFP_ATOMIC); | |
1212 | if (!creq) | |
1213 | return NULL; | |
1214 | ||
1215 | /* SSIDs come after channels */ | |
1216 | creq->ssids = (void *)&creq->channels[n_channels]; | |
1217 | creq->n_channels = n_channels; | |
1218 | creq->n_ssids = 1; | |
1219 | ||
1220 | /* Scan all available channels */ | |
1221 | i = 0; | |
1222 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
1223 | int j; | |
1224 | ||
1225 | if (!wiphy->bands[band]) | |
1226 | continue; | |
1227 | ||
1228 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
1229 | /* ignore disabled channels */ | |
1230 | if (wiphy->bands[band]->channels[j].flags & | |
1231 | IEEE80211_CHAN_DISABLED) | |
1232 | continue; | |
1233 | ||
1234 | creq->channels[i] = &wiphy->bands[band]->channels[j]; | |
1235 | i++; | |
1236 | } | |
1237 | } | |
1238 | if (i) { | |
1239 | /* Set real number of channels specified in creq->channels[] */ | |
1240 | creq->n_channels = i; | |
1241 | ||
1242 | /* Scan for the SSID we're going to connect to */ | |
1243 | memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len); | |
1244 | creq->ssids[0].ssid_len = sme->ssid_len; | |
1245 | } else { | |
1246 | /* No channels found... */ | |
1247 | kfree(creq); | |
1248 | creq = NULL; | |
1249 | } | |
e86dc1ca | 1250 | |
cc026819 DW |
1251 | return creq; |
1252 | } | |
e86dc1ca KD |
1253 | |
1254 | static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev, | |
1255 | struct cfg80211_connect_params *sme) | |
1256 | { | |
1257 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1258 | struct cfg80211_bss *bss = NULL; | |
1259 | int ret = 0; | |
1260 | u8 preamble = RADIO_PREAMBLE_SHORT; | |
1261 | ||
1262 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1263 | ||
cc026819 DW |
1264 | if (!sme->bssid) { |
1265 | /* Run a scan if one isn't in-progress already and if the last | |
1266 | * scan was done more than 2 seconds ago. | |
e86dc1ca | 1267 | */ |
cc026819 DW |
1268 | if (priv->scan_req == NULL && |
1269 | time_after(jiffies, priv->last_scan + (2 * HZ))) { | |
1270 | struct cfg80211_scan_request *creq; | |
e86dc1ca | 1271 | |
cc026819 DW |
1272 | creq = _new_connect_scan_req(wiphy, sme); |
1273 | if (!creq) { | |
1274 | ret = -EINVAL; | |
1275 | goto done; | |
1276 | } | |
1277 | ||
1278 | lbs_deb_assoc("assoc: scanning for compatible AP\n"); | |
1279 | _internal_start_scan(priv, true, creq); | |
1280 | } | |
1281 | ||
1282 | /* Wait for any in-progress scan to complete */ | |
1283 | lbs_deb_assoc("assoc: waiting for scan to complete\n"); | |
1284 | wait_event_interruptible_timeout(priv->scan_q, | |
1285 | (priv->scan_req == NULL), | |
1286 | (15 * HZ)); | |
1287 | lbs_deb_assoc("assoc: scanning competed\n"); | |
1288 | } | |
e86dc1ca | 1289 | |
cc026819 DW |
1290 | /* Find the BSS we want using available scan results */ |
1291 | bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, | |
1292 | sme->ssid, sme->ssid_len, | |
1293 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); | |
e86dc1ca | 1294 | if (!bss) { |
cc026819 | 1295 | lbs_pr_err("assoc: bss %pM not in scan results\n", |
e86dc1ca KD |
1296 | sme->bssid); |
1297 | ret = -ENOENT; | |
1298 | goto done; | |
1299 | } | |
cc026819 | 1300 | lbs_deb_assoc("trying %pM\n", bss->bssid); |
e86dc1ca KD |
1301 | lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n", |
1302 | sme->crypto.cipher_group, | |
1303 | sme->key_idx, sme->key_len); | |
1304 | ||
1305 | /* As this is a new connection, clear locally stored WEP keys */ | |
1306 | priv->wep_tx_key = 0; | |
1307 | memset(priv->wep_key, 0, sizeof(priv->wep_key)); | |
1308 | memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len)); | |
1309 | ||
1310 | /* set/remove WEP keys */ | |
1311 | switch (sme->crypto.cipher_group) { | |
1312 | case WLAN_CIPHER_SUITE_WEP40: | |
1313 | case WLAN_CIPHER_SUITE_WEP104: | |
1314 | /* Store provided WEP keys in priv-> */ | |
1315 | priv->wep_tx_key = sme->key_idx; | |
1316 | priv->wep_key_len[sme->key_idx] = sme->key_len; | |
1317 | memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len); | |
1318 | /* Set WEP keys and WEP mode */ | |
1319 | lbs_set_wep_keys(priv); | |
1320 | priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE; | |
1321 | lbs_set_mac_control(priv); | |
1322 | /* No RSN mode for WEP */ | |
1323 | lbs_enable_rsn(priv, 0); | |
1324 | break; | |
1325 | case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */ | |
1326 | /* | |
1327 | * If we don't have no WEP, no WPA and no WPA2, | |
1328 | * we remove all keys like in the WPA/WPA2 setup, | |
1329 | * we just don't set RSN. | |
1330 | * | |
1331 | * Therefore: fall-throught | |
1332 | */ | |
1333 | case WLAN_CIPHER_SUITE_TKIP: | |
1334 | case WLAN_CIPHER_SUITE_CCMP: | |
1335 | /* Remove WEP keys and WEP mode */ | |
1336 | lbs_remove_wep_keys(priv); | |
1337 | priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE; | |
1338 | lbs_set_mac_control(priv); | |
1339 | ||
1340 | /* clear the WPA/WPA2 keys */ | |
1341 | lbs_set_key_material(priv, | |
1342 | KEY_TYPE_ID_WEP, /* doesn't matter */ | |
1343 | KEY_INFO_WPA_UNICAST, | |
1344 | NULL, 0); | |
1345 | lbs_set_key_material(priv, | |
1346 | KEY_TYPE_ID_WEP, /* doesn't matter */ | |
1347 | KEY_INFO_WPA_MCAST, | |
1348 | NULL, 0); | |
1349 | /* RSN mode for WPA/WPA2 */ | |
1350 | lbs_enable_rsn(priv, sme->crypto.cipher_group != 0); | |
1351 | break; | |
1352 | default: | |
1353 | lbs_pr_err("unsupported cipher group 0x%x\n", | |
1354 | sme->crypto.cipher_group); | |
1355 | ret = -ENOTSUPP; | |
1356 | goto done; | |
1357 | } | |
1358 | ||
1359 | lbs_set_authtype(priv, sme); | |
1360 | lbs_set_radio(priv, preamble, 1); | |
1361 | ||
1362 | /* Do the actual association */ | |
cc026819 | 1363 | ret = lbs_associate(priv, bss, sme); |
e86dc1ca KD |
1364 | |
1365 | done: | |
1366 | if (bss) | |
1367 | cfg80211_put_bss(bss); | |
1368 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1369 | return ret; | |
1370 | } | |
1371 | ||
e86dc1ca KD |
1372 | static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev, |
1373 | u16 reason_code) | |
1374 | { | |
1375 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1376 | struct cmd_ds_802_11_deauthenticate cmd; | |
ff9fc791 | 1377 | |
e86dc1ca | 1378 | lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code); |
ff9fc791 | 1379 | |
e86dc1ca KD |
1380 | /* store for lbs_cfg_ret_disconnect() */ |
1381 | priv->disassoc_reason = reason_code; | |
1382 | ||
1383 | memset(&cmd, 0, sizeof(cmd)); | |
1384 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1385 | /* Mildly ugly to use a locally store my own BSSID ... */ | |
1386 | memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN); | |
1387 | cmd.reasoncode = cpu_to_le16(reason_code); | |
1388 | ||
e4fe4eaf KD |
1389 | if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd)) |
1390 | return -EFAULT; | |
1391 | ||
1392 | cfg80211_disconnected(priv->dev, | |
1393 | priv->disassoc_reason, | |
1394 | NULL, 0, | |
1395 | GFP_KERNEL); | |
1396 | priv->connect_status = LBS_DISCONNECTED; | |
e86dc1ca KD |
1397 | |
1398 | return 0; | |
1399 | } | |
1400 | ||
1401 | ||
1402 | static int lbs_cfg_set_default_key(struct wiphy *wiphy, | |
1403 | struct net_device *netdev, | |
1404 | u8 key_index) | |
1405 | { | |
1406 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1407 | ||
1408 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1409 | ||
1410 | if (key_index != priv->wep_tx_key) { | |
1411 | lbs_deb_assoc("set_default_key: to %d\n", key_index); | |
1412 | priv->wep_tx_key = key_index; | |
1413 | lbs_set_wep_keys(priv); | |
1414 | } | |
1415 | ||
1416 | return 0; | |
1417 | } | |
1418 | ||
1419 | ||
1420 | static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev, | |
1421 | u8 idx, const u8 *mac_addr, | |
1422 | struct key_params *params) | |
1423 | { | |
1424 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1425 | u16 key_info; | |
1426 | u16 key_type; | |
1427 | int ret = 0; | |
1428 | ||
1429 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1430 | ||
1431 | lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n", | |
1432 | params->cipher, mac_addr); | |
1433 | lbs_deb_assoc("add_key: key index %d, key len %d\n", | |
1434 | idx, params->key_len); | |
1435 | if (params->key_len) | |
1436 | lbs_deb_hex(LBS_DEB_CFG80211, "KEY", | |
1437 | params->key, params->key_len); | |
1438 | ||
1439 | lbs_deb_assoc("add_key: seq len %d\n", params->seq_len); | |
1440 | if (params->seq_len) | |
1441 | lbs_deb_hex(LBS_DEB_CFG80211, "SEQ", | |
1442 | params->seq, params->seq_len); | |
1443 | ||
1444 | switch (params->cipher) { | |
1445 | case WLAN_CIPHER_SUITE_WEP40: | |
1446 | case WLAN_CIPHER_SUITE_WEP104: | |
1447 | /* actually compare if something has changed ... */ | |
1448 | if ((priv->wep_key_len[idx] != params->key_len) || | |
1449 | memcmp(priv->wep_key[idx], | |
1450 | params->key, params->key_len) != 0) { | |
1451 | priv->wep_key_len[idx] = params->key_len; | |
1452 | memcpy(priv->wep_key[idx], | |
1453 | params->key, params->key_len); | |
1454 | lbs_set_wep_keys(priv); | |
1455 | } | |
1456 | break; | |
1457 | case WLAN_CIPHER_SUITE_TKIP: | |
1458 | case WLAN_CIPHER_SUITE_CCMP: | |
1459 | key_info = KEY_INFO_WPA_ENABLED | ((idx == 0) | |
1460 | ? KEY_INFO_WPA_UNICAST | |
1461 | : KEY_INFO_WPA_MCAST); | |
1462 | key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP) | |
1463 | ? KEY_TYPE_ID_TKIP | |
1464 | : KEY_TYPE_ID_AES; | |
1465 | lbs_set_key_material(priv, | |
1466 | key_type, | |
1467 | key_info, | |
1468 | params->key, params->key_len); | |
1469 | break; | |
1470 | default: | |
1471 | lbs_pr_err("unhandled cipher 0x%x\n", params->cipher); | |
1472 | ret = -ENOTSUPP; | |
1473 | break; | |
1474 | } | |
1475 | ||
1476 | return ret; | |
1477 | } | |
1478 | ||
1479 | ||
1480 | static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev, | |
1481 | u8 key_index, const u8 *mac_addr) | |
1482 | { | |
1483 | ||
1484 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1485 | ||
1486 | lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n", | |
1487 | key_index, mac_addr); | |
1488 | ||
1489 | #ifdef TODO | |
1490 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1491 | /* | |
1492 | * I think can keep this a NO-OP, because: | |
1493 | ||
1494 | * - we clear all keys whenever we do lbs_cfg_connect() anyway | |
1495 | * - neither "iw" nor "wpa_supplicant" won't call this during | |
1496 | * an ongoing connection | |
1497 | * - TODO: but I have to check if this is still true when | |
1498 | * I set the AP to periodic re-keying | |
1499 | * - we've not kzallec() something when we've added a key at | |
1500 | * lbs_cfg_connect() or lbs_cfg_add_key(). | |
1501 | * | |
1502 | * This causes lbs_cfg_del_key() only called at disconnect time, | |
1503 | * where we'd just waste time deleting a key that is not going | |
1504 | * to be used anyway. | |
1505 | */ | |
1506 | if (key_index < 3 && priv->wep_key_len[key_index]) { | |
1507 | priv->wep_key_len[key_index] = 0; | |
1508 | lbs_set_wep_keys(priv); | |
1509 | } | |
1510 | #endif | |
1511 | ||
1512 | return 0; | |
1513 | } | |
1514 | ||
1515 | ||
e86dc1ca KD |
1516 | /*************************************************************************** |
1517 | * Get station | |
1518 | */ | |
1519 | ||
e86dc1ca KD |
1520 | static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev, |
1521 | u8 *mac, struct station_info *sinfo) | |
1522 | { | |
1523 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1524 | s8 signal, noise; | |
1525 | int ret; | |
1526 | size_t i; | |
1527 | ||
1528 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1529 | ||
1530 | sinfo->filled |= STATION_INFO_TX_BYTES | | |
1531 | STATION_INFO_TX_PACKETS | | |
1532 | STATION_INFO_RX_BYTES | | |
1533 | STATION_INFO_RX_PACKETS; | |
1534 | sinfo->tx_bytes = priv->dev->stats.tx_bytes; | |
1535 | sinfo->tx_packets = priv->dev->stats.tx_packets; | |
1536 | sinfo->rx_bytes = priv->dev->stats.rx_bytes; | |
1537 | sinfo->rx_packets = priv->dev->stats.rx_packets; | |
1538 | ||
1539 | /* Get current RSSI */ | |
9fb7663d | 1540 | ret = lbs_get_rssi(priv, &signal, &noise); |
e86dc1ca KD |
1541 | if (ret == 0) { |
1542 | sinfo->signal = signal; | |
1543 | sinfo->filled |= STATION_INFO_SIGNAL; | |
1544 | } | |
1545 | ||
1546 | /* Convert priv->cur_rate from hw_value to NL80211 value */ | |
1547 | for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) { | |
1548 | if (priv->cur_rate == lbs_rates[i].hw_value) { | |
1549 | sinfo->txrate.legacy = lbs_rates[i].bitrate; | |
1550 | sinfo->filled |= STATION_INFO_TX_BITRATE; | |
1551 | break; | |
1552 | } | |
1553 | } | |
1554 | ||
1555 | return 0; | |
1556 | } | |
1557 | ||
1558 | ||
1559 | ||
1560 | ||
1561 | /*************************************************************************** | |
1562 | * "Site survey", here just current channel and noise level | |
1563 | */ | |
1564 | ||
1565 | static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev, | |
1566 | int idx, struct survey_info *survey) | |
1567 | { | |
1568 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1569 | s8 signal, noise; | |
1570 | int ret; | |
1571 | ||
1572 | if (idx != 0) | |
1573 | ret = -ENOENT; | |
1574 | ||
1575 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1576 | ||
1577 | survey->channel = ieee80211_get_channel(wiphy, | |
1578 | ieee80211_channel_to_frequency(priv->channel)); | |
1579 | ||
9fb7663d | 1580 | ret = lbs_get_rssi(priv, &signal, &noise); |
e86dc1ca KD |
1581 | if (ret == 0) { |
1582 | survey->filled = SURVEY_INFO_NOISE_DBM; | |
1583 | survey->noise = noise; | |
1584 | } | |
1585 | ||
1586 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1587 | return ret; | |
1588 | } | |
1589 | ||
1590 | ||
1591 | ||
1592 | ||
1593 | /*************************************************************************** | |
1594 | * Change interface | |
1595 | */ | |
1596 | ||
1597 | static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev, | |
1598 | enum nl80211_iftype type, u32 *flags, | |
1599 | struct vif_params *params) | |
1600 | { | |
1601 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1602 | int ret = 0; | |
1603 | ||
1604 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1605 | ||
1606 | switch (type) { | |
1607 | case NL80211_IFTYPE_MONITOR: | |
a45b6f4f | 1608 | ret = lbs_set_monitor_mode(priv, 1); |
e86dc1ca KD |
1609 | break; |
1610 | case NL80211_IFTYPE_STATION: | |
1611 | if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) | |
a45b6f4f | 1612 | ret = lbs_set_monitor_mode(priv, 0); |
e86dc1ca KD |
1613 | if (!ret) |
1614 | ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1); | |
1615 | break; | |
1616 | case NL80211_IFTYPE_ADHOC: | |
1617 | if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) | |
a45b6f4f | 1618 | ret = lbs_set_monitor_mode(priv, 0); |
e86dc1ca KD |
1619 | if (!ret) |
1620 | ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2); | |
1621 | break; | |
1622 | default: | |
1623 | ret = -ENOTSUPP; | |
1624 | } | |
1625 | ||
1626 | if (!ret) | |
1627 | priv->wdev->iftype = type; | |
1628 | ||
1629 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1630 | return ret; | |
1631 | } | |
1632 | ||
1633 | ||
1634 | ||
1635 | /*************************************************************************** | |
1636 | * IBSS (Ad-Hoc) | |
1637 | */ | |
1638 | ||
1639 | /* The firmware needs the following bits masked out of the beacon-derived | |
1640 | * capability field when associating/joining to a BSS: | |
1641 | * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused) | |
1642 | */ | |
1643 | #define CAPINFO_MASK (~(0xda00)) | |
1644 | ||
1645 | ||
1646 | static void lbs_join_post(struct lbs_private *priv, | |
1647 | struct cfg80211_ibss_params *params, | |
1648 | u8 *bssid, u16 capability) | |
1649 | { | |
1650 | u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */ | |
1651 | 2 + 4 + /* basic rates */ | |
1652 | 2 + 1 + /* DS parameter */ | |
1653 | 2 + 2 + /* atim */ | |
1654 | 2 + 8]; /* extended rates */ | |
1655 | u8 *fake = fake_ie; | |
1656 | ||
1657 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1658 | ||
1659 | /* | |
1660 | * For cfg80211_inform_bss, we'll need a fake IE, as we can't get | |
1661 | * the real IE from the firmware. So we fabricate a fake IE based on | |
1662 | * what the firmware actually sends (sniffed with wireshark). | |
1663 | */ | |
1664 | /* Fake SSID IE */ | |
1665 | *fake++ = WLAN_EID_SSID; | |
1666 | *fake++ = params->ssid_len; | |
1667 | memcpy(fake, params->ssid, params->ssid_len); | |
1668 | fake += params->ssid_len; | |
1669 | /* Fake supported basic rates IE */ | |
1670 | *fake++ = WLAN_EID_SUPP_RATES; | |
1671 | *fake++ = 4; | |
1672 | *fake++ = 0x82; | |
1673 | *fake++ = 0x84; | |
1674 | *fake++ = 0x8b; | |
1675 | *fake++ = 0x96; | |
1676 | /* Fake DS channel IE */ | |
1677 | *fake++ = WLAN_EID_DS_PARAMS; | |
1678 | *fake++ = 1; | |
1679 | *fake++ = params->channel->hw_value; | |
1680 | /* Fake IBSS params IE */ | |
1681 | *fake++ = WLAN_EID_IBSS_PARAMS; | |
1682 | *fake++ = 2; | |
1683 | *fake++ = 0; /* ATIM=0 */ | |
1684 | *fake++ = 0; | |
1685 | /* Fake extended rates IE, TODO: don't add this for 802.11b only, | |
1686 | * but I don't know how this could be checked */ | |
1687 | *fake++ = WLAN_EID_EXT_SUPP_RATES; | |
1688 | *fake++ = 8; | |
1689 | *fake++ = 0x0c; | |
1690 | *fake++ = 0x12; | |
1691 | *fake++ = 0x18; | |
1692 | *fake++ = 0x24; | |
1693 | *fake++ = 0x30; | |
1694 | *fake++ = 0x48; | |
1695 | *fake++ = 0x60; | |
1696 | *fake++ = 0x6c; | |
1697 | lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie); | |
1698 | ||
1699 | cfg80211_inform_bss(priv->wdev->wiphy, | |
1700 | params->channel, | |
1701 | bssid, | |
1702 | 0, | |
1703 | capability, | |
1704 | params->beacon_interval, | |
1705 | fake_ie, fake - fake_ie, | |
1706 | 0, GFP_KERNEL); | |
e4fe4eaf KD |
1707 | |
1708 | memcpy(priv->wdev->ssid, params->ssid, params->ssid_len); | |
1709 | priv->wdev->ssid_len = params->ssid_len; | |
1710 | ||
e86dc1ca KD |
1711 | cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL); |
1712 | ||
1713 | /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */ | |
1714 | priv->connect_status = LBS_CONNECTED; | |
1715 | netif_carrier_on(priv->dev); | |
1716 | if (!priv->tx_pending_len) | |
1717 | netif_wake_queue(priv->dev); | |
1718 | ||
1719 | lbs_deb_leave(LBS_DEB_CFG80211); | |
1720 | } | |
1721 | ||
1722 | static int lbs_ibss_join_existing(struct lbs_private *priv, | |
1723 | struct cfg80211_ibss_params *params, | |
1724 | struct cfg80211_bss *bss) | |
1725 | { | |
1726 | const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES); | |
1727 | struct cmd_ds_802_11_ad_hoc_join cmd; | |
1728 | u8 preamble = RADIO_PREAMBLE_SHORT; | |
1729 | int ret = 0; | |
1730 | ||
1731 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1732 | ||
1733 | /* TODO: set preamble based on scan result */ | |
1734 | ret = lbs_set_radio(priv, preamble, 1); | |
1735 | if (ret) | |
1736 | goto out; | |
1737 | ||
1738 | /* | |
1739 | * Example CMD_802_11_AD_HOC_JOIN command: | |
1740 | * | |
1741 | * command 2c 00 CMD_802_11_AD_HOC_JOIN | |
1742 | * size 65 00 | |
1743 | * sequence xx xx | |
1744 | * result 00 00 | |
1745 | * bssid 02 27 27 97 2f 96 | |
1746 | * ssid 49 42 53 53 00 00 00 00 | |
1747 | * 00 00 00 00 00 00 00 00 | |
1748 | * 00 00 00 00 00 00 00 00 | |
1749 | * 00 00 00 00 00 00 00 00 | |
1750 | * type 02 CMD_BSS_TYPE_IBSS | |
1751 | * beacon period 64 00 | |
1752 | * dtim period 00 | |
1753 | * timestamp 00 00 00 00 00 00 00 00 | |
1754 | * localtime 00 00 00 00 00 00 00 00 | |
1755 | * IE DS 03 | |
1756 | * IE DS len 01 | |
1757 | * IE DS channel 01 | |
1758 | * reserveed 00 00 00 00 | |
1759 | * IE IBSS 06 | |
1760 | * IE IBSS len 02 | |
1761 | * IE IBSS atim 00 00 | |
1762 | * reserved 00 00 00 00 | |
1763 | * capability 02 00 | |
1764 | * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00 | |
1765 | * fail timeout ff 00 | |
1766 | * probe delay 00 00 | |
1767 | */ | |
1768 | memset(&cmd, 0, sizeof(cmd)); | |
1769 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1770 | ||
1771 | memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN); | |
1772 | memcpy(cmd.bss.ssid, params->ssid, params->ssid_len); | |
1773 | cmd.bss.type = CMD_BSS_TYPE_IBSS; | |
1774 | cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval); | |
1775 | cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS; | |
1776 | cmd.bss.ds.header.len = 1; | |
1777 | cmd.bss.ds.channel = params->channel->hw_value; | |
1778 | cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS; | |
1779 | cmd.bss.ibss.header.len = 2; | |
1780 | cmd.bss.ibss.atimwindow = 0; | |
1781 | cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); | |
1782 | ||
1783 | /* set rates to the intersection of our rates and the rates in the | |
1784 | bss */ | |
1785 | if (!rates_eid) { | |
1786 | lbs_add_rates(cmd.bss.rates); | |
1787 | } else { | |
1788 | int hw, i; | |
1789 | u8 rates_max = rates_eid[1]; | |
1790 | u8 *rates = cmd.bss.rates; | |
1791 | for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) { | |
1792 | u8 hw_rate = lbs_rates[hw].bitrate / 5; | |
1793 | for (i = 0; i < rates_max; i++) { | |
1794 | if (hw_rate == (rates_eid[i+2] & 0x7f)) { | |
1795 | u8 rate = rates_eid[i+2]; | |
1796 | if (rate == 0x02 || rate == 0x04 || | |
1797 | rate == 0x0b || rate == 0x16) | |
1798 | rate |= 0x80; | |
1799 | *rates++ = rate; | |
1800 | } | |
1801 | } | |
1802 | } | |
1803 | } | |
1804 | ||
1805 | /* Only v8 and below support setting this */ | |
1806 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) { | |
1807 | cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); | |
1808 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | |
1809 | } | |
1810 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd); | |
1811 | if (ret) | |
1812 | goto out; | |
1813 | ||
1814 | /* | |
1815 | * This is a sample response to CMD_802_11_AD_HOC_JOIN: | |
1816 | * | |
1817 | * response 2c 80 | |
1818 | * size 09 00 | |
1819 | * sequence xx xx | |
1820 | * result 00 00 | |
1821 | * reserved 00 | |
1822 | */ | |
1823 | lbs_join_post(priv, params, bss->bssid, bss->capability); | |
1824 | ||
1825 | out: | |
1826 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1827 | return ret; | |
1828 | } | |
1829 | ||
1830 | ||
1831 | ||
1832 | static int lbs_ibss_start_new(struct lbs_private *priv, | |
1833 | struct cfg80211_ibss_params *params) | |
1834 | { | |
1835 | struct cmd_ds_802_11_ad_hoc_start cmd; | |
1836 | struct cmd_ds_802_11_ad_hoc_result *resp = | |
1837 | (struct cmd_ds_802_11_ad_hoc_result *) &cmd; | |
1838 | u8 preamble = RADIO_PREAMBLE_SHORT; | |
1839 | int ret = 0; | |
1840 | u16 capability; | |
1841 | ||
1842 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1843 | ||
1844 | ret = lbs_set_radio(priv, preamble, 1); | |
1845 | if (ret) | |
1846 | goto out; | |
1847 | ||
1848 | /* | |
1849 | * Example CMD_802_11_AD_HOC_START command: | |
1850 | * | |
1851 | * command 2b 00 CMD_802_11_AD_HOC_START | |
1852 | * size b1 00 | |
1853 | * sequence xx xx | |
1854 | * result 00 00 | |
1855 | * ssid 54 45 53 54 00 00 00 00 | |
1856 | * 00 00 00 00 00 00 00 00 | |
1857 | * 00 00 00 00 00 00 00 00 | |
1858 | * 00 00 00 00 00 00 00 00 | |
1859 | * bss type 02 | |
1860 | * beacon period 64 00 | |
1861 | * dtim period 00 | |
1862 | * IE IBSS 06 | |
1863 | * IE IBSS len 02 | |
1864 | * IE IBSS atim 00 00 | |
1865 | * reserved 00 00 00 00 | |
1866 | * IE DS 03 | |
1867 | * IE DS len 01 | |
1868 | * IE DS channel 01 | |
1869 | * reserved 00 00 00 00 | |
1870 | * probe delay 00 00 | |
1871 | * capability 02 00 | |
1872 | * rates 82 84 8b 96 (basic rates with have bit 7 set) | |
1873 | * 0c 12 18 24 30 48 60 6c | |
1874 | * padding 100 bytes | |
1875 | */ | |
1876 | memset(&cmd, 0, sizeof(cmd)); | |
1877 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1878 | memcpy(cmd.ssid, params->ssid, params->ssid_len); | |
1879 | cmd.bsstype = CMD_BSS_TYPE_IBSS; | |
1880 | cmd.beaconperiod = cpu_to_le16(params->beacon_interval); | |
1881 | cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS; | |
1882 | cmd.ibss.header.len = 2; | |
1883 | cmd.ibss.atimwindow = 0; | |
1884 | cmd.ds.header.id = WLAN_EID_DS_PARAMS; | |
1885 | cmd.ds.header.len = 1; | |
1886 | cmd.ds.channel = params->channel->hw_value; | |
1887 | /* Only v8 and below support setting probe delay */ | |
1888 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) | |
1889 | cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME); | |
1890 | /* TODO: mix in WLAN_CAPABILITY_PRIVACY */ | |
1891 | capability = WLAN_CAPABILITY_IBSS; | |
1892 | cmd.capability = cpu_to_le16(capability); | |
1893 | lbs_add_rates(cmd.rates); | |
1894 | ||
1895 | ||
1896 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd); | |
1897 | if (ret) | |
1898 | goto out; | |
1899 | ||
1900 | /* | |
1901 | * This is a sample response to CMD_802_11_AD_HOC_JOIN: | |
1902 | * | |
1903 | * response 2b 80 | |
1904 | * size 14 00 | |
1905 | * sequence xx xx | |
1906 | * result 00 00 | |
1907 | * reserved 00 | |
1908 | * bssid 02 2b 7b 0f 86 0e | |
1909 | */ | |
1910 | lbs_join_post(priv, params, resp->bssid, capability); | |
1911 | ||
1912 | out: | |
1913 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1914 | return ret; | |
1915 | } | |
1916 | ||
1917 | ||
1918 | static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev, | |
1919 | struct cfg80211_ibss_params *params) | |
1920 | { | |
1921 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1922 | int ret = 0; | |
1923 | struct cfg80211_bss *bss; | |
1924 | DECLARE_SSID_BUF(ssid_buf); | |
1925 | ||
1926 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1927 | ||
1928 | if (!params->channel) { | |
1929 | ret = -ENOTSUPP; | |
1930 | goto out; | |
1931 | } | |
1932 | ||
1933 | ret = lbs_set_channel(priv, params->channel->hw_value); | |
1934 | if (ret) | |
ff9fc791 HS |
1935 | goto out; |
1936 | ||
e86dc1ca KD |
1937 | /* Search if someone is beaconing. This assumes that the |
1938 | * bss list is populated already */ | |
1939 | bss = cfg80211_get_bss(wiphy, params->channel, params->bssid, | |
1940 | params->ssid, params->ssid_len, | |
1941 | WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS); | |
1942 | ||
1943 | if (bss) { | |
1944 | ret = lbs_ibss_join_existing(priv, params, bss); | |
1945 | cfg80211_put_bss(bss); | |
1946 | } else | |
1947 | ret = lbs_ibss_start_new(priv, params); | |
1948 | ||
ff9fc791 HS |
1949 | |
1950 | out: | |
1951 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1952 | return ret; | |
1953 | } | |
1954 | ||
1955 | ||
e86dc1ca KD |
1956 | static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev) |
1957 | { | |
1958 | struct lbs_private *priv = wiphy_priv(wiphy); | |
1959 | struct cmd_ds_802_11_ad_hoc_stop cmd; | |
1960 | int ret = 0; | |
1961 | ||
1962 | lbs_deb_enter(LBS_DEB_CFG80211); | |
1963 | ||
1964 | memset(&cmd, 0, sizeof(cmd)); | |
1965 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1966 | ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd); | |
1967 | ||
1968 | /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */ | |
1969 | lbs_mac_event_disconnected(priv); | |
1970 | ||
1971 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
1972 | return ret; | |
1973 | } | |
1974 | ||
ff9fc791 HS |
1975 | |
1976 | ||
e86dc1ca KD |
1977 | |
1978 | /*************************************************************************** | |
1979 | * Initialization | |
1980 | */ | |
1981 | ||
ff9fc791 HS |
1982 | static struct cfg80211_ops lbs_cfg80211_ops = { |
1983 | .set_channel = lbs_cfg_set_channel, | |
e86dc1ca KD |
1984 | .scan = lbs_cfg_scan, |
1985 | .connect = lbs_cfg_connect, | |
1986 | .disconnect = lbs_cfg_disconnect, | |
1987 | .add_key = lbs_cfg_add_key, | |
1988 | .del_key = lbs_cfg_del_key, | |
1989 | .set_default_key = lbs_cfg_set_default_key, | |
1990 | .get_station = lbs_cfg_get_station, | |
1991 | .dump_survey = lbs_get_survey, | |
1992 | .change_virtual_intf = lbs_change_intf, | |
1993 | .join_ibss = lbs_join_ibss, | |
1994 | .leave_ibss = lbs_leave_ibss, | |
ff9fc791 HS |
1995 | }; |
1996 | ||
1997 | ||
1998 | /* | |
1999 | * At this time lbs_private *priv doesn't even exist, so we just allocate | |
2000 | * memory and don't initialize the wiphy further. This is postponed until we | |
2001 | * can talk to the firmware and happens at registration time in | |
2002 | * lbs_cfg_wiphy_register(). | |
2003 | */ | |
2004 | struct wireless_dev *lbs_cfg_alloc(struct device *dev) | |
2005 | { | |
2006 | int ret = 0; | |
2007 | struct wireless_dev *wdev; | |
2008 | ||
2009 | lbs_deb_enter(LBS_DEB_CFG80211); | |
2010 | ||
2011 | wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); | |
2012 | if (!wdev) { | |
2013 | dev_err(dev, "cannot allocate wireless device\n"); | |
2014 | return ERR_PTR(-ENOMEM); | |
2015 | } | |
2016 | ||
2017 | wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private)); | |
2018 | if (!wdev->wiphy) { | |
2019 | dev_err(dev, "cannot allocate wiphy\n"); | |
2020 | ret = -ENOMEM; | |
2021 | goto err_wiphy_new; | |
2022 | } | |
2023 | ||
2024 | lbs_deb_leave(LBS_DEB_CFG80211); | |
2025 | return wdev; | |
2026 | ||
2027 | err_wiphy_new: | |
2028 | kfree(wdev); | |
2029 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); | |
2030 | return ERR_PTR(ret); | |
2031 | } | |
2032 | ||
2033 | ||
e86dc1ca KD |
2034 | static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv) |
2035 | { | |
2036 | struct region_code_mapping { | |
2037 | const char *cn; | |
2038 | int code; | |
2039 | }; | |
2040 | ||
2041 | /* Section 5.17.2 */ | |
2042 | static struct region_code_mapping regmap[] = { | |
2043 | {"US ", 0x10}, /* US FCC */ | |
2044 | {"CA ", 0x20}, /* Canada */ | |
2045 | {"EU ", 0x30}, /* ETSI */ | |
2046 | {"ES ", 0x31}, /* Spain */ | |
2047 | {"FR ", 0x32}, /* France */ | |
2048 | {"JP ", 0x40}, /* Japan */ | |
2049 | }; | |
2050 | size_t i; | |
2051 | ||
2052 | lbs_deb_enter(LBS_DEB_CFG80211); | |
2053 | ||
2054 | for (i = 0; i < ARRAY_SIZE(regmap); i++) | |
2055 | if (regmap[i].code == priv->regioncode) { | |
2056 | regulatory_hint(priv->wdev->wiphy, regmap[i].cn); | |
2057 | break; | |
2058 | } | |
2059 | ||
2060 | lbs_deb_leave(LBS_DEB_CFG80211); | |
2061 | } | |
2062 | ||
2063 | ||
ff9fc791 HS |
2064 | /* |
2065 | * This function get's called after lbs_setup_firmware() determined the | |
2066 | * firmware capabities. So we can setup the wiphy according to our | |
2067 | * hardware/firmware. | |
2068 | */ | |
2069 | int lbs_cfg_register(struct lbs_private *priv) | |
2070 | { | |
2071 | struct wireless_dev *wdev = priv->wdev; | |
2072 | int ret; | |
2073 | ||
2074 | lbs_deb_enter(LBS_DEB_CFG80211); | |
2075 | ||
2076 | wdev->wiphy->max_scan_ssids = 1; | |
2077 | wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; | |
2078 | ||
e86dc1ca KD |
2079 | wdev->wiphy->interface_modes = |
2080 | BIT(NL80211_IFTYPE_STATION) | | |
2081 | BIT(NL80211_IFTYPE_ADHOC); | |
2082 | if (lbs_rtap_supported(priv)) | |
2083 | wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR); | |
ff9fc791 | 2084 | |
ff9fc791 HS |
2085 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz; |
2086 | ||
2087 | /* | |
2088 | * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have | |
2089 | * never seen a firmware without WPA | |
2090 | */ | |
2091 | wdev->wiphy->cipher_suites = cipher_suites; | |
2092 | wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
1047d5ed | 2093 | wdev->wiphy->reg_notifier = lbs_reg_notifier; |
ff9fc791 HS |
2094 | |
2095 | ret = wiphy_register(wdev->wiphy); | |
2096 | if (ret < 0) | |
2097 | lbs_pr_err("cannot register wiphy device\n"); | |
2098 | ||
73714004 DM |
2099 | priv->wiphy_registered = true; |
2100 | ||
ff9fc791 HS |
2101 | ret = register_netdev(priv->dev); |
2102 | if (ret) | |
2103 | lbs_pr_err("cannot register network device\n"); | |
2104 | ||
e86dc1ca KD |
2105 | INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker); |
2106 | ||
2107 | lbs_cfg_set_regulatory_hint(priv); | |
2108 | ||
ff9fc791 HS |
2109 | lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); |
2110 | return ret; | |
2111 | } | |
2112 | ||
1047d5ed KD |
2113 | int lbs_reg_notifier(struct wiphy *wiphy, |
2114 | struct regulatory_request *request) | |
2115 | { | |
cc4b9d39 DW |
2116 | struct lbs_private *priv = wiphy_priv(wiphy); |
2117 | int ret; | |
2118 | ||
1047d5ed KD |
2119 | lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain " |
2120 | "callback for domain %c%c\n", request->alpha2[0], | |
2121 | request->alpha2[1]); | |
2122 | ||
cc4b9d39 | 2123 | ret = lbs_set_11d_domain_info(priv, request, wiphy->bands); |
1047d5ed KD |
2124 | |
2125 | lbs_deb_leave(LBS_DEB_CFG80211); | |
cc4b9d39 | 2126 | return ret; |
1047d5ed | 2127 | } |
ff9fc791 | 2128 | |
e86dc1ca KD |
2129 | void lbs_scan_deinit(struct lbs_private *priv) |
2130 | { | |
2131 | lbs_deb_enter(LBS_DEB_CFG80211); | |
2132 | cancel_delayed_work_sync(&priv->scan_work); | |
2133 | } | |
2134 | ||
2135 | ||
ff9fc791 HS |
2136 | void lbs_cfg_free(struct lbs_private *priv) |
2137 | { | |
2138 | struct wireless_dev *wdev = priv->wdev; | |
2139 | ||
2140 | lbs_deb_enter(LBS_DEB_CFG80211); | |
2141 | ||
2142 | if (!wdev) | |
2143 | return; | |
2144 | ||
73714004 | 2145 | if (priv->wiphy_registered) |
ff9fc791 | 2146 | wiphy_unregister(wdev->wiphy); |
73714004 DM |
2147 | |
2148 | if (wdev->wiphy) | |
ff9fc791 | 2149 | wiphy_free(wdev->wiphy); |
73714004 | 2150 | |
ff9fc791 HS |
2151 | kfree(wdev); |
2152 | } |