Skip to contentSkip to conversation

add add_iface/remove_iface back to sysfs

PATCH New Johannes Berg 1 participant 1 message Feb 20, 2007

Subsystems (2)
lore
Share & tools
lore

Johannes Berg

author maintainer
#0 lore raw

PATCH 1/1 add add_iface/remove_iface back to sysfs

This patch adds the wiphy add_iface/remove_iface sysfs attributes back into sysfs. However, they are implemented on top of cfg80211 now and nl80211 userspace should work as well.

---
This is temporary API. Before the merge, we should clean up all sysfs stuff that we have and probably move most of it to debugfs.

Tested to work by Michael Buesch, thanks!

---
 net/d80211/ieee80211_cfg.c |   76 +++++++++++++++++++++++++++++++++++++++++++++
 net/wireless/sysfs.c       |   47 +++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 1 deletion(-)
net/d80211/ieee80211_cfg.c +76 -0
@@ -6,10 +6,24 @@
  * This file is GPLv2 as found in COPYING.
  */
 
+#include <linux/nl80211.h>
+#include <linux/rtnetlink.h>
 #include <net/cfg80211.h>
 #include "ieee80211_i.h"
 #include "ieee80211_cfg.h"
 
+/* copied from ieee80211_sysfs.c for now ... */
+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;
+}
+
+
 static int ieee80211_list_interfaces(struct wiphy *wiphy, void *data,
 				     int (*one)(void *data, int ifindex))
 {
@@ -27,6 +41,68 @@ static int ieee80211_list_interfaces(str
 	return err;
 }
 
+static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
+			       unsigned int type)
+{
+	struct ieee80211_local *local = wiphy_priv(wiphy);
+	struct net_device *new_dev;
+	int res, itype;
+
+	switch (type) {
+	case NL80211_IFTYPE_UNSPECIFIED:
+		itype = IEEE80211_IF_TYPE_STA;
+		break;
+	case NL80211_IFTYPE_ADHOC:
+		itype = IEEE80211_IF_TYPE_IBSS;
+		break;
+	case NL80211_IFTYPE_STATION:
+		itype = IEEE80211_IF_TYPE_STA;
+		break;
+	case NL80211_IFTYPE_AP:
+		itype = IEEE80211_IF_TYPE_AP;
+		break;
+	case NL80211_IFTYPE_WDS:
+		itype = IEEE80211_IF_TYPE_WDS;
+		break;
+	case NL80211_IFTYPE_MONITOR:
+		itype = IEEE80211_IF_TYPE_MNTR;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	res = rtnl_lock_local(local);
+	if (res)
+		return res;
+
+	res = ieee80211_if_add(local->mdev, name, 0, &new_dev);
+	if (res == 0)
+		ieee80211_if_set_type(new_dev, itype);
+	rtnl_unlock();
+	return res;
+}
+
+static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
+{
+	struct ieee80211_local *local = wiphy_priv(wiphy);
+	int res;
+	struct net_device *dev;
+	char *name;
+
+	res = rtnl_lock_local(local);
+	if (res)
+		return res;
+	dev = dev_get_by_index(ifindex);
+	name = dev->name;
+	dev_put(dev);
+
+	res = ieee80211_if_remove(local->mdev, name, -1);
+	rtnl_unlock();
+	return res;
+}
+
 struct cfg80211_ops d80211_config_ops = {
 	.list_interfaces = ieee80211_list_interfaces,
+	.add_virtual_intf = ieee80211_add_iface,
+	.del_virtual_intf = ieee80211_del_iface,
 };
net/wireless/sysfs.c +46 -1

62 lines not on this page · raw message