sysfs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. static DEVICE_ATTR_RO(name)
  32. SHOW_FMT(index, "%d", wiphy_idx);
  33. SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
  34. SHOW_FMT(address_mask, "%pM", wiphy.addr_mask);
  35. static ssize_t name_show(struct device *dev,
  36. struct device_attribute *attr,
  37. char *buf) {
  38. struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy;
  39. return sprintf(buf, "%s\n", dev_name(&wiphy->dev));
  40. }
  41. static DEVICE_ATTR_RO(name);
  42. static ssize_t addresses_show(struct device *dev,
  43. struct device_attribute *attr,
  44. char *buf)
  45. {
  46. struct wiphy *wiphy = &dev_to_rdev(dev)->wiphy;
  47. char *start = buf;
  48. int i;
  49. if (!wiphy->addresses)
  50. return sprintf(buf, "%pM\n", wiphy->perm_addr);
  51. for (i = 0; i < wiphy->n_addresses; i++)
  52. buf += sprintf(buf, "%pM\n", &wiphy->addresses[i].addr);
  53. return buf - start;
  54. }
  55. static DEVICE_ATTR_RO(addresses);
  56. static struct attribute *ieee80211_attrs[] = {
  57. &dev_attr_index.attr,
  58. &dev_attr_macaddress.attr,
  59. &dev_attr_address_mask.attr,
  60. &dev_attr_addresses.attr,
  61. &dev_attr_name.attr,
  62. NULL,
  63. };
  64. ATTRIBUTE_GROUPS(ieee80211);
  65. static void wiphy_dev_release(struct device *dev)
  66. {
  67. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  68. cfg80211_dev_free(rdev);
  69. }
  70. static int wiphy_uevent(struct device *dev, struct kobj_uevent_env *env)
  71. {
  72. /* TODO, we probably need stuff here */
  73. return 0;
  74. }
  75. #ifdef CONFIG_PM
  76. static void cfg80211_leave_all(struct cfg80211_registered_device *rdev)
  77. {
  78. struct wireless_dev *wdev;
  79. list_for_each_entry(wdev, &rdev->wdev_list, list)
  80. cfg80211_leave(rdev, wdev);
  81. }
  82. static int wiphy_suspend(struct device *dev, pm_message_t state)
  83. {
  84. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  85. int ret = 0;
  86. rdev->suspend_at = get_seconds();
  87. rtnl_lock();
  88. if (rdev->wiphy.registered) {
  89. if (!rdev->wiphy.wowlan_config)
  90. cfg80211_leave_all(rdev);
  91. if (rdev->ops->suspend)
  92. ret = rdev_suspend(rdev, rdev->wiphy.wowlan_config);
  93. if (ret == 1) {
  94. /* Driver refuse to configure wowlan */
  95. cfg80211_leave_all(rdev);
  96. ret = rdev_suspend(rdev, NULL);
  97. }
  98. }
  99. rtnl_unlock();
  100. return ret;
  101. }
  102. static int wiphy_resume(struct device *dev)
  103. {
  104. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  105. int ret = 0;
  106. /* Age scan results with time spent in suspend */
  107. cfg80211_bss_age(rdev, get_seconds() - rdev->suspend_at);
  108. if (rdev->ops->resume) {
  109. rtnl_lock();
  110. if (rdev->wiphy.registered)
  111. ret = rdev_resume(rdev);
  112. rtnl_unlock();
  113. }
  114. return ret;
  115. }
  116. #endif
  117. static const void *wiphy_namespace(struct device *d)
  118. {
  119. struct wiphy *wiphy = container_of(d, struct wiphy, dev);
  120. return wiphy_net(wiphy);
  121. }
  122. struct class ieee80211_class = {
  123. .name = "ieee80211",
  124. .owner = THIS_MODULE,
  125. .dev_release = wiphy_dev_release,
  126. .dev_groups = ieee80211_groups,
  127. .dev_uevent = wiphy_uevent,
  128. #ifdef CONFIG_PM
  129. .suspend = wiphy_suspend,
  130. .resume = wiphy_resume,
  131. #endif
  132. .ns_type = &net_ns_type_operations,
  133. .namespace = wiphy_namespace,
  134. };
  135. int wiphy_sysfs_init(void)
  136. {
  137. return class_register(&ieee80211_class);
  138. }
  139. void wiphy_sysfs_exit(void)
  140. {
  141. class_unregister(&ieee80211_class);
  142. }