2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
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.
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"
17 #include "debugfs_netdev.h"
19 void ieee80211_if_sdata_init(struct ieee80211_sub_if_data
*sdata
)
23 /* Default values for sub-interface parameters */
24 sdata
->drop_unencrypted
= 0;
26 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++)
27 skb_queue_head_init(&sdata
->fragments
[i
].skb_list
);
30 static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data
*sdata
)
34 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
35 __skb_queue_purge(&sdata
->fragments
[i
].skb_list
);
39 /* Must be called with rtnl lock held. */
40 int ieee80211_if_add(struct net_device
*dev
, const char *name
,
41 struct net_device
**new_dev
, int type
)
43 struct net_device
*ndev
;
44 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
45 struct ieee80211_sub_if_data
*sdata
= NULL
;
49 ndev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
50 name
, ieee80211_if_setup
);
54 ret
= dev_alloc_name(ndev
, ndev
->name
);
58 memcpy(ndev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
59 ndev
->base_addr
= dev
->base_addr
;
61 ndev
->mem_start
= dev
->mem_start
;
62 ndev
->mem_end
= dev
->mem_end
;
63 SET_NETDEV_DEV(ndev
, wiphy_dev(local
->hw
.wiphy
));
65 sdata
= IEEE80211_DEV_TO_SUB_IF(ndev
);
66 ndev
->ieee80211_ptr
= &sdata
->wdev
;
67 sdata
->wdev
.wiphy
= local
->hw
.wiphy
;
68 sdata
->type
= IEEE80211_IF_TYPE_AP
;
71 ieee80211_if_sdata_init(sdata
);
73 ret
= register_netdevice(ndev
);
77 ieee80211_debugfs_add_netdev(sdata
);
78 ieee80211_if_set_type(ndev
, type
);
80 write_lock_bh(&local
->sub_if_lock
);
81 if (unlikely(local
->reg_state
== IEEE80211_DEV_UNREGISTERED
)) {
82 write_unlock_bh(&local
->sub_if_lock
);
83 __ieee80211_if_del(local
, sdata
);
86 list_add(&sdata
->list
, &local
->sub_if_list
);
89 write_unlock_bh(&local
->sub_if_lock
);
91 ieee80211_update_default_wep_only(local
);
100 int ieee80211_if_add_mgmt(struct ieee80211_local
*local
)
102 struct net_device
*ndev
;
103 struct ieee80211_sub_if_data
*nsdata
;
108 ndev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
), "wmgmt%d",
109 ieee80211_if_mgmt_setup
);
112 ret
= dev_alloc_name(ndev
, ndev
->name
);
116 memcpy(ndev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
117 SET_NETDEV_DEV(ndev
, wiphy_dev(local
->hw
.wiphy
));
119 nsdata
= IEEE80211_DEV_TO_SUB_IF(ndev
);
120 ndev
->ieee80211_ptr
= &nsdata
->wdev
;
121 nsdata
->wdev
.wiphy
= local
->hw
.wiphy
;
122 nsdata
->type
= IEEE80211_IF_TYPE_MGMT
;
124 nsdata
->local
= local
;
125 ieee80211_if_sdata_init(nsdata
);
127 ret
= register_netdevice(ndev
);
131 ieee80211_debugfs_add_netdev(nsdata
);
133 if (local
->open_count
> 0)
143 void ieee80211_if_del_mgmt(struct ieee80211_local
*local
)
145 struct net_device
*apdev
;
148 apdev
= local
->apdev
;
149 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(apdev
));
151 unregister_netdevice(apdev
);
154 void ieee80211_if_set_type(struct net_device
*dev
, int type
)
156 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
157 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
158 int oldtype
= sdata
->type
;
162 case IEEE80211_IF_TYPE_WDS
:
165 case IEEE80211_IF_TYPE_VLAN
:
167 case IEEE80211_IF_TYPE_AP
:
168 sdata
->u
.ap
.dtim_period
= 2;
169 sdata
->u
.ap
.force_unicast_rateidx
= -1;
170 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
171 skb_queue_head_init(&sdata
->u
.ap
.ps_bc_buf
);
172 sdata
->bss
= &sdata
->u
.ap
;
174 case IEEE80211_IF_TYPE_STA
:
175 case IEEE80211_IF_TYPE_IBSS
: {
176 struct ieee80211_sub_if_data
*msdata
;
177 struct ieee80211_if_sta
*ifsta
;
179 ifsta
= &sdata
->u
.sta
;
180 INIT_WORK(&ifsta
->work
, ieee80211_sta_work
);
181 setup_timer(&ifsta
->timer
, ieee80211_sta_timer
,
182 (unsigned long) sdata
);
183 skb_queue_head_init(&ifsta
->skb_queue
);
185 init_timer(&ifsta
->admit_timer
);
186 ifsta
->admit_timer
.data
= (unsigned long) dev
;
187 ifsta
->admit_timer
.function
= ieee80211_admit_refresh
;
189 ifsta
->capab
= WLAN_CAPABILITY_ESS
;
190 ifsta
->auth_algs
= IEEE80211_AUTH_ALG_OPEN
|
191 IEEE80211_AUTH_ALG_SHARED_KEY
;
192 ifsta
->create_ibss
= 1;
193 ifsta
->wmm_enabled
= 1;
194 ifsta
->ht_enabled
= 1;
195 ifsta
->auto_channel_sel
= 1;
196 ifsta
->auto_bssid_sel
= 1;
198 /* Initialize non-AP QSTA QoS Params */
199 ifsta
->dot11EDCAAveragingPeriod
= 5;
200 ifsta
->MPDUExchangeTime
= 0;
201 #ifdef CONFIG_MAC80211_DEBUGFS
202 ifsta
->tspec
.nominal_msdu_size
= cpu_to_le16(200),
203 ifsta
->tspec
.inactivity_interval
= cpu_to_le32(40),
204 ifsta
->tspec
.mean_data_rate
= cpu_to_le32(40000),
205 ifsta
->tspec
.min_phy_rate
= cpu_to_le32(6000000),
206 ifsta
->tspec
.surplus_band_allow
= cpu_to_le16(8192),
207 ifsta
->tspec
.medium_time
= cpu_to_le16(30),
210 msdata
= IEEE80211_DEV_TO_SUB_IF(sdata
->local
->mdev
);
211 sdata
->bss
= &msdata
->u
.ap
;
214 case IEEE80211_IF_TYPE_MNTR
:
215 dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
218 printk(KERN_WARNING
"%s: %s: Unknown interface type 0x%x",
219 dev
->name
, __FUNCTION__
, type
);
221 ieee80211_debugfs_change_if_type(sdata
, oldtype
);
222 ieee80211_update_default_wep_only(local
);
225 /* Must be called with rtnl lock held. */
226 void ieee80211_if_reinit(struct net_device
*dev
)
228 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
229 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
230 struct sta_info
*sta
;
234 ieee80211_if_sdata_deinit(sdata
);
235 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
239 /* The interface is down at the moment, so there is not
240 * really much point in disabling the keys at this point. */
241 memset(addr
, 0xff, ETH_ALEN
);
242 if (local
->ops
->set_key
)
243 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
, addr
,
246 ieee80211_key_free(sdata
->keys
[i
]);
247 sdata
->keys
[i
] = NULL
;
250 switch (sdata
->type
) {
251 case IEEE80211_IF_TYPE_AP
: {
252 /* Remove all virtual interfaces that use this BSS
253 * as their sdata->bss */
254 struct ieee80211_sub_if_data
*tsdata
, *n
;
257 write_lock_bh(&local
->sub_if_lock
);
258 list_for_each_entry_safe(tsdata
, n
, &local
->sub_if_list
, list
) {
259 if (tsdata
!= sdata
&& tsdata
->bss
== &sdata
->u
.ap
) {
260 printk(KERN_DEBUG
"%s: removing virtual "
261 "interface %s because its BSS interface"
262 " is being removed\n",
263 sdata
->dev
->name
, tsdata
->dev
->name
);
264 list_move_tail(&tsdata
->list
, &tmp_list
);
267 write_unlock_bh(&local
->sub_if_lock
);
269 list_for_each_entry_safe(tsdata
, n
, &tmp_list
, list
)
270 __ieee80211_if_del(local
, tsdata
);
272 kfree(sdata
->u
.ap
.beacon_head
);
273 kfree(sdata
->u
.ap
.beacon_tail
);
274 kfree(sdata
->u
.ap
.generic_elem
);
276 if (dev
!= local
->mdev
) {
278 while ((skb
= skb_dequeue(&sdata
->u
.ap
.ps_bc_buf
))) {
279 local
->total_ps_buffered
--;
286 case IEEE80211_IF_TYPE_WDS
:
287 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
290 sta_info_free(sta
, 0);
292 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
293 printk(KERN_DEBUG
"%s: Someone had deleted my STA "
294 "entry for the WDS link\n", dev
->name
);
295 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
298 case IEEE80211_IF_TYPE_STA
:
299 case IEEE80211_IF_TYPE_IBSS
:
300 kfree(sdata
->u
.sta
.extra_ie
);
301 sdata
->u
.sta
.extra_ie
= NULL
;
302 kfree(sdata
->u
.sta
.assocreq_ies
);
303 sdata
->u
.sta
.assocreq_ies
= NULL
;
304 kfree(sdata
->u
.sta
.assocresp_ies
);
305 sdata
->u
.sta
.assocresp_ies
= NULL
;
306 if (sdata
->u
.sta
.probe_resp
) {
307 dev_kfree_skb(sdata
->u
.sta
.probe_resp
);
308 sdata
->u
.sta
.probe_resp
= NULL
;
312 case IEEE80211_IF_TYPE_MNTR
:
313 dev
->type
= ARPHRD_ETHER
;
317 /* remove all STAs that are bound to this virtual interface */
318 sta_info_flush(local
, dev
);
320 memset(&sdata
->u
, 0, sizeof(sdata
->u
));
321 ieee80211_if_sdata_init(sdata
);
324 /* Must be called with rtnl lock held. */
325 void __ieee80211_if_del(struct ieee80211_local
*local
,
326 struct ieee80211_sub_if_data
*sdata
)
328 struct net_device
*dev
= sdata
->dev
;
330 ieee80211_debugfs_remove_netdev(sdata
);
331 unregister_netdevice(dev
);
332 /* Except master interface, the net_device will be freed by
333 * net_device->destructor (i. e. ieee80211_if_free). */
336 /* Must be called with rtnl lock held. */
337 int ieee80211_if_remove(struct net_device
*dev
, const char *name
, int id
)
339 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
340 struct ieee80211_sub_if_data
*sdata
, *n
;
344 write_lock_bh(&local
->sub_if_lock
);
345 list_for_each_entry_safe(sdata
, n
, &local
->sub_if_list
, list
) {
346 if ((sdata
->type
== id
|| id
== -1) &&
347 strcmp(name
, sdata
->dev
->name
) == 0 &&
348 sdata
->dev
!= local
->mdev
) {
349 list_del(&sdata
->list
);
350 write_unlock_bh(&local
->sub_if_lock
);
351 __ieee80211_if_del(local
, sdata
);
352 ieee80211_update_default_wep_only(local
);
356 write_unlock_bh(&local
->sub_if_lock
);
360 void ieee80211_if_free(struct net_device
*dev
)
362 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
363 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
365 /* local->apdev must be NULL when freeing management interface */
366 BUG_ON(dev
== local
->apdev
);
367 ieee80211_if_sdata_deinit(sdata
);