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 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12 #include <net/mac80211.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/rtnetlink.h>
22 #include <linux/bitmap.h>
23 #include <linux/inetdevice.h>
24 #include <net/net_namespace.h>
25 #include <net/cfg80211.h>
26 #include <net/addrconf.h>
27
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
30 #include "rate.h"
31 #include "mesh.h"
32 #include "wep.h"
33 #include "led.h"
34 #include "debugfs.h"
35
ieee80211_configure_filter(struct ieee80211_local * local)36 void ieee80211_configure_filter(struct ieee80211_local *local)
37 {
38 u64 mc;
39 unsigned int changed_flags;
40 unsigned int new_flags = 0;
41
42 if (atomic_read(&local->iff_allmultis))
43 new_flags |= FIF_ALLMULTI;
44
45 if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
46 test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
47 new_flags |= FIF_BCN_PRBRESP_PROMISC;
48
49 if (local->fif_probe_req || local->probe_req_reg)
50 new_flags |= FIF_PROBE_REQ;
51
52 if (local->fif_fcsfail)
53 new_flags |= FIF_FCSFAIL;
54
55 if (local->fif_plcpfail)
56 new_flags |= FIF_PLCPFAIL;
57
58 if (local->fif_control)
59 new_flags |= FIF_CONTROL;
60
61 if (local->fif_other_bss)
62 new_flags |= FIF_OTHER_BSS;
63
64 if (local->fif_pspoll)
65 new_flags |= FIF_PSPOLL;
66
67 spin_lock_bh(&local->filter_lock);
68 changed_flags = local->filter_flags ^ new_flags;
69
70 mc = drv_prepare_multicast(local, &local->mc_list);
71 spin_unlock_bh(&local->filter_lock);
72
73 /* be a bit nasty */
74 new_flags |= (1<<31);
75
76 drv_configure_filter(local, changed_flags, &new_flags, mc);
77
78 WARN_ON(new_flags & (1<<31));
79
80 local->filter_flags = new_flags & ~(1<<31);
81 }
82
ieee80211_reconfig_filter(struct work_struct * work)83 static void ieee80211_reconfig_filter(struct work_struct *work)
84 {
85 struct ieee80211_local *local =
86 container_of(work, struct ieee80211_local, reconfig_filter);
87
88 ieee80211_configure_filter(local);
89 }
90
ieee80211_hw_conf_chan(struct ieee80211_local * local)91 static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
92 {
93 struct ieee80211_sub_if_data *sdata;
94 struct cfg80211_chan_def chandef = {};
95 u32 changed = 0;
96 int power;
97 u32 offchannel_flag;
98
99 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
100
101 if (local->scan_chandef.chan) {
102 chandef = local->scan_chandef;
103 } else if (local->tmp_channel) {
104 chandef.chan = local->tmp_channel;
105 chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
106 chandef.center_freq1 = chandef.chan->center_freq;
107 } else
108 chandef = local->_oper_chandef;
109
110 WARN(!cfg80211_chandef_valid(&chandef),
111 "control:%d MHz width:%d center: %d/%d MHz",
112 chandef.chan->center_freq, chandef.width,
113 chandef.center_freq1, chandef.center_freq2);
114
115 if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
116 local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
117 else
118 local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
119
120 offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
121
122 if (offchannel_flag ||
123 !cfg80211_chandef_identical(&local->hw.conf.chandef,
124 &local->_oper_chandef)) {
125 local->hw.conf.chandef = chandef;
126 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
127 }
128
129 if (!conf_is_ht(&local->hw.conf)) {
130 /*
131 * mac80211.h documents that this is only valid
132 * when the channel is set to an HT type, and
133 * that otherwise STATIC is used.
134 */
135 local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
136 } else if (local->hw.conf.smps_mode != local->smps_mode) {
137 local->hw.conf.smps_mode = local->smps_mode;
138 changed |= IEEE80211_CONF_CHANGE_SMPS;
139 }
140
141 power = ieee80211_chandef_max_power(&chandef);
142
143 rcu_read_lock();
144 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
145 if (!rcu_access_pointer(sdata->vif.chanctx_conf))
146 continue;
147 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
148 continue;
149 power = min(power, sdata->vif.bss_conf.txpower);
150 }
151 rcu_read_unlock();
152
153 if (local->hw.conf.power_level != power) {
154 changed |= IEEE80211_CONF_CHANGE_POWER;
155 local->hw.conf.power_level = power;
156 }
157
158 return changed;
159 }
160
ieee80211_hw_config(struct ieee80211_local * local,u32 changed)161 int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
162 {
163 int ret = 0;
164
165 might_sleep();
166
167 if (!local->use_chanctx)
168 changed |= ieee80211_hw_conf_chan(local);
169 else
170 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
171 IEEE80211_CONF_CHANGE_POWER);
172
173 if (changed && local->open_count) {
174 ret = drv_config(local, changed);
175 /*
176 * Goal:
177 * HW reconfiguration should never fail, the driver has told
178 * us what it can support so it should live up to that promise.
179 *
180 * Current status:
181 * rfkill is not integrated with mac80211 and a
182 * configuration command can thus fail if hardware rfkill
183 * is enabled
184 *
185 * FIXME: integrate rfkill with mac80211 and then add this
186 * WARN_ON() back
187 *
188 */
189 /* WARN_ON(ret); */
190 }
191
192 return ret;
193 }
194
ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data * sdata,u32 changed)195 void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
196 u32 changed)
197 {
198 struct ieee80211_local *local = sdata->local;
199
200 if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
201 return;
202
203 drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
204 }
205
ieee80211_reset_erp_info(struct ieee80211_sub_if_data * sdata)206 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
207 {
208 sdata->vif.bss_conf.use_cts_prot = false;
209 sdata->vif.bss_conf.use_short_preamble = false;
210 sdata->vif.bss_conf.use_short_slot = false;
211 return BSS_CHANGED_ERP_CTS_PROT |
212 BSS_CHANGED_ERP_PREAMBLE |
213 BSS_CHANGED_ERP_SLOT;
214 }
215
ieee80211_tasklet_handler(unsigned long data)216 static void ieee80211_tasklet_handler(unsigned long data)
217 {
218 struct ieee80211_local *local = (struct ieee80211_local *) data;
219 struct sk_buff *skb;
220
221 while ((skb = skb_dequeue(&local->skb_queue)) ||
222 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
223 switch (skb->pkt_type) {
224 case IEEE80211_RX_MSG:
225 /* Clear skb->pkt_type in order to not confuse kernel
226 * netstack. */
227 skb->pkt_type = 0;
228 ieee80211_rx(&local->hw, skb);
229 break;
230 case IEEE80211_TX_STATUS_MSG:
231 skb->pkt_type = 0;
232 ieee80211_tx_status(&local->hw, skb);
233 break;
234 default:
235 WARN(1, "mac80211: Packet is of unknown type %d\n",
236 skb->pkt_type);
237 dev_kfree_skb(skb);
238 break;
239 }
240 }
241 }
242
ieee80211_restart_work(struct work_struct * work)243 static void ieee80211_restart_work(struct work_struct *work)
244 {
245 struct ieee80211_local *local =
246 container_of(work, struct ieee80211_local, restart_work);
247 struct ieee80211_sub_if_data *sdata;
248
249 /* wait for scan work complete */
250 flush_workqueue(local->workqueue);
251
252 WARN(test_bit(SCAN_HW_SCANNING, &local->scanning),
253 "%s called with hardware scan in progress\n", __func__);
254
255 rtnl_lock();
256 list_for_each_entry(sdata, &local->interfaces, list) {
257 /*
258 * XXX: there may be more work for other vif types and even
259 * for station mode: a good thing would be to run most of
260 * the iface type's dependent _stop (ieee80211_mg_stop,
261 * ieee80211_ibss_stop) etc...
262 * For now, fix only the specific bug that was seen: race
263 * between csa_connection_drop_work and us.
264 */
265 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
266 /*
267 * This worker is scheduled from the iface worker that
268 * runs on mac80211's workqueue, so we can't be
269 * scheduling this worker after the cancel right here.
270 * The exception is ieee80211_chswitch_done.
271 * Then we can have a race...
272 */
273 cancel_work_sync(&sdata->u.mgd.csa_connection_drop_work);
274 }
275 flush_delayed_work(&sdata->dec_tailroom_needed_wk);
276 }
277 ieee80211_scan_cancel(local);
278 ieee80211_reconfig(local);
279 rtnl_unlock();
280 }
281
ieee80211_restart_hw(struct ieee80211_hw * hw)282 void ieee80211_restart_hw(struct ieee80211_hw *hw)
283 {
284 struct ieee80211_local *local = hw_to_local(hw);
285
286 trace_api_restart_hw(local);
287
288 wiphy_info(hw->wiphy,
289 "Hardware restart was requested\n");
290
291 /* use this reason, ieee80211_reconfig will unblock it */
292 ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
293 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
294 false);
295
296 /*
297 * Stop all Rx during the reconfig. We don't want state changes
298 * or driver callbacks while this is in progress.
299 */
300 local->in_reconfig = true;
301 barrier();
302
303 queue_work(system_freezable_wq, &local->restart_work);
304 }
305 EXPORT_SYMBOL(ieee80211_restart_hw);
306
307 #ifdef CONFIG_INET
ieee80211_ifa_changed(struct notifier_block * nb,unsigned long data,void * arg)308 static int ieee80211_ifa_changed(struct notifier_block *nb,
309 unsigned long data, void *arg)
310 {
311 struct in_ifaddr *ifa = arg;
312 struct ieee80211_local *local =
313 container_of(nb, struct ieee80211_local,
314 ifa_notifier);
315 struct net_device *ndev = ifa->ifa_dev->dev;
316 struct wireless_dev *wdev = ndev->ieee80211_ptr;
317 struct in_device *idev;
318 struct ieee80211_sub_if_data *sdata;
319 struct ieee80211_bss_conf *bss_conf;
320 struct ieee80211_if_managed *ifmgd;
321 int c = 0;
322
323 /* Make sure it's our interface that got changed */
324 if (!wdev)
325 return NOTIFY_DONE;
326
327 if (wdev->wiphy != local->hw.wiphy)
328 return NOTIFY_DONE;
329
330 sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
331 bss_conf = &sdata->vif.bss_conf;
332
333 /* ARP filtering is only supported in managed mode */
334 if (sdata->vif.type != NL80211_IFTYPE_STATION)
335 return NOTIFY_DONE;
336
337 idev = __in_dev_get_rtnl(sdata->dev);
338 if (!idev)
339 return NOTIFY_DONE;
340
341 ifmgd = &sdata->u.mgd;
342 sdata_lock(sdata);
343
344 /* Copy the addresses to the bss_conf list */
345 ifa = idev->ifa_list;
346 while (ifa) {
347 if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
348 bss_conf->arp_addr_list[c] = ifa->ifa_address;
349 ifa = ifa->ifa_next;
350 c++;
351 }
352
353 bss_conf->arp_addr_cnt = c;
354
355 /* Configure driver only if associated (which also implies it is up) */
356 if (ifmgd->associated)
357 ieee80211_bss_info_change_notify(sdata,
358 BSS_CHANGED_ARP_FILTER);
359
360 sdata_unlock(sdata);
361
362 return NOTIFY_OK;
363 }
364 #endif
365
366 #if IS_ENABLED(CONFIG_IPV6)
ieee80211_ifa6_changed(struct notifier_block * nb,unsigned long data,void * arg)367 static int ieee80211_ifa6_changed(struct notifier_block *nb,
368 unsigned long data, void *arg)
369 {
370 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
371 struct inet6_dev *idev = ifa->idev;
372 struct net_device *ndev = ifa->idev->dev;
373 struct ieee80211_local *local =
374 container_of(nb, struct ieee80211_local, ifa6_notifier);
375 struct wireless_dev *wdev = ndev->ieee80211_ptr;
376 struct ieee80211_sub_if_data *sdata;
377
378 /* Make sure it's our interface that got changed */
379 if (!wdev || wdev->wiphy != local->hw.wiphy)
380 return NOTIFY_DONE;
381
382 sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
383
384 /*
385 * For now only support station mode. This is mostly because
386 * doing AP would have to handle AP_VLAN in some way ...
387 */
388 if (sdata->vif.type != NL80211_IFTYPE_STATION)
389 return NOTIFY_DONE;
390
391 drv_ipv6_addr_change(local, sdata, idev);
392
393 return NOTIFY_OK;
394 }
395 #endif
396
397 /* There isn't a lot of sense in it, but you can transmit anything you like */
398 static const struct ieee80211_txrx_stypes
399 ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
400 [NL80211_IFTYPE_ADHOC] = {
401 .tx = 0xffff,
402 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
403 BIT(IEEE80211_STYPE_AUTH >> 4) |
404 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
405 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
406 },
407 [NL80211_IFTYPE_STATION] = {
408 .tx = 0xffff,
409 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
410 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
411 },
412 [NL80211_IFTYPE_AP] = {
413 .tx = 0xffff,
414 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
415 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
416 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
417 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
418 BIT(IEEE80211_STYPE_AUTH >> 4) |
419 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
420 BIT(IEEE80211_STYPE_ACTION >> 4),
421 },
422 [NL80211_IFTYPE_AP_VLAN] = {
423 /* copy AP */
424 .tx = 0xffff,
425 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
426 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
427 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
428 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
429 BIT(IEEE80211_STYPE_AUTH >> 4) |
430 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
431 BIT(IEEE80211_STYPE_ACTION >> 4),
432 },
433 [NL80211_IFTYPE_P2P_CLIENT] = {
434 .tx = 0xffff,
435 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
436 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
437 },
438 [NL80211_IFTYPE_P2P_GO] = {
439 .tx = 0xffff,
440 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
441 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
442 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
443 BIT(IEEE80211_STYPE_DISASSOC >> 4) |
444 BIT(IEEE80211_STYPE_AUTH >> 4) |
445 BIT(IEEE80211_STYPE_DEAUTH >> 4) |
446 BIT(IEEE80211_STYPE_ACTION >> 4),
447 },
448 [NL80211_IFTYPE_MESH_POINT] = {
449 .tx = 0xffff,
450 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
451 BIT(IEEE80211_STYPE_AUTH >> 4) |
452 BIT(IEEE80211_STYPE_DEAUTH >> 4),
453 },
454 [NL80211_IFTYPE_P2P_DEVICE] = {
455 .tx = 0xffff,
456 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
457 BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
458 },
459 };
460
461 static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
462 .ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
463 IEEE80211_HT_AMPDU_PARM_DENSITY,
464
465 .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
466 IEEE80211_HT_CAP_MAX_AMSDU |
467 IEEE80211_HT_CAP_SGI_20 |
468 IEEE80211_HT_CAP_SGI_40 |
469 IEEE80211_HT_CAP_LDPC_CODING |
470 IEEE80211_HT_CAP_40MHZ_INTOLERANT),
471 .mcs = {
472 .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
473 0xff, 0xff, 0xff, 0xff, 0xff, },
474 },
475 };
476
477 static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
478 .vht_cap_info =
479 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
480 IEEE80211_VHT_CAP_SHORT_GI_80 |
481 IEEE80211_VHT_CAP_SHORT_GI_160 |
482 IEEE80211_VHT_CAP_RXSTBC_MASK |
483 IEEE80211_VHT_CAP_TXSTBC |
484 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
485 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
486 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
487 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
488 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
489 .supp_mcs = {
490 .rx_mcs_map = cpu_to_le16(~0),
491 .tx_mcs_map = cpu_to_le16(~0),
492 },
493 };
494
ieee80211_alloc_hw_nm(size_t priv_data_len,const struct ieee80211_ops * ops,const char * requested_name)495 struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
496 const struct ieee80211_ops *ops,
497 const char *requested_name)
498 {
499 struct ieee80211_local *local;
500 int priv_size, i;
501 struct wiphy *wiphy;
502 bool use_chanctx;
503
504 if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
505 !ops->add_interface || !ops->remove_interface ||
506 !ops->configure_filter))
507 return NULL;
508
509 if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
510 return NULL;
511
512 /* check all or no channel context operations exist */
513 i = !!ops->add_chanctx + !!ops->remove_chanctx +
514 !!ops->change_chanctx + !!ops->assign_vif_chanctx +
515 !!ops->unassign_vif_chanctx;
516 if (WARN_ON(i != 0 && i != 5))
517 return NULL;
518 use_chanctx = i == 5;
519
520 /* Ensure 32-byte alignment of our private data and hw private data.
521 * We use the wiphy priv data for both our ieee80211_local and for
522 * the driver's private data
523 *
524 * In memory it'll be like this:
525 *
526 * +-------------------------+
527 * | struct wiphy |
528 * +-------------------------+
529 * | struct ieee80211_local |
530 * +-------------------------+
531 * | driver's private data |
532 * +-------------------------+
533 *
534 */
535 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
536
537 wiphy = wiphy_new_nm(&mac80211_config_ops, priv_size, requested_name);
538
539 if (!wiphy)
540 return NULL;
541
542 wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
543
544 wiphy->privid = mac80211_wiphy_privid;
545
546 wiphy->flags |= WIPHY_FLAG_NETNS_OK |
547 WIPHY_FLAG_4ADDR_AP |
548 WIPHY_FLAG_4ADDR_STATION |
549 WIPHY_FLAG_REPORTS_OBSS |
550 WIPHY_FLAG_OFFCHAN_TX;
551
552 if (ops->remain_on_channel)
553 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
554
555 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
556 NL80211_FEATURE_SAE |
557 NL80211_FEATURE_HT_IBSS |
558 NL80211_FEATURE_VIF_TXPOWER |
559 NL80211_FEATURE_MAC_ON_CREATE |
560 NL80211_FEATURE_USERSPACE_MPM;
561
562 if (!ops->hw_scan)
563 wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
564 NL80211_FEATURE_AP_SCAN;
565
566
567 if (!ops->set_key)
568 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
569
570 wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
571
572 local = wiphy_priv(wiphy);
573
574 if (sta_info_init(local))
575 goto err_free;
576
577 local->hw.wiphy = wiphy;
578
579 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
580
581 local->ops = ops;
582 local->use_chanctx = use_chanctx;
583
584 /* set up some defaults */
585 local->hw.queues = 1;
586 local->hw.max_rates = 1;
587 local->hw.max_report_rates = 0;
588 local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
589 local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
590 local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
591 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
592 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
593 local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
594 IEEE80211_RADIOTAP_MCS_HAVE_GI |
595 IEEE80211_RADIOTAP_MCS_HAVE_BW;
596 local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
597 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
598 local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
599 local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
600 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
601 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
602 wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
603
604 local->ext_capa[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF;
605
606 wiphy->extended_capabilities = local->ext_capa;
607 wiphy->extended_capabilities_mask = local->ext_capa;
608 wiphy->extended_capabilities_len =
609 ARRAY_SIZE(local->ext_capa);
610
611 INIT_LIST_HEAD(&local->interfaces);
612
613 __hw_addr_init(&local->mc_list);
614
615 mutex_init(&local->iflist_mtx);
616 mutex_init(&local->mtx);
617
618 mutex_init(&local->key_mtx);
619 spin_lock_init(&local->filter_lock);
620 spin_lock_init(&local->rx_path_lock);
621 spin_lock_init(&local->queue_stop_reason_lock);
622
623 INIT_LIST_HEAD(&local->chanctx_list);
624 mutex_init(&local->chanctx_mtx);
625
626 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
627
628 INIT_WORK(&local->restart_work, ieee80211_restart_work);
629
630 INIT_WORK(&local->radar_detected_work,
631 ieee80211_dfs_radar_detected_work);
632
633 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
634 local->smps_mode = IEEE80211_SMPS_OFF;
635
636 INIT_WORK(&local->dynamic_ps_enable_work,
637 ieee80211_dynamic_ps_enable_work);
638 INIT_WORK(&local->dynamic_ps_disable_work,
639 ieee80211_dynamic_ps_disable_work);
640 setup_timer(&local->dynamic_ps_timer,
641 ieee80211_dynamic_ps_timer, (unsigned long) local);
642
643 INIT_WORK(&local->sched_scan_stopped_work,
644 ieee80211_sched_scan_stopped_work);
645
646 INIT_WORK(&local->tdls_chsw_work, ieee80211_tdls_chsw_work);
647
648 spin_lock_init(&local->ack_status_lock);
649 idr_init(&local->ack_status_frames);
650
651 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
652 skb_queue_head_init(&local->pending[i]);
653 atomic_set(&local->agg_queue_stop[i], 0);
654 }
655 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
656 (unsigned long)local);
657
658 tasklet_init(&local->tasklet,
659 ieee80211_tasklet_handler,
660 (unsigned long) local);
661
662 skb_queue_head_init(&local->skb_queue);
663 skb_queue_head_init(&local->skb_queue_unreliable);
664 skb_queue_head_init(&local->skb_queue_tdls_chsw);
665
666 ieee80211_alloc_led_names(local);
667
668 ieee80211_roc_setup(local);
669
670 return &local->hw;
671 err_free:
672 wiphy_free(wiphy);
673 return NULL;
674 }
675 EXPORT_SYMBOL(ieee80211_alloc_hw_nm);
676
ieee80211_init_cipher_suites(struct ieee80211_local * local)677 static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
678 {
679 bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
680 IS_ERR(local->wep_rx_tfm));
681 bool have_mfp = ieee80211_hw_check(&local->hw, MFP_CAPABLE);
682 int n_suites = 0, r = 0, w = 0;
683 u32 *suites;
684 static const u32 cipher_suites[] = {
685 /* keep WEP first, it may be removed below */
686 WLAN_CIPHER_SUITE_WEP40,
687 WLAN_CIPHER_SUITE_WEP104,
688 WLAN_CIPHER_SUITE_TKIP,
689 WLAN_CIPHER_SUITE_CCMP,
690 WLAN_CIPHER_SUITE_CCMP_256,
691 WLAN_CIPHER_SUITE_GCMP,
692 WLAN_CIPHER_SUITE_GCMP_256,
693
694 /* keep last -- depends on hw flags! */
695 WLAN_CIPHER_SUITE_AES_CMAC,
696 WLAN_CIPHER_SUITE_BIP_CMAC_256,
697 WLAN_CIPHER_SUITE_BIP_GMAC_128,
698 WLAN_CIPHER_SUITE_BIP_GMAC_256,
699 };
700
701 if (ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL) ||
702 local->hw.wiphy->cipher_suites) {
703 /* If the driver advertises, or doesn't support SW crypto,
704 * we only need to remove WEP if necessary.
705 */
706 if (have_wep)
707 return 0;
708
709 /* well if it has _no_ ciphers ... fine */
710 if (!local->hw.wiphy->n_cipher_suites)
711 return 0;
712
713 /* Driver provides cipher suites, but we need to exclude WEP */
714 suites = kmemdup(local->hw.wiphy->cipher_suites,
715 sizeof(u32) * local->hw.wiphy->n_cipher_suites,
716 GFP_KERNEL);
717 if (!suites)
718 return -ENOMEM;
719
720 for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
721 u32 suite = local->hw.wiphy->cipher_suites[r];
722
723 if (suite == WLAN_CIPHER_SUITE_WEP40 ||
724 suite == WLAN_CIPHER_SUITE_WEP104)
725 continue;
726 suites[w++] = suite;
727 }
728 } else if (!local->hw.cipher_schemes) {
729 /* If the driver doesn't have cipher schemes, there's nothing
730 * else to do other than assign the (software supported and
731 * perhaps offloaded) cipher suites.
732 */
733 local->hw.wiphy->cipher_suites = cipher_suites;
734 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
735
736 if (!have_mfp)
737 local->hw.wiphy->n_cipher_suites -= 4;
738
739 if (!have_wep) {
740 local->hw.wiphy->cipher_suites += 2;
741 local->hw.wiphy->n_cipher_suites -= 2;
742 }
743
744 /* not dynamically allocated, so just return */
745 return 0;
746 } else {
747 const struct ieee80211_cipher_scheme *cs;
748
749 cs = local->hw.cipher_schemes;
750
751 /* Driver specifies cipher schemes only (but not cipher suites
752 * including the schemes)
753 *
754 * We start counting ciphers defined by schemes, TKIP, CCMP,
755 * CCMP-256, GCMP, and GCMP-256
756 */
757 n_suites = local->hw.n_cipher_schemes + 5;
758
759 /* check if we have WEP40 and WEP104 */
760 if (have_wep)
761 n_suites += 2;
762
763 /* check if we have AES_CMAC, BIP-CMAC-256, BIP-GMAC-128,
764 * BIP-GMAC-256
765 */
766 if (have_mfp)
767 n_suites += 4;
768
769 suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
770 if (!suites)
771 return -ENOMEM;
772
773 suites[w++] = WLAN_CIPHER_SUITE_CCMP;
774 suites[w++] = WLAN_CIPHER_SUITE_CCMP_256;
775 suites[w++] = WLAN_CIPHER_SUITE_TKIP;
776 suites[w++] = WLAN_CIPHER_SUITE_GCMP;
777 suites[w++] = WLAN_CIPHER_SUITE_GCMP_256;
778
779 if (have_wep) {
780 suites[w++] = WLAN_CIPHER_SUITE_WEP40;
781 suites[w++] = WLAN_CIPHER_SUITE_WEP104;
782 }
783
784 if (have_mfp) {
785 suites[w++] = WLAN_CIPHER_SUITE_AES_CMAC;
786 suites[w++] = WLAN_CIPHER_SUITE_BIP_CMAC_256;
787 suites[w++] = WLAN_CIPHER_SUITE_BIP_GMAC_128;
788 suites[w++] = WLAN_CIPHER_SUITE_BIP_GMAC_256;
789 }
790
791 for (r = 0; r < local->hw.n_cipher_schemes; r++) {
792 suites[w++] = cs[r].cipher;
793 if (WARN_ON(cs[r].pn_len > IEEE80211_MAX_PN_LEN)) {
794 kfree(suites);
795 return -EINVAL;
796 }
797 }
798 }
799
800 local->hw.wiphy->cipher_suites = suites;
801 local->hw.wiphy->n_cipher_suites = w;
802 local->wiphy_ciphers_allocated = true;
803
804 return 0;
805 }
806
ieee80211_register_hw(struct ieee80211_hw * hw)807 int ieee80211_register_hw(struct ieee80211_hw *hw)
808 {
809 struct ieee80211_local *local = hw_to_local(hw);
810 int result, i;
811 enum ieee80211_band band;
812 int channels, max_bitrates;
813 bool supp_ht, supp_vht;
814 netdev_features_t feature_whitelist;
815 struct cfg80211_chan_def dflt_chandef = {};
816
817 if (ieee80211_hw_check(hw, QUEUE_CONTROL) &&
818 (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
819 local->hw.offchannel_tx_hw_queue >= local->hw.queues))
820 return -EINVAL;
821
822 if ((hw->wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) &&
823 (!local->ops->tdls_channel_switch ||
824 !local->ops->tdls_cancel_channel_switch ||
825 !local->ops->tdls_recv_channel_switch))
826 return -EOPNOTSUPP;
827
828 #ifdef CONFIG_PM
829 if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
830 return -EINVAL;
831 #endif
832
833 if (!local->use_chanctx) {
834 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
835 const struct ieee80211_iface_combination *comb;
836
837 comb = &local->hw.wiphy->iface_combinations[i];
838
839 if (comb->num_different_channels > 1)
840 return -EINVAL;
841 }
842 } else {
843 /*
844 * WDS is currently prohibited when channel contexts are used
845 * because there's no clear definition of which channel WDS
846 * type interfaces use
847 */
848 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
849 return -EINVAL;
850
851 /* DFS is not supported with multi-channel combinations yet */
852 for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
853 const struct ieee80211_iface_combination *comb;
854
855 comb = &local->hw.wiphy->iface_combinations[i];
856
857 if (comb->radar_detect_widths &&
858 comb->num_different_channels > 1)
859 return -EINVAL;
860 }
861 }
862
863 /* Only HW csum features are currently compatible with mac80211 */
864 feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
865 NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_HIGHDMA |
866 NETIF_F_GSO_SOFTWARE;
867 if (WARN_ON(hw->netdev_features & ~feature_whitelist))
868 return -EINVAL;
869
870 if (hw->max_report_rates == 0)
871 hw->max_report_rates = hw->max_rates;
872
873 local->rx_chains = 1;
874
875 /*
876 * generic code guarantees at least one band,
877 * set this very early because much code assumes
878 * that hw.conf.channel is assigned
879 */
880 channels = 0;
881 max_bitrates = 0;
882 supp_ht = false;
883 supp_vht = false;
884 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
885 struct ieee80211_supported_band *sband;
886
887 sband = local->hw.wiphy->bands[band];
888 if (!sband)
889 continue;
890
891 if (!dflt_chandef.chan) {
892 /*
893 * Assign the first enabled channel to dflt_chandef
894 * from the list of channels
895 */
896 for (i = 0; i < sband->n_channels; i++)
897 if (!(sband->channels[i].flags &
898 IEEE80211_CHAN_DISABLED))
899 break;
900 /* if none found then use the first anyway */
901 if (i == sband->n_channels)
902 i = 0;
903 cfg80211_chandef_create(&dflt_chandef,
904 &sband->channels[i],
905 NL80211_CHAN_NO_HT);
906 /* init channel we're on */
907 if (!local->use_chanctx && !local->_oper_chandef.chan) {
908 local->hw.conf.chandef = dflt_chandef;
909 local->_oper_chandef = dflt_chandef;
910 }
911 local->monitor_chandef = dflt_chandef;
912 }
913
914 channels += sband->n_channels;
915
916 if (max_bitrates < sband->n_bitrates)
917 max_bitrates = sband->n_bitrates;
918 supp_ht = supp_ht || sband->ht_cap.ht_supported;
919 supp_vht = supp_vht || sband->vht_cap.vht_supported;
920
921 if (!sband->ht_cap.ht_supported)
922 continue;
923
924 /* TODO: consider VHT for RX chains, hopefully it's the same */
925 local->rx_chains =
926 max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
927 local->rx_chains);
928
929 /* no need to mask, SM_PS_DISABLED has all bits set */
930 sband->ht_cap.cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
931 IEEE80211_HT_CAP_SM_PS_SHIFT;
932 }
933
934 /* if low-level driver supports AP, we also support VLAN */
935 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
936 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
937 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
938 }
939
940 /* mac80211 always supports monitor */
941 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
942 hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
943
944 /* mac80211 doesn't support more than one IBSS interface right now */
945 for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
946 const struct ieee80211_iface_combination *c;
947 int j;
948
949 c = &hw->wiphy->iface_combinations[i];
950
951 for (j = 0; j < c->n_limits; j++)
952 if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
953 c->limits[j].max > 1)
954 return -EINVAL;
955 }
956
957 local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
958 sizeof(void *) * channels, GFP_KERNEL);
959 if (!local->int_scan_req)
960 return -ENOMEM;
961
962 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
963 if (!local->hw.wiphy->bands[band])
964 continue;
965 local->int_scan_req->rates[band] = (u32) -1;
966 }
967
968 #ifndef CONFIG_MAC80211_MESH
969 /* mesh depends on Kconfig, but drivers should set it if they want */
970 local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
971 #endif
972
973 /* if the underlying driver supports mesh, mac80211 will (at least)
974 * provide routing of mesh authentication frames to userspace */
975 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
976 local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
977
978 /* mac80211 supports control port protocol changing */
979 local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
980
981 if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) {
982 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
983 } else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC)) {
984 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
985 if (hw->max_signal <= 0) {
986 result = -EINVAL;
987 goto fail_wiphy_register;
988 }
989 }
990
991 /*
992 * Calculate scan IE length -- we need this to alloc
993 * memory and to subtract from the driver limit. It
994 * includes the DS Params, (extended) supported rates, and HT
995 * information -- SSID is the driver's responsibility.
996 */
997 local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
998 3 /* DS Params */;
999 if (supp_ht)
1000 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
1001
1002 if (supp_vht)
1003 local->scan_ies_len +=
1004 2 + sizeof(struct ieee80211_vht_cap);
1005
1006 if (!local->ops->hw_scan) {
1007 /* For hw_scan, driver needs to set these up. */
1008 local->hw.wiphy->max_scan_ssids = 4;
1009 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
1010 }
1011
1012 /*
1013 * If the driver supports any scan IEs, then assume the
1014 * limit includes the IEs mac80211 will add, otherwise
1015 * leave it at zero and let the driver sort it out; we
1016 * still pass our IEs to the driver but userspace will
1017 * not be allowed to in that case.
1018 */
1019 if (local->hw.wiphy->max_scan_ie_len)
1020 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
1021
1022 if (WARN_ON(!ieee80211_cs_list_valid(local->hw.cipher_schemes,
1023 local->hw.n_cipher_schemes))) {
1024 result = -EINVAL;
1025 goto fail_workqueue;
1026 }
1027
1028 result = ieee80211_init_cipher_suites(local);
1029 if (result < 0)
1030 goto fail_wiphy_register;
1031
1032 if (!local->ops->remain_on_channel)
1033 local->hw.wiphy->max_remain_on_channel_duration = 5000;
1034
1035 /* mac80211 based drivers don't support internal TDLS setup */
1036 if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
1037 local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
1038
1039 /* mac80211 supports eCSA, if the driver supports STA CSA at all */
1040 if (ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA))
1041 local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
1042
1043 local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
1044
1045 result = wiphy_register(local->hw.wiphy);
1046 if (result < 0)
1047 goto fail_wiphy_register;
1048
1049 /*
1050 * We use the number of queues for feature tests (QoS, HT) internally
1051 * so restrict them appropriately.
1052 */
1053 if (hw->queues > IEEE80211_MAX_QUEUES)
1054 hw->queues = IEEE80211_MAX_QUEUES;
1055
1056 local->workqueue =
1057 alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
1058 if (!local->workqueue) {
1059 result = -ENOMEM;
1060 goto fail_workqueue;
1061 }
1062
1063 /*
1064 * The hardware needs headroom for sending the frame,
1065 * and we need some headroom for passing the frame to monitor
1066 * interfaces, but never both at the same time.
1067 */
1068 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1069 IEEE80211_TX_STATUS_HEADROOM);
1070
1071 debugfs_hw_add(local);
1072
1073 /*
1074 * if the driver doesn't specify a max listen interval we
1075 * use 5 which should be a safe default
1076 */
1077 if (local->hw.max_listen_interval == 0)
1078 local->hw.max_listen_interval = 5;
1079
1080 local->hw.conf.listen_interval = local->hw.max_listen_interval;
1081
1082 local->dynamic_ps_forced_timeout = -1;
1083
1084 if (!local->hw.txq_ac_max_pending)
1085 local->hw.txq_ac_max_pending = 64;
1086
1087 result = ieee80211_wep_init(local);
1088 if (result < 0)
1089 wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
1090 result);
1091
1092 local->hw.conf.flags = IEEE80211_CONF_IDLE;
1093
1094 ieee80211_led_init(local);
1095
1096 rtnl_lock();
1097
1098 result = ieee80211_init_rate_ctrl_alg(local,
1099 hw->rate_control_algorithm);
1100 if (result < 0) {
1101 wiphy_debug(local->hw.wiphy,
1102 "Failed to initialize rate control algorithm\n");
1103 goto fail_rate;
1104 }
1105
1106 /* add one default STA interface if supported */
1107 if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
1108 !ieee80211_hw_check(hw, NO_AUTO_VIF)) {
1109 result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
1110 NL80211_IFTYPE_STATION, NULL);
1111 if (result)
1112 wiphy_warn(local->hw.wiphy,
1113 "Failed to add default virtual iface\n");
1114 }
1115
1116 rtnl_unlock();
1117
1118 #ifdef CONFIG_INET
1119 local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
1120 result = register_inetaddr_notifier(&local->ifa_notifier);
1121 if (result)
1122 goto fail_ifa;
1123 #endif
1124
1125 #if IS_ENABLED(CONFIG_IPV6)
1126 local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
1127 result = register_inet6addr_notifier(&local->ifa6_notifier);
1128 if (result)
1129 goto fail_ifa6;
1130 #endif
1131
1132 return 0;
1133
1134 #if IS_ENABLED(CONFIG_IPV6)
1135 fail_ifa6:
1136 #ifdef CONFIG_INET
1137 unregister_inetaddr_notifier(&local->ifa_notifier);
1138 #endif
1139 #endif
1140 #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
1141 fail_ifa:
1142 #endif
1143 rtnl_lock();
1144 rate_control_deinitialize(local);
1145 ieee80211_remove_interfaces(local);
1146 fail_rate:
1147 rtnl_unlock();
1148 ieee80211_led_exit(local);
1149 ieee80211_wep_free(local);
1150 destroy_workqueue(local->workqueue);
1151 fail_workqueue:
1152 wiphy_unregister(local->hw.wiphy);
1153 fail_wiphy_register:
1154 if (local->wiphy_ciphers_allocated)
1155 kfree(local->hw.wiphy->cipher_suites);
1156 kfree(local->int_scan_req);
1157 return result;
1158 }
1159 EXPORT_SYMBOL(ieee80211_register_hw);
1160
ieee80211_unregister_hw(struct ieee80211_hw * hw)1161 void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1162 {
1163 struct ieee80211_local *local = hw_to_local(hw);
1164
1165 tasklet_kill(&local->tx_pending_tasklet);
1166 tasklet_kill(&local->tasklet);
1167
1168 #ifdef CONFIG_INET
1169 unregister_inetaddr_notifier(&local->ifa_notifier);
1170 #endif
1171 #if IS_ENABLED(CONFIG_IPV6)
1172 unregister_inet6addr_notifier(&local->ifa6_notifier);
1173 #endif
1174
1175 rtnl_lock();
1176
1177 /*
1178 * At this point, interface list manipulations are fine
1179 * because the driver cannot be handing us frames any
1180 * more and the tasklet is killed.
1181 */
1182 ieee80211_remove_interfaces(local);
1183
1184 rtnl_unlock();
1185
1186 cancel_work_sync(&local->restart_work);
1187 cancel_work_sync(&local->reconfig_filter);
1188 cancel_work_sync(&local->tdls_chsw_work);
1189 flush_work(&local->sched_scan_stopped_work);
1190
1191 ieee80211_clear_tx_pending(local);
1192 rate_control_deinitialize(local);
1193
1194 if (skb_queue_len(&local->skb_queue) ||
1195 skb_queue_len(&local->skb_queue_unreliable))
1196 wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
1197 skb_queue_purge(&local->skb_queue);
1198 skb_queue_purge(&local->skb_queue_unreliable);
1199 skb_queue_purge(&local->skb_queue_tdls_chsw);
1200
1201 destroy_workqueue(local->workqueue);
1202 wiphy_unregister(local->hw.wiphy);
1203 ieee80211_wep_free(local);
1204 ieee80211_led_exit(local);
1205 kfree(local->int_scan_req);
1206 }
1207 EXPORT_SYMBOL(ieee80211_unregister_hw);
1208
ieee80211_free_ack_frame(int id,void * p,void * data)1209 static int ieee80211_free_ack_frame(int id, void *p, void *data)
1210 {
1211 WARN_ONCE(1, "Have pending ack frames!\n");
1212 kfree_skb(p);
1213 return 0;
1214 }
1215
ieee80211_free_hw(struct ieee80211_hw * hw)1216 void ieee80211_free_hw(struct ieee80211_hw *hw)
1217 {
1218 struct ieee80211_local *local = hw_to_local(hw);
1219
1220 mutex_destroy(&local->iflist_mtx);
1221 mutex_destroy(&local->mtx);
1222
1223 if (local->wiphy_ciphers_allocated)
1224 kfree(local->hw.wiphy->cipher_suites);
1225
1226 idr_for_each(&local->ack_status_frames,
1227 ieee80211_free_ack_frame, NULL);
1228 idr_destroy(&local->ack_status_frames);
1229
1230 sta_info_stop(local);
1231
1232 ieee80211_free_led_names(local);
1233
1234 wiphy_free(local->hw.wiphy);
1235 }
1236 EXPORT_SYMBOL(ieee80211_free_hw);
1237
ieee80211_init(void)1238 static int __init ieee80211_init(void)
1239 {
1240 struct sk_buff *skb;
1241 int ret;
1242
1243 BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1244 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1245 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
1246
1247 ret = rc80211_minstrel_init();
1248 if (ret)
1249 return ret;
1250
1251 ret = rc80211_minstrel_ht_init();
1252 if (ret)
1253 goto err_minstrel;
1254
1255 ret = ieee80211_iface_init();
1256 if (ret)
1257 goto err_netdev;
1258
1259 return 0;
1260 err_netdev:
1261 rc80211_minstrel_ht_exit();
1262 err_minstrel:
1263 rc80211_minstrel_exit();
1264
1265 return ret;
1266 }
1267
ieee80211_exit(void)1268 static void __exit ieee80211_exit(void)
1269 {
1270 rc80211_minstrel_ht_exit();
1271 rc80211_minstrel_exit();
1272
1273 ieee80211s_stop();
1274
1275 ieee80211_iface_exit();
1276
1277 rcu_barrier();
1278 }
1279
1280
1281 subsys_initcall(ieee80211_init);
1282 module_exit(ieee80211_exit);
1283
1284 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1285 MODULE_LICENSE("GPL");
1286