sysfs.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. static ssize_t _show_index(struct device *dev, struct device_attribute *attr,
  24. char *buf)
  25. {
  26. return sprintf(buf, "%d\n", dev_to_rdev(dev)->idx);
  27. }
  28. static ssize_t _show_permaddr(struct device *dev,
  29. struct device_attribute *attr,
  30. char *buf)
  31. {
  32. unsigned char *addr = dev_to_rdev(dev)->wiphy.perm_addr;
  33. return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
  34. addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
  35. }
  36. static struct device_attribute ieee80211_dev_attrs[] = {
  37. __ATTR(index, S_IRUGO, _show_index, NULL),
  38. __ATTR(macaddress, S_IRUGO, _show_permaddr, NULL),
  39. {}
  40. };
  41. static void wiphy_dev_release(struct device *dev)
  42. {
  43. struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
  44. cfg80211_dev_free(rdev);
  45. }
  46. #ifdef CONFIG_HOTPLUG
  47. static int wiphy_uevent(struct device *dev, struct kobj_uevent_env *env)
  48. {
  49. /* TODO, we probably need stuff here */
  50. return 0;
  51. }
  52. #endif
  53. struct class ieee80211_class = {
  54. .name = "ieee80211",
  55. .owner = THIS_MODULE,
  56. .dev_release = wiphy_dev_release,
  57. .dev_attrs = ieee80211_dev_attrs,
  58. #ifdef CONFIG_HOTPLUG
  59. .dev_uevent = wiphy_uevent,
  60. #endif
  61. };
  62. int wiphy_sysfs_init(void)
  63. {
  64. return class_register(&ieee80211_class);
  65. }
  66. void wiphy_sysfs_exit(void)
  67. {
  68. class_unregister(&ieee80211_class);
  69. }