Commit 75636525 authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville

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: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 3e122be0
...@@ -50,9 +50,6 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name, ...@@ -50,9 +50,6 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
struct ieee80211_sub_if_data *sdata; struct ieee80211_sub_if_data *sdata;
int err; int err;
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
return -ENODEV;
itype = nl80211_type_to_mac80211_type(type); itype = nl80211_type_to_mac80211_type(type);
if (itype == IEEE80211_IF_TYPE_INVALID) if (itype == IEEE80211_IF_TYPE_INVALID)
return -EINVAL; return -EINVAL;
...@@ -68,35 +65,26 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name, ...@@ -68,35 +65,26 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
{ {
struct ieee80211_local *local = wiphy_priv(wiphy);
struct net_device *dev; struct net_device *dev;
char *name;
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
return -ENODEV;
/* we're under RTNL */ /* we're under RTNL */
dev = __dev_get_by_index(&init_net, ifindex); dev = __dev_get_by_index(&init_net, ifindex);
if (!dev) if (!dev)
return 0; return -ENODEV;
name = dev->name; ieee80211_if_remove(dev);
return ieee80211_if_remove(local->mdev, name, -1); return 0;
} }
static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
enum nl80211_iftype type, u32 *flags, enum nl80211_iftype type, u32 *flags,
struct vif_params *params) struct vif_params *params)
{ {
struct ieee80211_local *local = wiphy_priv(wiphy);
struct net_device *dev; struct net_device *dev;
enum ieee80211_if_types itype; enum ieee80211_if_types itype;
struct ieee80211_sub_if_data *sdata; struct ieee80211_sub_if_data *sdata;
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
return -ENODEV;
/* we're under RTNL */ /* we're under RTNL */
dev = __dev_get_by_index(&init_net, ifindex); dev = __dev_get_by_index(&init_net, ifindex);
if (!dev) if (!dev)
...@@ -111,11 +99,7 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, ...@@ -111,11 +99,7 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) ieee80211_if_change_type(sdata, itype);
return -EOPNOTSUPP;
ieee80211_if_reinit(dev);
ieee80211_if_set_type(dev, itype);
if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
ieee80211_if_sta_set_mesh_id(&sdata->u.sta, ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
......
...@@ -70,16 +70,6 @@ DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", ...@@ -70,16 +70,6 @@ DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
/* statistics stuff */ /* statistics stuff */
static inline int rtnl_lock_local(struct ieee80211_local *local)
{
rtnl_lock();
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
rtnl_unlock();
return -ENODEV;
}
return 0;
}
#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value) DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
...@@ -96,10 +86,7 @@ static ssize_t format_devstat_counter(struct ieee80211_local *local, ...@@ -96,10 +86,7 @@ static ssize_t format_devstat_counter(struct ieee80211_local *local,
if (!local->ops->get_stats) if (!local->ops->get_stats)
return -EOPNOTSUPP; return -EOPNOTSUPP;
res = rtnl_lock_local(local); rtnl_lock();
if (res)
return res;
res = local->ops->get_stats(local_to_hw(local), &stats); res = local->ops->get_stats(local_to_hw(local), &stats);
rtnl_unlock(); rtnl_unlock();
if (!res) if (!res)
......
...@@ -476,12 +476,12 @@ static void del_mesh_config(struct ieee80211_sub_if_data *sdata) ...@@ -476,12 +476,12 @@ static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
} }
#endif #endif
static void del_files(struct ieee80211_sub_if_data *sdata, int type) static void del_files(struct ieee80211_sub_if_data *sdata)
{ {
if (!sdata->debugfsdir) if (!sdata->debugfsdir)
return; return;
switch (type) { switch (sdata->vif.type) {
case IEEE80211_IF_TYPE_MESH_POINT: case IEEE80211_IF_TYPE_MESH_POINT:
#ifdef CONFIG_MAC80211_MESH #ifdef CONFIG_MAC80211_MESH
del_mesh_stats(sdata); del_mesh_stats(sdata);
...@@ -521,22 +521,16 @@ void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata) ...@@ -521,22 +521,16 @@ void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
sprintf(buf, "netdev:%s", sdata->dev->name); sprintf(buf, "netdev:%s", sdata->dev->name);
sdata->debugfsdir = debugfs_create_dir(buf, sdata->debugfsdir = debugfs_create_dir(buf,
sdata->local->hw.wiphy->debugfsdir); sdata->local->hw.wiphy->debugfsdir);
add_files(sdata);
} }
void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
{ {
del_files(sdata, sdata->vif.type); del_files(sdata);
debugfs_remove(sdata->debugfsdir); debugfs_remove(sdata->debugfsdir);
sdata->debugfsdir = NULL; sdata->debugfsdir = NULL;
} }
void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
int oldtype)
{
del_files(sdata, oldtype);
add_files(sdata);
}
static int netdev_notify(struct notifier_block *nb, static int netdev_notify(struct notifier_block *nb,
unsigned long state, unsigned long state,
void *ndev) void *ndev)
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#ifdef CONFIG_MAC80211_DEBUGFS #ifdef CONFIG_MAC80211_DEBUGFS
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata); void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata); void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
int oldtype);
void ieee80211_debugfs_netdev_init(void); void ieee80211_debugfs_netdev_init(void);
void ieee80211_debugfs_netdev_exit(void); void ieee80211_debugfs_netdev_exit(void);
#else #else
...@@ -17,9 +15,6 @@ static inline void ieee80211_debugfs_add_netdev( ...@@ -17,9 +15,6 @@ static inline void ieee80211_debugfs_add_netdev(
static inline void ieee80211_debugfs_remove_netdev( static inline void ieee80211_debugfs_remove_netdev(
struct ieee80211_sub_if_data *sdata) struct ieee80211_sub_if_data *sdata)
{} {}
static inline void ieee80211_debugfs_change_if_type(
struct ieee80211_sub_if_data *sdata, int oldtype)
{}
static inline void ieee80211_debugfs_netdev_init(void) static inline void ieee80211_debugfs_netdev_init(void)
{} {}
......
...@@ -558,12 +558,6 @@ struct ieee80211_local { ...@@ -558,12 +558,6 @@ struct ieee80211_local {
bool tim_in_locked_section; /* see ieee80211_beacon_get() */ bool tim_in_locked_section; /* see ieee80211_beacon_get() */
int tx_headroom; /* required headroom for hardware/radiotap */ int tx_headroom; /* required headroom for hardware/radiotap */
enum {
IEEE80211_DEV_UNINITIALIZED = 0,
IEEE80211_DEV_REGISTERED,
IEEE80211_DEV_UNREGISTERED,
} reg_state;
/* Tasklet and skb queue to process calls from IRQ mode. All frames /* Tasklet and skb queue to process calls from IRQ mode. All frames
* added to skb_queue will be processed, but frames in * added to skb_queue will be processed, but frames in
* skb_queue_unreliable may be dropped if the total length of these * skb_queue_unreliable may be dropped if the total length of these
...@@ -863,7 +857,6 @@ int ieee80211_hw_config(struct ieee80211_local *local); ...@@ -863,7 +857,6 @@ int ieee80211_hw_config(struct ieee80211_local *local);
int ieee80211_if_config(struct net_device *dev); int ieee80211_if_config(struct net_device *dev);
int ieee80211_if_config_beacon(struct net_device *dev); int ieee80211_if_config_beacon(struct net_device *dev);
void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx); void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
void ieee80211_if_setup(struct net_device *dev);
u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht, u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
struct ieee80211_ht_info *req_ht_cap, struct ieee80211_ht_info *req_ht_cap,
struct ieee80211_ht_bss_info *req_bss_cap); struct ieee80211_ht_bss_info *req_bss_cap);
...@@ -933,16 +926,14 @@ static inline void ieee80211_start_mesh(struct net_device *dev) ...@@ -933,16 +926,14 @@ static inline void ieee80211_start_mesh(struct net_device *dev)
#endif #endif
/* interface handling */ /* interface handling */
void ieee80211_if_setup(struct net_device *dev);
int ieee80211_if_add(struct ieee80211_local *local, const char *name, int ieee80211_if_add(struct ieee80211_local *local, const char *name,
struct net_device **new_dev, int type, struct net_device **new_dev, enum ieee80211_if_types type,
struct vif_params *params); struct vif_params *params);
void ieee80211_if_set_type(struct net_device *dev, int type); void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
void ieee80211_if_reinit(struct net_device *dev); enum ieee80211_if_types type);
void __ieee80211_if_del(struct ieee80211_local *local, void ieee80211_if_remove(struct net_device *dev);
struct ieee80211_sub_if_data *sdata); void ieee80211_remove_interfaces(struct ieee80211_local *local);
int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
void ieee80211_if_free(struct net_device *dev);
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
/* tx handling */ /* tx handling */
void ieee80211_clear_tx_pending(struct ieee80211_local *local); void ieee80211_clear_tx_pending(struct ieee80211_local *local);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright 2002-2005, Instant802 Networks, Inc. * Copyright 2002-2005, Instant802 Networks, Inc.
* Copyright 2005-2006, Devicescape Software, Inc. * Copyright 2005-2006, Devicescape Software, Inc.
* Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
* Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
...@@ -17,130 +18,91 @@ ...@@ -17,130 +18,91 @@
#include "debugfs_netdev.h" #include "debugfs_netdev.h"
#include "mesh.h" #include "mesh.h"
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata) /*
* Called when the netdev is removed or, by the code below, before
* the interface type changes.
*/
static void ieee80211_teardown_sdata(struct net_device *dev)
{ {
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
struct ieee80211_local *local = sdata->local;
struct beacon_data *beacon;
struct sk_buff *skb;
int flushed;
int i; int i;
/* Default values for sub-interface parameters */ ieee80211_debugfs_remove_netdev(sdata);
sdata->drop_unencrypted = 0;
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
skb_queue_head_init(&sdata->fragments[i].skb_list);
INIT_LIST_HEAD(&sdata->key_list);
sdata->force_unicast_rateidx = -1;
sdata->max_ratectrl_rateidx = -1;
}
static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata) /* free extra data */
{ ieee80211_free_keys(sdata);
int i;
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
__skb_queue_purge(&sdata->fragments[i].skb_list); __skb_queue_purge(&sdata->fragments[i].skb_list);
} sdata->fragment_next = 0;
/* Must be called with rtnl lock held. */
int ieee80211_if_add(struct ieee80211_local *local, const char *name,
struct net_device **new_dev, int type,
struct vif_params *params)
{
struct net_device *ndev;
struct ieee80211_sub_if_data *sdata = NULL;
int ret;
ASSERT_RTNL();
ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size,
name, ieee80211_if_setup);
if (!ndev)
return -ENOMEM;
ndev->needed_headroom = local->tx_headroom +
4*6 /* four MAC addresses */
+ 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
+ 6 /* mesh */
+ 8 /* rfc1042/bridge tunnel */
- ETH_HLEN /* ethernet hard_header_len */
+ IEEE80211_ENCRYPT_HEADROOM;
ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
ret = dev_alloc_name(ndev, ndev->name);
if (ret < 0)
goto fail;
memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
/* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
sdata = netdev_priv(ndev);
ndev->ieee80211_ptr = &sdata->wdev;
sdata->wdev.wiphy = local->hw.wiphy;
sdata->vif.type = IEEE80211_IF_TYPE_AP;
sdata->dev = ndev;
sdata->local = local;
ieee80211_if_sdata_init(sdata);
ret = register_netdevice(ndev);
if (ret)
goto fail;
ieee80211_debugfs_add_netdev(sdata);
ieee80211_if_set_type(ndev, type);
if (ieee80211_vif_is_mesh(&sdata->vif) && switch (sdata->vif.type) {
params && params->mesh_id_len) case IEEE80211_IF_TYPE_AP:
ieee80211_if_sta_set_mesh_id(&sdata->u.sta, beacon = sdata->u.ap.beacon;
params->mesh_id_len, rcu_assign_pointer(sdata->u.ap.beacon, NULL);
params->mesh_id); synchronize_rcu();
kfree(beacon);
/* we're under RTNL so all this is fine */ while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) { local->total_ps_buffered--;
__ieee80211_if_del(local, sdata); dev_kfree_skb(skb);
return -ENODEV;
} }
list_add_tail_rcu(&sdata->list, &local->interfaces);
if (new_dev) break;
*new_dev = ndev; case IEEE80211_IF_TYPE_MESH_POINT:
/* Allow compiler to elide mesh_rmc_free call. */
return 0; if (ieee80211_vif_is_mesh(&sdata->vif))
mesh_rmc_free(dev);
/* fall through */
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
kfree(sdata->u.sta.extra_ie);
kfree(sdata->u.sta.assocreq_ies);
kfree(sdata->u.sta.assocresp_ies);
kfree_skb(sdata->u.sta.probe_resp);
break;
case IEEE80211_IF_TYPE_WDS:
case IEEE80211_IF_TYPE_VLAN:
case IEEE80211_IF_TYPE_MNTR:
break;
case IEEE80211_IF_TYPE_INVALID:
BUG();
break;
}
fail: flushed = sta_info_flush(local, sdata);
free_netdev(ndev); WARN_ON(flushed);
return ret;
} }
void ieee80211_if_set_type(struct net_device *dev, int type) /*
* Helper function to initialise an interface to a specific type.
*/
static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
enum ieee80211_if_types type)
{ {
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_if_sta *ifsta;
int oldtype = sdata->vif.type;
/* /* clear type-dependent union */
* Called even when register_netdevice fails, it would memset(&sdata->u, 0, sizeof(sdata->u));
* oops if assigned before initialising the rest.
*/
dev->uninit = ieee80211_if_reinit;
/* most have no BSS pointer */ /* and set some type-dependent values */
sdata->bss = NULL;
sdata->vif.type = type; sdata->vif.type = type;
sdata->basic_rates = 0; /* only monitor differs */
sdata->dev->type = ARPHRD_ETHER;
switch (type) { switch (type) {
case IEEE80211_IF_TYPE_WDS:
case IEEE80211_IF_TYPE_VLAN:
/* nothing special */
break;
case IEEE80211_IF_TYPE_AP: case IEEE80211_IF_TYPE_AP:
skb_queue_head_init(&sdata->u.ap.ps_bc_buf); skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
INIT_LIST_HEAD(&sdata->u.ap.vlans); INIT_LIST_HEAD(&sdata->u.ap.vlans);
break; break;
case IEEE80211_IF_TYPE_MESH_POINT: case IEEE80211_IF_TYPE_MESH_POINT:
case IEEE80211_IF_TYPE_STA: case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS: { case IEEE80211_IF_TYPE_IBSS:
struct ieee80211_if_sta *ifsta;
ifsta = &sdata->u.sta; ifsta = &sdata->u.sta;
INIT_WORK(&ifsta->work, ieee80211_sta_work); INIT_WORK(&ifsta->work, ieee80211_sta_work);
setup_timer(&ifsta->timer, ieee80211_sta_timer, setup_timer(&ifsta->timer, ieee80211_sta_timer,
...@@ -159,127 +121,134 @@ void ieee80211_if_set_type(struct net_device *dev, int type) ...@@ -159,127 +121,134 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
if (ieee80211_vif_is_mesh(&sdata->vif)) if (ieee80211_vif_is_mesh(&sdata->vif))
ieee80211_mesh_init_sdata(sdata); ieee80211_mesh_init_sdata(sdata);
break; break;
}
case IEEE80211_IF_TYPE_MNTR: case IEEE80211_IF_TYPE_MNTR:
dev->type = ARPHRD_IEEE80211_RADIOTAP; sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
dev->hard_start_xmit = ieee80211_monitor_start_xmit; sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit;
sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
MONITOR_FLAG_OTHER_BSS; MONITOR_FLAG_OTHER_BSS;
break; break;
case IEEE80211_IF_TYPE_WDS:
case IEEE80211_IF_TYPE_VLAN:
break;
case IEEE80211_IF_TYPE_INVALID: case IEEE80211_IF_TYPE_INVALID:
BUG(); BUG();
break; break;
} }
ieee80211_debugfs_change_if_type(sdata, oldtype);
ieee80211_debugfs_add_netdev(sdata);
} }
/* Must be called with rtnl lock held. */ void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
void ieee80211_if_reinit(struct net_device *dev) enum ieee80211_if_types type)
{ {
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); /* Purge and reset type-dependent state. */
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); ieee80211_teardown_sdata(sdata->dev);
struct sk_buff *skb; ieee80211_setup_sdata(sdata, type);
int flushed;
/* reset some values that shouldn't be kept across type changes */
sdata->basic_rates = 0;
sdata->drop_unencrypted = 0;
sdata->sequence = 0;
}
int ieee80211_if_add(struct ieee80211_local *local, const char *name,
struct net_device **new_dev, enum ieee80211_if_types type,
struct vif_params *params)
{
struct net_device *ndev;
struct ieee80211_sub_if_data *sdata = NULL;
int ret, i;
ASSERT_RTNL(); ASSERT_RTNL();
ieee80211_free_keys(sdata); ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size,
name, ieee80211_if_setup);
if (!ndev)
return -ENOMEM;
ieee80211_if_sdata_deinit(sdata); ndev->needed_headroom = local->tx_headroom +
4*6 /* four MAC addresses */
+ 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
+ 6 /* mesh */
+ 8 /* rfc1042/bridge tunnel */
- ETH_HLEN /* ethernet hard_header_len */
+ IEEE80211_ENCRYPT_HEADROOM;
ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
/* Need to handle mesh specially to allow eliding the function call */ ret = dev_alloc_name(ndev, ndev->name);
if (ieee80211_vif_is_mesh(&sdata->vif)) if (ret < 0)
mesh_rmc_free(dev); goto fail;
switch (sdata->vif.type) { memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
case IEEE80211_IF_TYPE_INVALID: SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
/* cannot happen */
WARN_ON(1);
break;
case IEEE80211_IF_TYPE_AP: {
struct beacon_data *beacon;
beacon = sdata->u.ap.beacon; /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
rcu_assign_pointer(sdata->u.ap.beacon, NULL); sdata = netdev_priv(ndev);
synchronize_rcu(); ndev->ieee80211_ptr = &sdata->wdev;
kfree(beacon);
while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) { /* initialise type-independent data */
local->total_ps_buffered--; sdata->wdev.wiphy = local->hw.wiphy;
dev_kfree_skb(skb); sdata->local = local;
} sdata->dev = ndev;
break; for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
} skb_queue_head_init(&sdata->fragments[i].skb_list);
case IEEE80211_IF_TYPE_WDS:
case IEEE80211_IF_TYPE_VLAN:
/* nothing to do */
break;
case IEEE80211_IF_TYPE_MESH_POINT:
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
kfree(sdata->u.sta.extra_ie);
sdata->u.sta.extra_ie = NULL;
kfree(sdata->u.sta.assocreq_ies);
sdata->u.sta.assocreq_ies = NULL;
kfree(sdata->u.sta.assocresp_ies);
sdata->u.sta.assocresp_ies = NULL;
if (sdata->u.sta.probe_resp) {
dev_kfree_skb(sdata->u.sta.probe_resp);
sdata->u.sta.probe_resp = NULL;
}
break; INIT_LIST_HEAD(&sdata->key_list);
case IEEE80211_IF_TYPE_MNTR:
dev->type = ARPHRD_ETHER;
break;
}
flushed = sta_info_flush(local, sdata); sdata->force_unicast_rateidx = -1;
WARN_ON(flushed); sdata->max_ratectrl_rateidx = -1;
memset(&sdata->u, 0, sizeof(sdata->u)); /* setup type-dependent data */
ieee80211_if_sdata_init(sdata); ieee80211_setup_sdata(sdata, type);
}
/* Must be called with rtnl lock held. */ ret = register_netdevice(ndev);
void __ieee80211_if_del(struct ieee80211_local *local, if (ret)
struct ieee80211_sub_if_data *sdata) goto fail;
{
struct net_device *dev = sdata->dev;
ieee80211_debugfs_remove_netdev(sdata); ndev->uninit = ieee80211_teardown_sdata;
unregister_netdevice(dev);
/* if (ieee80211_vif_is_mesh(&sdata->vif) &&
* The net_device will be freed by its destructor, params && params->mesh_id_len)
* i.e. ieee80211_if_free. ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
*/ params->mesh_id_len,
params->mesh_id);
list_add_tail_rcu(&sdata->list, &local->interfaces);
if (new_dev)
*new_dev = ndev;
return 0;
fail:
free_netdev(ndev);
return ret;
} }
/* Must be called with rtnl lock held. */ void ieee80211_if_remove(struct net_device *dev)
int ieee80211_if_remove(struct net_device *dev, const char *name, int id)
{ {
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
struct ieee80211_sub_if_data *sdata, *n;
ASSERT_RTNL(); ASSERT_RTNL();
list_for_each_entry_safe(sdata, n, &local->interfaces, list) {
if ((sdata->vif.type == id || id == -1) &&
strcmp(name, sdata->dev->name) == 0) {
list_del_rcu(&sdata->list); list_del_rcu(&sdata->list);
synchronize_rcu(); synchronize_rcu();
__ieee80211_if_del(local, sdata); unregister_netdevice(dev);
return 0;
}
}
return -ENODEV;
} }
void ieee80211_if_free(struct net_device *dev) /*
* Remove all interfaces, may only be called at hardware unregistration
* time because it doesn't do RCU-safe list removals.
*/
void ieee80211_remove_interfaces(struct ieee80211_local *local)
{ {
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); struct ieee80211_sub_if_data *sdata, *tmp;
ieee80211_if_sdata_deinit(sdata); ASSERT_RTNL();
free_netdev(dev);
list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
list_del(&sdata->list);
unregister_netdevice(sdata->dev);
}
} }
...@@ -971,7 +971,6 @@ static const struct header_ops ieee80211_header_ops = { ...@@ -971,7 +971,6 @@ static const struct header_ops ieee80211_header_ops = {
.cache_update = eth_header_cache_update, .cache_update = eth_header_cache_update,
}; };
/* Must not be called for mdev */
void ieee80211_if_setup(struct net_device *dev) void ieee80211_if_setup(struct net_device *dev)
{ {
ether_setup(dev); ether_setup(dev);
...@@ -981,7 +980,7 @@ void ieee80211_if_setup(struct net_device *dev) ...@@ -981,7 +980,7 @@ void ieee80211_if_setup(struct net_device *dev)
dev->change_mtu = ieee80211_change_mtu; dev->change_mtu = ieee80211_change_mtu;
dev->open = ieee80211_open; dev->open = ieee80211_open;
dev->stop = ieee80211_stop; dev->stop = ieee80211_stop;
dev->destructor = ieee80211_if_free; dev->destructor = free_netdev;
} }
/* everything else */ /* everything else */
...@@ -1776,7 +1775,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) ...@@ -1776,7 +1775,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
printk(KERN_WARNING "%s: Failed to add default virtual iface\n", printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
wiphy_name(local->hw.wiphy)); wiphy_name(local->hw.wiphy));
local->reg_state = IEEE80211_DEV_REGISTERED;
rtnl_unlock(); rtnl_unlock();
ieee80211_led_init(local); ieee80211_led_init(local);
...@@ -1806,30 +1804,20 @@ EXPORT_SYMBOL(ieee80211_register_hw); ...@@ -1806,30 +1804,20 @@ EXPORT_SYMBOL(ieee80211_register_hw);
void ieee80211_unregister_hw(struct ieee80211_hw *hw) void ieee80211_unregister_hw(struct ieee80211_hw *hw)
{ {
struct ieee80211_local *local = hw_to_local(hw); struct ieee80211_local *local = hw_to_local(hw);
struct ieee80211_sub_if_data *sdata, *tmp;
tasklet_kill(&local->tx_pending_tasklet); tasklet_kill(&local->tx_pending_tasklet);
tasklet_kill(&local->tasklet); tasklet_kill(&local->tasklet);
rtnl_lock(); rtnl_lock();
BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
local->reg_state = IEEE80211_DEV_UNREGISTERED;
/* /*
* At this point, interface list manipulations are fine * At this point, interface list manipulations are fine
* because the driver cannot be handing us frames any * because the driver cannot be handing us frames any
* more and the tasklet is killed. * more and the tasklet is killed.
*/ */
/* /* First, we remove all virtual interfaces. */
* First, we remove all virtual interfaces. ieee80211_remove_interfaces(local);
*/
list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
list_del(&sdata->list);
__ieee80211_if_del(local, sdata);
}
/* then, finally, remove the master interface */ /* then, finally, remove the master interface */
unregister_netdevice(local->mdev); unregister_netdevice(local->mdev);
......
...@@ -301,8 +301,7 @@ static int ieee80211_ioctl_siwmode(struct net_device *dev, ...@@ -301,8 +301,7 @@ static int ieee80211_ioctl_siwmode(struct net_device *dev,
if (netif_running(dev)) if (netif_running(dev))
return -EBUSY; return -EBUSY;
ieee80211_if_reinit(dev); ieee80211_if_change_type(sdata, type);
ieee80211_if_set_type(dev, type);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment