Commit 9ea92774 authored by Martin Pitt's avatar Martin Pitt Committed by Johannes Berg

mac80211_hwsim: Register and bind to driver

Properly register our mac80211_hwsim_driver, attach it to the platform bus.
Bind newly created hwsim devices to that driver, so that our wlan devices get
a proper "driver" sysfs attribute.

This makes mac80211_hwsim interfaces work with NetworkManager.
Signed-off-by: default avatarMartin Pitt <martin.pitt@ubuntu.com>
[fix an old and a new message to not be line-broken,
 also fix the driver_register error path]
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent ddc4db2e
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/platform_device.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/ktime.h> #include <linux/ktime.h>
...@@ -1687,6 +1688,7 @@ static void mac80211_hwsim_free(void) ...@@ -1687,6 +1688,7 @@ static void mac80211_hwsim_free(void)
debugfs_remove(data->debugfs_ps); debugfs_remove(data->debugfs_ps);
debugfs_remove(data->debugfs); debugfs_remove(data->debugfs);
ieee80211_unregister_hw(data->hw); ieee80211_unregister_hw(data->hw);
device_release_driver(data->dev);
device_unregister(data->dev); device_unregister(data->dev);
ieee80211_free_hw(data->hw); ieee80211_free_hw(data->hw);
} }
...@@ -1695,7 +1697,9 @@ static void mac80211_hwsim_free(void) ...@@ -1695,7 +1697,9 @@ static void mac80211_hwsim_free(void)
static struct device_driver mac80211_hwsim_driver = { static struct device_driver mac80211_hwsim_driver = {
.name = "mac80211_hwsim" .name = "mac80211_hwsim",
.bus = &platform_bus_type,
.owner = THIS_MODULE,
}; };
static const struct net_device_ops hwsim_netdev_ops = { static const struct net_device_ops hwsim_netdev_ops = {
...@@ -2187,9 +2191,15 @@ static int __init init_mac80211_hwsim(void) ...@@ -2187,9 +2191,15 @@ static int __init init_mac80211_hwsim(void)
spin_lock_init(&hwsim_radio_lock); spin_lock_init(&hwsim_radio_lock);
INIT_LIST_HEAD(&hwsim_radios); INIT_LIST_HEAD(&hwsim_radios);
err = driver_register(&mac80211_hwsim_driver);
if (err)
return err;
hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim"); hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
if (IS_ERR(hwsim_class)) if (IS_ERR(hwsim_class)) {
return PTR_ERR(hwsim_class); err = PTR_ERR(hwsim_class);
goto failed_unregister_driver;
}
memset(addr, 0, ETH_ALEN); memset(addr, 0, ETH_ALEN);
addr[0] = 0x02; addr[0] = 0x02;
...@@ -2211,12 +2221,20 @@ static int __init init_mac80211_hwsim(void) ...@@ -2211,12 +2221,20 @@ static int __init init_mac80211_hwsim(void)
"hwsim%d", i); "hwsim%d", i);
if (IS_ERR(data->dev)) { if (IS_ERR(data->dev)) {
printk(KERN_DEBUG printk(KERN_DEBUG
"mac80211_hwsim: device_create " "mac80211_hwsim: device_create failed (%ld)\n",
"failed (%ld)\n", PTR_ERR(data->dev)); PTR_ERR(data->dev));
err = -ENOMEM; err = -ENOMEM;
goto failed_drvdata; goto failed_drvdata;
} }
data->dev->driver = &mac80211_hwsim_driver; data->dev->driver = &mac80211_hwsim_driver;
err = device_bind_driver(data->dev);
if (err != 0) {
printk(KERN_DEBUG
"mac80211_hwsim: device_bind_driver failed (%d)\n",
err);
goto failed_hw;
}
skb_queue_head_init(&data->pending); skb_queue_head_init(&data->pending);
SET_IEEE80211_DEV(hw, data->dev); SET_IEEE80211_DEV(hw, data->dev);
...@@ -2515,6 +2533,8 @@ static int __init init_mac80211_hwsim(void) ...@@ -2515,6 +2533,8 @@ static int __init init_mac80211_hwsim(void)
ieee80211_free_hw(hw); ieee80211_free_hw(hw);
failed: failed:
mac80211_hwsim_free(); mac80211_hwsim_free();
failed_unregister_driver:
driver_unregister(&mac80211_hwsim_driver);
return err; return err;
} }
module_init(init_mac80211_hwsim); module_init(init_mac80211_hwsim);
...@@ -2527,5 +2547,6 @@ static void __exit exit_mac80211_hwsim(void) ...@@ -2527,5 +2547,6 @@ static void __exit exit_mac80211_hwsim(void)
mac80211_hwsim_free(); mac80211_hwsim_free();
unregister_netdev(hwsim_mon); unregister_netdev(hwsim_mon);
driver_unregister(&mac80211_hwsim_driver);
} }
module_exit(exit_mac80211_hwsim); module_exit(exit_mac80211_hwsim);
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