aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2008-07-09 08:40:35 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-07-14 14:30:07 -0400
commit75636525fbfa78fa33fd754c89785cfde750acd3 (patch)
tree2c614681382a53bec50248c621ba4c8bb07ce670 /net/mac80211
parent3e122be089e6fb8d3f322416da4cdbb80ce12927 (diff)
mac80211: revamp virtual interface handling
This patch revamps the virtual interface handling and makes the code much easier to follow. Fewer functions, better names, less spaghetti code. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/cfg.c24
-rw-r--r--net/mac80211/debugfs.c15
-rw-r--r--net/mac80211/debugfs_netdev.c14
-rw-r--r--net/mac80211/debugfs_netdev.h5
-rw-r--r--net/mac80211/ieee80211_i.h21
-rw-r--r--net/mac80211/iface.c337
-rw-r--r--net/mac80211/main.c18
-rw-r--r--net/mac80211/wext.c3
8 files changed, 172 insertions, 265 deletions
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 3c95cd9bf8ee..6aa49ad172aa 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -50,9 +50,6 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
50 struct ieee80211_sub_if_data *sdata; 50 struct ieee80211_sub_if_data *sdata;
51 int err; 51 int err;
52 52
53 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
54 return -ENODEV;
55
56 itype = nl80211_type_to_mac80211_type(type); 53 itype = nl80211_type_to_mac80211_type(type);
57 if (itype == IEEE80211_IF_TYPE_INVALID) 54 if (itype == IEEE80211_IF_TYPE_INVALID)
58 return -EINVAL; 55 return -EINVAL;
@@ -68,35 +65,26 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
68 65
69static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) 66static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
70{ 67{
71 struct ieee80211_local *local = wiphy_priv(wiphy);
72 struct net_device *dev; 68 struct net_device *dev;
73 char *name;
74
75 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
76 return -ENODEV;
77 69
78 /* we're under RTNL */ 70 /* we're under RTNL */
79 dev = __dev_get_by_index(&init_net, ifindex); 71 dev = __dev_get_by_index(&init_net, ifindex);
80 if (!dev) 72 if (!dev)
81 return 0; 73 return -ENODEV;
82 74
83 name = dev->name; 75 ieee80211_if_remove(dev);
84 76
85 return ieee80211_if_remove(local->mdev, name, -1); 77 return 0;
86} 78}
87 79
88static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, 80static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
89 enum nl80211_iftype type, u32 *flags, 81 enum nl80211_iftype type, u32 *flags,
90 struct vif_params *params) 82 struct vif_params *params)
91{ 83{
92 struct ieee80211_local *local = wiphy_priv(wiphy);
93 struct net_device *dev; 84 struct net_device *dev;
94 enum ieee80211_if_types itype; 85 enum ieee80211_if_types itype;
95 struct ieee80211_sub_if_data *sdata; 86 struct ieee80211_sub_if_data *sdata;
96 87
97 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
98 return -ENODEV;
99
100 /* we're under RTNL */ 88 /* we're under RTNL */
101 dev = __dev_get_by_index(&init_net, ifindex); 89 dev = __dev_get_by_index(&init_net, ifindex);
102 if (!dev) 90 if (!dev)
@@ -111,11 +99,7 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
111 99
112 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 100 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
113 101
114 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) 102 ieee80211_if_change_type(sdata, itype);
115 return -EOPNOTSUPP;
116
117 ieee80211_if_reinit(dev);
118 ieee80211_if_set_type(dev, itype);
119 103
120 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) 104 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
121 ieee80211_if_sta_set_mesh_id(&sdata->u.sta, 105 ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index d20d90eead1f..ee509f1109e2 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -70,16 +70,6 @@ DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
70 70
71/* statistics stuff */ 71/* statistics stuff */
72 72
73static inline int rtnl_lock_local(struct ieee80211_local *local)
74{
75 rtnl_lock();
76 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
77 rtnl_unlock();
78 return -ENODEV;
79 }
80 return 0;
81}
82
83#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ 73#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
84 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value) 74 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
85 75
@@ -96,10 +86,7 @@ static ssize_t format_devstat_counter(struct ieee80211_local *local,
96 if (!local->ops->get_stats) 86 if (!local->ops->get_stats)
97 return -EOPNOTSUPP; 87 return -EOPNOTSUPP;
98 88
99 res = rtnl_lock_local(local); 89 rtnl_lock();
100 if (res)
101 return res;
102
103 res = local->ops->get_stats(local_to_hw(local), &stats); 90 res = local->ops->get_stats(local_to_hw(local), &stats);
104 rtnl_unlock(); 91 rtnl_unlock();
105 if (!res) 92 if (!res)
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 4aa6621f9970..475f89a8aee1 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -476,12 +476,12 @@ static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
476} 476}
477#endif 477#endif
478 478
479static void del_files(struct ieee80211_sub_if_data *sdata, int type) 479static void del_files(struct ieee80211_sub_if_data *sdata)
480{ 480{
481 if (!sdata->debugfsdir) 481 if (!sdata->debugfsdir)
482 return; 482 return;
483 483
484 switch (type) { 484 switch (sdata->vif.type) {
485 case IEEE80211_IF_TYPE_MESH_POINT: 485 case IEEE80211_IF_TYPE_MESH_POINT:
486#ifdef CONFIG_MAC80211_MESH 486#ifdef CONFIG_MAC80211_MESH
487 del_mesh_stats(sdata); 487 del_mesh_stats(sdata);
@@ -521,22 +521,16 @@ void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
521 sprintf(buf, "netdev:%s", sdata->dev->name); 521 sprintf(buf, "netdev:%s", sdata->dev->name);
522 sdata->debugfsdir = debugfs_create_dir(buf, 522 sdata->debugfsdir = debugfs_create_dir(buf,
523 sdata->local->hw.wiphy->debugfsdir); 523 sdata->local->hw.wiphy->debugfsdir);
524 add_files(sdata);
524} 525}
525 526
526void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) 527void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
527{ 528{
528 del_files(sdata, sdata->vif.type); 529 del_files(sdata);
529 debugfs_remove(sdata->debugfsdir); 530 debugfs_remove(sdata->debugfsdir);
530 sdata->debugfsdir = NULL; 531 sdata->debugfsdir = NULL;
531} 532}
532 533
533void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
534 int oldtype)
535{
536 del_files(sdata, oldtype);
537 add_files(sdata);
538}
539
540static int netdev_notify(struct notifier_block *nb, 534static int netdev_notify(struct notifier_block *nb,
541 unsigned long state, 535 unsigned long state,
542 void *ndev) 536 void *ndev)
diff --git a/net/mac80211/debugfs_netdev.h b/net/mac80211/debugfs_netdev.h
index a690071fde8a..7af731f0b731 100644
--- a/net/mac80211/debugfs_netdev.h
+++ b/net/mac80211/debugfs_netdev.h
@@ -6,8 +6,6 @@
6#ifdef CONFIG_MAC80211_DEBUGFS 6#ifdef CONFIG_MAC80211_DEBUGFS
7void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata); 7void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata);
8void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata); 8void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata);
9void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
10 int oldtype);
11void ieee80211_debugfs_netdev_init(void); 9void ieee80211_debugfs_netdev_init(void);
12void ieee80211_debugfs_netdev_exit(void); 10void ieee80211_debugfs_netdev_exit(void);
13#else 11#else
@@ -17,9 +15,6 @@ static inline void ieee80211_debugfs_add_netdev(
17static inline void ieee80211_debugfs_remove_netdev( 15static inline void ieee80211_debugfs_remove_netdev(
18 struct ieee80211_sub_if_data *sdata) 16 struct ieee80211_sub_if_data *sdata)
19{} 17{}
20static inline void ieee80211_debugfs_change_if_type(
21 struct ieee80211_sub_if_data *sdata, int oldtype)
22{}
23static inline void ieee80211_debugfs_netdev_init(void) 18static inline void ieee80211_debugfs_netdev_init(void)
24{} 19{}
25 20
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 1b1fc53dad36..35bcdfef9045 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -558,12 +558,6 @@ struct ieee80211_local {
558 bool tim_in_locked_section; /* see ieee80211_beacon_get() */ 558 bool tim_in_locked_section; /* see ieee80211_beacon_get() */
559 int tx_headroom; /* required headroom for hardware/radiotap */ 559 int tx_headroom; /* required headroom for hardware/radiotap */
560 560
561 enum {
562 IEEE80211_DEV_UNINITIALIZED = 0,
563 IEEE80211_DEV_REGISTERED,
564 IEEE80211_DEV_UNREGISTERED,
565 } reg_state;
566
567 /* Tasklet and skb queue to process calls from IRQ mode. All frames 561 /* Tasklet and skb queue to process calls from IRQ mode. All frames
568 * added to skb_queue will be processed, but frames in 562 * added to skb_queue will be processed, but frames in
569 * skb_queue_unreliable may be dropped if the total length of these 563 * skb_queue_unreliable may be dropped if the total length of these
@@ -863,7 +857,6 @@ int ieee80211_hw_config(struct ieee80211_local *local);
863int ieee80211_if_config(struct net_device *dev); 857int ieee80211_if_config(struct net_device *dev);
864int ieee80211_if_config_beacon(struct net_device *dev); 858int ieee80211_if_config_beacon(struct net_device *dev);
865void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx); 859void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
866void ieee80211_if_setup(struct net_device *dev);
867u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht, 860u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
868 struct ieee80211_ht_info *req_ht_cap, 861 struct ieee80211_ht_info *req_ht_cap,
869 struct ieee80211_ht_bss_info *req_bss_cap); 862 struct ieee80211_ht_bss_info *req_bss_cap);
@@ -933,16 +926,14 @@ static inline void ieee80211_start_mesh(struct net_device *dev)
933#endif 926#endif
934 927
935/* interface handling */ 928/* interface handling */
929void ieee80211_if_setup(struct net_device *dev);
936int ieee80211_if_add(struct ieee80211_local *local, const char *name, 930int ieee80211_if_add(struct ieee80211_local *local, const char *name,
937 struct net_device **new_dev, int type, 931 struct net_device **new_dev, enum ieee80211_if_types type,
938 struct vif_params *params); 932 struct vif_params *params);
939void ieee80211_if_set_type(struct net_device *dev, int type); 933void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
940void ieee80211_if_reinit(struct net_device *dev); 934 enum ieee80211_if_types type);
941void __ieee80211_if_del(struct ieee80211_local *local, 935void ieee80211_if_remove(struct net_device *dev);
942 struct ieee80211_sub_if_data *sdata); 936void ieee80211_remove_interfaces(struct ieee80211_local *local);
943int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
944void ieee80211_if_free(struct net_device *dev);
945void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
946 937
947/* tx handling */ 938/* tx handling */
948void ieee80211_clear_tx_pending(struct ieee80211_local *local); 939void ieee80211_clear_tx_pending(struct ieee80211_local *local);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index f2aefd4b8637..6cf121bebd7a 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -2,6 +2,7 @@
2 * Copyright 2002-2005, Instant802 Networks, Inc. 2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc. 3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> 4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -17,39 +18,149 @@
17#include "debugfs_netdev.h" 18#include "debugfs_netdev.h"
18#include "mesh.h" 19#include "mesh.h"
19 20
20void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata) 21/*
22 * Called when the netdev is removed or, by the code below, before
23 * the interface type changes.
24 */
25static void ieee80211_teardown_sdata(struct net_device *dev)
21{ 26{
27 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28 struct ieee80211_local *local = sdata->local;
29 struct beacon_data *beacon;
30 struct sk_buff *skb;
31 int flushed;
22 int i; 32 int i;
23 33
24 /* Default values for sub-interface parameters */ 34 ieee80211_debugfs_remove_netdev(sdata);
25 sdata->drop_unencrypted = 0; 35
36 /* free extra data */
37 ieee80211_free_keys(sdata);
38
26 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) 39 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
27 skb_queue_head_init(&sdata->fragments[i].skb_list); 40 __skb_queue_purge(&sdata->fragments[i].skb_list);
41 sdata->fragment_next = 0;
28 42
29 INIT_LIST_HEAD(&sdata->key_list); 43 switch (sdata->vif.type) {
44 case IEEE80211_IF_TYPE_AP:
45 beacon = sdata->u.ap.beacon;
46 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
47 synchronize_rcu();
48 kfree(beacon);
30 49
31 sdata->force_unicast_rateidx = -1; 50 while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
32 sdata->max_ratectrl_rateidx = -1; 51 local->total_ps_buffered--;
52 dev_kfree_skb(skb);
53 }
54
55 break;
56 case IEEE80211_IF_TYPE_MESH_POINT:
57 /* Allow compiler to elide mesh_rmc_free call. */
58 if (ieee80211_vif_is_mesh(&sdata->vif))
59 mesh_rmc_free(dev);
60 /* fall through */
61 case IEEE80211_IF_TYPE_STA:
62 case IEEE80211_IF_TYPE_IBSS:
63 kfree(sdata->u.sta.extra_ie);
64 kfree(sdata->u.sta.assocreq_ies);
65 kfree(sdata->u.sta.assocresp_ies);
66 kfree_skb(sdata->u.sta.probe_resp);
67 break;
68 case IEEE80211_IF_TYPE_WDS:
69 case IEEE80211_IF_TYPE_VLAN:
70 case IEEE80211_IF_TYPE_MNTR:
71 break;
72 case IEEE80211_IF_TYPE_INVALID:
73 BUG();
74 break;
75 }
76
77 flushed = sta_info_flush(local, sdata);
78 WARN_ON(flushed);
33} 79}
34 80
35static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata) 81/*
82 * Helper function to initialise an interface to a specific type.
83 */
84static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
85 enum ieee80211_if_types type)
36{ 86{
37 int i; 87 struct ieee80211_if_sta *ifsta;
38 88
39 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) 89 /* clear type-dependent union */
40 __skb_queue_purge(&sdata->fragments[i].skb_list); 90 memset(&sdata->u, 0, sizeof(sdata->u));
91
92 /* and set some type-dependent values */
93 sdata->vif.type = type;
94
95 /* only monitor differs */
96 sdata->dev->type = ARPHRD_ETHER;
97
98 switch (type) {
99 case IEEE80211_IF_TYPE_AP:
100 skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
101 INIT_LIST_HEAD(&sdata->u.ap.vlans);
102 break;
103 case IEEE80211_IF_TYPE_MESH_POINT:
104 case IEEE80211_IF_TYPE_STA:
105 case IEEE80211_IF_TYPE_IBSS:
106 ifsta = &sdata->u.sta;
107 INIT_WORK(&ifsta->work, ieee80211_sta_work);
108 setup_timer(&ifsta->timer, ieee80211_sta_timer,
109 (unsigned long) sdata);
110 skb_queue_head_init(&ifsta->skb_queue);
111
112 ifsta->capab = WLAN_CAPABILITY_ESS;
113 ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
114 IEEE80211_AUTH_ALG_SHARED_KEY;
115 ifsta->flags |= IEEE80211_STA_CREATE_IBSS |
116 IEEE80211_STA_AUTO_BSSID_SEL |
117 IEEE80211_STA_AUTO_CHANNEL_SEL;
118 if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4)
119 ifsta->flags |= IEEE80211_STA_WMM_ENABLED;
120
121 if (ieee80211_vif_is_mesh(&sdata->vif))
122 ieee80211_mesh_init_sdata(sdata);
123 break;
124 case IEEE80211_IF_TYPE_MNTR:
125 sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
126 sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit;
127 sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
128 MONITOR_FLAG_OTHER_BSS;
129 break;
130 case IEEE80211_IF_TYPE_WDS:
131 case IEEE80211_IF_TYPE_VLAN:
132 break;
133 case IEEE80211_IF_TYPE_INVALID:
134 BUG();
135 break;
136 }
137
138 ieee80211_debugfs_add_netdev(sdata);
139}
140
141void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
142 enum ieee80211_if_types type)
143{
144 /* Purge and reset type-dependent state. */
145 ieee80211_teardown_sdata(sdata->dev);
146 ieee80211_setup_sdata(sdata, type);
147
148 /* reset some values that shouldn't be kept across type changes */
149 sdata->basic_rates = 0;
150 sdata->drop_unencrypted = 0;
151 sdata->sequence = 0;
41} 152}
42 153
43/* Must be called with rtnl lock held. */
44int ieee80211_if_add(struct ieee80211_local *local, const char *name, 154int ieee80211_if_add(struct ieee80211_local *local, const char *name,
45 struct net_device **new_dev, int type, 155 struct net_device **new_dev, enum ieee80211_if_types type,
46 struct vif_params *params) 156 struct vif_params *params)
47{ 157{
48 struct net_device *ndev; 158 struct net_device *ndev;
49 struct ieee80211_sub_if_data *sdata = NULL; 159 struct ieee80211_sub_if_data *sdata = NULL;
50 int ret; 160 int ret, i;
51 161
52 ASSERT_RTNL(); 162 ASSERT_RTNL();
163
53 ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, 164 ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size,
54 name, ieee80211_if_setup); 165 name, ieee80211_if_setup);
55 if (!ndev) 166 if (!ndev)
@@ -74,18 +185,28 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
74 /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */ 185 /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
75 sdata = netdev_priv(ndev); 186 sdata = netdev_priv(ndev);
76 ndev->ieee80211_ptr = &sdata->wdev; 187 ndev->ieee80211_ptr = &sdata->wdev;
188
189 /* initialise type-independent data */
77 sdata->wdev.wiphy = local->hw.wiphy; 190 sdata->wdev.wiphy = local->hw.wiphy;
78 sdata->vif.type = IEEE80211_IF_TYPE_AP;
79 sdata->dev = ndev;
80 sdata->local = local; 191 sdata->local = local;
81 ieee80211_if_sdata_init(sdata); 192 sdata->dev = ndev;
193
194 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
195 skb_queue_head_init(&sdata->fragments[i].skb_list);
196
197 INIT_LIST_HEAD(&sdata->key_list);
198
199 sdata->force_unicast_rateidx = -1;
200 sdata->max_ratectrl_rateidx = -1;
201
202 /* setup type-dependent data */
203 ieee80211_setup_sdata(sdata, type);
82 204
83 ret = register_netdevice(ndev); 205 ret = register_netdevice(ndev);
84 if (ret) 206 if (ret)
85 goto fail; 207 goto fail;
86 208
87 ieee80211_debugfs_add_netdev(sdata); 209 ndev->uninit = ieee80211_teardown_sdata;
88 ieee80211_if_set_type(ndev, type);
89 210
90 if (ieee80211_vif_is_mesh(&sdata->vif) && 211 if (ieee80211_vif_is_mesh(&sdata->vif) &&
91 params && params->mesh_id_len) 212 params && params->mesh_id_len)
@@ -93,11 +214,6 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
93 params->mesh_id_len, 214 params->mesh_id_len,
94 params->mesh_id); 215 params->mesh_id);
95 216
96 /* we're under RTNL so all this is fine */
97 if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) {
98 __ieee80211_if_del(local, sdata);
99 return -ENODEV;
100 }
101 list_add_tail_rcu(&sdata->list, &local->interfaces); 217 list_add_tail_rcu(&sdata->list, &local->interfaces);
102 218
103 if (new_dev) 219 if (new_dev)
@@ -105,181 +221,34 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
105 221
106 return 0; 222 return 0;
107 223
108fail: 224 fail:
109 free_netdev(ndev); 225 free_netdev(ndev);
110 return ret; 226 return ret;
111} 227}
112 228
113void ieee80211_if_set_type(struct net_device *dev, int type) 229void ieee80211_if_remove(struct net_device *dev)
114{ 230{
115 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
116 int oldtype = sdata->vif.type;
117
118 /*
119 * Called even when register_netdevice fails, it would
120 * oops if assigned before initialising the rest.
121 */
122 dev->uninit = ieee80211_if_reinit;
123
124 /* most have no BSS pointer */
125 sdata->bss = NULL;
126 sdata->vif.type = type;
127
128 sdata->basic_rates = 0;
129
130 switch (type) {
131 case IEEE80211_IF_TYPE_WDS:
132 case IEEE80211_IF_TYPE_VLAN:
133 /* nothing special */
134 break;
135 case IEEE80211_IF_TYPE_AP:
136 skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
137 INIT_LIST_HEAD(&sdata->u.ap.vlans);
138 break;
139 case IEEE80211_IF_TYPE_MESH_POINT:
140 case IEEE80211_IF_TYPE_STA:
141 case IEEE80211_IF_TYPE_IBSS: {
142 struct ieee80211_if_sta *ifsta;
143
144 ifsta = &sdata->u.sta;
145 INIT_WORK(&ifsta->work, ieee80211_sta_work);
146 setup_timer(&ifsta->timer, ieee80211_sta_timer,
147 (unsigned long) sdata);
148 skb_queue_head_init(&ifsta->skb_queue);
149
150 ifsta->capab = WLAN_CAPABILITY_ESS;
151 ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
152 IEEE80211_AUTH_ALG_SHARED_KEY;
153 ifsta->flags |= IEEE80211_STA_CREATE_IBSS |
154 IEEE80211_STA_AUTO_BSSID_SEL |
155 IEEE80211_STA_AUTO_CHANNEL_SEL;
156 if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4)
157 ifsta->flags |= IEEE80211_STA_WMM_ENABLED;
158
159 if (ieee80211_vif_is_mesh(&sdata->vif))
160 ieee80211_mesh_init_sdata(sdata);
161 break;
162 }
163 case IEEE80211_IF_TYPE_MNTR:
164 dev->type = ARPHRD_IEEE80211_RADIOTAP;
165 dev->hard_start_xmit = ieee80211_monitor_start_xmit;
166 sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
167 MONITOR_FLAG_OTHER_BSS;
168 break;
169 case IEEE80211_IF_TYPE_INVALID:
170 BUG();
171 break;
172 }
173 ieee80211_debugfs_change_if_type(sdata, oldtype);
174}
175
176/* Must be called with rtnl lock held. */
177void ieee80211_if_reinit(struct net_device *dev)
178{
179 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
180 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
181 struct sk_buff *skb;
182 int flushed;
183 232
184 ASSERT_RTNL(); 233 ASSERT_RTNL();
185 234
186 ieee80211_free_keys(sdata); 235 list_del_rcu(&sdata->list);
187 236 synchronize_rcu();
188 ieee80211_if_sdata_deinit(sdata);
189
190 /* Need to handle mesh specially to allow eliding the function call */
191 if (ieee80211_vif_is_mesh(&sdata->vif))
192 mesh_rmc_free(dev);
193
194 switch (sdata->vif.type) {
195 case IEEE80211_IF_TYPE_INVALID:
196 /* cannot happen */
197 WARN_ON(1);
198 break;
199 case IEEE80211_IF_TYPE_AP: {
200 struct beacon_data *beacon;
201
202 beacon = sdata->u.ap.beacon;
203 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
204 synchronize_rcu();
205 kfree(beacon);
206
207 while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
208 local->total_ps_buffered--;
209 dev_kfree_skb(skb);
210 }
211
212 break;
213 }
214 case IEEE80211_IF_TYPE_WDS:
215 case IEEE80211_IF_TYPE_VLAN:
216 /* nothing to do */
217 break;
218 case IEEE80211_IF_TYPE_MESH_POINT:
219 case IEEE80211_IF_TYPE_STA:
220 case IEEE80211_IF_TYPE_IBSS:
221 kfree(sdata->u.sta.extra_ie);
222 sdata->u.sta.extra_ie = NULL;
223 kfree(sdata->u.sta.assocreq_ies);
224 sdata->u.sta.assocreq_ies = NULL;
225 kfree(sdata->u.sta.assocresp_ies);
226 sdata->u.sta.assocresp_ies = NULL;
227 if (sdata->u.sta.probe_resp) {
228 dev_kfree_skb(sdata->u.sta.probe_resp);
229 sdata->u.sta.probe_resp = NULL;
230 }
231
232 break;
233 case IEEE80211_IF_TYPE_MNTR:
234 dev->type = ARPHRD_ETHER;
235 break;
236 }
237
238 flushed = sta_info_flush(local, sdata);
239 WARN_ON(flushed);
240
241 memset(&sdata->u, 0, sizeof(sdata->u));
242 ieee80211_if_sdata_init(sdata);
243}
244
245/* Must be called with rtnl lock held. */
246void __ieee80211_if_del(struct ieee80211_local *local,
247 struct ieee80211_sub_if_data *sdata)
248{
249 struct net_device *dev = sdata->dev;
250
251 ieee80211_debugfs_remove_netdev(sdata);
252 unregister_netdevice(dev); 237 unregister_netdevice(dev);
253 /*
254 * The net_device will be freed by its destructor,
255 * i.e. ieee80211_if_free.
256 */
257} 238}
258 239
259/* Must be called with rtnl lock held. */ 240/*
260int ieee80211_if_remove(struct net_device *dev, const char *name, int id) 241 * Remove all interfaces, may only be called at hardware unregistration
242 * time because it doesn't do RCU-safe list removals.
243 */
244void ieee80211_remove_interfaces(struct ieee80211_local *local)
261{ 245{
262 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 246 struct ieee80211_sub_if_data *sdata, *tmp;
263 struct ieee80211_sub_if_data *sdata, *n;
264 247
265 ASSERT_RTNL(); 248 ASSERT_RTNL();
266 249
267 list_for_each_entry_safe(sdata, n, &local->interfaces, list) { 250 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
268 if ((sdata->vif.type == id || id == -1) && 251 list_del(&sdata->list);
269 strcmp(name, sdata->dev->name) == 0) { 252 unregister_netdevice(sdata->dev);
270 list_del_rcu(&sdata->list);
271 synchronize_rcu();
272 __ieee80211_if_del(local, sdata);
273 return 0;
274 }
275 } 253 }
276 return -ENODEV;
277}
278
279void ieee80211_if_free(struct net_device *dev)
280{
281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
282
283 ieee80211_if_sdata_deinit(sdata);
284 free_netdev(dev);
285} 254}
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 863923964d21..0759ab2ca3ff 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -971,7 +971,6 @@ static const struct header_ops ieee80211_header_ops = {
971 .cache_update = eth_header_cache_update, 971 .cache_update = eth_header_cache_update,
972}; 972};
973 973
974/* Must not be called for mdev */
975void ieee80211_if_setup(struct net_device *dev) 974void ieee80211_if_setup(struct net_device *dev)
976{ 975{
977 ether_setup(dev); 976 ether_setup(dev);
@@ -981,7 +980,7 @@ void ieee80211_if_setup(struct net_device *dev)
981 dev->change_mtu = ieee80211_change_mtu; 980 dev->change_mtu = ieee80211_change_mtu;
982 dev->open = ieee80211_open; 981 dev->open = ieee80211_open;
983 dev->stop = ieee80211_stop; 982 dev->stop = ieee80211_stop;
984 dev->destructor = ieee80211_if_free; 983 dev->destructor = free_netdev;
985} 984}
986 985
987/* everything else */ 986/* everything else */
@@ -1776,7 +1775,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1776 printk(KERN_WARNING "%s: Failed to add default virtual iface\n", 1775 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1777 wiphy_name(local->hw.wiphy)); 1776 wiphy_name(local->hw.wiphy));
1778 1777
1779 local->reg_state = IEEE80211_DEV_REGISTERED;
1780 rtnl_unlock(); 1778 rtnl_unlock();
1781 1779
1782 ieee80211_led_init(local); 1780 ieee80211_led_init(local);
@@ -1806,30 +1804,20 @@ EXPORT_SYMBOL(ieee80211_register_hw);
1806void ieee80211_unregister_hw(struct ieee80211_hw *hw) 1804void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1807{ 1805{
1808 struct ieee80211_local *local = hw_to_local(hw); 1806 struct ieee80211_local *local = hw_to_local(hw);
1809 struct ieee80211_sub_if_data *sdata, *tmp;
1810 1807
1811 tasklet_kill(&local->tx_pending_tasklet); 1808 tasklet_kill(&local->tx_pending_tasklet);
1812 tasklet_kill(&local->tasklet); 1809 tasklet_kill(&local->tasklet);
1813 1810
1814 rtnl_lock(); 1811 rtnl_lock();
1815 1812
1816 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1817
1818 local->reg_state = IEEE80211_DEV_UNREGISTERED;
1819
1820 /* 1813 /*
1821 * At this point, interface list manipulations are fine 1814 * At this point, interface list manipulations are fine
1822 * because the driver cannot be handing us frames any 1815 * because the driver cannot be handing us frames any
1823 * more and the tasklet is killed. 1816 * more and the tasklet is killed.
1824 */ 1817 */
1825 1818
1826 /* 1819 /* First, we remove all virtual interfaces. */
1827 * First, we remove all virtual interfaces. 1820 ieee80211_remove_interfaces(local);
1828 */
1829 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1830 list_del(&sdata->list);
1831 __ieee80211_if_del(local, sdata);
1832 }
1833 1821
1834 /* then, finally, remove the master interface */ 1822 /* then, finally, remove the master interface */
1835 unregister_netdevice(local->mdev); 1823 unregister_netdevice(local->mdev);
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index e8e4a6215e89..f2fdd3342195 100644
--- a/net/mac80211/wext.c
+++ b/net/mac80211/wext.c
@@ -301,8 +301,7 @@ static int ieee80211_ioctl_siwmode(struct net_device *dev,
301 if (netif_running(dev)) 301 if (netif_running(dev))
302 return -EBUSY; 302 return -EBUSY;
303 303
304 ieee80211_if_reinit(dev); 304 ieee80211_if_change_type(sdata, type);
305 ieee80211_if_set_type(dev, type);
306 305
307 return 0; 306 return 0;
308} 307}