ieee80211_led.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2006, Johannes Berg <johannes@sipsolutions.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. /* just for IFNAMSIZ */
  9. #include <linux/if.h>
  10. #include "ieee80211_led.h"
  11. void ieee80211_led_rx(struct ieee80211_local *local)
  12. {
  13. if (unlikely(!local->rx_led))
  14. return;
  15. if (local->rx_led_counter++ % 2 == 0)
  16. led_trigger_event(local->rx_led, LED_OFF);
  17. else
  18. led_trigger_event(local->rx_led, LED_FULL);
  19. }
  20. /* q is 1 if a packet was enqueued, 0 if it has been transmitted */
  21. void ieee80211_led_tx(struct ieee80211_local *local, int q)
  22. {
  23. if (unlikely(!local->tx_led))
  24. return;
  25. /* not sure how this is supposed to work ... */
  26. local->tx_led_counter += 2*q-1;
  27. if (local->tx_led_counter % 2 == 0)
  28. led_trigger_event(local->tx_led, LED_OFF);
  29. else
  30. led_trigger_event(local->tx_led, LED_FULL);
  31. }
  32. void ieee80211_led_assoc(struct ieee80211_local *local, bool associated)
  33. {
  34. if (unlikely(!local->assoc_led))
  35. return;
  36. if (associated)
  37. led_trigger_event(local->assoc_led, LED_FULL);
  38. else
  39. led_trigger_event(local->assoc_led, LED_OFF);
  40. }
  41. void ieee80211_led_init(struct ieee80211_local *local)
  42. {
  43. local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  44. if (local->rx_led) {
  45. snprintf(local->rx_led_name, sizeof(local->rx_led_name),
  46. "%srx", wiphy_name(local->hw.wiphy));
  47. local->rx_led->name = local->rx_led_name;
  48. if (led_trigger_register(local->rx_led)) {
  49. kfree(local->rx_led);
  50. local->rx_led = NULL;
  51. }
  52. }
  53. local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  54. if (local->tx_led) {
  55. snprintf(local->tx_led_name, sizeof(local->tx_led_name),
  56. "%stx", wiphy_name(local->hw.wiphy));
  57. local->tx_led->name = local->tx_led_name;
  58. if (led_trigger_register(local->tx_led)) {
  59. kfree(local->tx_led);
  60. local->tx_led = NULL;
  61. }
  62. }
  63. local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  64. if (local->assoc_led) {
  65. snprintf(local->assoc_led_name, sizeof(local->assoc_led_name),
  66. "%sassoc", wiphy_name(local->hw.wiphy));
  67. local->assoc_led->name = local->assoc_led_name;
  68. if (led_trigger_register(local->assoc_led)) {
  69. kfree(local->assoc_led);
  70. local->assoc_led = NULL;
  71. }
  72. }
  73. }
  74. void ieee80211_led_exit(struct ieee80211_local *local)
  75. {
  76. if (local->assoc_led) {
  77. led_trigger_unregister(local->assoc_led);
  78. kfree(local->assoc_led);
  79. }
  80. if (local->tx_led) {
  81. led_trigger_unregister(local->tx_led);
  82. kfree(local->tx_led);
  83. }
  84. if (local->rx_led) {
  85. led_trigger_unregister(local->rx_led);
  86. kfree(local->rx_led);
  87. }
  88. }
  89. char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw)
  90. {
  91. struct ieee80211_local *local = hw_to_local(hw);
  92. if (local->assoc_led)
  93. return local->assoc_led_name;
  94. return NULL;
  95. }
  96. EXPORT_SYMBOL(__ieee80211_get_assoc_led_name);
  97. char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
  98. {
  99. struct ieee80211_local *local = hw_to_local(hw);
  100. if (local->tx_led)
  101. return local->tx_led_name;
  102. return NULL;
  103. }
  104. EXPORT_SYMBOL(__ieee80211_get_tx_led_name);
  105. char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
  106. {
  107. struct ieee80211_local *local = hw_to_local(hw);
  108. if (local->rx_led)
  109. return local->rx_led_name;
  110. return NULL;
  111. }
  112. EXPORT_SYMBOL(__ieee80211_get_rx_led_name);