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