Skip to content

Commit

Permalink
mac80211: push interface checks down
Browse files Browse the repository at this point in the history
This patch pushes the "netif_running()" and "same type as before"
checks down into ieee80211_if_change_type() to centralise the
logic instead of duplicating it for cfg80211 and wext.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Johannes Berg authored and John W. Linville committed Jul 14, 2008
1 parent 7563652 commit f3947e2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
struct net_device *dev;
enum ieee80211_if_types itype;
struct ieee80211_sub_if_data *sdata;
int ret;

/* we're under RTNL */
dev = __dev_get_by_index(&init_net, ifindex);
if (!dev)
return -ENODEV;

if (netif_running(dev))
return -EBUSY;

itype = nl80211_type_to_mac80211_type(type);
if (itype == IEEE80211_IF_TYPE_INVALID)
return -EINVAL;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

ieee80211_if_change_type(sdata, itype);
ret = ieee80211_if_change_type(sdata, itype);
if (ret)
return ret;

if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
Expand Down
4 changes: 2 additions & 2 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,8 @@ void ieee80211_if_setup(struct net_device *dev);
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);
void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
enum ieee80211_if_types type);
int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
enum ieee80211_if_types type);
void ieee80211_if_remove(struct net_device *dev);
void ieee80211_remove_interfaces(struct ieee80211_local *local);

Expand Down
20 changes: 18 additions & 2 deletions net/mac80211/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,23 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
ieee80211_debugfs_add_netdev(sdata);
}

void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
enum ieee80211_if_types type)
int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
enum ieee80211_if_types type)
{
ASSERT_RTNL();

if (type == sdata->vif.type)
return 0;

/*
* We could, here, on changes between IBSS/STA/MESH modes,
* invoke an MLME function instead that disassociates etc.
* and goes into the requested mode.
*/

if (netif_running(sdata->dev))
return -EBUSY;

/* Purge and reset type-dependent state. */
ieee80211_teardown_sdata(sdata->dev);
ieee80211_setup_sdata(sdata, type);
Expand All @@ -149,6 +163,8 @@ void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
sdata->basic_rates = 0;
sdata->drop_unencrypted = 0;
sdata->sequence = 0;

return 0;
}

int ieee80211_if_add(struct ieee80211_local *local, const char *name,
Expand Down
9 changes: 1 addition & 8 deletions net/mac80211/wext.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,7 @@ static int ieee80211_ioctl_siwmode(struct net_device *dev,
return -EINVAL;
}

if (type == sdata->vif.type)
return 0;
if (netif_running(dev))
return -EBUSY;

ieee80211_if_change_type(sdata, type);

return 0;
return ieee80211_if_change_type(sdata, type);
}


Expand Down

0 comments on commit f3947e2

Please sign in to comment.