sysfs.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. static int wiphy_uevent(struct device *dev, char **envp,
  47. int num_envp, char *buf, int size)
  48. {
  49. /* TODO, we probably need stuff here */
  50. return 0;
  51. }
  52. struct class ieee80211_class = {
  53. .name = "ieee80211",
  54. .owner = THIS_MODULE,
  55. .dev_release = wiphy_dev_release,
  56. .dev_attrs = ieee80211_dev_attrs,
  57. #ifdef CONFIG_HOTPLUG
  58. .dev_uevent = wiphy_uevent,
  59. #endif
  60. };
  61. int wiphy_sysfs_init(void)
  62. {
  63. return class_register(&ieee80211_class);
  64. }
  65. void wiphy_sysfs_exit(void)
  66. {
  67. class_unregister(&ieee80211_class);
  68. }