led.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 "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_radio(struct ieee80211_local *local, bool enabled)
  42. {
  43. if (unlikely(!local->radio_led))
  44. return;
  45. if (enabled)
  46. led_trigger_event(local->radio_led, LED_FULL);
  47. else
  48. led_trigger_event(local->radio_led, LED_OFF);
  49. }
  50. void ieee80211_led_init(struct ieee80211_local *local)
  51. {
  52. local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  53. if (local->rx_led) {
  54. snprintf(local->rx_led_name, sizeof(local->rx_led_name),
  55. "%srx", wiphy_name(local->hw.wiphy));
  56. local->rx_led->name = local->rx_led_name;
  57. if (led_trigger_register(local->rx_led)) {
  58. kfree(local->rx_led);
  59. local->rx_led = NULL;
  60. }
  61. }
  62. local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  63. if (local->tx_led) {
  64. snprintf(local->tx_led_name, sizeof(local->tx_led_name),
  65. "%stx", wiphy_name(local->hw.wiphy));
  66. local->tx_led->name = local->tx_led_name;
  67. if (led_trigger_register(local->tx_led)) {
  68. kfree(local->tx_led);
  69. local->tx_led = NULL;
  70. }
  71. }
  72. local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  73. if (local->assoc_led) {
  74. snprintf(local->assoc_led_name, sizeof(local->assoc_led_name),
  75. "%sassoc", wiphy_name(local->hw.wiphy));
  76. local->assoc_led->name = local->assoc_led_name;
  77. if (led_trigger_register(local->assoc_led)) {
  78. kfree(local->assoc_led);
  79. local->assoc_led = NULL;
  80. }
  81. }
  82. local->radio_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  83. if (local->radio_led) {
  84. snprintf(local->radio_led_name, sizeof(local->radio_led_name),
  85. "%sradio", wiphy_name(local->hw.wiphy));
  86. local->radio_led->name = local->radio_led_name;
  87. if (led_trigger_register(local->radio_led)) {
  88. kfree(local->radio_led);
  89. local->radio_led = NULL;
  90. }
  91. }
  92. }
  93. void ieee80211_led_exit(struct ieee80211_local *local)
  94. {
  95. if (local->radio_led) {
  96. led_trigger_unregister(local->radio_led);
  97. kfree(local->radio_led);
  98. }
  99. if (local->assoc_led) {
  100. led_trigger_unregister(local->assoc_led);
  101. kfree(local->assoc_led);
  102. }
  103. if (local->tx_led) {
  104. led_trigger_unregister(local->tx_led);
  105. kfree(local->tx_led);
  106. }
  107. if (local->rx_led) {
  108. led_trigger_unregister(local->rx_led);
  109. kfree(local->rx_led);
  110. }
  111. }
  112. char *__ieee80211_get_radio_led_name(struct ieee80211_hw *hw)
  113. {
  114. struct ieee80211_local *local = hw_to_local(hw);
  115. if (local->radio_led)
  116. return local->radio_led_name;
  117. return NULL;
  118. }
  119. EXPORT_SYMBOL(__ieee80211_get_radio_led_name);
  120. char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw)
  121. {
  122. struct ieee80211_local *local = hw_to_local(hw);
  123. if (local->assoc_led)
  124. return local->assoc_led_name;
  125. return NULL;
  126. }
  127. EXPORT_SYMBOL(__ieee80211_get_assoc_led_name);
  128. char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
  129. {
  130. struct ieee80211_local *local = hw_to_local(hw);
  131. if (local->tx_led)
  132. return local->tx_led_name;
  133. return NULL;
  134. }
  135. EXPORT_SYMBOL(__ieee80211_get_tx_led_name);
  136. char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
  137. {
  138. struct ieee80211_local *local = hw_to_local(hw);
  139. if (local->rx_led)
  140. return local->rx_led_name;
  141. return NULL;
  142. }
  143. EXPORT_SYMBOL(__ieee80211_get_rx_led_name);