sysfs.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * This file provides /sys/class/ieee80211/<wiphy name>/
  3. * and some default attributes.
  4. *
  5. * Copyright 2005-2006 Jiri Benc <jbenc@suse.cz>
  6. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  7. *
  8. * This file is GPLv2 as found in COPYING.
  9. */
  10. #include <linux/device.h>
  11. #include <linux/module.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/nl80211.h>
  14. #include <linux/rtnetlink.h>
  15. #include <net/cfg80211.h>
  16. #include "sysfs.h"
  17. #include "core.h"
  18. static inline struct cfg80211_registered_device *dev_to_rdev(
  19. struct device *dev)
  20. {
  21. return container_of(dev, struct cfg80211_registered_device, wiphy.dev);
  22. }
  23. #define SHOW_FMT(name, fmt, member) \
  24. static ssize_t name ## _show(struct device *dev, \
  25. struct device_attribute *attr, \
  26. char *buf) \
  27. { \
  28. return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
  29. }
  30. SHOW_FMT(index, "%d", wiphy_idx);
  31. SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
  32. static struct device_attribute ieee80211_dev_attrs[] = {
  33. __ATTR_RO(index),
  34. __ATTR_RO(macaddress),
  35. {}
  36. };
  37. static void wiphy_dev_release(struct device *dev)
  38. {
  39. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  40. cfg80211_dev_free(rdev);
  41. }
  42. #ifdef CONFIG_HOTPLUG
  43. static int wiphy_uevent(struct device *dev, struct kobj_uevent_env *env)
  44. {
  45. /* TODO, we probably need stuff here */
  46. return 0;
  47. }
  48. #endif
  49. static int wiphy_suspend(struct device *dev, pm_message_t state)
  50. {
  51. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  52. int ret = 0;
  53. rdev->suspend_at = get_seconds();
  54. if (rdev->ops->suspend) {
  55. rtnl_lock();
  56. ret = rdev->ops->suspend(&rdev->wiphy);
  57. rtnl_unlock();
  58. }
  59. return ret;
  60. }
  61. static int wiphy_resume(struct device *dev)
  62. {
  63. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  64. int ret = 0;
  65. /* Age scan results with time spent in suspend */
  66. spin_lock_bh(&rdev->bss_lock);
  67. cfg80211_bss_age(rdev, get_seconds() - rdev->suspend_at);
  68. spin_unlock_bh(&rdev->bss_lock);
  69. if (rdev->ops->resume) {
  70. rtnl_lock();
  71. ret = rdev->ops->resume(&rdev->wiphy);
  72. rtnl_unlock();
  73. }
  74. return ret;
  75. }
  76. struct class ieee80211_class = {
  77. .name = "ieee80211",
  78. .owner = THIS_MODULE,
  79. .dev_release = wiphy_dev_release,
  80. .dev_attrs = ieee80211_dev_attrs,
  81. #ifdef CONFIG_HOTPLUG
  82. .dev_uevent = wiphy_uevent,
  83. #endif
  84. .suspend = wiphy_suspend,
  85. .resume = wiphy_resume,
  86. };
  87. int wiphy_sysfs_init(void)
  88. {
  89. return class_register(&ieee80211_class);
  90. }
  91. void wiphy_sysfs_exit(void)
  92. {
  93. class_unregister(&ieee80211_class);
  94. }