aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/ieee80211_iface.c
diff options
context:
space:
mode:
authorJiri Benc <jbenc@suse.cz>2007-05-05 14:45:53 -0400
committerDavid S. Miller <davem@davemloft.net>2007-05-05 14:45:53 -0400
commitf0706e828e96d0fa4e80c0d25aa98523f6d589a0 (patch)
treea03c7f94939d74c1e1b82fcd9a215871590d8b35 /net/mac80211/ieee80211_iface.c
parenta9de8ce0943e03b425be18561f51159fcceb873d (diff)
[MAC80211]: Add mac80211 wireless stack.
Add mac80211, the IEEE 802.11 software MAC layer. Signed-off-by: Jiri Benc <jbenc@suse.cz> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211/ieee80211_iface.c')
-rw-r--r--net/mac80211/ieee80211_iface.c344
1 files changed, 344 insertions, 0 deletions
diff --git a/net/mac80211/ieee80211_iface.c b/net/mac80211/ieee80211_iface.c
new file mode 100644
index 000000000000..64267d4b31a4
--- /dev/null
+++ b/net/mac80211/ieee80211_iface.c
@@ -0,0 +1,344 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/kernel.h>
11#include <linux/if_arp.h>
12#include <linux/netdevice.h>
13#include <linux/rtnetlink.h>
14#include <net/mac80211.h>
15#include "ieee80211_i.h"
16#include "sta_info.h"
17
18void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
19{
20 int i;
21
22 /* Default values for sub-interface parameters */
23 sdata->drop_unencrypted = 0;
24 sdata->eapol = 1;
25 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
26 skb_queue_head_init(&sdata->fragments[i].skb_list);
27}
28
29static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata)
30{
31 int i;
32
33 for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
34 __skb_queue_purge(&sdata->fragments[i].skb_list);
35 }
36}
37
38/* Must be called with rtnl lock held. */
39int ieee80211_if_add(struct net_device *dev, const char *name,
40 struct net_device **new_dev, int type)
41{
42 struct net_device *ndev;
43 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
44 struct ieee80211_sub_if_data *sdata = NULL;
45 int ret;
46
47 ASSERT_RTNL();
48 ndev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
49 name, ieee80211_if_setup);
50 if (!ndev)
51 return -ENOMEM;
52
53 ret = dev_alloc_name(ndev, ndev->name);
54 if (ret < 0)
55 goto fail;
56
57 memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
58 ndev->base_addr = dev->base_addr;
59 ndev->irq = dev->irq;
60 ndev->mem_start = dev->mem_start;
61 ndev->mem_end = dev->mem_end;
62 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
63
64 sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
65 ndev->ieee80211_ptr = &sdata->wdev;
66 sdata->wdev.wiphy = local->hw.wiphy;
67 sdata->type = IEEE80211_IF_TYPE_AP;
68 sdata->dev = ndev;
69 sdata->local = local;
70 ieee80211_if_sdata_init(sdata);
71
72 ret = register_netdevice(ndev);
73 if (ret)
74 goto fail;
75
76 ieee80211_if_set_type(ndev, type);
77
78 write_lock_bh(&local->sub_if_lock);
79 if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) {
80 write_unlock_bh(&local->sub_if_lock);
81 __ieee80211_if_del(local, sdata);
82 return -ENODEV;
83 }
84 list_add(&sdata->list, &local->sub_if_list);
85 if (new_dev)
86 *new_dev = ndev;
87 write_unlock_bh(&local->sub_if_lock);
88
89 ieee80211_update_default_wep_only(local);
90
91 return 0;
92
93fail:
94 free_netdev(ndev);
95 return ret;
96}
97
98int ieee80211_if_add_mgmt(struct ieee80211_local *local)
99{
100 struct net_device *ndev;
101 struct ieee80211_sub_if_data *nsdata;
102 int ret;
103
104 ASSERT_RTNL();
105
106 ndev = alloc_netdev(sizeof(struct ieee80211_sub_if_data), "wmgmt%d",
107 ieee80211_if_mgmt_setup);
108 if (!ndev)
109 return -ENOMEM;
110 ret = dev_alloc_name(ndev, ndev->name);
111 if (ret < 0)
112 goto fail;
113
114 memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
115 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
116
117 nsdata = IEEE80211_DEV_TO_SUB_IF(ndev);
118 ndev->ieee80211_ptr = &nsdata->wdev;
119 nsdata->wdev.wiphy = local->hw.wiphy;
120 nsdata->type = IEEE80211_IF_TYPE_MGMT;
121 nsdata->dev = ndev;
122 nsdata->local = local;
123 ieee80211_if_sdata_init(nsdata);
124
125 ret = register_netdevice(ndev);
126 if (ret)
127 goto fail;
128
129 if (local->open_count > 0)
130 dev_open(ndev);
131 local->apdev = ndev;
132 return 0;
133
134fail:
135 free_netdev(ndev);
136 return ret;
137}
138
139void ieee80211_if_del_mgmt(struct ieee80211_local *local)
140{
141 struct net_device *apdev;
142
143 ASSERT_RTNL();
144 apdev = local->apdev;
145 local->apdev = NULL;
146 unregister_netdevice(apdev);
147}
148
149void ieee80211_if_set_type(struct net_device *dev, int type)
150{
151 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
152 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
153
154 sdata->type = type;
155 switch (type) {
156 case IEEE80211_IF_TYPE_WDS:
157 sdata->bss = NULL;
158 break;
159 case IEEE80211_IF_TYPE_VLAN:
160 break;
161 case IEEE80211_IF_TYPE_AP:
162 sdata->u.ap.dtim_period = 2;
163 sdata->u.ap.force_unicast_rateidx = -1;
164 sdata->u.ap.max_ratectrl_rateidx = -1;
165 skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
166 sdata->bss = &sdata->u.ap;
167 break;
168 case IEEE80211_IF_TYPE_STA:
169 case IEEE80211_IF_TYPE_IBSS: {
170 struct ieee80211_sub_if_data *msdata;
171 struct ieee80211_if_sta *ifsta;
172
173 ifsta = &sdata->u.sta;
174 INIT_WORK(&ifsta->work, ieee80211_sta_work);
175 setup_timer(&ifsta->timer, ieee80211_sta_timer,
176 (unsigned long) sdata);
177 skb_queue_head_init(&ifsta->skb_queue);
178
179 ifsta->capab = WLAN_CAPABILITY_ESS;
180 ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
181 IEEE80211_AUTH_ALG_SHARED_KEY;
182 ifsta->create_ibss = 1;
183 ifsta->wmm_enabled = 1;
184 ifsta->auto_channel_sel = 1;
185 ifsta->auto_bssid_sel = 1;
186
187 msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev);
188 sdata->bss = &msdata->u.ap;
189 break;
190 }
191 case IEEE80211_IF_TYPE_MNTR:
192 dev->type = ARPHRD_IEEE80211_RADIOTAP;
193 break;
194 default:
195 printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x",
196 dev->name, __FUNCTION__, type);
197 }
198 ieee80211_update_default_wep_only(local);
199}
200
201/* Must be called with rtnl lock held. */
202void ieee80211_if_reinit(struct net_device *dev)
203{
204 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
205 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
206 struct sta_info *sta;
207 int i;
208
209 ASSERT_RTNL();
210 ieee80211_if_sdata_deinit(sdata);
211 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
212 if (!sdata->keys[i])
213 continue;
214#if 0
215 /* The interface is down at the moment, so there is not
216 * really much point in disabling the keys at this point. */
217 memset(addr, 0xff, ETH_ALEN);
218 if (local->ops->set_key)
219 local->ops->set_key(local_to_hw(local), DISABLE_KEY, addr,
220 local->keys[i], 0);
221#endif
222 ieee80211_key_free(sdata->keys[i]);
223 sdata->keys[i] = NULL;
224 }
225
226 switch (sdata->type) {
227 case IEEE80211_IF_TYPE_AP: {
228 /* Remove all virtual interfaces that use this BSS
229 * as their sdata->bss */
230 struct ieee80211_sub_if_data *tsdata, *n;
231 LIST_HEAD(tmp_list);
232
233 write_lock_bh(&local->sub_if_lock);
234 list_for_each_entry_safe(tsdata, n, &local->sub_if_list, list) {
235 if (tsdata != sdata && tsdata->bss == &sdata->u.ap) {
236 printk(KERN_DEBUG "%s: removing virtual "
237 "interface %s because its BSS interface"
238 " is being removed\n",
239 sdata->dev->name, tsdata->dev->name);
240 list_move_tail(&tsdata->list, &tmp_list);
241 }
242 }
243 write_unlock_bh(&local->sub_if_lock);
244
245 list_for_each_entry_safe(tsdata, n, &tmp_list, list)
246 __ieee80211_if_del(local, tsdata);
247
248 kfree(sdata->u.ap.beacon_head);
249 kfree(sdata->u.ap.beacon_tail);
250 kfree(sdata->u.ap.generic_elem);
251
252 if (dev != local->mdev) {
253 struct sk_buff *skb;
254 while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
255 local->total_ps_buffered--;
256 dev_kfree_skb(skb);
257 }
258 }
259
260 break;
261 }
262 case IEEE80211_IF_TYPE_WDS:
263 sta = sta_info_get(local, sdata->u.wds.remote_addr);
264 if (sta) {
265 sta_info_put(sta);
266 sta_info_free(sta, 0);
267 } else {
268#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
269 printk(KERN_DEBUG "%s: Someone had deleted my STA "
270 "entry for the WDS link\n", dev->name);
271#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
272 }
273 break;
274 case IEEE80211_IF_TYPE_STA:
275 case IEEE80211_IF_TYPE_IBSS:
276 kfree(sdata->u.sta.extra_ie);
277 sdata->u.sta.extra_ie = NULL;
278 kfree(sdata->u.sta.assocreq_ies);
279 sdata->u.sta.assocreq_ies = NULL;
280 kfree(sdata->u.sta.assocresp_ies);
281 sdata->u.sta.assocresp_ies = NULL;
282 if (sdata->u.sta.probe_resp) {
283 dev_kfree_skb(sdata->u.sta.probe_resp);
284 sdata->u.sta.probe_resp = NULL;
285 }
286
287 break;
288 case IEEE80211_IF_TYPE_MNTR:
289 dev->type = ARPHRD_ETHER;
290 break;
291 }
292
293 /* remove all STAs that are bound to this virtual interface */
294 sta_info_flush(local, dev);
295
296 memset(&sdata->u, 0, sizeof(sdata->u));
297 ieee80211_if_sdata_init(sdata);
298}
299
300/* Must be called with rtnl lock held. */
301void __ieee80211_if_del(struct ieee80211_local *local,
302 struct ieee80211_sub_if_data *sdata)
303{
304 struct net_device *dev = sdata->dev;
305
306 unregister_netdevice(dev);
307 /* Except master interface, the net_device will be freed by
308 * net_device->destructor (i. e. ieee80211_if_free). */
309}
310
311/* Must be called with rtnl lock held. */
312int ieee80211_if_remove(struct net_device *dev, const char *name, int id)
313{
314 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
315 struct ieee80211_sub_if_data *sdata, *n;
316
317 ASSERT_RTNL();
318
319 write_lock_bh(&local->sub_if_lock);
320 list_for_each_entry_safe(sdata, n, &local->sub_if_list, list) {
321 if ((sdata->type == id || id == -1) &&
322 strcmp(name, sdata->dev->name) == 0 &&
323 sdata->dev != local->mdev) {
324 list_del(&sdata->list);
325 write_unlock_bh(&local->sub_if_lock);
326 __ieee80211_if_del(local, sdata);
327 ieee80211_update_default_wep_only(local);
328 return 0;
329 }
330 }
331 write_unlock_bh(&local->sub_if_lock);
332 return -ENODEV;
333}
334
335void ieee80211_if_free(struct net_device *dev)
336{
337 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
338 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
339
340 /* local->apdev must be NULL when freeing management interface */
341 BUG_ON(dev == local->apdev);
342 ieee80211_if_sdata_deinit(sdata);
343 free_netdev(dev);
344}