sysfs.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #include "rdev-ops.h"
  19. static inline struct cfg80211_registered_device *dev_to_rdev(
  20. struct device *dev)
  21. {
  22. return container_of(dev, struct cfg80211_registered_device, wiphy.dev);
  23. }
  24. #define SHOW_FMT(name, fmt, member) \
  25. static ssize_t name ## _show(struct device *dev, \
  26. struct device_attribute *attr, \
  27. char *buf) \
  28. { \
  29. return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
  30. }
  31. SHOW_FMT(index, "%d", wiphy_idx);
  32. SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
  33. SHOW_FMT(address_mask, "%pM", wiphy.addr_mask);
  34. static ssize_t name_show(struct device *dev,
  35. struct device_attribute *attr,
  36. char *buf) {
  37. struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy;
  38. return sprintf(buf, "%s\n", dev_name(&wiphy->dev));
  39. }
  40. static ssize_t addresses_show(struct device *dev,
  41. struct device_attribute *attr,
  42. char *buf)
  43. {
  44. struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy;
  45. char *start = buf;
  46. int i;
  47. if (!wiphy->addresses)
  48. return sprintf(buf, "%pM\n", wiphy->perm_addr);
  49. for (i = 0; i < wiphy->n_addresses; i++)
  50. buf += sprintf(buf, "%pM\n", &wiphy->addresses[i].addr);
  51. return buf - start;
  52. }
  53. static struct device_attribute ieee80211_dev_attrs[] = {
  54. __ATTR_RO(index),
  55. __ATTR_RO(macaddress),
  56. __ATTR_RO(address_mask),
  57. __ATTR_RO(addresses),
  58. __ATTR_RO(name),
  59. {}
  60. };
  61. static void wiphy_dev_release(struct device *dev)
  62. {
  63. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  64. cfg80211_dev_free(rdev);
  65. }
  66. static int wiphy_uevent(struct device *dev, struct kobj_uevent_env *env)
  67. {
  68. /* TODO, we probably need stuff here */
  69. return 0;
  70. }
  71. static int wiphy_suspend(struct device *dev, pm_message_t state)
  72. {
  73. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  74. int ret = 0;
  75. rdev->suspend_at = get_seconds();
  76. if (rdev->ops->suspend) {
  77. rtnl_lock();
  78. if (rdev->wiphy.registered)
  79. ret = rdev_suspend(rdev);
  80. rtnl_unlock();
  81. }
  82. return ret;
  83. }
  84. static int wiphy_resume(struct device *dev)
  85. {
  86. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  87. int ret = 0;
  88. /* Age scan results with time spent in suspend */
  89. spin_lock_bh(&rdev->bss_lock);
  90. cfg80211_bss_age(rdev, get_seconds() - rdev->suspend_at);
  91. spin_unlock_bh(&rdev->bss_lock);
  92. if (rdev->ops->resume) {
  93. rtnl_lock();
  94. if (rdev->wiphy.registered)
  95. ret = rdev_resume(rdev);
  96. rtnl_unlock();
  97. }
  98. return ret;
  99. }
  100. static const void *wiphy_namespace(struct device *d)
  101. {
  102. struct wiphy *wiphy = container_of(d, struct wiphy, dev);
  103. return wiphy_net(wiphy);
  104. }
  105. struct class ieee80211_class = {
  106. .name = "ieee80211",
  107. .owner = THIS_MODULE,
  108. .dev_release = wiphy_dev_release,
  109. .dev_attrs = ieee80211_dev_attrs,
  110. .dev_uevent = wiphy_uevent,
  111. .suspend = wiphy_suspend,
  112. .resume = wiphy_resume,
  113. .ns_type = &net_ns_type_operations,
  114. .namespace = wiphy_namespace,
  115. };
  116. int wiphy_sysfs_init(void)
  117. {
  118. return class_register(&ieee80211_class);
  119. }
  120. void wiphy_sysfs_exit(void)
  121. {
  122. class_unregister(&ieee80211_class);
  123. }