Commit eec60b03 authored by Jouni Malinen's avatar Jouni Malinen Committed by John W. Linville

nl80211: Check iftype in cfg80211 code

We do not want to require all the drivers using cfg80211 to need to do
this. In addition, make the error values consistent by using
EOPNOTSUPP instead of semi-random assortment of errno values.
Signed-off-by: default avatarJouni Malinen <jouni.malinen@atheros.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 35a8efe1
...@@ -540,9 +540,6 @@ static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, ...@@ -540,9 +540,6 @@ static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_AP)
return -EINVAL;
old = sdata->u.ap.beacon; old = sdata->u.ap.beacon;
if (old) if (old)
...@@ -559,9 +556,6 @@ static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev, ...@@ -559,9 +556,6 @@ static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_AP)
return -EINVAL;
old = sdata->u.ap.beacon; old = sdata->u.ap.beacon;
if (!old) if (!old)
...@@ -577,9 +571,6 @@ static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) ...@@ -577,9 +571,6 @@ static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_AP)
return -EINVAL;
old = sdata->u.ap.beacon; old = sdata->u.ap.beacon;
if (!old) if (!old)
...@@ -858,9 +849,6 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, ...@@ -858,9 +849,6 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
return -ENOTSUPP;
rcu_read_lock(); rcu_read_lock();
sta = sta_info_get(local, next_hop); sta = sta_info_get(local, next_hop);
if (!sta) { if (!sta) {
...@@ -908,9 +896,6 @@ static int ieee80211_change_mpath(struct wiphy *wiphy, ...@@ -908,9 +896,6 @@ static int ieee80211_change_mpath(struct wiphy *wiphy,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
return -ENOTSUPP;
rcu_read_lock(); rcu_read_lock();
sta = sta_info_get(local, next_hop); sta = sta_info_get(local, next_hop);
...@@ -979,9 +964,6 @@ static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, ...@@ -979,9 +964,6 @@ static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
return -ENOTSUPP;
rcu_read_lock(); rcu_read_lock();
mpath = mesh_path_lookup(dst, sdata); mpath = mesh_path_lookup(dst, sdata);
if (!mpath) { if (!mpath) {
...@@ -1003,9 +985,6 @@ static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, ...@@ -1003,9 +985,6 @@ static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
return -ENOTSUPP;
rcu_read_lock(); rcu_read_lock();
mpath = mesh_path_lookup_by_idx(idx, sdata); mpath = mesh_path_lookup_by_idx(idx, sdata);
if (!mpath) { if (!mpath) {
...@@ -1025,8 +1004,6 @@ static int ieee80211_get_mesh_params(struct wiphy *wiphy, ...@@ -1025,8 +1004,6 @@ static int ieee80211_get_mesh_params(struct wiphy *wiphy,
struct ieee80211_sub_if_data *sdata; struct ieee80211_sub_if_data *sdata;
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
return -ENOTSUPP;
memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
return 0; return 0;
} }
...@@ -1044,9 +1021,6 @@ static int ieee80211_set_mesh_params(struct wiphy *wiphy, ...@@ -1044,9 +1021,6 @@ static int ieee80211_set_mesh_params(struct wiphy *wiphy,
struct ieee80211_sub_if_data *sdata; struct ieee80211_sub_if_data *sdata;
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
return -ENOTSUPP;
/* Set the config options which we are interested in setting */ /* Set the config options which we are interested in setting */
conf = &(sdata->u.mesh.mshcfg); conf = &(sdata->u.mesh.mshcfg);
if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
...@@ -1094,9 +1068,6 @@ static int ieee80211_change_bss(struct wiphy *wiphy, ...@@ -1094,9 +1068,6 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_AP)
return -EINVAL;
if (params->use_cts_prot >= 0) { if (params->use_cts_prot >= 0) {
sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
changed |= BSS_CHANGED_ERP_CTS_PROT; changed |= BSS_CHANGED_ERP_CTS_PROT;
...@@ -1209,9 +1180,6 @@ static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, ...@@ -1209,9 +1180,6 @@ static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_STATION)
return -EOPNOTSUPP;
switch (req->auth_type) { switch (req->auth_type) {
case NL80211_AUTHTYPE_OPEN_SYSTEM: case NL80211_AUTHTYPE_OPEN_SYSTEM:
sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN; sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
...@@ -1268,9 +1236,6 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, ...@@ -1268,9 +1236,6 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_STATION)
return -EOPNOTSUPP;
if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 || if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
!(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED)) !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
return -ENOLINK; /* not authenticated */ return -ENOLINK; /* not authenticated */
...@@ -1305,8 +1270,6 @@ static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, ...@@ -1305,8 +1270,6 @@ static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_sub_if_data *sdata; struct ieee80211_sub_if_data *sdata;
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_STATION)
return -EOPNOTSUPP;
/* TODO: req->ie */ /* TODO: req->ie */
return ieee80211_sta_deauthenticate(sdata, req->reason_code); return ieee80211_sta_deauthenticate(sdata, req->reason_code);
...@@ -1319,9 +1282,6 @@ static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, ...@@ -1319,9 +1282,6 @@ static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->vif.type != NL80211_IFTYPE_STATION)
return -EOPNOTSUPP;
/* TODO: req->ie */ /* TODO: req->ie */
return ieee80211_sta_disassociate(sdata, req->reason_code); return ieee80211_sta_disassociate(sdata, req->reason_code);
} }
......
...@@ -1049,6 +1049,11 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) ...@@ -1049,6 +1049,11 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
if (err) if (err)
goto unlock_rtnl; goto unlock_rtnl;
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
err = -EOPNOTSUPP;
goto out;
}
switch (info->genlhdr->cmd) { switch (info->genlhdr->cmd) {
case NL80211_CMD_NEW_BEACON: case NL80211_CMD_NEW_BEACON:
/* these are required for NEW_BEACON */ /* these are required for NEW_BEACON */
...@@ -1136,6 +1141,10 @@ static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) ...@@ -1136,6 +1141,10 @@ static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
err = -EOPNOTSUPP;
goto out;
}
err = drv->ops->del_beacon(&drv->wiphy, dev); err = drv->ops->del_beacon(&drv->wiphy, dev);
out: out:
...@@ -1324,7 +1333,7 @@ static int nl80211_dump_station(struct sk_buff *skb, ...@@ -1324,7 +1333,7 @@ static int nl80211_dump_station(struct sk_buff *skb,
} }
if (!dev->ops->dump_station) { if (!dev->ops->dump_station) {
err = -ENOSYS; err = -EOPNOTSUPP;
goto out_err; goto out_err;
} }
...@@ -1698,10 +1707,15 @@ static int nl80211_dump_mpath(struct sk_buff *skb, ...@@ -1698,10 +1707,15 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
} }
if (!dev->ops->dump_mpath) { if (!dev->ops->dump_mpath) {
err = -ENOSYS; err = -EOPNOTSUPP;
goto out_err; goto out_err;
} }
if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
err = -EOPNOTSUPP;
goto out;
}
while (1) { while (1) {
err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
dst, next_hop, &pinfo); dst, next_hop, &pinfo);
...@@ -1759,6 +1773,11 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) ...@@ -1759,6 +1773,11 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
err = -EOPNOTSUPP;
goto out;
}
err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
if (err) if (err)
goto out; goto out;
...@@ -1813,6 +1832,11 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) ...@@ -1813,6 +1832,11 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
err = -EOPNOTSUPP;
goto out;
}
if (!netif_running(dev)) { if (!netif_running(dev)) {
err = -ENETDOWN; err = -ENETDOWN;
goto out; goto out;
...@@ -1856,6 +1880,11 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) ...@@ -1856,6 +1880,11 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
err = -EOPNOTSUPP;
goto out;
}
if (!netif_running(dev)) { if (!netif_running(dev)) {
err = -ENETDOWN; err = -ENETDOWN;
goto out; goto out;
...@@ -1944,6 +1973,11 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) ...@@ -1944,6 +1973,11 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
err = -EOPNOTSUPP;
goto out;
}
err = drv->ops->change_bss(&drv->wiphy, dev, &params); err = drv->ops->change_bss(&drv->wiphy, dev, &params);
out: out:
...@@ -2661,6 +2695,11 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) ...@@ -2661,6 +2695,11 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
err = -EOPNOTSUPP;
goto out;
}
if (!netif_running(dev)) { if (!netif_running(dev)) {
err = -ENETDOWN; err = -ENETDOWN;
goto out; goto out;
...@@ -2734,6 +2773,11 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) ...@@ -2734,6 +2773,11 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
err = -EOPNOTSUPP;
goto out;
}
if (!netif_running(dev)) { if (!netif_running(dev)) {
err = -ENETDOWN; err = -ENETDOWN;
goto out; goto out;
...@@ -2797,6 +2841,11 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) ...@@ -2797,6 +2841,11 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
err = -EOPNOTSUPP;
goto out;
}
if (!netif_running(dev)) { if (!netif_running(dev)) {
err = -ENETDOWN; err = -ENETDOWN;
goto out; goto out;
...@@ -2856,6 +2905,11 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) ...@@ -2856,6 +2905,11 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
goto out; goto out;
} }
if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
err = -EOPNOTSUPP;
goto out;
}
if (!netif_running(dev)) { if (!netif_running(dev)) {
err = -ENETDOWN; err = -ENETDOWN;
goto out; goto out;
......
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