sysfs.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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", 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. struct class ieee80211_class = {
  50. .name = "ieee80211",
  51. .owner = THIS_MODULE,
  52. .dev_release = wiphy_dev_release,
  53. .dev_attrs = ieee80211_dev_attrs,
  54. #ifdef CONFIG_HOTPLUG
  55. .dev_uevent = wiphy_uevent,
  56. #endif
  57. };
  58. int wiphy_sysfs_init(void)
  59. {
  60. return class_register(&ieee80211_class);
  61. }
  62. void wiphy_sysfs_exit(void)
  63. {
  64. class_unregister(&ieee80211_class);
  65. }