Commit | Line | Data |
---|---|---|
f0706e82 JB |
1 | /* |
2 | * Copyright 2002-2005, Instant802 Networks, Inc. | |
3 | * Copyright 2005-2006, Devicescape Software, Inc. | |
4 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | ||
11 | #include <net/mac80211.h> | |
12 | #include <net/ieee80211_radiotap.h> | |
13 | #include <linux/module.h> | |
14 | #include <linux/init.h> | |
15 | #include <linux/netdevice.h> | |
16 | #include <linux/types.h> | |
17 | #include <linux/slab.h> | |
18 | #include <linux/skbuff.h> | |
19 | #include <linux/etherdevice.h> | |
20 | #include <linux/if_arp.h> | |
21 | #include <linux/wireless.h> | |
22 | #include <linux/rtnetlink.h> | |
f0706e82 | 23 | #include <linux/bitmap.h> |
881d966b | 24 | #include <net/net_namespace.h> |
f0706e82 JB |
25 | #include <net/cfg80211.h> |
26 | ||
f0706e82 | 27 | #include "ieee80211_i.h" |
2c8dccc7 | 28 | #include "rate.h" |
f7a92144 | 29 | #include "mesh.h" |
f0706e82 | 30 | #include "wep.h" |
f0706e82 JB |
31 | #include "wme.h" |
32 | #include "aes_ccm.h" | |
2c8dccc7 | 33 | #include "led.h" |
e0eb6859 | 34 | #include "cfg.h" |
e9f207f0 JB |
35 | #include "debugfs.h" |
36 | #include "debugfs_netdev.h" | |
f0706e82 | 37 | |
b306f453 JB |
38 | /* |
39 | * For seeing transmitted packets on monitor interfaces | |
40 | * we have a radiotap header too. | |
41 | */ | |
42 | struct ieee80211_tx_status_rtap_hdr { | |
43 | struct ieee80211_radiotap_header hdr; | |
44 | __le16 tx_flags; | |
45 | u8 data_retries; | |
46 | } __attribute__ ((packed)); | |
47 | ||
f0706e82 | 48 | |
4150c572 | 49 | /* must be called under mdev tx lock */ |
0d143fe1 | 50 | void ieee80211_configure_filter(struct ieee80211_local *local) |
4150c572 JB |
51 | { |
52 | unsigned int changed_flags; | |
53 | unsigned int new_flags = 0; | |
54 | ||
53918994 | 55 | if (atomic_read(&local->iff_promiscs)) |
4150c572 JB |
56 | new_flags |= FIF_PROMISC_IN_BSS; |
57 | ||
53918994 | 58 | if (atomic_read(&local->iff_allmultis)) |
4150c572 JB |
59 | new_flags |= FIF_ALLMULTI; |
60 | ||
61 | if (local->monitors) | |
8cc9a739 MW |
62 | new_flags |= FIF_BCN_PRBRESP_PROMISC; |
63 | ||
64 | if (local->fif_fcsfail) | |
65 | new_flags |= FIF_FCSFAIL; | |
66 | ||
67 | if (local->fif_plcpfail) | |
68 | new_flags |= FIF_PLCPFAIL; | |
69 | ||
70 | if (local->fif_control) | |
71 | new_flags |= FIF_CONTROL; | |
72 | ||
73 | if (local->fif_other_bss) | |
74 | new_flags |= FIF_OTHER_BSS; | |
4150c572 JB |
75 | |
76 | changed_flags = local->filter_flags ^ new_flags; | |
77 | ||
78 | /* be a bit nasty */ | |
79 | new_flags |= (1<<31); | |
80 | ||
81 | local->ops->configure_filter(local_to_hw(local), | |
82 | changed_flags, &new_flags, | |
83 | local->mdev->mc_count, | |
84 | local->mdev->mc_list); | |
85 | ||
86 | WARN_ON(new_flags & (1<<31)); | |
87 | ||
88 | local->filter_flags = new_flags & ~(1<<31); | |
89 | } | |
90 | ||
b2c258fb | 91 | /* master interface */ |
f0706e82 | 92 | |
0d143fe1 JB |
93 | static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr) |
94 | { | |
95 | memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */ | |
96 | return ETH_ALEN; | |
97 | } | |
98 | ||
99 | static const struct header_ops ieee80211_header_ops = { | |
100 | .create = eth_header, | |
101 | .parse = header_parse_80211, | |
102 | .rebuild = eth_rebuild_header, | |
103 | .cache = eth_header_cache, | |
104 | .cache_update = eth_header_cache_update, | |
105 | }; | |
106 | ||
b2c258fb JB |
107 | static int ieee80211_master_open(struct net_device *dev) |
108 | { | |
133b8226 JB |
109 | struct ieee80211_master_priv *mpriv = netdev_priv(dev); |
110 | struct ieee80211_local *local = mpriv->local; | |
b2c258fb JB |
111 | struct ieee80211_sub_if_data *sdata; |
112 | int res = -EOPNOTSUPP; | |
f0706e82 | 113 | |
79010420 JB |
114 | /* we hold the RTNL here so can safely walk the list */ |
115 | list_for_each_entry(sdata, &local->interfaces, list) { | |
3e122be0 | 116 | if (netif_running(sdata->dev)) { |
b2c258fb JB |
117 | res = 0; |
118 | break; | |
119 | } | |
120 | } | |
36d6825b JB |
121 | |
122 | if (res) | |
123 | return res; | |
124 | ||
51cb6db0 | 125 | netif_tx_start_all_queues(local->mdev); |
36d6825b JB |
126 | |
127 | return 0; | |
b2c258fb | 128 | } |
f0706e82 | 129 | |
b2c258fb | 130 | static int ieee80211_master_stop(struct net_device *dev) |
f0706e82 | 131 | { |
133b8226 JB |
132 | struct ieee80211_master_priv *mpriv = netdev_priv(dev); |
133 | struct ieee80211_local *local = mpriv->local; | |
b2c258fb | 134 | struct ieee80211_sub_if_data *sdata; |
f0706e82 | 135 | |
79010420 JB |
136 | /* we hold the RTNL here so can safely walk the list */ |
137 | list_for_each_entry(sdata, &local->interfaces, list) | |
3e122be0 | 138 | if (netif_running(sdata->dev)) |
b2c258fb | 139 | dev_close(sdata->dev); |
f0706e82 | 140 | |
b2c258fb JB |
141 | return 0; |
142 | } | |
f0706e82 | 143 | |
4150c572 JB |
144 | static void ieee80211_master_set_multicast_list(struct net_device *dev) |
145 | { | |
133b8226 JB |
146 | struct ieee80211_master_priv *mpriv = netdev_priv(dev); |
147 | struct ieee80211_local *local = mpriv->local; | |
4150c572 JB |
148 | |
149 | ieee80211_configure_filter(local); | |
150 | } | |
151 | ||
b2c258fb JB |
152 | /* everything else */ |
153 | ||
9d139c81 | 154 | int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed) |
b2c258fb | 155 | { |
9d139c81 | 156 | struct ieee80211_local *local = sdata->local; |
b2c258fb | 157 | struct ieee80211_if_conf conf; |
b2c258fb | 158 | |
9d139c81 JB |
159 | if (WARN_ON(!netif_running(sdata->dev))) |
160 | return 0; | |
161 | ||
7a725f73 JB |
162 | if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) |
163 | return -EINVAL; | |
164 | ||
9d139c81 | 165 | if (!local->ops->config_interface) |
f0706e82 | 166 | return 0; |
f0706e82 | 167 | |
b2c258fb | 168 | memset(&conf, 0, sizeof(conf)); |
9d139c81 JB |
169 | conf.changed = changed; |
170 | ||
05c914fe JB |
171 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
172 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
4150c572 | 173 | conf.bssid = sdata->u.sta.bssid; |
b2c258fb JB |
174 | conf.ssid = sdata->u.sta.ssid; |
175 | conf.ssid_len = sdata->u.sta.ssid_len; | |
05c914fe | 176 | } else if (sdata->vif.type == NL80211_IFTYPE_AP) { |
9d139c81 | 177 | conf.bssid = sdata->dev->dev_addr; |
b2c258fb JB |
178 | conf.ssid = sdata->u.ap.ssid; |
179 | conf.ssid_len = sdata->u.ap.ssid_len; | |
9d139c81 JB |
180 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { |
181 | u8 zero[ETH_ALEN] = { 0 }; | |
182 | conf.bssid = zero; | |
183 | conf.ssid = zero; | |
184 | conf.ssid_len = 0; | |
185 | } else { | |
186 | WARN_ON(1); | |
187 | return -EINVAL; | |
f0706e82 | 188 | } |
f0706e82 | 189 | |
9d139c81 JB |
190 | if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID))) |
191 | return -EINVAL; | |
f0706e82 | 192 | |
9d139c81 JB |
193 | if (WARN_ON(!conf.ssid && (changed & IEEE80211_IFCC_SSID))) |
194 | return -EINVAL; | |
f0706e82 | 195 | |
9d139c81 JB |
196 | return local->ops->config_interface(local_to_hw(local), |
197 | &sdata->vif, &conf); | |
b2c258fb | 198 | } |
f0706e82 | 199 | |
b2c258fb JB |
200 | int ieee80211_hw_config(struct ieee80211_local *local) |
201 | { | |
b2c258fb JB |
202 | struct ieee80211_channel *chan; |
203 | int ret = 0; | |
f0706e82 | 204 | |
c2b13452 | 205 | if (local->sw_scanning) |
b2c258fb | 206 | chan = local->scan_channel; |
8318d78a | 207 | else |
b2c258fb | 208 | chan = local->oper_channel; |
f0706e82 | 209 | |
8318d78a JB |
210 | local->hw.conf.channel = chan; |
211 | ||
212 | if (!local->hw.conf.power_level) | |
213 | local->hw.conf.power_level = chan->max_power; | |
214 | else | |
215 | local->hw.conf.power_level = min(chan->max_power, | |
216 | local->hw.conf.power_level); | |
217 | ||
b2c258fb | 218 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
8318d78a JB |
219 | printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n", |
220 | wiphy_name(local->hw.wiphy), chan->center_freq); | |
221 | #endif | |
b2c258fb | 222 | |
d73782fd | 223 | if (local->open_count) { |
b2c258fb | 224 | ret = local->ops->config(local_to_hw(local), &local->hw.conf); |
d73782fd JB |
225 | /* |
226 | * HW reconfiguration should never fail, the driver has told | |
227 | * us what it can support so it should live up to that promise. | |
228 | */ | |
229 | WARN_ON(ret); | |
230 | } | |
f0706e82 | 231 | |
b2c258fb JB |
232 | return ret; |
233 | } | |
f0706e82 | 234 | |
d3c990fb | 235 | /** |
38668c05 TW |
236 | * ieee80211_handle_ht should be used only after legacy configuration |
237 | * has been determined namely band, as ht configuration depends upon | |
238 | * the hardware's HT abilities for a _specific_ band. | |
d3c990fb | 239 | */ |
38668c05 | 240 | u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht, |
d3c990fb RR |
241 | struct ieee80211_ht_info *req_ht_cap, |
242 | struct ieee80211_ht_bss_info *req_bss_cap) | |
243 | { | |
244 | struct ieee80211_conf *conf = &local->hw.conf; | |
8318d78a | 245 | struct ieee80211_supported_band *sband; |
38668c05 TW |
246 | struct ieee80211_ht_info ht_conf; |
247 | struct ieee80211_ht_bss_info ht_bss_conf; | |
38668c05 | 248 | u32 changed = 0; |
edcdf8b2 RR |
249 | int i; |
250 | u8 max_tx_streams = IEEE80211_HT_CAP_MAX_STREAMS; | |
251 | u8 tx_mcs_set_cap; | |
d3c990fb | 252 | |
8318d78a JB |
253 | sband = local->hw.wiphy->bands[conf->channel->band]; |
254 | ||
edcdf8b2 RR |
255 | memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info)); |
256 | memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info)); | |
257 | ||
d3c990fb | 258 | /* HT is not supported */ |
8318d78a | 259 | if (!sband->ht_info.ht_supported) { |
d3c990fb | 260 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; |
edcdf8b2 | 261 | goto out; |
d3c990fb RR |
262 | } |
263 | ||
edcdf8b2 RR |
264 | /* disable HT */ |
265 | if (!enable_ht) { | |
266 | if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) | |
38668c05 | 267 | changed |= BSS_CHANGED_HT; |
edcdf8b2 RR |
268 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; |
269 | conf->ht_conf.ht_supported = 0; | |
270 | goto out; | |
271 | } | |
38668c05 | 272 | |
38668c05 | 273 | |
edcdf8b2 RR |
274 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) |
275 | changed |= BSS_CHANGED_HT; | |
38668c05 | 276 | |
edcdf8b2 RR |
277 | conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; |
278 | ht_conf.ht_supported = 1; | |
38668c05 | 279 | |
edcdf8b2 | 280 | ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap; |
00c5ae2f TW |
281 | ht_conf.cap &= ~(IEEE80211_HT_CAP_SM_PS); |
282 | ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_SM_PS; | |
edcdf8b2 RR |
283 | ht_bss_conf.primary_channel = req_bss_cap->primary_channel; |
284 | ht_bss_conf.bss_cap = req_bss_cap->bss_cap; | |
285 | ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; | |
38668c05 | 286 | |
edcdf8b2 RR |
287 | ht_conf.ampdu_factor = req_ht_cap->ampdu_factor; |
288 | ht_conf.ampdu_density = req_ht_cap->ampdu_density; | |
38668c05 | 289 | |
edcdf8b2 RR |
290 | /* Bits 96-100 */ |
291 | tx_mcs_set_cap = sband->ht_info.supp_mcs_set[12]; | |
292 | ||
293 | /* configure suppoerted Tx MCS according to requested MCS | |
294 | * (based in most cases on Rx capabilities of peer) and self | |
295 | * Tx MCS capabilities (as defined by low level driver HW | |
296 | * Tx capabilities) */ | |
297 | if (!(tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_DEFINED)) | |
298 | goto check_changed; | |
d3c990fb | 299 | |
edcdf8b2 RR |
300 | /* Counting from 0 therfore + 1 */ |
301 | if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_RX_DIFF) | |
302 | max_tx_streams = ((tx_mcs_set_cap & | |
303 | IEEE80211_HT_CAP_MCS_TX_STREAMS) >> 2) + 1; | |
304 | ||
305 | for (i = 0; i < max_tx_streams; i++) | |
306 | ht_conf.supp_mcs_set[i] = | |
307 | sband->ht_info.supp_mcs_set[i] & | |
308 | req_ht_cap->supp_mcs_set[i]; | |
309 | ||
310 | if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_UEQM) | |
311 | for (i = IEEE80211_SUPP_MCS_SET_UEQM; | |
312 | i < IEEE80211_SUPP_MCS_SET_LEN; i++) | |
313 | ht_conf.supp_mcs_set[i] = | |
314 | sband->ht_info.supp_mcs_set[i] & | |
315 | req_ht_cap->supp_mcs_set[i]; | |
316 | ||
317 | check_changed: | |
318 | /* if bss configuration changed store the new one */ | |
319 | if (memcmp(&conf->ht_conf, &ht_conf, sizeof(ht_conf)) || | |
320 | memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) { | |
321 | changed |= BSS_CHANGED_HT; | |
322 | memcpy(&conf->ht_conf, &ht_conf, sizeof(ht_conf)); | |
323 | memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf)); | |
324 | } | |
325 | out: | |
38668c05 | 326 | return changed; |
d3c990fb RR |
327 | } |
328 | ||
471b3efd JB |
329 | void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, |
330 | u32 changed) | |
d9430a32 | 331 | { |
471b3efd JB |
332 | struct ieee80211_local *local = sdata->local; |
333 | ||
7a725f73 JB |
334 | if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) |
335 | return; | |
336 | ||
471b3efd JB |
337 | if (!changed) |
338 | return; | |
339 | ||
340 | if (local->ops->bss_info_changed) | |
341 | local->ops->bss_info_changed(local_to_hw(local), | |
342 | &sdata->vif, | |
343 | &sdata->bss_conf, | |
344 | changed); | |
d9430a32 DD |
345 | } |
346 | ||
f698d856 | 347 | u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata) |
d9430a32 | 348 | { |
471b3efd JB |
349 | sdata->bss_conf.use_cts_prot = 0; |
350 | sdata->bss_conf.use_short_preamble = 0; | |
fc32f924 | 351 | return BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_PREAMBLE; |
d9430a32 DD |
352 | } |
353 | ||
f0706e82 | 354 | void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, |
e039fa4a | 355 | struct sk_buff *skb) |
f0706e82 JB |
356 | { |
357 | struct ieee80211_local *local = hw_to_local(hw); | |
e039fa4a | 358 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
f0706e82 JB |
359 | int tmp; |
360 | ||
361 | skb->dev = local->mdev; | |
f0706e82 | 362 | skb->pkt_type = IEEE80211_TX_STATUS_MSG; |
e039fa4a | 363 | skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ? |
f0706e82 JB |
364 | &local->skb_queue : &local->skb_queue_unreliable, skb); |
365 | tmp = skb_queue_len(&local->skb_queue) + | |
366 | skb_queue_len(&local->skb_queue_unreliable); | |
367 | while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT && | |
368 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { | |
f0706e82 JB |
369 | dev_kfree_skb_irq(skb); |
370 | tmp--; | |
371 | I802_DEBUG_INC(local->tx_status_drop); | |
372 | } | |
373 | tasklet_schedule(&local->tasklet); | |
374 | } | |
375 | EXPORT_SYMBOL(ieee80211_tx_status_irqsafe); | |
376 | ||
377 | static void ieee80211_tasklet_handler(unsigned long data) | |
378 | { | |
379 | struct ieee80211_local *local = (struct ieee80211_local *) data; | |
380 | struct sk_buff *skb; | |
381 | struct ieee80211_rx_status rx_status; | |
eadc8d9e | 382 | struct ieee80211_ra_tid *ra_tid; |
f0706e82 JB |
383 | |
384 | while ((skb = skb_dequeue(&local->skb_queue)) || | |
385 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { | |
386 | switch (skb->pkt_type) { | |
387 | case IEEE80211_RX_MSG: | |
388 | /* status is in skb->cb */ | |
389 | memcpy(&rx_status, skb->cb, sizeof(rx_status)); | |
51fb61e7 | 390 | /* Clear skb->pkt_type in order to not confuse kernel |
f0706e82 JB |
391 | * netstack. */ |
392 | skb->pkt_type = 0; | |
393 | __ieee80211_rx(local_to_hw(local), skb, &rx_status); | |
394 | break; | |
395 | case IEEE80211_TX_STATUS_MSG: | |
f0706e82 | 396 | skb->pkt_type = 0; |
e039fa4a | 397 | ieee80211_tx_status(local_to_hw(local), skb); |
f0706e82 | 398 | break; |
eadc8d9e RR |
399 | case IEEE80211_DELBA_MSG: |
400 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
401 | ieee80211_stop_tx_ba_cb(local_to_hw(local), | |
402 | ra_tid->ra, ra_tid->tid); | |
403 | dev_kfree_skb(skb); | |
404 | break; | |
405 | case IEEE80211_ADDBA_MSG: | |
406 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
407 | ieee80211_start_tx_ba_cb(local_to_hw(local), | |
408 | ra_tid->ra, ra_tid->tid); | |
409 | dev_kfree_skb(skb); | |
410 | break ; | |
f4ea83dd JB |
411 | default: |
412 | WARN_ON(1); | |
f0706e82 JB |
413 | dev_kfree_skb(skb); |
414 | break; | |
415 | } | |
416 | } | |
417 | } | |
418 | ||
f0706e82 JB |
419 | /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to |
420 | * make a prepared TX frame (one that has been given to hw) to look like brand | |
421 | * new IEEE 802.11 frame that is ready to go through TX processing again. | |
d0f09804 | 422 | */ |
f0706e82 JB |
423 | static void ieee80211_remove_tx_extra(struct ieee80211_local *local, |
424 | struct ieee80211_key *key, | |
e039fa4a | 425 | struct sk_buff *skb) |
f0706e82 | 426 | { |
62bf1d76 HH |
427 | unsigned int hdrlen, iv_len, mic_len; |
428 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
f0706e82 | 429 | |
62bf1d76 | 430 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
f0706e82 JB |
431 | |
432 | if (!key) | |
433 | goto no_key; | |
434 | ||
8f20fc24 | 435 | switch (key->conf.alg) { |
f0706e82 JB |
436 | case ALG_WEP: |
437 | iv_len = WEP_IV_LEN; | |
438 | mic_len = WEP_ICV_LEN; | |
439 | break; | |
440 | case ALG_TKIP: | |
441 | iv_len = TKIP_IV_LEN; | |
442 | mic_len = TKIP_ICV_LEN; | |
443 | break; | |
444 | case ALG_CCMP: | |
445 | iv_len = CCMP_HDR_LEN; | |
446 | mic_len = CCMP_MIC_LEN; | |
447 | break; | |
448 | default: | |
449 | goto no_key; | |
450 | } | |
451 | ||
62bf1d76 | 452 | if (skb->len >= hdrlen + mic_len && |
11a843b7 | 453 | !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
f0706e82 | 454 | skb_trim(skb, skb->len - mic_len); |
62bf1d76 | 455 | if (skb->len >= hdrlen + iv_len) { |
f0706e82 | 456 | memmove(skb->data + iv_len, skb->data, hdrlen); |
62bf1d76 | 457 | hdr = (struct ieee80211_hdr *)skb_pull(skb, iv_len); |
f0706e82 JB |
458 | } |
459 | ||
460 | no_key: | |
62bf1d76 HH |
461 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
462 | hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA); | |
463 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, skb->data, | |
464 | hdrlen - IEEE80211_QOS_CTL_LEN); | |
465 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); | |
f0706e82 JB |
466 | } |
467 | } | |
468 | ||
d46e144b JB |
469 | static void ieee80211_handle_filtered_frame(struct ieee80211_local *local, |
470 | struct sta_info *sta, | |
e039fa4a | 471 | struct sk_buff *skb) |
d46e144b | 472 | { |
e039fa4a JB |
473 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
474 | ||
d46e144b JB |
475 | sta->tx_filtered_count++; |
476 | ||
477 | /* | |
478 | * Clear the TX filter mask for this STA when sending the next | |
479 | * packet. If the STA went to power save mode, this will happen | |
f6d97104 | 480 | * when it wakes up for the next time. |
d46e144b | 481 | */ |
07346f81 | 482 | set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT); |
d46e144b JB |
483 | |
484 | /* | |
485 | * This code races in the following way: | |
486 | * | |
487 | * (1) STA sends frame indicating it will go to sleep and does so | |
488 | * (2) hardware/firmware adds STA to filter list, passes frame up | |
489 | * (3) hardware/firmware processes TX fifo and suppresses a frame | |
490 | * (4) we get TX status before having processed the frame and | |
491 | * knowing that the STA has gone to sleep. | |
492 | * | |
493 | * This is actually quite unlikely even when both those events are | |
494 | * processed from interrupts coming in quickly after one another or | |
495 | * even at the same time because we queue both TX status events and | |
496 | * RX frames to be processed by a tasklet and process them in the | |
497 | * same order that they were received or TX status last. Hence, there | |
498 | * is no race as long as the frame RX is processed before the next TX | |
499 | * status, which drivers can ensure, see below. | |
500 | * | |
501 | * Note that this can only happen if the hardware or firmware can | |
502 | * actually add STAs to the filter list, if this is done by the | |
503 | * driver in response to set_tim() (which will only reduce the race | |
504 | * this whole filtering tries to solve, not completely solve it) | |
505 | * this situation cannot happen. | |
506 | * | |
507 | * To completely solve this race drivers need to make sure that they | |
508 | * (a) don't mix the irq-safe/not irq-safe TX status/RX processing | |
509 | * functions and | |
510 | * (b) always process RX events before TX status events if ordering | |
511 | * can be unknown, for example with different interrupt status | |
512 | * bits. | |
513 | */ | |
07346f81 | 514 | if (test_sta_flags(sta, WLAN_STA_PS) && |
d46e144b | 515 | skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) { |
e039fa4a | 516 | ieee80211_remove_tx_extra(local, sta->key, skb); |
d46e144b JB |
517 | skb_queue_tail(&sta->tx_filtered, skb); |
518 | return; | |
519 | } | |
520 | ||
07346f81 | 521 | if (!test_sta_flags(sta, WLAN_STA_PS) && |
e039fa4a | 522 | !(info->flags & IEEE80211_TX_CTL_REQUEUE)) { |
d46e144b | 523 | /* Software retry the packet once */ |
e039fa4a JB |
524 | info->flags |= IEEE80211_TX_CTL_REQUEUE; |
525 | ieee80211_remove_tx_extra(local, sta->key, skb); | |
d46e144b JB |
526 | dev_queue_xmit(skb); |
527 | return; | |
528 | } | |
529 | ||
f4ea83dd | 530 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
d46e144b JB |
531 | if (net_ratelimit()) |
532 | printk(KERN_DEBUG "%s: dropped TX filtered frame, " | |
533 | "queue_len=%d PS=%d @%lu\n", | |
534 | wiphy_name(local->hw.wiphy), | |
535 | skb_queue_len(&sta->tx_filtered), | |
07346f81 | 536 | !!test_sta_flags(sta, WLAN_STA_PS), jiffies); |
f4ea83dd | 537 | #endif |
d46e144b JB |
538 | dev_kfree_skb(skb); |
539 | } | |
540 | ||
e039fa4a | 541 | void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) |
f0706e82 JB |
542 | { |
543 | struct sk_buff *skb2; | |
544 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
545 | struct ieee80211_local *local = hw_to_local(hw); | |
e039fa4a | 546 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
f0706e82 | 547 | u16 frag, type; |
429a3805 | 548 | __le16 fc; |
4b7679a5 | 549 | struct ieee80211_supported_band *sband; |
b306f453 JB |
550 | struct ieee80211_tx_status_rtap_hdr *rthdr; |
551 | struct ieee80211_sub_if_data *sdata; | |
3d30d949 | 552 | struct net_device *prev_dev = NULL; |
429a3805 | 553 | struct sta_info *sta; |
f0706e82 | 554 | |
d0709a65 JB |
555 | rcu_read_lock(); |
556 | ||
95dac040 JB |
557 | sta = sta_info_get(local, hdr->addr1); |
558 | ||
559 | if (sta) { | |
560 | if (info->status.excessive_retries && | |
561 | test_sta_flags(sta, WLAN_STA_PS)) { | |
562 | /* | |
563 | * The STA is in power save mode, so assume | |
564 | * that this TX packet failed because of that. | |
565 | */ | |
566 | ieee80211_handle_filtered_frame(local, sta, skb); | |
567 | rcu_read_unlock(); | |
568 | return; | |
f0706e82 | 569 | } |
f0706e82 | 570 | |
95dac040 JB |
571 | fc = hdr->frame_control; |
572 | ||
573 | if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) && | |
574 | (ieee80211_is_data_qos(fc))) { | |
575 | u16 tid, ssn; | |
576 | u8 *qc; | |
429a3805 | 577 | |
429a3805 RR |
578 | qc = ieee80211_get_qos_ctl(hdr); |
579 | tid = qc[0] & 0xf; | |
580 | ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10) | |
581 | & IEEE80211_SCTL_SEQ); | |
f698d856 | 582 | ieee80211_send_bar(sta->sdata, hdr->addr1, |
429a3805 RR |
583 | tid, ssn); |
584 | } | |
429a3805 | 585 | |
95dac040 | 586 | if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) { |
e039fa4a | 587 | ieee80211_handle_filtered_frame(local, sta, skb); |
d0709a65 | 588 | rcu_read_unlock(); |
f0706e82 | 589 | return; |
95dac040 JB |
590 | } else { |
591 | if (info->status.excessive_retries) | |
592 | sta->tx_retry_failed++; | |
593 | sta->tx_retry_count += info->status.retry_count; | |
f0706e82 | 594 | } |
95dac040 | 595 | |
4b7679a5 JB |
596 | sband = local->hw.wiphy->bands[info->band]; |
597 | rate_control_tx_status(local, sband, sta, skb); | |
95dac040 | 598 | } |
f0706e82 | 599 | |
d0709a65 JB |
600 | rcu_read_unlock(); |
601 | ||
f0706e82 JB |
602 | ieee80211_led_tx(local, 0); |
603 | ||
604 | /* SNMP counters | |
605 | * Fragments are passed to low-level drivers as separate skbs, so these | |
606 | * are actually fragments, not frames. Update frame counters only for | |
607 | * the first fragment of the frame. */ | |
608 | ||
609 | frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; | |
610 | type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE; | |
611 | ||
e039fa4a | 612 | if (info->flags & IEEE80211_TX_STAT_ACK) { |
f0706e82 JB |
613 | if (frag == 0) { |
614 | local->dot11TransmittedFrameCount++; | |
615 | if (is_multicast_ether_addr(hdr->addr1)) | |
616 | local->dot11MulticastTransmittedFrameCount++; | |
e039fa4a | 617 | if (info->status.retry_count > 0) |
f0706e82 | 618 | local->dot11RetryCount++; |
e039fa4a | 619 | if (info->status.retry_count > 1) |
f0706e82 JB |
620 | local->dot11MultipleRetryCount++; |
621 | } | |
622 | ||
623 | /* This counter shall be incremented for an acknowledged MPDU | |
624 | * with an individual address in the address 1 field or an MPDU | |
625 | * with a multicast address in the address 1 field of type Data | |
626 | * or Management. */ | |
627 | if (!is_multicast_ether_addr(hdr->addr1) || | |
628 | type == IEEE80211_FTYPE_DATA || | |
629 | type == IEEE80211_FTYPE_MGMT) | |
630 | local->dot11TransmittedFragmentCount++; | |
631 | } else { | |
632 | if (frag == 0) | |
633 | local->dot11FailedCount++; | |
634 | } | |
635 | ||
b306f453 JB |
636 | /* this was a transmitted frame, but now we want to reuse it */ |
637 | skb_orphan(skb); | |
638 | ||
3d30d949 MW |
639 | /* |
640 | * This is a bit racy but we can avoid a lot of work | |
641 | * with this test... | |
642 | */ | |
643 | if (!local->monitors && !local->cooked_mntrs) { | |
f0706e82 JB |
644 | dev_kfree_skb(skb); |
645 | return; | |
646 | } | |
647 | ||
b306f453 | 648 | /* send frame to monitor interfaces now */ |
f0706e82 | 649 | |
b306f453 JB |
650 | if (skb_headroom(skb) < sizeof(*rthdr)) { |
651 | printk(KERN_ERR "ieee80211_tx_status: headroom too small\n"); | |
f0706e82 JB |
652 | dev_kfree_skb(skb); |
653 | return; | |
654 | } | |
f0706e82 | 655 | |
988c0f72 | 656 | rthdr = (struct ieee80211_tx_status_rtap_hdr *) |
b306f453 JB |
657 | skb_push(skb, sizeof(*rthdr)); |
658 | ||
659 | memset(rthdr, 0, sizeof(*rthdr)); | |
660 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); | |
661 | rthdr->hdr.it_present = | |
662 | cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) | | |
663 | (1 << IEEE80211_RADIOTAP_DATA_RETRIES)); | |
664 | ||
e039fa4a | 665 | if (!(info->flags & IEEE80211_TX_STAT_ACK) && |
b306f453 JB |
666 | !is_multicast_ether_addr(hdr->addr1)) |
667 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL); | |
668 | ||
e039fa4a JB |
669 | if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) && |
670 | (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) | |
b306f453 | 671 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS); |
e039fa4a | 672 | else if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) |
b306f453 JB |
673 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS); |
674 | ||
e039fa4a | 675 | rthdr->data_retries = info->status.retry_count; |
b306f453 | 676 | |
3d30d949 MW |
677 | /* XXX: is this sufficient for BPF? */ |
678 | skb_set_mac_header(skb, 0); | |
679 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
680 | skb->pkt_type = PACKET_OTHERHOST; | |
681 | skb->protocol = htons(ETH_P_802_2); | |
682 | memset(skb->cb, 0, sizeof(skb->cb)); | |
683 | ||
79010420 | 684 | rcu_read_lock(); |
79010420 | 685 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
05c914fe | 686 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
b306f453 JB |
687 | if (!netif_running(sdata->dev)) |
688 | continue; | |
3d30d949 MW |
689 | |
690 | if (prev_dev) { | |
79010420 | 691 | skb2 = skb_clone(skb, GFP_ATOMIC); |
3d30d949 MW |
692 | if (skb2) { |
693 | skb2->dev = prev_dev; | |
694 | netif_rx(skb2); | |
695 | } | |
696 | } | |
697 | ||
698 | prev_dev = sdata->dev; | |
b306f453 JB |
699 | } |
700 | } | |
3d30d949 MW |
701 | if (prev_dev) { |
702 | skb->dev = prev_dev; | |
703 | netif_rx(skb); | |
704 | skb = NULL; | |
705 | } | |
79010420 | 706 | rcu_read_unlock(); |
3d30d949 | 707 | dev_kfree_skb(skb); |
f0706e82 JB |
708 | } |
709 | EXPORT_SYMBOL(ieee80211_tx_status); | |
710 | ||
f0706e82 JB |
711 | struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, |
712 | const struct ieee80211_ops *ops) | |
713 | { | |
f0706e82 | 714 | struct ieee80211_local *local; |
f0706e82 JB |
715 | int priv_size; |
716 | struct wiphy *wiphy; | |
717 | ||
718 | /* Ensure 32-byte alignment of our private data and hw private data. | |
719 | * We use the wiphy priv data for both our ieee80211_local and for | |
720 | * the driver's private data | |
721 | * | |
722 | * In memory it'll be like this: | |
723 | * | |
724 | * +-------------------------+ | |
725 | * | struct wiphy | | |
726 | * +-------------------------+ | |
727 | * | struct ieee80211_local | | |
728 | * +-------------------------+ | |
729 | * | driver's private data | | |
730 | * +-------------------------+ | |
731 | * | |
732 | */ | |
733 | priv_size = ((sizeof(struct ieee80211_local) + | |
734 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) + | |
735 | priv_data_len; | |
736 | ||
737 | wiphy = wiphy_new(&mac80211_config_ops, priv_size); | |
738 | ||
739 | if (!wiphy) | |
740 | return NULL; | |
741 | ||
742 | wiphy->privid = mac80211_wiphy_privid; | |
743 | ||
744 | local = wiphy_priv(wiphy); | |
745 | local->hw.wiphy = wiphy; | |
746 | ||
747 | local->hw.priv = (char *)local + | |
748 | ((sizeof(struct ieee80211_local) + | |
749 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST); | |
750 | ||
4480f15c | 751 | BUG_ON(!ops->tx); |
4150c572 JB |
752 | BUG_ON(!ops->start); |
753 | BUG_ON(!ops->stop); | |
4480f15c JB |
754 | BUG_ON(!ops->config); |
755 | BUG_ON(!ops->add_interface); | |
4150c572 JB |
756 | BUG_ON(!ops->remove_interface); |
757 | BUG_ON(!ops->configure_filter); | |
f0706e82 JB |
758 | local->ops = ops; |
759 | ||
f0706e82 JB |
760 | local->hw.queues = 1; /* default */ |
761 | ||
f0706e82 JB |
762 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
763 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
764 | local->short_retry_limit = 7; | |
765 | local->long_retry_limit = 4; | |
766 | local->hw.conf.radio_enabled = 1; | |
f0706e82 | 767 | |
79010420 | 768 | INIT_LIST_HEAD(&local->interfaces); |
f0706e82 | 769 | |
b16bd15c JB |
770 | spin_lock_init(&local->key_lock); |
771 | ||
c2b13452 | 772 | INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); |
f0706e82 JB |
773 | |
774 | sta_info_init(local); | |
775 | ||
f0706e82 JB |
776 | tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, |
777 | (unsigned long)local); | |
778 | tasklet_disable(&local->tx_pending_tasklet); | |
779 | ||
780 | tasklet_init(&local->tasklet, | |
781 | ieee80211_tasklet_handler, | |
782 | (unsigned long) local); | |
783 | tasklet_disable(&local->tasklet); | |
784 | ||
785 | skb_queue_head_init(&local->skb_queue); | |
786 | skb_queue_head_init(&local->skb_queue_unreliable); | |
787 | ||
788 | return local_to_hw(local); | |
789 | } | |
790 | EXPORT_SYMBOL(ieee80211_alloc_hw); | |
791 | ||
792 | int ieee80211_register_hw(struct ieee80211_hw *hw) | |
793 | { | |
794 | struct ieee80211_local *local = hw_to_local(hw); | |
795 | const char *name; | |
796 | int result; | |
8318d78a | 797 | enum ieee80211_band band; |
96d51056 | 798 | struct net_device *mdev; |
133b8226 | 799 | struct ieee80211_master_priv *mpriv; |
8318d78a JB |
800 | |
801 | /* | |
802 | * generic code guarantees at least one band, | |
803 | * set this very early because much code assumes | |
804 | * that hw.conf.channel is assigned | |
805 | */ | |
806 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
807 | struct ieee80211_supported_band *sband; | |
808 | ||
809 | sband = local->hw.wiphy->bands[band]; | |
810 | if (sband) { | |
811 | /* init channel we're on */ | |
812 | local->hw.conf.channel = | |
813 | local->oper_channel = | |
814 | local->scan_channel = &sband->channels[0]; | |
815 | break; | |
816 | } | |
817 | } | |
f0706e82 | 818 | |
f59ac048 LR |
819 | /* if low-level driver supports AP, we also support VLAN */ |
820 | if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) | |
821 | local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN); | |
822 | ||
823 | /* mac80211 always supports monitor */ | |
824 | local->hw.wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR); | |
825 | ||
f0706e82 JB |
826 | result = wiphy_register(local->hw.wiphy); |
827 | if (result < 0) | |
828 | return result; | |
829 | ||
e2530083 JB |
830 | /* |
831 | * We use the number of queues for feature tests (QoS, HT) internally | |
832 | * so restrict them appropriately. | |
833 | */ | |
e2530083 JB |
834 | if (hw->queues > IEEE80211_MAX_QUEUES) |
835 | hw->queues = IEEE80211_MAX_QUEUES; | |
836 | if (hw->ampdu_queues > IEEE80211_MAX_AMPDU_QUEUES) | |
837 | hw->ampdu_queues = IEEE80211_MAX_AMPDU_QUEUES; | |
838 | if (hw->queues < 4) | |
839 | hw->ampdu_queues = 0; | |
e2530083 | 840 | |
133b8226 | 841 | mdev = alloc_netdev_mq(sizeof(struct ieee80211_master_priv), |
e2530083 JB |
842 | "wmaster%d", ether_setup, |
843 | ieee80211_num_queues(hw)); | |
96d51056 JB |
844 | if (!mdev) |
845 | goto fail_mdev_alloc; | |
846 | ||
133b8226 JB |
847 | mpriv = netdev_priv(mdev); |
848 | mpriv->local = local; | |
96d51056 JB |
849 | local->mdev = mdev; |
850 | ||
3e122be0 | 851 | ieee80211_rx_bss_list_init(local); |
96d51056 JB |
852 | |
853 | mdev->hard_start_xmit = ieee80211_master_start_xmit; | |
854 | mdev->open = ieee80211_master_open; | |
855 | mdev->stop = ieee80211_master_stop; | |
856 | mdev->type = ARPHRD_IEEE80211; | |
857 | mdev->header_ops = &ieee80211_header_ops; | |
858 | mdev->set_multicast_list = ieee80211_master_set_multicast_list; | |
859 | ||
f0706e82 | 860 | name = wiphy_dev(local->hw.wiphy)->driver->name; |
59959a61 | 861 | local->hw.workqueue = create_freezeable_workqueue(name); |
f0706e82 JB |
862 | if (!local->hw.workqueue) { |
863 | result = -ENOMEM; | |
864 | goto fail_workqueue; | |
865 | } | |
866 | ||
b306f453 JB |
867 | /* |
868 | * The hardware needs headroom for sending the frame, | |
869 | * and we need some headroom for passing the frame to monitor | |
870 | * interfaces, but never both at the same time. | |
871 | */ | |
33ccad35 JB |
872 | local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom, |
873 | sizeof(struct ieee80211_tx_status_rtap_hdr)); | |
b306f453 | 874 | |
e9f207f0 JB |
875 | debugfs_hw_add(local); |
876 | ||
dc0ae30c TW |
877 | if (local->hw.conf.beacon_int < 10) |
878 | local->hw.conf.beacon_int = 100; | |
f0706e82 | 879 | |
ea95bba4 TW |
880 | if (local->hw.max_listen_interval == 0) |
881 | local->hw.max_listen_interval = 1; | |
882 | ||
883 | local->hw.conf.listen_interval = local->hw.max_listen_interval; | |
884 | ||
566bfe5a BR |
885 | local->wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC | |
886 | IEEE80211_HW_SIGNAL_DB | | |
887 | IEEE80211_HW_SIGNAL_DBM) ? | |
f0706e82 | 888 | IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID; |
566bfe5a | 889 | local->wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ? |
f0706e82 | 890 | IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID; |
566bfe5a | 891 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
f0706e82 JB |
892 | local->wstats_flags |= IW_QUAL_DBM; |
893 | ||
894 | result = sta_info_start(local); | |
895 | if (result < 0) | |
896 | goto fail_sta_info; | |
897 | ||
898 | rtnl_lock(); | |
899 | result = dev_alloc_name(local->mdev, local->mdev->name); | |
900 | if (result < 0) | |
901 | goto fail_dev; | |
902 | ||
903 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); | |
904 | SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy)); | |
905 | ||
906 | result = register_netdevice(local->mdev); | |
907 | if (result < 0) | |
908 | goto fail_dev; | |
909 | ||
830f9038 JB |
910 | result = ieee80211_init_rate_ctrl_alg(local, |
911 | hw->rate_control_algorithm); | |
f0706e82 JB |
912 | if (result < 0) { |
913 | printk(KERN_DEBUG "%s: Failed to initialize rate control " | |
dd1cd4c6 | 914 | "algorithm\n", wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
915 | goto fail_rate; |
916 | } | |
917 | ||
918 | result = ieee80211_wep_init(local); | |
919 | ||
920 | if (result < 0) { | |
023a04be JF |
921 | printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n", |
922 | wiphy_name(local->hw.wiphy), result); | |
f0706e82 JB |
923 | goto fail_wep; |
924 | } | |
925 | ||
51cb6db0 | 926 | local->mdev->select_queue = ieee80211_select_queue; |
f0706e82 JB |
927 | |
928 | /* add one default STA interface */ | |
3e122be0 | 929 | result = ieee80211_if_add(local, "wlan%d", NULL, |
05c914fe | 930 | NL80211_IFTYPE_STATION, NULL); |
f0706e82 JB |
931 | if (result) |
932 | printk(KERN_WARNING "%s: Failed to add default virtual iface\n", | |
dd1cd4c6 | 933 | wiphy_name(local->hw.wiphy)); |
f0706e82 | 934 | |
f0706e82 JB |
935 | rtnl_unlock(); |
936 | ||
937 | ieee80211_led_init(local); | |
938 | ||
939 | return 0; | |
940 | ||
941 | fail_wep: | |
942 | rate_control_deinitialize(local); | |
943 | fail_rate: | |
944 | unregister_netdevice(local->mdev); | |
339a7c41 | 945 | local->mdev = NULL; |
f0706e82 JB |
946 | fail_dev: |
947 | rtnl_unlock(); | |
948 | sta_info_stop(local); | |
949 | fail_sta_info: | |
e9f207f0 | 950 | debugfs_hw_del(local); |
f0706e82 JB |
951 | destroy_workqueue(local->hw.workqueue); |
952 | fail_workqueue: | |
3e122be0 JB |
953 | if (local->mdev) |
954 | free_netdev(local->mdev); | |
96d51056 | 955 | fail_mdev_alloc: |
f0706e82 JB |
956 | wiphy_unregister(local->hw.wiphy); |
957 | return result; | |
958 | } | |
959 | EXPORT_SYMBOL(ieee80211_register_hw); | |
960 | ||
f0706e82 JB |
961 | void ieee80211_unregister_hw(struct ieee80211_hw *hw) |
962 | { | |
963 | struct ieee80211_local *local = hw_to_local(hw); | |
f0706e82 JB |
964 | |
965 | tasklet_kill(&local->tx_pending_tasklet); | |
966 | tasklet_kill(&local->tasklet); | |
967 | ||
968 | rtnl_lock(); | |
969 | ||
79010420 JB |
970 | /* |
971 | * At this point, interface list manipulations are fine | |
972 | * because the driver cannot be handing us frames any | |
973 | * more and the tasklet is killed. | |
974 | */ | |
5b2812e9 | 975 | |
75636525 JB |
976 | /* First, we remove all virtual interfaces. */ |
977 | ieee80211_remove_interfaces(local); | |
5b2812e9 JB |
978 | |
979 | /* then, finally, remove the master interface */ | |
3e122be0 | 980 | unregister_netdevice(local->mdev); |
f0706e82 JB |
981 | |
982 | rtnl_unlock(); | |
983 | ||
3e122be0 | 984 | ieee80211_rx_bss_list_deinit(local); |
f0706e82 JB |
985 | ieee80211_clear_tx_pending(local); |
986 | sta_info_stop(local); | |
987 | rate_control_deinitialize(local); | |
e9f207f0 | 988 | debugfs_hw_del(local); |
f0706e82 | 989 | |
f0706e82 JB |
990 | if (skb_queue_len(&local->skb_queue) |
991 | || skb_queue_len(&local->skb_queue_unreliable)) | |
992 | printk(KERN_WARNING "%s: skb_queue not empty\n", | |
dd1cd4c6 | 993 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
994 | skb_queue_purge(&local->skb_queue); |
995 | skb_queue_purge(&local->skb_queue_unreliable); | |
996 | ||
997 | destroy_workqueue(local->hw.workqueue); | |
998 | wiphy_unregister(local->hw.wiphy); | |
999 | ieee80211_wep_free(local); | |
1000 | ieee80211_led_exit(local); | |
3e122be0 | 1001 | free_netdev(local->mdev); |
f0706e82 JB |
1002 | } |
1003 | EXPORT_SYMBOL(ieee80211_unregister_hw); | |
1004 | ||
1005 | void ieee80211_free_hw(struct ieee80211_hw *hw) | |
1006 | { | |
1007 | struct ieee80211_local *local = hw_to_local(hw); | |
1008 | ||
f0706e82 JB |
1009 | wiphy_free(local->hw.wiphy); |
1010 | } | |
1011 | EXPORT_SYMBOL(ieee80211_free_hw); | |
1012 | ||
f0706e82 JB |
1013 | static int __init ieee80211_init(void) |
1014 | { | |
1015 | struct sk_buff *skb; | |
1016 | int ret; | |
1017 | ||
e039fa4a JB |
1018 | BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb)); |
1019 | BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) + | |
c6a1fa12 | 1020 | IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb)); |
f0706e82 | 1021 | |
cccf129f FF |
1022 | ret = rc80211_minstrel_init(); |
1023 | if (ret) | |
1024 | return ret; | |
1025 | ||
4b475898 | 1026 | ret = rc80211_pid_init(); |
ad018375 | 1027 | if (ret) |
51cb6db0 | 1028 | return ret; |
f0706e82 | 1029 | |
e9f207f0 JB |
1030 | ieee80211_debugfs_netdev_init(); |
1031 | ||
f0706e82 JB |
1032 | return 0; |
1033 | } | |
1034 | ||
f0706e82 JB |
1035 | static void __exit ieee80211_exit(void) |
1036 | { | |
4b475898 | 1037 | rc80211_pid_exit(); |
cccf129f | 1038 | rc80211_minstrel_exit(); |
ac71c691 | 1039 | |
3b96766f JB |
1040 | /* |
1041 | * For key todo, it'll be empty by now but the work | |
1042 | * might still be scheduled. | |
1043 | */ | |
1044 | flush_scheduled_work(); | |
1045 | ||
f7a92144 LCC |
1046 | if (mesh_allocated) |
1047 | ieee80211s_stop(); | |
902acc78 | 1048 | |
e9f207f0 | 1049 | ieee80211_debugfs_netdev_exit(); |
f0706e82 JB |
1050 | } |
1051 | ||
1052 | ||
ca9938fe | 1053 | subsys_initcall(ieee80211_init); |
f0706e82 JB |
1054 | module_exit(ieee80211_exit); |
1055 | ||
1056 | MODULE_DESCRIPTION("IEEE 802.11 subsystem"); | |
1057 | MODULE_LICENSE("GPL"); |