ieee80211_led.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_init(struct ieee80211_local *local)
  33. {
  34. local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  35. if (!local->rx_led)
  36. return;
  37. snprintf(local->rx_led_name, sizeof(local->rx_led_name),
  38. "%srx", wiphy_name(local->hw.wiphy));
  39. local->rx_led->name = local->rx_led_name;
  40. if (led_trigger_register(local->rx_led)) {
  41. kfree(local->rx_led);
  42. local->rx_led = NULL;
  43. }
  44. local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
  45. if (!local->tx_led)
  46. return;
  47. snprintf(local->tx_led_name, sizeof(local->tx_led_name),
  48. "%stx", wiphy_name(local->hw.wiphy));
  49. local->tx_led->name = local->tx_led_name;
  50. if (led_trigger_register(local->tx_led)) {
  51. kfree(local->tx_led);
  52. local->tx_led = NULL;
  53. }
  54. }
  55. void ieee80211_led_exit(struct ieee80211_local *local)
  56. {
  57. if (local->tx_led) {
  58. led_trigger_unregister(local->tx_led);
  59. kfree(local->tx_led);
  60. }
  61. if (local->rx_led) {
  62. led_trigger_unregister(local->rx_led);
  63. kfree(local->rx_led);
  64. }
  65. }
  66. char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
  67. {
  68. struct ieee80211_local *local = hw_to_local(hw);
  69. if (local->tx_led)
  70. return local->tx_led_name;
  71. return NULL;
  72. }
  73. EXPORT_SYMBOL(__ieee80211_get_tx_led_name);
  74. char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
  75. {
  76. struct ieee80211_local *local = hw_to_local(hw);
  77. if (local->rx_led)
  78. return local->rx_led_name;
  79. return NULL;
  80. }
  81. EXPORT_SYMBOL(__ieee80211_get_rx_led_name);