sysfs.c 4.0 KB

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