led.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 <linux/slab.h>
  11. #include "led.h"
  12. void ieee80211_led_rx(struct ieee80211_local *local)
  13. {
  14. if (unlikely(!local->rx_led))
  15. return;
  16. if (local->rx_led_counter++ % 2 == 0)
  17. led_trigger_event(local->rx_led, LED_OFF);
  18. else
  19. led_trigger_event(local->rx_led, LED_FULL);
  20. }
  21. /* q is 1 if a packet was enqueued, 0 if it has been transmitted */
  22. void ieee80211_led_tx(struct ieee80211_local *local, int q)
  23. {
  24. if (unlikely(!local->tx_led))
  25. return;
  26. /* not sure how this is supposed to work ... */
  27. local->tx_led_counter += 2*q-1;
  28. if (local->tx_led_counter % 2 == 0)
  29. led_trigger_event(local->tx_led, LED_OFF);
  30. else
  31. led_trigger_event(local->tx_led, LED_FULL);
  32. }
  33. void ieee80211_led_assoc(struct ieee80211_local *local, bool associated)
  34. {
  35. if (unlikely(!local->assoc_led))
  36. return;
  37. if (associated)
  38. led_trigger_event(local->assoc_led, LED_FULL);
  39. else
  40. led_trigger_event(local->assoc_led, LED_OFF);
  41. }
  42. void ieee80211_led_radio(struct ieee80211_local *local, bool enabled)
  43. {
  44. if (unlikely(!local->radio_led))
  45. return;
  46. if (enabled)
  47. led_trigger_event(local->radio_led, LED_FULL);
  48. else
  49. led_trigger_event(local->radio_led, LED_OFF);
  50. }
  51. void ieee80211_led_init(struct ieee80211_local *local)
  52. {
  53. local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  54. if (local->rx_led) {
  55. snprintf(local->rx_led_name, sizeof(local->rx_led_name),
  56. "%srx", wiphy_name(local->hw.wiphy));
  57. local->rx_led->name = local->rx_led_name;
  58. if (led_trigger_register(local->rx_led)) {
  59. kfree(local->rx_led);
  60. local->rx_led = NULL;
  61. }
  62. }
  63. local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  64. if (local->tx_led) {
  65. snprintf(local->tx_led_name, sizeof(local->tx_led_name),
  66. "%stx", wiphy_name(local->hw.wiphy));
  67. local->tx_led->name = local->tx_led_name;
  68. if (led_trigger_register(local->tx_led)) {
  69. kfree(local->tx_led);
  70. local->tx_led = NULL;
  71. }
  72. }
  73. local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  74. if (local->assoc_led) {
  75. snprintf(local->assoc_led_name, sizeof(local->assoc_led_name),
  76. "%sassoc", wiphy_name(local->hw.wiphy));
  77. local->assoc_led->name = local->assoc_led_name;
  78. if (led_trigger_register(local->assoc_led)) {
  79. kfree(local->assoc_led);
  80. local->assoc_led = NULL;
  81. }
  82. }
  83. local->radio_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  84. if (local->radio_led) {
  85. snprintf(local->radio_led_name, sizeof(local->radio_led_name),
  86. "%sradio", wiphy_name(local->hw.wiphy));
  87. local->radio_led->name = local->radio_led_name;
  88. if (led_trigger_register(local->radio_led)) {
  89. kfree(local->radio_led);
  90. local->radio_led = NULL;
  91. }
  92. }
  93. }
  94. void ieee80211_led_exit(struct ieee80211_local *local)
  95. {
  96. if (local->radio_led) {
  97. led_trigger_unregister(local->radio_led);
  98. kfree(local->radio_led);
  99. }
  100. if (local->assoc_led) {
  101. led_trigger_unregister(local->assoc_led);
  102. kfree(local->assoc_led);
  103. }
  104. if (local->tx_led) {
  105. led_trigger_unregister(local->tx_led);
  106. kfree(local->tx_led);
  107. }
  108. if (local->rx_led) {
  109. led_trigger_unregister(local->rx_led);
  110. kfree(local->rx_led);
  111. }
  112. }
  113. char *__ieee80211_get_radio_led_name(struct ieee80211_hw *hw)
  114. {
  115. struct ieee80211_local *local = hw_to_local(hw);
  116. if (local->radio_led)
  117. return local->radio_led_name;
  118. return NULL;
  119. }
  120. EXPORT_SYMBOL(__ieee80211_get_radio_led_name);
  121. char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw)
  122. {
  123. struct ieee80211_local *local = hw_to_local(hw);
  124. if (local->assoc_led)
  125. return local->assoc_led_name;
  126. return NULL;
  127. }
  128. EXPORT_SYMBOL(__ieee80211_get_assoc_led_name);
  129. char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
  130. {
  131. struct ieee80211_local *local = hw_to_local(hw);
  132. if (local->tx_led)
  133. return local->tx_led_name;
  134. return NULL;
  135. }
  136. EXPORT_SYMBOL(__ieee80211_get_tx_led_name);
  137. char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
  138. {
  139. struct ieee80211_local *local = hw_to_local(hw);
  140. if (local->rx_led)
  141. return local->rx_led_name;
  142. return NULL;
  143. }
  144. EXPORT_SYMBOL(__ieee80211_get_rx_led_name);