main.c revision e269d8600a8f6a9f2387b3f283bfb579a5479dc3
1f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc/*
2f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc * Copyright 2002-2005, Instant802 Networks, Inc.
3f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc * Copyright 2005-2006, Devicescape Software, Inc.
4f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
5f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc *
6f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc * This program is free software; you can redistribute it and/or modify
7f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc * it under the terms of the GNU General Public License version 2 as
8f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc * published by the Free Software Foundation.
9f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc */
10f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
11f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <net/mac80211.h>
12f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/module.h>
13f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/init.h>
14f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/netdevice.h>
15f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/types.h>
16f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/slab.h>
17f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/skbuff.h>
18f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/etherdevice.h>
19f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/if_arp.h>
20f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/rtnetlink.h>
21f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <linux/bitmap.h>
22e8db0be1245de16a6cc6365506abc392c3c212d4Jean Pihet#include <linux/pm_qos.h>
23685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen#include <linux/inetdevice.h>
24881d966b48b035ab3f3aeaae0f3d3f9b584f45b2Eric W. Biederman#include <net/net_namespace.h>
25f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include <net/cfg80211.h>
26f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
27f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include "ieee80211_i.h"
282448798133d747ad339e57099e32a1d1e68aca1cJohannes Berg#include "driver-ops.h"
292c8dccc77420fb7433da5674818959d3499d35beJohannes Berg#include "rate.h"
30f7a921443740d7dafc65b17aa32531730d358f50Luis Carlos Cobo#include "mesh.h"
31f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc#include "wep.h"
322c8dccc77420fb7433da5674818959d3499d35beJohannes Berg#include "led.h"
33e0eb68596232788bc352368f2fbc3cb088e42e41Michael Wu#include "cfg.h"
34e9f207f0ff90bf60b825800d7450e6f2ff2eab88Jiri Benc#include "debugfs.h"
35f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
36681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Bergstatic struct lock_class_key ieee80211_rx_skb_queue_class;
37681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg
380d143fe1e2efc084fa730d2dfa22d0d1ca2ee5f1Johannes Bergvoid ieee80211_configure_filter(struct ieee80211_local *local)
394150c57212ad134765dd78c654a4b9906252b66dJohannes Berg{
403ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	u64 mc;
414150c57212ad134765dd78c654a4b9906252b66dJohannes Berg	unsigned int changed_flags;
424150c57212ad134765dd78c654a4b9906252b66dJohannes Berg	unsigned int new_flags = 0;
434150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
4453918994b7c8c3bf0af5f641e1f299856799d883Johannes Berg	if (atomic_read(&local->iff_promiscs))
454150c57212ad134765dd78c654a4b9906252b66dJohannes Berg		new_flags |= FIF_PROMISC_IN_BSS;
464150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
4753918994b7c8c3bf0af5f641e1f299856799d883Johannes Berg	if (atomic_read(&local->iff_allmultis))
484150c57212ad134765dd78c654a4b9906252b66dJohannes Berg		new_flags |= FIF_ALLMULTI;
494150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
508a690674e0601efbe9a7b16a5826fc522645cca3Ben Greear	if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
518a690674e0601efbe9a7b16a5826fc522645cca3Ben Greear	    test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
528cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu		new_flags |= FIF_BCN_PRBRESP_PROMISC;
538cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu
547be5086d4cb7cceb71d724a9524d5e927785d04fJohannes Berg	if (local->fif_probe_req || local->probe_req_reg)
557be5086d4cb7cceb71d724a9524d5e927785d04fJohannes Berg		new_flags |= FIF_PROBE_REQ;
567be5086d4cb7cceb71d724a9524d5e927785d04fJohannes Berg
578cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu	if (local->fif_fcsfail)
588cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu		new_flags |= FIF_FCSFAIL;
598cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu
608cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu	if (local->fif_plcpfail)
618cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu		new_flags |= FIF_PLCPFAIL;
628cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu
638cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu	if (local->fif_control)
648cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu		new_flags |= FIF_CONTROL;
658cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu
668cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu	if (local->fif_other_bss)
678cc9a73914b07b5908d8a59320f4557fc9639f2eMichael Wu		new_flags |= FIF_OTHER_BSS;
684150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
69e3b90ca28412fb9dcc8c5ca38e179e78fec07eeeIgor Perminov	if (local->fif_pspoll)
70e3b90ca28412fb9dcc8c5ca38e179e78fec07eeeIgor Perminov		new_flags |= FIF_PSPOLL;
71e3b90ca28412fb9dcc8c5ca38e179e78fec07eeeIgor Perminov
723ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	spin_lock_bh(&local->filter_lock);
734150c57212ad134765dd78c654a4b9906252b66dJohannes Berg	changed_flags = local->filter_flags ^ new_flags;
744150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
7522bedad3ce112d5ca1eaf043d4990fa2ed698c87Jiri Pirko	mc = drv_prepare_multicast(local, &local->mc_list);
763ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	spin_unlock_bh(&local->filter_lock);
773ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg
784150c57212ad134765dd78c654a4b9906252b66dJohannes Berg	/* be a bit nasty */
794150c57212ad134765dd78c654a4b9906252b66dJohannes Berg	new_flags |= (1<<31);
804150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
813ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	drv_configure_filter(local, changed_flags, &new_flags, mc);
824150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
834150c57212ad134765dd78c654a4b9906252b66dJohannes Berg	WARN_ON(new_flags & (1<<31));
844150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
854150c57212ad134765dd78c654a4b9906252b66dJohannes Berg	local->filter_flags = new_flags & ~(1<<31);
864150c57212ad134765dd78c654a4b9906252b66dJohannes Berg}
874150c57212ad134765dd78c654a4b9906252b66dJohannes Berg
883ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Bergstatic void ieee80211_reconfig_filter(struct work_struct *work)
893ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg{
903ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	struct ieee80211_local *local =
913ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg		container_of(work, struct ieee80211_local, reconfig_filter);
923ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg
933ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	ieee80211_configure_filter(local);
943ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg}
953ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg
96e8975581f63870be42ff4662b293d1b0c8c21350Johannes Bergint ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
97b2c258fb11b3fc77a73f8b0453ff1256de812bc6Johannes Berg{
985e5202a406896fb6d656d0e7d3f2f1cbfdda6384Stanislaw Gruszka	struct ieee80211_channel *chan;
99b2c258fb11b3fc77a73f8b0453ff1256de812bc6Johannes Berg	int ret = 0;
100e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg	int power;
101094d05dc32fc2930e381189a942016e5561775d9Sujith	enum nl80211_channel_type channel_type;
102ffd2778bb984afe3cc264e22a125c06587020aa3Felix Fietkau	u32 offchannel_flag;
103f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
104cb121bad67a32cde37adc2729b7e18aa4fd3063eJohannes Berg	might_sleep();
105cb121bad67a32cde37adc2729b7e18aa4fd3063eJohannes Berg
106ffd2778bb984afe3cc264e22a125c06587020aa3Felix Fietkau	offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
1075e5202a406896fb6d656d0e7d3f2f1cbfdda6384Stanislaw Gruszka	if (local->scan_channel) {
1085e5202a406896fb6d656d0e7d3f2f1cbfdda6384Stanislaw Gruszka		chan = local->scan_channel;
1094f2e9d91f84ce39698517203974ffc2bcc32a21dBen Greear		/* If scanning on oper channel, use whatever channel-type
1104f2e9d91f84ce39698517203974ffc2bcc32a21dBen Greear		 * is currently in use.
1114f2e9d91f84ce39698517203974ffc2bcc32a21dBen Greear		 */
1124f2e9d91f84ce39698517203974ffc2bcc32a21dBen Greear		if (chan == local->oper_channel)
1134f2e9d91f84ce39698517203974ffc2bcc32a21dBen Greear			channel_type = local->_oper_channel_type;
1144f2e9d91f84ce39698517203974ffc2bcc32a21dBen Greear		else
1154f2e9d91f84ce39698517203974ffc2bcc32a21dBen Greear			channel_type = NL80211_CHAN_NO_HT;
116b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear	} else if (local->tmp_channel) {
1175e5202a406896fb6d656d0e7d3f2f1cbfdda6384Stanislaw Gruszka		chan = local->tmp_channel;
118b8bc4b0aa9bfba755c64b11b8f60e6cfab25dc9dJohannes Berg		channel_type = local->tmp_channel_type;
11972bdcf34380917260da41e3c49e10edee04bc5cdJouni Malinen	} else {
120b2c258fb11b3fc77a73f8b0453ff1256de812bc6Johannes Berg		chan = local->oper_channel;
1210aaffa9b9699894aab3266195a529baf9f96ac29Johannes Berg		channel_type = local->_oper_channel_type;
12272bdcf34380917260da41e3c49e10edee04bc5cdJouni Malinen	}
123b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear
124b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear	if (chan != local->oper_channel ||
125b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear	    channel_type != local->_oper_channel_type)
126b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear		local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
127b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear	else
128b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear		local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
129b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear
130ffd2778bb984afe3cc264e22a125c06587020aa3Felix Fietkau	offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
131f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
132ffd2778bb984afe3cc264e22a125c06587020aa3Felix Fietkau	if (offchannel_flag || chan != local->hw.conf.channel ||
1334797938c5dfa22af30fd16679192972f878419a1Johannes Berg	    channel_type != local->hw.conf.channel_type) {
134e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg		local->hw.conf.channel = chan;
1354797938c5dfa22af30fd16679192972f878419a1Johannes Berg		local->hw.conf.channel_type = channel_type;
136e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg		changed |= IEEE80211_CONF_CHANGE_CHANNEL;
137e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg	}
1388318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg
1390f78231bffb868a30e8533aace142213266bb811Johannes Berg	if (!conf_is_ht(&local->hw.conf)) {
1400f78231bffb868a30e8533aace142213266bb811Johannes Berg		/*
1410f78231bffb868a30e8533aace142213266bb811Johannes Berg		 * mac80211.h documents that this is only valid
1420f78231bffb868a30e8533aace142213266bb811Johannes Berg		 * when the channel is set to an HT type, and
1430f78231bffb868a30e8533aace142213266bb811Johannes Berg		 * that otherwise STATIC is used.
1440f78231bffb868a30e8533aace142213266bb811Johannes Berg		 */
1450f78231bffb868a30e8533aace142213266bb811Johannes Berg		local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
1460f78231bffb868a30e8533aace142213266bb811Johannes Berg	} else if (local->hw.conf.smps_mode != local->smps_mode) {
1470f78231bffb868a30e8533aace142213266bb811Johannes Berg		local->hw.conf.smps_mode = local->smps_mode;
1480f78231bffb868a30e8533aace142213266bb811Johannes Berg		changed |= IEEE80211_CONF_CHANGE_SMPS;
1490f78231bffb868a30e8533aace142213266bb811Johannes Berg	}
1500f78231bffb868a30e8533aace142213266bb811Johannes Berg
151cd6c524e9e0b5ad8ce52bc3b4a3a1e272e3a8410Dmitry TARNYAGIN	if (test_bit(SCAN_SW_SCANNING, &local->scanning) ||
1528a690674e0601efbe9a7b16a5826fc522645cca3Ben Greear	    test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning) ||
15304b7b2ff50fc77380c1e711f1d7223734547e41bJohannes Berg	    test_bit(SCAN_HW_SCANNING, &local->scanning) ||
15404b7b2ff50fc77380c1e711f1d7223734547e41bJohannes Berg	    !local->ap_power_level)
155e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg		power = chan->max_power;
1568318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	else
15704b7b2ff50fc77380c1e711f1d7223734547e41bJohannes Berg		power = min(chan->max_power, local->ap_power_level);
158a8302de934b5d1897ff146cd0c7ab87d1417c092Vasanthakumar Thiagarajan
15947afbaf5af9454a7a1a64591e20cbfcc27ca67a8Johannes Berg	if (local->user_power_level >= 0)
160a8302de934b5d1897ff146cd0c7ab87d1417c092Vasanthakumar Thiagarajan		power = min(power, local->user_power_level);
161a8302de934b5d1897ff146cd0c7ab87d1417c092Vasanthakumar Thiagarajan
162e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg	if (local->hw.conf.power_level != power) {
163e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg		changed |= IEEE80211_CONF_CHANGE_POWER;
164e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg		local->hw.conf.power_level = power;
165e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg	}
166b2c258fb11b3fc77a73f8b0453ff1256de812bc6Johannes Berg
167e8975581f63870be42ff4662b293d1b0c8c21350Johannes Berg	if (changed && local->open_count) {
1682448798133d747ad339e57099e32a1d1e68aca1cJohannes Berg		ret = drv_config(local, changed);
169d73782fdde76554016abf73b46f843b29f520848Johannes Berg		/*
170447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 * Goal:
171d73782fdde76554016abf73b46f843b29f520848Johannes Berg		 * HW reconfiguration should never fail, the driver has told
172d73782fdde76554016abf73b46f843b29f520848Johannes Berg		 * us what it can support so it should live up to that promise.
173447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 *
174447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 * Current status:
175447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 * rfkill is not integrated with mac80211 and a
176447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 * configuration command can thus fail if hardware rfkill
177447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 * is enabled
178447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 *
179447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 * FIXME: integrate rfkill with mac80211 and then add this
180447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 * WARN_ON() back
181447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		 *
182d73782fdde76554016abf73b46f843b29f520848Johannes Berg		 */
183447107fb32d75425c95a33f58e6b4b760b470092Reinette Chatre		/* WARN_ON(ret); */
184d73782fdde76554016abf73b46f843b29f520848Johannes Berg	}
185f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
186b2c258fb11b3fc77a73f8b0453ff1256de812bc6Johannes Berg	return ret;
187b2c258fb11b3fc77a73f8b0453ff1256de812bc6Johannes Berg}
188f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
189471b3efdfccc257591331724145f8ccf8b3217e1Johannes Bergvoid ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
190471b3efdfccc257591331724145f8ccf8b3217e1Johannes Berg				      u32 changed)
191d9430a32886f70c0c16d67c525f6cda2df7906eeDaniel Drake{
192471b3efdfccc257591331724145f8ccf8b3217e1Johannes Berg	struct ieee80211_local *local = sdata->local;
1939cef873798dfcdc10ff40b02abf1de935ceeba85Johannes Berg	static const u8 zero[ETH_ALEN] = { 0 };
194471b3efdfccc257591331724145f8ccf8b3217e1Johannes Berg
195471b3efdfccc257591331724145f8ccf8b3217e1Johannes Berg	if (!changed)
196471b3efdfccc257591331724145f8ccf8b3217e1Johannes Berg		return;
197471b3efdfccc257591331724145f8ccf8b3217e1Johannes Berg
1989cef873798dfcdc10ff40b02abf1de935ceeba85Johannes Berg	if (sdata->vif.type == NL80211_IFTYPE_STATION) {
19966e67e418908442389d3a9e6509985f01cbaf9b0Johannes Berg		sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
2009cef873798dfcdc10ff40b02abf1de935ceeba85Johannes Berg	} else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
2012d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
2022d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	else if (sdata->vif.type == NL80211_IFTYPE_AP)
20347846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg		sdata->vif.bss_conf.bssid = sdata->vif.addr;
2041be7fe8de9f25e173282f8f989f83bc5b5decfe9Bill Jordan	else if (sdata->vif.type == NL80211_IFTYPE_WDS)
2051be7fe8de9f25e173282f8f989f83bc5b5decfe9Bill Jordan		sdata->vif.bss_conf.bssid = NULL;
2062d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2072d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		sdata->vif.bss_conf.bssid = zero;
208f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg	} else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
209f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg		sdata->vif.bss_conf.bssid = sdata->vif.addr;
210f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg		WARN_ONCE(changed & ~(BSS_CHANGED_IDLE),
211f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg			  "P2P Device BSS changed %#x", changed);
2122d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	} else {
2132d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		WARN_ON(1);
2142d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		return;
2152d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	}
2162d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg
2172d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	switch (sdata->vif.type) {
2182d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	case NL80211_IFTYPE_AP:
2192d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	case NL80211_IFTYPE_ADHOC:
2201be7fe8de9f25e173282f8f989f83bc5b5decfe9Bill Jordan	case NL80211_IFTYPE_WDS:
2212d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	case NL80211_IFTYPE_MESH_POINT:
2222d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		break;
2232d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	default:
2242d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		/* do not warn to simplify caller in scan.c */
2252d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		changed &= ~BSS_CHANGED_BEACON_ENABLED;
2262d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		if (WARN_ON(changed & BSS_CHANGED_BEACON))
2272d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			return;
2282d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		break;
2292d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	}
2302d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg
2312d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	if (changed & BSS_CHANGED_BEACON_ENABLED) {
2329607e6b66a0d25ca63b70d54a4283fa13d8f7c9dJohannes Berg		if (local->quiescing || !ieee80211_sdata_running(sdata) ||
233b23b025fe246f3acc2988eb6d400df34c27cb8aeBen Greear		    test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) {
2342d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			sdata->vif.bss_conf.enable_beacon = false;
2352d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		} else {
2362d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			/*
2372d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			 * Beacon should be enabled, but AP mode must
2382d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			 * check whether there is a beacon configured.
2392d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			 */
2402d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			switch (sdata->vif.type) {
2412d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			case NL80211_IFTYPE_AP:
2422d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				sdata->vif.bss_conf.enable_beacon =
2430379185b6c0d1e8252023698cf1091da92a3dc03Johannes Berg					!!sdata->u.ap.beacon;
2442d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				break;
2452d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			case NL80211_IFTYPE_ADHOC:
2462d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				sdata->vif.bss_conf.enable_beacon =
2470379185b6c0d1e8252023698cf1091da92a3dc03Johannes Berg					!!sdata->u.ibss.presp;
2482d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				break;
2497659a193f94c0003dd06e9e874d19bade1a8c952Javier Cardona#ifdef CONFIG_MAC80211_MESH
2502d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			case NL80211_IFTYPE_MESH_POINT:
25129cbe68c516a48a9a88b3226878570c6cbd83c02Johannes Berg				sdata->vif.bss_conf.enable_beacon =
25229cbe68c516a48a9a88b3226878570c6cbd83c02Johannes Berg					!!sdata->u.mesh.mesh_id_len;
2532d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				break;
2547659a193f94c0003dd06e9e874d19bade1a8c952Javier Cardona#endif
2552d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			default:
2562d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				/* not reached */
2572d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				WARN_ON(1);
2582d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg				break;
2592d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg			}
2602d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg		}
2612d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg	}
2622d0ddec5b2b859f06116f631fc0ffe94fbceb556Johannes Berg
26312375ef933fa8271396ed0c1e318cb1bd2e2689dJohannes Berg	drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
264d9430a32886f70c0c16d67c525f6cda2df7906eeDaniel Drake}
265d9430a32886f70c0c16d67c525f6cda2df7906eeDaniel Drake
266f698d856f65c3fea091cc303a135967965c5b880Jasper Bryant-Greeneu32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
267d9430a32886f70c0c16d67c525f6cda2df7906eeDaniel Drake{
268bda3933a8aceedd03e0dd410844bd310033ca756Johannes Berg	sdata->vif.bss_conf.use_cts_prot = false;
269bda3933a8aceedd03e0dd410844bd310033ca756Johannes Berg	sdata->vif.bss_conf.use_short_preamble = false;
270bda3933a8aceedd03e0dd410844bd310033ca756Johannes Berg	sdata->vif.bss_conf.use_short_slot = false;
2717a5158ef8da70fdedeb0530faaa8128aa645be3cJohannes Berg	return BSS_CHANGED_ERP_CTS_PROT |
2727a5158ef8da70fdedeb0530faaa8128aa645be3cJohannes Berg	       BSS_CHANGED_ERP_PREAMBLE |
2737a5158ef8da70fdedeb0530faaa8128aa645be3cJohannes Berg	       BSS_CHANGED_ERP_SLOT;
274d9430a32886f70c0c16d67c525f6cda2df7906eeDaniel Drake}
275d9430a32886f70c0c16d67c525f6cda2df7906eeDaniel Drake
276f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencstatic void ieee80211_tasklet_handler(unsigned long data)
277f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc{
278f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct ieee80211_local *local = (struct ieee80211_local *) data;
27937fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg	struct sta_info *sta, *tmp;
28037fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg	struct skb_eosp_msg_data *eosp_data;
281f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct sk_buff *skb;
282f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
283f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	while ((skb = skb_dequeue(&local->skb_queue)) ||
284f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	       (skb = skb_dequeue(&local->skb_queue_unreliable))) {
285f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		switch (skb->pkt_type) {
286f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		case IEEE80211_RX_MSG:
28751fb61e76d952e6bc2fbdd9f0d38425fbab1cf31Johannes Berg			/* Clear skb->pkt_type in order to not confuse kernel
288f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc			 * netstack. */
289f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc			skb->pkt_type = 0;
290005e472b45131250fe09c194f8b872b86fd266c1Johannes Berg			ieee80211_rx(&local->hw, skb);
291f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc			break;
292f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		case IEEE80211_TX_STATUS_MSG:
293f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc			skb->pkt_type = 0;
294005e472b45131250fe09c194f8b872b86fd266c1Johannes Berg			ieee80211_tx_status(&local->hw, skb);
295f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc			break;
29637fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg		case IEEE80211_EOSP_MSG:
29737fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg			eosp_data = (void *)skb->cb;
29837fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg			for_each_sta_info(local, eosp_data->sta, sta, tmp) {
29937fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg				/* skip wrong virtual interface */
30037fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg				if (memcmp(eosp_data->iface,
30137fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg					   sta->sdata->vif.addr, ETH_ALEN))
30237fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg					continue;
30337fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg				clear_sta_flag(sta, WLAN_STA_SP);
30437fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg				break;
30537fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg			}
30637fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg			dev_kfree_skb(skb);
30737fbd9080088f5f98ab81a6f2ad456857971a089Johannes Berg			break;
308f4ea83dd743d3e1bec8fdf954ac911c6b12ae87aJohannes Berg		default:
3095e3f308997f53d00e8cbebdb89d4f6e347aa963aLarry Finger			WARN(1, "mac80211: Packet is of unknown type %d\n",
3105e3f308997f53d00e8cbebdb89d4f6e347aa963aLarry Finger			     skb->pkt_type);
311f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc			dev_kfree_skb(skb);
312f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc			break;
313f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		}
314f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	}
315f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc}
316f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
317f2753ddbadb0873a98421415882318251bbd9eaaJohannes Bergstatic void ieee80211_restart_work(struct work_struct *work)
318f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg{
319f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	struct ieee80211_local *local =
320f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg		container_of(work, struct ieee80211_local, restart_work);
321f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg
322bc86863de63e6ae7ec6f9f524604631608c6cb02Stanislaw Gruszka	/* wait for scan work complete */
323bc86863de63e6ae7ec6f9f524604631608c6cb02Stanislaw Gruszka	flush_workqueue(local->workqueue);
324bc86863de63e6ae7ec6f9f524604631608c6cb02Stanislaw Gruszka
325bc86863de63e6ae7ec6f9f524604631608c6cb02Stanislaw Gruszka	mutex_lock(&local->mtx);
32679f460ca49d8d5700756ab7071c951311c7f29ccLuciano Coelho	WARN(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
3275260a5b2c3524f198ea062fe0a6a4faa724e6a9dJohannes Berg	     rcu_dereference_protected(local->sched_scan_sdata,
3285260a5b2c3524f198ea062fe0a6a4faa724e6a9dJohannes Berg				       lockdep_is_held(&local->mtx)),
329bc86863de63e6ae7ec6f9f524604631608c6cb02Stanislaw Gruszka		"%s called with hardware scan in progress\n", __func__);
330bc86863de63e6ae7ec6f9f524604631608c6cb02Stanislaw Gruszka	mutex_unlock(&local->mtx);
331bc86863de63e6ae7ec6f9f524604631608c6cb02Stanislaw Gruszka
332f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	rtnl_lock();
3334136c4224ccf1907d309e1cdfaefef9da97dbc5eStanislaw Gruszka	ieee80211_scan_cancel(local);
334f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	ieee80211_reconfig(local);
335f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	rtnl_unlock();
336f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg}
337f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg
338f2753ddbadb0873a98421415882318251bbd9eaaJohannes Bergvoid ieee80211_restart_hw(struct ieee80211_hw *hw)
339f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg{
340f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	struct ieee80211_local *local = hw_to_local(hw);
341f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg
342b5878a2dc5e7e7f031a52c3e15b571224cb6b540Johannes Berg	trace_api_restart_hw(local);
343b5878a2dc5e7e7f031a52c3e15b571224cb6b540Johannes Berg
344b196d031f2bb29c253050d554130e41c7e3cbfb0Michael Buesch	wiphy_info(hw->wiphy,
345b196d031f2bb29c253050d554130e41c7e3cbfb0Michael Buesch		   "Hardware restart was requested\n");
346b196d031f2bb29c253050d554130e41c7e3cbfb0Michael Buesch
34718145c69349f2ab60c470798f83b3a2639e2a8d9John W. Linville	/* use this reason, ieee80211_reconfig will unblock it */
348f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	ieee80211_stop_queues_by_reason(hw,
349f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg		IEEE80211_QUEUE_STOP_REASON_SUSPEND);
350f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg
35104800ada2acc3a9ffc754c1d73576cef326f3311Arik Nemtsov	/*
35204800ada2acc3a9ffc754c1d73576cef326f3311Arik Nemtsov	 * Stop all Rx during the reconfig. We don't want state changes
35304800ada2acc3a9ffc754c1d73576cef326f3311Arik Nemtsov	 * or driver callbacks while this is in progress.
35404800ada2acc3a9ffc754c1d73576cef326f3311Arik Nemtsov	 */
35504800ada2acc3a9ffc754c1d73576cef326f3311Arik Nemtsov	local->in_reconfig = true;
35604800ada2acc3a9ffc754c1d73576cef326f3311Arik Nemtsov	barrier();
35704800ada2acc3a9ffc754c1d73576cef326f3311Arik Nemtsov
358f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	schedule_work(&local->restart_work);
359f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg}
360f2753ddbadb0873a98421415882318251bbd9eaaJohannes BergEXPORT_SYMBOL(ieee80211_restart_hw);
361f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg
3620f78231bffb868a30e8533aace142213266bb811Johannes Bergstatic void ieee80211_recalc_smps_work(struct work_struct *work)
3630f78231bffb868a30e8533aace142213266bb811Johannes Berg{
3640f78231bffb868a30e8533aace142213266bb811Johannes Berg	struct ieee80211_local *local =
3650f78231bffb868a30e8533aace142213266bb811Johannes Berg		container_of(work, struct ieee80211_local, recalc_smps);
3660f78231bffb868a30e8533aace142213266bb811Johannes Berg
367025e6be220e448c02045e8499c7db8ce4bc8eea2Johannes Berg	ieee80211_recalc_smps(local);
3680f78231bffb868a30e8533aace142213266bb811Johannes Berg}
3690f78231bffb868a30e8533aace142213266bb811Johannes Berg
37026b36cfefaf2be98b225e3c1a399edb0daf52dddJohn W. Linville#ifdef CONFIG_INET
3712b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinenstatic int ieee80211_ifa_changed(struct notifier_block *nb,
3722b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen				 unsigned long data, void *arg)
3732b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen{
3742b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	struct in_ifaddr *ifa = arg;
3752b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	struct ieee80211_local *local =
3762b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen		container_of(nb, struct ieee80211_local,
3772b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen			     ifa_notifier);
3782b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	struct net_device *ndev = ifa->ifa_dev->dev;
3792b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	struct wireless_dev *wdev = ndev->ieee80211_ptr;
380685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	struct in_device *idev;
3812b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	struct ieee80211_sub_if_data *sdata;
382685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	struct ieee80211_bss_conf *bss_conf;
3832b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	struct ieee80211_if_managed *ifmgd;
384685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	int c = 0;
3852b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
3862b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	/* Make sure it's our interface that got changed */
3872b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	if (!wdev)
3882b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen		return NOTIFY_DONE;
3892b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
3902b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	if (wdev->wiphy != local->hw.wiphy)
3912b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen		return NOTIFY_DONE;
3922b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
3932b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
394685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	bss_conf = &sdata->vif.bss_conf;
3952b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
3962b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	/* ARP filtering is only supported in managed mode */
3972b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	if (sdata->vif.type != NL80211_IFTYPE_STATION)
3982b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen		return NOTIFY_DONE;
3992b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
40095ae6b228f814fc0528d0506ee9f18ac333d6851Eric Dumazet	idev = __in_dev_get_rtnl(sdata->dev);
401685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	if (!idev)
402685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		return NOTIFY_DONE;
403685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen
4042b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	ifmgd = &sdata->u.mgd;
4052b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	mutex_lock(&ifmgd->mtx);
406685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen
407685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	/* Copy the addresses to the bss_conf list */
408685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	ifa = idev->ifa_list;
409685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	while (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN && ifa) {
410685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		bss_conf->arp_addr_list[c] = ifa->ifa_address;
411685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		ifa = ifa->ifa_next;
412685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		c++;
413685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	}
414685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen
415685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	/* If not all addresses fit the list, disable filtering */
416685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	if (ifa) {
417685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		sdata->arp_filter_state = false;
418685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		c = 0;
419685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	} else {
420685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		sdata->arp_filter_state = true;
421685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	}
422685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	bss_conf->arp_addr_cnt = c;
423685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen
42453d69c399abf3b382c1e737ff9402d31ca5a7a51Eliad Peller	/* Configure driver only if associated (which also implies it is up) */
425685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	if (ifmgd->associated) {
426685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		bss_conf->arp_filter_enabled = sdata->arp_filter_state;
427685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen		ieee80211_bss_info_change_notify(sdata,
428685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen						 BSS_CHANGED_ARP_FILTER);
429685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen	}
430685429623f88d84f98bd5daffc3c427c408740d4Juuso Oikarinen
4312b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	mutex_unlock(&ifmgd->mtx);
4322b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
4332b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	return NOTIFY_DONE;
4342b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen}
43526b36cfefaf2be98b225e3c1a399edb0daf52dddJohn W. Linville#endif
4362b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
4374e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linvillestatic int ieee80211_napi_poll(struct napi_struct *napi, int budget)
4384e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville{
4394e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	struct ieee80211_local *local =
4404e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville		container_of(napi, struct ieee80211_local, napi);
4414e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
4424e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	return local->ops->napi_poll(&local->hw, budget);
4434e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville}
4444e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
4454e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linvillevoid ieee80211_napi_schedule(struct ieee80211_hw *hw)
4464e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville{
4474e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	struct ieee80211_local *local = hw_to_local(hw);
4484e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
4494e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	napi_schedule(&local->napi);
4504e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville}
4514e6cbfd09c66893e5134c9896e9af353c2322b66John W. LinvilleEXPORT_SYMBOL(ieee80211_napi_schedule);
4524e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
4534e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linvillevoid ieee80211_napi_complete(struct ieee80211_hw *hw)
4544e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville{
4554e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	struct ieee80211_local *local = hw_to_local(hw);
4564e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
4574e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	napi_complete(&local->napi);
4584e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville}
4594e6cbfd09c66893e5134c9896e9af353c2322b66John W. LinvilleEXPORT_SYMBOL(ieee80211_napi_complete);
4604e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
4612e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg/* There isn't a lot of sense in it, but you can transmit anything you like */
4622e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Bergstatic const struct ieee80211_txrx_stypes
4632e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Bergieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
4642e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	[NL80211_IFTYPE_ADHOC] = {
4652e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		.tx = 0xffff,
4663bfda62c50b0a4b118dcfce36686508ca2892292Will Hawkins		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
4673bfda62c50b0a4b118dcfce36686508ca2892292Will Hawkins			BIT(IEEE80211_STYPE_AUTH >> 4) |
4683bfda62c50b0a4b118dcfce36686508ca2892292Will Hawkins			BIT(IEEE80211_STYPE_DEAUTH >> 4),
4692e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	},
4702e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	[NL80211_IFTYPE_STATION] = {
4712e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		.tx = 0xffff,
4722e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
4732e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
4742e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	},
4752e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	[NL80211_IFTYPE_AP] = {
4762e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		.tx = 0xffff,
4772e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
4782e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
4792e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
4802e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_DISASSOC >> 4) |
4812e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_AUTH >> 4) |
4822e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_DEAUTH >> 4) |
4832e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_ACTION >> 4),
4842e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	},
4852e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	[NL80211_IFTYPE_AP_VLAN] = {
4862e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		/* copy AP */
4872e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		.tx = 0xffff,
4882e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg		.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
4892e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
4902e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
4912e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_DISASSOC >> 4) |
4922e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_AUTH >> 4) |
4932e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_DEAUTH >> 4) |
4942ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg			BIT(IEEE80211_STYPE_ACTION >> 4),
4952ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg	},
4962ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg	[NL80211_IFTYPE_P2P_CLIENT] = {
4972ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg		.tx = 0xffff,
4982ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
4992ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg			BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
5002ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg	},
5012ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg	[NL80211_IFTYPE_P2P_GO] = {
5022ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg		.tx = 0xffff,
5032ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg		.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5042ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg			BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5052ca27bcff7127da1aa7dd39cd2a6f7cb187e327fJohannes Berg			BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5062e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5072e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_AUTH >> 4) |
5082e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5092e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg			BIT(IEEE80211_STYPE_ACTION >> 4),
5102e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	},
511c7108a7111cd9e592d6ad498be37276dbea75d2bJavier Cardona	[NL80211_IFTYPE_MESH_POINT] = {
512c7108a7111cd9e592d6ad498be37276dbea75d2bJavier Cardona		.tx = 0xffff,
51371839121a0f35f9968d2e204a76eb22683156fd8Javier Cardona		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
51471839121a0f35f9968d2e204a76eb22683156fd8Javier Cardona			BIT(IEEE80211_STYPE_AUTH >> 4) |
51571839121a0f35f9968d2e204a76eb22683156fd8Javier Cardona			BIT(IEEE80211_STYPE_DEAUTH >> 4),
516c7108a7111cd9e592d6ad498be37276dbea75d2bJavier Cardona	},
517f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg	[NL80211_IFTYPE_P2P_DEVICE] = {
518f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg		.tx = 0xffff,
519f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
520f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg			BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
521f142c6b906da451ded2c7a8e17b2a0e6fee3e891Johannes Berg	},
5222e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg};
5232e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg
524ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greearstatic const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
525ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear	.ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
526ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear			     IEEE80211_HT_AMPDU_PARM_DENSITY,
527ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear
528ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear	.cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
529ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear				IEEE80211_HT_CAP_MAX_AMSDU |
530ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear				IEEE80211_HT_CAP_SGI_40),
531ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear	.mcs = {
532ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear		.rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
533ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear			     0xff, 0xff, 0xff, 0xff, 0xff, },
534ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear	},
535ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear};
536ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear
537f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencstruct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
538f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc					const struct ieee80211_ops *ops)
539f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc{
540f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct ieee80211_local *local;
54196f5e66e8a79810e2982cdcfa28e554f3d97da21Johannes Berg	int priv_size, i;
542f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct wiphy *wiphy;
543f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
544c0af07340aae5db9f976bfe71e2e9bcab3169409Johannes Berg	if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
545c0af07340aae5db9f976bfe71e2e9bcab3169409Johannes Berg		    !ops->add_interface || !ops->remove_interface ||
546c0af07340aae5db9f976bfe71e2e9bcab3169409Johannes Berg		    !ops->configure_filter))
547c0af07340aae5db9f976bfe71e2e9bcab3169409Johannes Berg		return NULL;
548c0af07340aae5db9f976bfe71e2e9bcab3169409Johannes Berg
549f09603a259ffef69ad4516a04eb06cd65ac522feJohannes Berg	if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
550f09603a259ffef69ad4516a04eb06cd65ac522feJohannes Berg		return NULL;
551f09603a259ffef69ad4516a04eb06cd65ac522feJohannes Berg
552e269d8600a8f6a9f2387b3f283bfb579a5479dc3Johannes Berg	/* check all or no channel context operations exist */
553e269d8600a8f6a9f2387b3f283bfb579a5479dc3Johannes Berg	i = !!ops->add_chanctx + !!ops->remove_chanctx +
554e269d8600a8f6a9f2387b3f283bfb579a5479dc3Johannes Berg	    !!ops->change_chanctx + !!ops->assign_vif_chanctx +
555e269d8600a8f6a9f2387b3f283bfb579a5479dc3Johannes Berg	    !!ops->unassign_vif_chanctx;
556e269d8600a8f6a9f2387b3f283bfb579a5479dc3Johannes Berg	if (WARN_ON(i != 0 && i != 5))
557e269d8600a8f6a9f2387b3f283bfb579a5479dc3Johannes Berg		return NULL;
558e269d8600a8f6a9f2387b3f283bfb579a5479dc3Johannes Berg
559f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	/* Ensure 32-byte alignment of our private data and hw private data.
560f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * We use the wiphy priv data for both our ieee80211_local and for
561f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * the driver's private data
562f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 *
563f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * In memory it'll be like this:
564f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 *
565f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * +-------------------------+
566f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * | struct wiphy	    |
567f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * +-------------------------+
568f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * | struct ieee80211_local  |
569f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * +-------------------------+
570f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * | driver's private data   |
571f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 * +-------------------------+
572f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 *
573f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	 */
5741ce8e7b57b3a4527ef83da1c5c7bd8a6b9d87b56Eric Dumazet	priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
575f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
576f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	wiphy = wiphy_new(&mac80211_config_ops, priv_size);
577f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
578f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	if (!wiphy)
579f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		return NULL;
580f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
5812e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg	wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
5822e161f78e5f63a7f9fd25a766bb7f816a01eb14aJohannes Berg
583207aba6018a7b1757b5248ced2b280d20790c498Johannes Berg	wiphy->privid = mac80211_wiphy_privid;
584207aba6018a7b1757b5248ced2b280d20790c498Johannes Berg
5859bc383de37090ba7ca3ff32a12c9d809dc5867f0Johannes Berg	wiphy->flags |= WIPHY_FLAG_NETNS_OK |
5869bc383de37090ba7ca3ff32a12c9d809dc5867f0Johannes Berg			WIPHY_FLAG_4ADDR_AP |
587ee971924543fe82f279d3e97f6f6d02320b381b7Johannes Berg			WIPHY_FLAG_4ADDR_STATION |
5887c4ef7122cef54dc49562eea35cbfaf0f44faa0bJohannes Berg			WIPHY_FLAG_REPORTS_OBSS |
58981ddbb5c1188dfaa98c67832a751117fcacda75dJohannes Berg			WIPHY_FLAG_OFFCHAN_TX;
59081ddbb5c1188dfaa98c67832a751117fcacda75dJohannes Berg
59181ddbb5c1188dfaa98c67832a751117fcacda75dJohannes Berg	if (ops->remain_on_channel)
59281ddbb5c1188dfaa98c67832a751117fcacda75dJohannes Berg		wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
593207aba6018a7b1757b5248ced2b280d20790c498Johannes Berg
59413c40c54682ffe62977f670681268a26d500d6faAlexander Simon	wiphy->features = NL80211_FEATURE_SK_TX_STATUS |
59513c40c54682ffe62977f670681268a26d500d6faAlexander Simon			  NL80211_FEATURE_HT_IBSS;
596a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg
597207aba6018a7b1757b5248ced2b280d20790c498Johannes Berg	if (!ops->set_key)
598207aba6018a7b1757b5248ced2b280d20790c498Johannes Berg		wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
59918a8365992a8041aa178ae9ad5f0d951d0457230Johannes Berg
6000c1ad2cac1cb54db38fd4cc1822965071ee83f6eJohannes Berg	wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
601f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
602f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	local = wiphy_priv(wiphy);
603de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg
604f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	local->hw.wiphy = wiphy;
605f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
6061ce8e7b57b3a4527ef83da1c5c7bd8a6b9d87b56Eric Dumazet	local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
607f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
608f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	local->ops = ops;
609f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
610e6a9854b05c1a6af1308fe2b8c68f35abf28a3eeJohannes Berg	/* set up some defaults */
611e6a9854b05c1a6af1308fe2b8c68f35abf28a3eeJohannes Berg	local->hw.queues = 1;
612e6a9854b05c1a6af1308fe2b8c68f35abf28a3eeJohannes Berg	local->hw.max_rates = 1;
61378be49ec2a0df34de9441930fdced20311fd709fHelmut Schaa	local->hw.max_report_rates = 0;
614df6ba5d80d6c9b51471d5fa046c3c06988e5f62aLuciano Coelho	local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
61539e68712d75700ec09770c7ad9e8e4abc65db7c6Helmut Schaa	local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
6163a25a8c8b75b430c4f4022918e26fa51d557ecdeJohannes Berg	local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
617b9a5f8cab751d362f7c2d94899ca788c22fcd1efJouni Malinen	local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
618b9a5f8cab751d362f7c2d94899ca788c22fcd1efJouni Malinen	local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
619ac55d2fe0576d272c4a98ed9dfb87b1cca29486eJohannes Berg	local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
620ac55d2fe0576d272c4a98ed9dfb87b1cca29486eJohannes Berg					 IEEE80211_RADIOTAP_MCS_HAVE_GI |
621ac55d2fe0576d272c4a98ed9dfb87b1cca29486eJohannes Berg					 IEEE80211_RADIOTAP_MCS_HAVE_BW;
622c428c89201a57a0ce24c37ed79e540d1f4101cf3Johannes Berg	local->user_power_level = -1;
623ef96a84202ccfb48a4569256ffba45e32308f7eeBen Greear	wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
624f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
62579010420cc3f78eab911598bfdd29c4b06a83e1fJohannes Berg	INIT_LIST_HEAD(&local->interfaces);
6262f787b0b76bf5de2eaa3ca3a29d89123ae03c856YOSHIFUJI Hideaki / 吉藤英明
6272f787b0b76bf5de2eaa3ca3a29d89123ae03c856YOSHIFUJI Hideaki / 吉藤英明	__hw_addr_init(&local->mc_list);
6282f787b0b76bf5de2eaa3ca3a29d89123ae03c856YOSHIFUJI Hideaki / 吉藤英明
629c771c9d8da1e8292ef8bf7fd4ce135dacc650130Johannes Berg	mutex_init(&local->iflist_mtx);
630a1699b75a1db31a1da2f0fc610ee696d02a19280Johannes Berg	mutex_init(&local->mtx);
631f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
632ad0e2b5a00dbec303e4682b403bb6703d11dcdb2Johannes Berg	mutex_init(&local->key_mtx);
6333b8d81e020f77c9da8b85b0685c8cd2ca7c7b150Johannes Berg	spin_lock_init(&local->filter_lock);
634ce7c9111a97492d04c504f40736a669c235d664aKalle Valo	spin_lock_init(&local->queue_stop_reason_lock);
635ce7c9111a97492d04c504f40736a669c235d664aKalle Valo
636d01a1e658606a0a69100f49c2ef09aacaf74d3e7Michal Kazior	INIT_LIST_HEAD(&local->chanctx_list);
637d01a1e658606a0a69100f49c2ef09aacaf74d3e7Michal Kazior	mutex_init(&local->chanctx_mtx);
638d01a1e658606a0a69100f49c2ef09aacaf74d3e7Michal Kazior
639681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	/*
640681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	 * The rx_skb_queue is only accessed from tasklets,
641681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	 * but other SKB queues are used from within IRQ
642681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	 * context. Therefore, this one needs a different
643681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	 * locking class so our direct, non-irq-safe use of
644681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	 * the queue's lock doesn't throw lockdep warnings.
645681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	 */
646681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg	skb_queue_head_init_class(&local->rx_skb_queue,
647681c4d07dd5b2ce2ad9f6dbbf7841e479fbc7754Johannes Berg				  &ieee80211_rx_skb_queue_class);
64824a8fdad35835e8d71f7c4b978a246fafed2e7b4Christian Lamparter
649c2b13452b283f9c4a5b02a6b53ed6416ebf4c03cJohannes Berg	INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
650f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
651f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg	INIT_WORK(&local->restart_work, ieee80211_restart_work);
652f2753ddbadb0873a98421415882318251bbd9eaaJohannes Berg
6533ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
6540f78231bffb868a30e8533aace142213266bb811Johannes Berg	INIT_WORK(&local->recalc_smps, ieee80211_recalc_smps_work);
6550f78231bffb868a30e8533aace142213266bb811Johannes Berg	local->smps_mode = IEEE80211_SMPS_OFF;
6563ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg
657520eb82076993b7f55ef9b80771d264272e5127bKalle Valo	INIT_WORK(&local->dynamic_ps_enable_work,
658520eb82076993b7f55ef9b80771d264272e5127bKalle Valo		  ieee80211_dynamic_ps_enable_work);
659520eb82076993b7f55ef9b80771d264272e5127bKalle Valo	INIT_WORK(&local->dynamic_ps_disable_work,
660520eb82076993b7f55ef9b80771d264272e5127bKalle Valo		  ieee80211_dynamic_ps_disable_work);
661520eb82076993b7f55ef9b80771d264272e5127bKalle Valo	setup_timer(&local->dynamic_ps_timer,
662520eb82076993b7f55ef9b80771d264272e5127bKalle Valo		    ieee80211_dynamic_ps_timer, (unsigned long) local);
663520eb82076993b7f55ef9b80771d264272e5127bKalle Valo
66485a9994a0a6cba1a6cc6af4bd3ebd85f778be0feLuciano Coelho	INIT_WORK(&local->sched_scan_stopped_work,
66585a9994a0a6cba1a6cc6af4bd3ebd85f778be0feLuciano Coelho		  ieee80211_sched_scan_stopped_work);
66685a9994a0a6cba1a6cc6af4bd3ebd85f778be0feLuciano Coelho
667a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	spin_lock_init(&local->ack_status_lock);
668a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	idr_init(&local->ack_status_frames);
669a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	/* preallocate at least one entry */
670a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	idr_pre_get(&local->ack_status_frames, GFP_KERNEL);
671a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg
672f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	sta_info_init(local);
673f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
674a6a67db2bc89d2b1ff07e0817f11235c20d2c329Johannes Berg	for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
6752a577d98712a284a612dd51d69db5cb989810dc2Johannes Berg		skb_queue_head_init(&local->pending[i]);
676a6a67db2bc89d2b1ff07e0817f11235c20d2c329Johannes Berg		atomic_set(&local->agg_queue_stop[i], 0);
677a6a67db2bc89d2b1ff07e0817f11235c20d2c329Johannes Berg	}
678f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
679f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		     (unsigned long)local);
680f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
681f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	tasklet_init(&local->tasklet,
682f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		     ieee80211_tasklet_handler,
683f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		     (unsigned long) local);
684f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
685f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	skb_queue_head_init(&local->skb_queue);
686f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	skb_queue_head_init(&local->skb_queue_unreliable);
687f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
6884e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	/* init dummy netdev for use w/ NAPI */
6894e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	init_dummy_netdev(&local->napi_dev);
6904e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
691fe67c913f1ec2a01aaa9176c80ef36eaf87d705dJohannes Berg	ieee80211_led_names(local);
692fe67c913f1ec2a01aaa9176c80ef36eaf87d705dJohannes Berg
6932eb278e083549f4eb29838037004054b3b55df62Johannes Berg	ieee80211_roc_setup(local);
69421f83589644bb2ed98079bf1e2154c8e70ca6a6cJohannes Berg
695005e472b45131250fe09c194f8b872b86fd266c1Johannes Berg	return &local->hw;
696f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc}
697f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri BencEXPORT_SYMBOL(ieee80211_alloc_hw);
698f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
699f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencint ieee80211_register_hw(struct ieee80211_hw *hw)
700f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc{
701f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct ieee80211_local *local = hw_to_local(hw);
7027527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg	int result, i;
7038318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	enum ieee80211_band band;
704be4a4b6a5d2f76393f545a2545fbaa1b65577e13Johannes Berg	int channels, max_bitrates;
705ba0afa2f22e1e3f332e45460f99328025d44564eMahesh Palivela	bool supp_ht, supp_vht;
70672d7872852e1734e94686012a2e9deade3457329Arik Nemtsov	netdev_features_t feature_whitelist;
70725e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg	static const u32 cipher_suites[] = {
7085daa8a8e691e28c6c725e7e91319b160b555c615Johannes Berg		/* keep WEP first, it may be removed below */
70925e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg		WLAN_CIPHER_SUITE_WEP40,
71025e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg		WLAN_CIPHER_SUITE_WEP104,
71125e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg		WLAN_CIPHER_SUITE_TKIP,
71225e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg		WLAN_CIPHER_SUITE_CCMP,
71325e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg
71425e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg		/* keep last -- depends on hw flags! */
71525e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg		WLAN_CIPHER_SUITE_AES_CMAC
71625e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg	};
7178318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg
7183a25a8c8b75b430c4f4022918e26fa51d557ecdeJohannes Berg	if (hw->flags & IEEE80211_HW_QUEUE_CONTROL &&
7193a25a8c8b75b430c4f4022918e26fa51d557ecdeJohannes Berg	    (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
7203a25a8c8b75b430c4f4022918e26fa51d557ecdeJohannes Berg	     local->hw.offchannel_tx_hw_queue >= local->hw.queues))
7213a25a8c8b75b430c4f4022918e26fa51d557ecdeJohannes Berg		return -EINVAL;
7223a25a8c8b75b430c4f4022918e26fa51d557ecdeJohannes Berg
72338bb3e9da62f6ebf1c6940d5482f0d6f431dac1cLarry Finger#ifdef CONFIG_PM
724dfb89c56add259b72a9c68d6b2846c1cd8c4e4b6Johannes Berg	if ((hw->wiphy->wowlan.flags || hw->wiphy->wowlan.n_patterns) &&
725dfb89c56add259b72a9c68d6b2846c1cd8c4e4b6Johannes Berg	    (!local->ops->suspend || !local->ops->resume))
726eecc48000afe2ca6da22122d553b7cad294e42fcJohannes Berg		return -EINVAL;
727dfb89c56add259b72a9c68d6b2846c1cd8c4e4b6Johannes Berg#endif
728eecc48000afe2ca6da22122d553b7cad294e42fcJohannes Berg
729885bd8eca6ac172e299750d99bd5c9fddbed89b9Eliad Peller	if ((hw->flags & IEEE80211_HW_SCAN_WHILE_IDLE) && !local->ops->hw_scan)
730885bd8eca6ac172e299750d99bd5c9fddbed89b9Eliad Peller		return -EINVAL;
731885bd8eca6ac172e299750d99bd5c9fddbed89b9Eliad Peller
73272d7872852e1734e94686012a2e9deade3457329Arik Nemtsov	/* Only HW csum features are currently compatible with mac80211 */
73372d7872852e1734e94686012a2e9deade3457329Arik Nemtsov	feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
73472d7872852e1734e94686012a2e9deade3457329Arik Nemtsov			    NETIF_F_HW_CSUM;
73572d7872852e1734e94686012a2e9deade3457329Arik Nemtsov	if (WARN_ON(hw->netdev_features & ~feature_whitelist))
73672d7872852e1734e94686012a2e9deade3457329Arik Nemtsov		return -EINVAL;
73772d7872852e1734e94686012a2e9deade3457329Arik Nemtsov
73878be49ec2a0df34de9441930fdced20311fd709fHelmut Schaa	if (hw->max_report_rates == 0)
73978be49ec2a0df34de9441930fdced20311fd709fHelmut Schaa		hw->max_report_rates = hw->max_rates;
74078be49ec2a0df34de9441930fdced20311fd709fHelmut Schaa
7418318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	/*
7428318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	 * generic code guarantees at least one band,
7438318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	 * set this very early because much code assumes
7448318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	 * that hw.conf.channel is assigned
7458318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	 */
7462a5193119269062608582418deba7af82844159aJohannes Berg	channels = 0;
747de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	max_bitrates = 0;
7485ef2d41afb7fce2315d12a8aaebe0c9f1b50755bJohannes Berg	supp_ht = false;
749ba0afa2f22e1e3f332e45460f99328025d44564eMahesh Palivela	supp_vht = false;
7508318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7518318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg		struct ieee80211_supported_band *sband;
7528318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg
7538318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg		sband = local->hw.wiphy->bands[band];
754de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		if (!sband)
755de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg			continue;
756de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		if (!local->oper_channel) {
7578318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg			/* init channel we're on */
7588318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg			local->hw.conf.channel =
75958905ca5b11a0ff3860f55b789cbbf052f7158a7Johannes Berg			local->oper_channel = &sband->channels[0];
76058905ca5b11a0ff3860f55b789cbbf052f7158a7Johannes Berg			local->hw.conf.channel_type = NL80211_CHAN_NO_HT;
7618318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg		}
762de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		channels += sband->n_channels;
763de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg
764de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		if (max_bitrates < sband->n_bitrates)
765de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg			max_bitrates = sband->n_bitrates;
7665ef2d41afb7fce2315d12a8aaebe0c9f1b50755bJohannes Berg		supp_ht = supp_ht || sband->ht_cap.ht_supported;
767ba0afa2f22e1e3f332e45460f99328025d44564eMahesh Palivela		supp_vht = supp_vht || sband->vht_cap.vht_supported;
7688318d78a44d49ac1edf2bdec7299de3617c4232eJohannes Berg	}
769f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
7705ba63533bbf653631faab60f6988506160ec6ba4Johannes Berg	local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
7715ba63533bbf653631faab60f6988506160ec6ba4Johannes Berg				      sizeof(void *) * channels, GFP_KERNEL);
7725ba63533bbf653631faab60f6988506160ec6ba4Johannes Berg	if (!local->int_scan_req)
7732a5193119269062608582418deba7af82844159aJohannes Berg		return -ENOMEM;
7742a5193119269062608582418deba7af82844159aJohannes Berg
775c72e8d335e2c6a309b6281f2abcf491f37b8b92bSimon Wunderlich	for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
776c72e8d335e2c6a309b6281f2abcf491f37b8b92bSimon Wunderlich		if (!local->hw.wiphy->bands[band])
777c72e8d335e2c6a309b6281f2abcf491f37b8b92bSimon Wunderlich			continue;
778c72e8d335e2c6a309b6281f2abcf491f37b8b92bSimon Wunderlich		local->int_scan_req->rates[band] = (u32) -1;
779c72e8d335e2c6a309b6281f2abcf491f37b8b92bSimon Wunderlich	}
780c72e8d335e2c6a309b6281f2abcf491f37b8b92bSimon Wunderlich
781f59ac0481660e66cec67f1d6b024e78b9dc715feLuis R. Rodriguez	/* if low-level driver supports AP, we also support VLAN */
7827527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
7837527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
7847527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg		hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
7857527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg	}
786f59ac0481660e66cec67f1d6b024e78b9dc715feLuis R. Rodriguez
787f59ac0481660e66cec67f1d6b024e78b9dc715feLuis R. Rodriguez	/* mac80211 always supports monitor */
7887527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg	hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
7897527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg	hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
7907527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg
7918e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg	/*
7928e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg	 * mac80211 doesn't support more than 1 channel, and also not more
7938e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg	 * than one IBSS interface
7948e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg	 */
7958e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg	for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
7968e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg		const struct ieee80211_iface_combination *c;
7978e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg		int j;
7988e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg
7998e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg		c = &hw->wiphy->iface_combinations[i];
8008e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg
8018e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg		if (c->num_different_channels > 1)
8027527a782e187d1214a5b3dc2897ce441033bb4efJohannes Berg			return -EINVAL;
803f59ac0481660e66cec67f1d6b024e78b9dc715feLuis R. Rodriguez
8048e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg		for (j = 0; j < c->n_limits; j++)
8058e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg			if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
8068e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg			    c->limits[j].max > 1)
8078e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg				return -EINVAL;
8088e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg	}
8098e621fc90b42fa2ca4ff65dd8d9cb21723e47837Johannes Berg
8105eb5a52da6ef04604cf8faca43ec670f69f417d3Johannes Berg#ifndef CONFIG_MAC80211_MESH
8115eb5a52da6ef04604cf8faca43ec670f69f417d3Johannes Berg	/* mesh depends on Kconfig, but drivers should set it if they want */
8125eb5a52da6ef04604cf8faca43ec670f69f417d3Johannes Berg	local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
8135eb5a52da6ef04604cf8faca43ec670f69f417d3Johannes Berg#endif
8145eb5a52da6ef04604cf8faca43ec670f69f417d3Johannes Berg
8151570ca59279a74db73b8ff840abdfaf64a9ee2ffJavier Cardona	/* if the underlying driver supports mesh, mac80211 will (at least)
8161570ca59279a74db73b8ff840abdfaf64a9ee2ffJavier Cardona	 * provide routing of mesh authentication frames to userspace */
8171570ca59279a74db73b8ff840abdfaf64a9ee2ffJavier Cardona	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
8181570ca59279a74db73b8ff840abdfaf64a9ee2ffJavier Cardona		local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
8191570ca59279a74db73b8ff840abdfaf64a9ee2ffJavier Cardona
820a621fa4d6a7fdf9d34938d2e129a72624833eeebJohannes Berg	/* mac80211 supports control port protocol changing */
821a621fa4d6a7fdf9d34938d2e129a72624833eeebJohannes Berg	local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
822a621fa4d6a7fdf9d34938d2e129a72624833eeebJohannes Berg
82377965c970d7da9c9b6349ff2b1d9adecf54c403bJohannes Berg	if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
82477965c970d7da9c9b6349ff2b1d9adecf54c403bJohannes Berg		local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
82577965c970d7da9c9b6349ff2b1d9adecf54c403bJohannes Berg	else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
82677965c970d7da9c9b6349ff2b1d9adecf54c403bJohannes Berg		local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
82777965c970d7da9c9b6349ff2b1d9adecf54c403bJohannes Berg
828ab13315af97919fae0e014748105fdc2e30afb2dKalle Valo	WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
829ab13315af97919fae0e014748105fdc2e30afb2dKalle Valo	     && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
830ab13315af97919fae0e014748105fdc2e30afb2dKalle Valo	     "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
831ab13315af97919fae0e014748105fdc2e30afb2dKalle Valo
832de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	/*
833de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * Calculate scan IE length -- we need this to alloc
834de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * memory and to subtract from the driver limit. It
835dc9f48ce7c7d345be31208def51572a8250a4a03Jouni Malinen	 * includes the DS Params, (extended) supported rates, and HT
836de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * information -- SSID is the driver's responsibility.
837de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 */
838dc9f48ce7c7d345be31208def51572a8250a4a03Jouni Malinen	local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
839dc9f48ce7c7d345be31208def51572a8250a4a03Jouni Malinen		3 /* DS Params */;
8405ef2d41afb7fce2315d12a8aaebe0c9f1b50755bJohannes Berg	if (supp_ht)
8415ef2d41afb7fce2315d12a8aaebe0c9f1b50755bJohannes Berg		local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
842de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg
843ba0afa2f22e1e3f332e45460f99328025d44564eMahesh Palivela	if (supp_vht)
844ba0afa2f22e1e3f332e45460f99328025d44564eMahesh Palivela		local->scan_ies_len +=
845ba0afa2f22e1e3f332e45460f99328025d44564eMahesh Palivela			2 + sizeof(struct ieee80211_vht_capabilities);
846ba0afa2f22e1e3f332e45460f99328025d44564eMahesh Palivela
847de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	if (!local->ops->hw_scan) {
848de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		/* For hw_scan, driver needs to set these up. */
849de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		local->hw.wiphy->max_scan_ssids = 4;
850de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
851de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	}
852de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg
853de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	/*
854de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * If the driver supports any scan IEs, then assume the
855de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * limit includes the IEs mac80211 will add, otherwise
856de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * leave it at zero and let the driver sort it out; we
857de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * still pass our IEs to the driver but userspace will
858de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 * not be allowed to in that case.
859de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	 */
860de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg	if (local->hw.wiphy->max_scan_ie_len)
861de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg		local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
862de95a54b1aebe5592cae971ca5e5d9ec6a381a17Johannes Berg
8633ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg	/* Set up cipher suites unless driver already did */
8643ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg	if (!local->hw.wiphy->cipher_suites) {
8653ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		local->hw.wiphy->cipher_suites = cipher_suites;
8663ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8673ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE))
8683ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			local->hw.wiphy->n_cipher_suites--;
8693ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg	}
8705daa8a8e691e28c6c725e7e91319b160b555c615Johannes Berg	if (IS_ERR(local->wep_tx_tfm) || IS_ERR(local->wep_rx_tfm)) {
8713ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		if (local->hw.wiphy->cipher_suites == cipher_suites) {
8723ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			local->hw.wiphy->cipher_suites += 2;
8733ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			local->hw.wiphy->n_cipher_suites -= 2;
8743ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		} else {
8753ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			u32 *suites;
8763ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			int r, w = 0;
8773ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg
8783ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			/* Filter out WEP */
8793ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg
8803ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			suites = kmemdup(
8813ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				local->hw.wiphy->cipher_suites,
8823ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				sizeof(u32) * local->hw.wiphy->n_cipher_suites,
8833ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				GFP_KERNEL);
8843ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			if (!suites)
8853ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				return -ENOMEM;
8863ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
8873ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				u32 suite = local->hw.wiphy->cipher_suites[r];
8883ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				if (suite == WLAN_CIPHER_SUITE_WEP40 ||
8893ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				    suite == WLAN_CIPHER_SUITE_WEP104)
8903ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg					continue;
8913ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg				suites[w++] = suite;
8923ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			}
8933ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			local->hw.wiphy->cipher_suites = suites;
8943ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			local->hw.wiphy->n_cipher_suites = w;
8953ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg			local->wiphy_ciphers_allocated = true;
8963ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		}
8975daa8a8e691e28c6c725e7e91319b160b555c615Johannes Berg	}
89825e47c18ac4d8ad09c2ed4b99c1dbbcb7e3d2c51Johannes Berg
89921f83589644bb2ed98079bf1e2154c8e70ca6a6cJohannes Berg	if (!local->ops->remain_on_channel)
90021f83589644bb2ed98079bf1e2154c8e70ca6a6cJohannes Berg		local->hw.wiphy->max_remain_on_channel_duration = 5000;
901a293911d4fd5e8593dbf478399a77f990d466269Johannes Berg
90279f460ca49d8d5700756ab7071c951311c7f29ccLuciano Coelho	if (local->ops->sched_scan_start)
90379f460ca49d8d5700756ab7071c951311c7f29ccLuciano Coelho		local->hw.wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
90479f460ca49d8d5700756ab7071c951311c7f29ccLuciano Coelho
905dfe018bf99537e42c816d3f543620a7e09fcf3cdArik Nemtsov	/* mac80211 based drivers don't support internal TDLS setup */
906dfe018bf99537e42c816d3f543620a7e09fcf3cdArik Nemtsov	if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
907dfe018bf99537e42c816d3f543620a7e09fcf3cdArik Nemtsov		local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
908dfe018bf99537e42c816d3f543620a7e09fcf3cdArik Nemtsov
909f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	result = wiphy_register(local->hw.wiphy);
910f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	if (result < 0)
9112a5193119269062608582418deba7af82844159aJohannes Berg		goto fail_wiphy_register;
912f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
913e2530083609148a7835b54c431f6b8956407c1f6Johannes Berg	/*
914e2530083609148a7835b54c431f6b8956407c1f6Johannes Berg	 * We use the number of queues for feature tests (QoS, HT) internally
915e2530083609148a7835b54c431f6b8956407c1f6Johannes Berg	 * so restrict them appropriately.
916e2530083609148a7835b54c431f6b8956407c1f6Johannes Berg	 */
917e2530083609148a7835b54c431f6b8956407c1f6Johannes Berg	if (hw->queues > IEEE80211_MAX_QUEUES)
918e2530083609148a7835b54c431f6b8956407c1f6Johannes Berg		hw->queues = IEEE80211_MAX_QUEUES;
919e2530083609148a7835b54c431f6b8956407c1f6Johannes Berg
92042935ecaf4e784d0815afa9a7e5fe7e141157ca3Luis R. Rodriguez	local->workqueue =
92199b88a0ecbdbc6df03527292571b2b442965814aTejun Heo		alloc_ordered_workqueue(wiphy_name(local->hw.wiphy), 0);
92242935ecaf4e784d0815afa9a7e5fe7e141157ca3Luis R. Rodriguez	if (!local->workqueue) {
923f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		result = -ENOMEM;
924f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		goto fail_workqueue;
925f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	}
926f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
927b306f45300866adc01b84f7aa083bfcd9cbb89c4Johannes Berg	/*
928b306f45300866adc01b84f7aa083bfcd9cbb89c4Johannes Berg	 * The hardware needs headroom for sending the frame,
929b306f45300866adc01b84f7aa083bfcd9cbb89c4Johannes Berg	 * and we need some headroom for passing the frame to monitor
930b306f45300866adc01b84f7aa083bfcd9cbb89c4Johannes Berg	 * interfaces, but never both at the same time.
931b306f45300866adc01b84f7aa083bfcd9cbb89c4Johannes Berg	 */
93233ccad35a21df51c0d23f3e3e88688524e7b51edJiri Benc	local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
933a2fe81667410723d941a688e1958a49d67ca3346Helmut Schaa				   IEEE80211_TX_STATUS_HEADROOM);
934b306f45300866adc01b84f7aa083bfcd9cbb89c4Johannes Berg
935e9f207f0ff90bf60b825800d7450e6f2ff2eab88Jiri Benc	debugfs_hw_add(local);
936e9f207f0ff90bf60b825800d7450e6f2ff2eab88Jiri Benc
937b446918b77c717a34eaa853dfab55f579d330551Helmut Schaa	/*
938b446918b77c717a34eaa853dfab55f579d330551Helmut Schaa	 * if the driver doesn't specify a max listen interval we
939b446918b77c717a34eaa853dfab55f579d330551Helmut Schaa	 * use 5 which should be a safe default
940b446918b77c717a34eaa853dfab55f579d330551Helmut Schaa	 */
941ea95bba41e69c616bb1512cf59d22f33266b8568Tomas Winkler	if (local->hw.max_listen_interval == 0)
942b446918b77c717a34eaa853dfab55f579d330551Helmut Schaa		local->hw.max_listen_interval = 5;
943ea95bba41e69c616bb1512cf59d22f33266b8568Tomas Winkler
944ea95bba41e69c616bb1512cf59d22f33266b8568Tomas Winkler	local->hw.conf.listen_interval = local->hw.max_listen_interval;
945ea95bba41e69c616bb1512cf59d22f33266b8568Tomas Winkler
946ff61638105db6f5832ef8700436ba6aa6d3a2fdaJuuso Oikarinen	local->dynamic_ps_forced_timeout = -1;
947195e294d21e88af879da4f88db2ceeb4ec28a755Juuso Oikarinen
948d4c4a9a1bce1912ed5681251f0037fd4f2364a3eAlan Jenkins	result = ieee80211_wep_init(local);
9493473187d2459a078e00e5fac8aafc30af69c57faJohn W. Linville	if (result < 0)
9500fb9a9ec27718fbf7fa3153bc94becefb716ceebJoe Perches		wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
9510fb9a9ec27718fbf7fa3153bc94becefb716ceebJoe Perches			    result);
952d4c4a9a1bce1912ed5681251f0037fd4f2364a3eAlan Jenkins
953b57e6b560fc2a2742910ac5ca0eb2c46e45aeac2Mohammed Shafi Shajakhan	ieee80211_led_init(local);
954b57e6b560fc2a2742910ac5ca0eb2c46e45aeac2Mohammed Shafi Shajakhan
955f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	rtnl_lock();
956f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
957830f903866a1611e9ce53f3e35202302bb938946Johannes Berg	result = ieee80211_init_rate_ctrl_alg(local,
958830f903866a1611e9ce53f3e35202302bb938946Johannes Berg					      hw->rate_control_algorithm);
959f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	if (result < 0) {
9600fb9a9ec27718fbf7fa3153bc94becefb716ceebJoe Perches		wiphy_debug(local->hw.wiphy,
9610fb9a9ec27718fbf7fa3153bc94becefb716ceebJoe Perches			    "Failed to initialize rate control algorithm\n");
962f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc		goto fail_rate;
963f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	}
964f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
9658dffff216fcac4f79078478085e86d68db64922eJohannes Berg	/* add one default STA interface if supported */
9668dffff216fcac4f79078478085e86d68db64922eJohannes Berg	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
9678dffff216fcac4f79078478085e86d68db64922eJohannes Berg		result = ieee80211_if_add(local, "wlan%d", NULL,
9688dffff216fcac4f79078478085e86d68db64922eJohannes Berg					  NL80211_IFTYPE_STATION, NULL);
9698dffff216fcac4f79078478085e86d68db64922eJohannes Berg		if (result)
9700fb9a9ec27718fbf7fa3153bc94becefb716ceebJoe Perches			wiphy_warn(local->hw.wiphy,
9710fb9a9ec27718fbf7fa3153bc94becefb716ceebJoe Perches				   "Failed to add default virtual iface\n");
9728dffff216fcac4f79078478085e86d68db64922eJohannes Berg	}
973f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
974f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	rtnl_unlock();
975f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
97610f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg	local->network_latency_notifier.notifier_call =
97710f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg		ieee80211_max_network_latency;
97810f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg	result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
97910f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg				     &local->network_latency_notifier);
98010f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg	if (result) {
98110f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg		rtnl_lock();
98210f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg		goto fail_pm_qos;
98310f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg	}
98410f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg
98526b36cfefaf2be98b225e3c1a399edb0daf52dddJohn W. Linville#ifdef CONFIG_INET
9862b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
9872b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	result = register_inetaddr_notifier(&local->ifa_notifier);
9882b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	if (result)
9892b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen		goto fail_ifa;
99026b36cfefaf2be98b225e3c1a399edb0daf52dddJohn W. Linville#endif
9912b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen
9924e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville	netif_napi_add(&local->napi_dev, &local->napi, ieee80211_napi_poll,
9934e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville			local->hw.napi_weight);
9944e6cbfd09c66893e5134c9896e9af353c2322b66John W. Linville
995f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	return 0;
996f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
99793c08c32914264f539baf7f04cce310a0dd30a7aJuuso Oikarinen#ifdef CONFIG_INET
9982b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen fail_ifa:
9992b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
10002b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen			       &local->network_latency_notifier);
10012b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	rtnl_lock();
100293c08c32914264f539baf7f04cce310a0dd30a7aJuuso Oikarinen#endif
100310f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg fail_pm_qos:
100410f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg	ieee80211_led_exit(local);
100510f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg	ieee80211_remove_interfaces(local);
100610f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg fail_rate:
1007f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	rtnl_unlock();
1008d4c4a9a1bce1912ed5681251f0037fd4f2364a3eAlan Jenkins	ieee80211_wep_free(local);
1009f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	sta_info_stop(local);
101042935ecaf4e784d0815afa9a7e5fe7e141157ca3Luis R. Rodriguez	destroy_workqueue(local->workqueue);
101110f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg fail_workqueue:
1012f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	wiphy_unregister(local->hw.wiphy);
101310f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg fail_wiphy_register:
10143ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg	if (local->wiphy_ciphers_allocated)
10153ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		kfree(local->hw.wiphy->cipher_suites);
101611ba964d4f936609a04e8b9f2051f6027ef761aeJohannes Berg	kfree(local->int_scan_req);
1017f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	return result;
1018f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc}
1019f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri BencEXPORT_SYMBOL(ieee80211_register_hw);
1020f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1021f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencvoid ieee80211_unregister_hw(struct ieee80211_hw *hw)
1022f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc{
1023f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct ieee80211_local *local = hw_to_local(hw);
1024f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1025f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	tasklet_kill(&local->tx_pending_tasklet);
1026f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	tasklet_kill(&local->tasklet);
1027f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
102810f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg	pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
102910f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg			       &local->network_latency_notifier);
103026b36cfefaf2be98b225e3c1a399edb0daf52dddJohn W. Linville#ifdef CONFIG_INET
10312b2c009ecf71f4c66ff8420b63dddbc9737e04e3Juuso Oikarinen	unregister_inetaddr_notifier(&local->ifa_notifier);
103226b36cfefaf2be98b225e3c1a399edb0daf52dddJohn W. Linville#endif
103310f644a47b76d3e61b98f2d02ce9690b94c51ee5Johannes Berg
1034f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	rtnl_lock();
1035f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
103679010420cc3f78eab911598bfdd29c4b06a83e1fJohannes Berg	/*
103779010420cc3f78eab911598bfdd29c4b06a83e1fJohannes Berg	 * At this point, interface list manipulations are fine
103879010420cc3f78eab911598bfdd29c4b06a83e1fJohannes Berg	 * because the driver cannot be handing us frames any
103979010420cc3f78eab911598bfdd29c4b06a83e1fJohannes Berg	 * more and the tasklet is killed.
104079010420cc3f78eab911598bfdd29c4b06a83e1fJohannes Berg	 */
104175636525fbfa78fa33fd754c89785cfde750acd3Johannes Berg	ieee80211_remove_interfaces(local);
10425b2812e925c8e976852867f8d760637c5926d817Johannes Berg
1043f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	rtnl_unlock();
1044f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1045258086a48b766d12a500f98834654ffa927ca475Christian Lamparter	cancel_work_sync(&local->restart_work);
10463ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg	cancel_work_sync(&local->reconfig_filter);
10473ac64beecd27400d12cc7afb4108eef26c499f6aJohannes Berg
1048f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	ieee80211_clear_tx_pending(local);
1049f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	rate_control_deinitialize(local);
1050f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1051f64f9e719261a87818dd192a3a2352e5b20fbd0fJoe Perches	if (skb_queue_len(&local->skb_queue) ||
1052f64f9e719261a87818dd192a3a2352e5b20fbd0fJoe Perches	    skb_queue_len(&local->skb_queue_unreliable))
10530fb9a9ec27718fbf7fa3153bc94becefb716ceebJoe Perches		wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
1054f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	skb_queue_purge(&local->skb_queue);
1055f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	skb_queue_purge(&local->skb_queue_unreliable);
105624a8fdad35835e8d71f7c4b978a246fafed2e7b4Christian Lamparter	skb_queue_purge(&local->rx_skb_queue);
1057f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
105842935ecaf4e784d0815afa9a7e5fe7e141157ca3Luis R. Rodriguez	destroy_workqueue(local->workqueue);
1059f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	wiphy_unregister(local->hw.wiphy);
1060ecb4433550f0620f3d1471ae7099037ede30a91eStanislaw Gruszka	sta_info_stop(local);
1061f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	ieee80211_wep_free(local);
1062f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	ieee80211_led_exit(local);
10635ba63533bbf653631faab60f6988506160ec6ba4Johannes Berg	kfree(local->int_scan_req);
1064f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc}
1065f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri BencEXPORT_SYMBOL(ieee80211_unregister_hw);
1066f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1067a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Bergstatic int ieee80211_free_ack_frame(int id, void *p, void *data)
1068a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg{
1069a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	WARN_ONCE(1, "Have pending ack frames!\n");
1070a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	kfree_skb(p);
1071a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	return 0;
1072a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg}
1073a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg
1074f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencvoid ieee80211_free_hw(struct ieee80211_hw *hw)
1075f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc{
1076f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct ieee80211_local *local = hw_to_local(hw);
1077f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1078c771c9d8da1e8292ef8bf7fd4ce135dacc650130Johannes Berg	mutex_destroy(&local->iflist_mtx);
1079a1699b75a1db31a1da2f0fc610ee696d02a19280Johannes Berg	mutex_destroy(&local->mtx);
1080c771c9d8da1e8292ef8bf7fd4ce135dacc650130Johannes Berg
10813ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg	if (local->wiphy_ciphers_allocated)
10823ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg		kfree(local->hw.wiphy->cipher_suites);
10833ffc2a905b1faae4c0fe39d66f0752c3a4cbb3c7Johannes Berg
1084a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	idr_for_each(&local->ack_status_frames,
1085a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg		     ieee80211_free_ack_frame, NULL);
1086a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg	idr_destroy(&local->ack_status_frames);
1087a729cff8ad5120d0d5172ec28a3843d1cb458f79Johannes Berg
1088f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	wiphy_free(local->hw.wiphy);
1089f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc}
1090f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri BencEXPORT_SYMBOL(ieee80211_free_hw);
1091f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1092f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencstatic int __init ieee80211_init(void)
1093f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc{
1094f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	struct sk_buff *skb;
1095f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	int ret;
1096f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1097e039fa4a4195ac4ee895e6f3d1334beed63256feJohannes Berg	BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1098e039fa4a4195ac4ee895e6f3d1334beed63256feJohannes Berg	BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1099c6a1fa12d206882757264869f8e32d606b930e2aJohannes Berg		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
1100f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1101cccf129f820e431d84690729254a32f1709328fbFelix Fietkau	ret = rc80211_minstrel_init();
1102cccf129f820e431d84690729254a32f1709328fbFelix Fietkau	if (ret)
1103cccf129f820e431d84690729254a32f1709328fbFelix Fietkau		return ret;
1104cccf129f820e431d84690729254a32f1709328fbFelix Fietkau
1105ec8aa669b8393b6789b1954d587c63264af7ff99Felix Fietkau	ret = rc80211_minstrel_ht_init();
1106ec8aa669b8393b6789b1954d587c63264af7ff99Felix Fietkau	if (ret)
1107ec8aa669b8393b6789b1954d587c63264af7ff99Felix Fietkau		goto err_minstrel;
1108ec8aa669b8393b6789b1954d587c63264af7ff99Felix Fietkau
11094b475898ec9dc6e62cebcb8fc0b3495c986a4590Johannes Berg	ret = rc80211_pid_init();
1110ad01837593338f13508463fa11c8dbf8109a1e5dMattias Nissler	if (ret)
111147846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg		goto err_pid;
1112f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
111347846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg	ret = ieee80211_iface_init();
111447846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg	if (ret)
111547846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg		goto err_netdev;
1116e9f207f0ff90bf60b825800d7450e6f2ff2eab88Jiri Benc
1117f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc	return 0;
111847846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg err_netdev:
111947846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg	rc80211_pid_exit();
112047846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg err_pid:
1121ec8aa669b8393b6789b1954d587c63264af7ff99Felix Fietkau	rc80211_minstrel_ht_exit();
1122ec8aa669b8393b6789b1954d587c63264af7ff99Felix Fietkau err_minstrel:
112347846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg	rc80211_minstrel_exit();
112447846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg
112547846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg	return ret;
1126f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc}
1127f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1128f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencstatic void __exit ieee80211_exit(void)
1129f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc{
11304b475898ec9dc6e62cebcb8fc0b3495c986a4590Johannes Berg	rc80211_pid_exit();
1131ec8aa669b8393b6789b1954d587c63264af7ff99Felix Fietkau	rc80211_minstrel_ht_exit();
1132cccf129f820e431d84690729254a32f1709328fbFelix Fietkau	rc80211_minstrel_exit();
1133ac71c691e6a5ce991fe221d3bdb0c972f617aa37Johannes Berg
1134f7a921443740d7dafc65b17aa32531730d358f50Luis Carlos Cobo	if (mesh_allocated)
1135f7a921443740d7dafc65b17aa32531730d358f50Luis Carlos Cobo		ieee80211s_stop();
1136902acc7896d7649fb30e4b22bd4e643c7f34b02cJohannes Berg
113747846c9b0c10808d9337d2e7d09361f3e0a0a71aJohannes Berg	ieee80211_iface_exit();
1138d07c7cf49ae7c488e778c4d668f4cc10bd2fa971Johannes Berg
1139d07c7cf49ae7c488e778c4d668f4cc10bd2fa971Johannes Berg	rcu_barrier();
1140f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc}
1141f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1142f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1143ca9938fea576ebbb8d8c4fbe8a5bcc937e49e1caJohannes Bergsubsys_initcall(ieee80211_init);
1144f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Bencmodule_exit(ieee80211_exit);
1145f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri Benc
1146f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri BencMODULE_DESCRIPTION("IEEE 802.11 subsystem");
1147f0706e828e96d0fa4e80c0d25aa98523f6d589a0Jiri BencMODULE_LICENSE("GPL");
1148