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/d80211.h>
15 #include "ieee80211_i.h"
18 void ieee80211_if_sdata_init(struct ieee80211_sub_if_data
*sdata
)
22 /* Default values for sub-interface parameters */
23 sdata
->drop_unencrypted
= 0;
25 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++)
26 skb_queue_head_init(&sdata
->fragments
[i
].skb_list
);
29 static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data
*sdata
)
33 for (i
= 0; i
< IEEE80211_FRAGMENT_MAX
; i
++) {
34 __skb_queue_purge(&sdata
->fragments
[i
].skb_list
);
38 /* Must be called with rtnl lock held. */
39 int ieee80211_if_add(struct net_device
*dev
, const char *name
,
40 int format
, struct net_device
**new_dev
)
42 struct net_device
*ndev
, *tmp_dev
;
43 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
44 struct ieee80211_sub_if_data
*sdata
= NULL
;
49 ndev
= *new_dev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
50 "", ieee80211_if_setup
);
54 ndev
->ieee80211_ptr
= local
;
55 if (strlen(name
) == 0) {
58 snprintf(ndev
->name
, sizeof(ndev
->name
), "%s.%d",
60 tmp_dev
= dev_get_by_name(ndev
->name
);
66 ret
= dev_alloc_name(ndev
, name
);
70 snprintf(ndev
->name
, IFNAMSIZ
, "%s", name
);
73 memcpy(ndev
->dev_addr
, local
->hw
.perm_addr
, ETH_ALEN
);
74 ndev
->base_addr
= dev
->base_addr
;
76 ndev
->mem_start
= dev
->mem_start
;
77 ndev
->mem_end
= dev
->mem_end
;
78 ndev
->flags
= dev
->flags
& IFF_MULTICAST
;
79 SET_NETDEV_DEV(ndev
, local
->hw
.dev
);
81 sdata
= IEEE80211_DEV_TO_SUB_IF(ndev
);
82 sdata
->type
= IEEE80211_IF_TYPE_AP
;
85 ieee80211_if_sdata_init(sdata
);
87 ret
= register_netdevice(ndev
);
90 ret
= ieee80211_sysfs_add_netdevice(ndev
);
92 /* ndev will be freed by ndev->destructor */
93 unregister_netdevice(ndev
);
98 list_add(&sdata
->list
, &local
->sub_if_list
);
99 ieee80211_update_default_wep_only(local
);
109 int ieee80211_if_add_mgmt(struct ieee80211_local
*local
)
111 struct net_device
*ndev
;
112 struct ieee80211_sub_if_data
*nsdata
;
117 ndev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
), "",
118 ieee80211_if_mgmt_setup
);
121 ret
= dev_alloc_name(ndev
, "wmgmt%d");
125 ndev
->ieee80211_ptr
= local
;
126 memcpy(ndev
->dev_addr
, local
->hw
.perm_addr
, ETH_ALEN
);
127 SET_NETDEV_DEV(ndev
, local
->hw
.dev
);
129 nsdata
= IEEE80211_DEV_TO_SUB_IF(ndev
);
130 nsdata
->type
= IEEE80211_IF_TYPE_MGMT
;
132 nsdata
->local
= local
;
133 ieee80211_if_sdata_init(nsdata
);
135 ret
= register_netdevice(ndev
);
138 ret
= ieee80211_sysfs_add_netdevice(ndev
);
141 if (local
->open_count
> 0)
147 unregister_netdevice(ndev
);
153 void ieee80211_if_del_mgmt(struct ieee80211_local
*local
)
155 struct net_device
*apdev
;
158 apdev
= local
->apdev
;
159 ieee80211_sysfs_remove_netdevice(apdev
);
161 unregister_netdevice(apdev
);
164 void ieee80211_if_set_type(struct net_device
*dev
, int type
)
166 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
167 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
171 case IEEE80211_IF_TYPE_WDS
:
174 case IEEE80211_IF_TYPE_VLAN
:
176 case IEEE80211_IF_TYPE_AP
:
177 sdata
->u
.ap
.dtim_period
= 2;
178 sdata
->u
.ap
.force_unicast_rateidx
= -1;
179 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
180 skb_queue_head_init(&sdata
->u
.ap
.ps_bc_buf
);
181 sdata
->bss
= &sdata
->u
.ap
;
183 case IEEE80211_IF_TYPE_STA
:
184 case IEEE80211_IF_TYPE_IBSS
: {
185 struct ieee80211_sub_if_data
*msdata
;
186 struct ieee80211_if_sta
*ifsta
;
188 ifsta
= &sdata
->u
.sta
;
189 INIT_DELAYED_WORK(&ifsta
->work
, ieee80211_sta_work
);
191 ifsta
->capab
= WLAN_CAPABILITY_ESS
;
192 ifsta
->auth_algs
= IEEE80211_AUTH_ALG_OPEN
|
193 IEEE80211_AUTH_ALG_SHARED_KEY
;
194 ifsta
->create_ibss
= 1;
195 ifsta
->wmm_enabled
= 1;
197 msdata
= IEEE80211_DEV_TO_SUB_IF(sdata
->local
->mdev
);
198 sdata
->bss
= &msdata
->u
.ap
;
201 case IEEE80211_IF_TYPE_MNTR
:
202 dev
->type
= ARPHRD_IEEE80211_PRISM
;
205 printk(KERN_WARNING
"%s: %s: Unknown interface type 0x%x",
206 dev
->name
, __FUNCTION__
, type
);
208 ieee80211_sysfs_change_if_type(dev
);
209 ieee80211_update_default_wep_only(local
);
212 /* Must be called with rtnl lock held. */
213 void ieee80211_if_reinit(struct net_device
*dev
)
215 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
216 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
217 struct sta_info
*sta
;
221 ieee80211_if_sdata_deinit(sdata
);
222 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
226 /* The interface is down at the moment, so there is not
227 * really much point in disabling the keys at this point. */
228 memset(addr
, 0xff, ETH_ALEN
);
229 if (local
->ops
->set_key
)
230 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
, addr
,
233 ieee80211_key_free(sdata
->keys
[i
]);
234 sdata
->keys
[i
] = NULL
;
237 switch (sdata
->type
) {
238 case IEEE80211_IF_TYPE_AP
: {
239 /* Remove all virtual interfaces that use this BSS
240 * as their sdata->bss */
241 struct ieee80211_sub_if_data
*tsdata
, *n
;
243 list_for_each_entry_safe(tsdata
, n
, &local
->sub_if_list
, list
) {
244 if (tsdata
!= sdata
&& tsdata
->bss
== &sdata
->u
.ap
) {
245 printk(KERN_DEBUG
"%s: removing virtual "
246 "interface %s because its BSS interface"
247 " is being removed\n",
248 sdata
->dev
->name
, tsdata
->dev
->name
);
249 __ieee80211_if_del(local
, tsdata
);
253 kfree(sdata
->u
.ap
.beacon_head
);
254 kfree(sdata
->u
.ap
.beacon_tail
);
255 kfree(sdata
->u
.ap
.generic_elem
);
257 if (dev
!= local
->mdev
) {
259 while ((skb
= skb_dequeue(&sdata
->u
.ap
.ps_bc_buf
))) {
260 local
->total_ps_buffered
--;
267 case IEEE80211_IF_TYPE_WDS
:
268 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
271 sta_info_free(sta
, 0);
273 #ifdef CONFIG_D80211_VERBOSE_DEBUG
274 printk(KERN_DEBUG
"%s: Someone had deleted my STA "
275 "entry for the WDS link\n", dev
->name
);
276 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
279 case IEEE80211_IF_TYPE_STA
:
280 case IEEE80211_IF_TYPE_IBSS
:
281 kfree(sdata
->u
.sta
.extra_ie
);
282 sdata
->u
.sta
.extra_ie
= NULL
;
283 kfree(sdata
->u
.sta
.assocreq_ies
);
284 sdata
->u
.sta
.assocreq_ies
= NULL
;
285 kfree(sdata
->u
.sta
.assocresp_ies
);
286 sdata
->u
.sta
.assocresp_ies
= NULL
;
287 if (sdata
->u
.sta
.probe_resp
) {
288 dev_kfree_skb(sdata
->u
.sta
.probe_resp
);
289 sdata
->u
.sta
.probe_resp
= NULL
;
293 case IEEE80211_IF_TYPE_MNTR
:
294 dev
->type
= ARPHRD_ETHER
;
298 /* remove all STAs that are bound to this virtual interface */
299 sta_info_flush(local
, dev
);
301 memset(&sdata
->u
, 0, sizeof(sdata
->u
));
302 ieee80211_if_sdata_init(sdata
);
305 /* Must be called with rtnl lock held. */
306 void __ieee80211_if_del(struct ieee80211_local
*local
,
307 struct ieee80211_sub_if_data
*sdata
)
309 struct net_device
*dev
= sdata
->dev
;
311 list_del(&sdata
->list
);
312 ieee80211_sysfs_remove_netdevice(dev
);
313 unregister_netdevice(dev
);
314 /* Except master interface, the net_device will be freed by
315 * net_device->destructor (i. e. ieee80211_if_free). */
318 /* Must be called with rtnl lock held. */
319 int ieee80211_if_remove(struct net_device
*dev
, const char *name
, int id
)
321 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
322 struct ieee80211_sub_if_data
*sdata
, *n
;
326 list_for_each_entry_safe(sdata
, n
, &local
->sub_if_list
, list
) {
327 if ((sdata
->type
== id
|| id
== -1) &&
328 strcmp(name
, sdata
->dev
->name
) == 0 &&
329 sdata
->dev
!= local
->mdev
) {
330 __ieee80211_if_del(local
, sdata
);
331 ieee80211_update_default_wep_only(local
);
338 void ieee80211_if_free(struct net_device
*dev
)
340 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
341 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
343 /* local->apdev must be NULL when freeing management interface */
344 BUG_ON(dev
== local
->apdev
);
345 ieee80211_if_sdata_deinit(sdata
);
349 /* Must be called with rtnl lock held. */
350 void ieee80211_if_flush(struct net_device
*dev
)
352 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
353 struct ieee80211_sub_if_data
*sdata
, *n
;
356 list_for_each_entry_safe(sdata
, n
, &local
->sub_if_list
, list
) {
357 __ieee80211_if_del(local
, sdata
);
361 void ieee80211_if_del(struct net_device
*dev
)
363 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
364 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
367 if (sdata
->type
== IEEE80211_IF_TYPE_MGMT
)
368 ieee80211_if_del_mgmt(local
);
370 __ieee80211_if_del(local
, sdata
);