Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 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 | |
| 9 | /* just for IFNAMSIZ */ |
| 10 | #include <linux/if.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 12 | #include "led.h" |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 13 | |
| 14 | void ieee80211_led_rx(struct ieee80211_local *local) |
| 15 | { |
| 16 | if (unlikely(!local->rx_led)) |
| 17 | return; |
| 18 | if (local->rx_led_counter++ % 2 == 0) |
| 19 | led_trigger_event(local->rx_led, LED_OFF); |
| 20 | else |
| 21 | led_trigger_event(local->rx_led, LED_FULL); |
| 22 | } |
| 23 | |
| 24 | /* q is 1 if a packet was enqueued, 0 if it has been transmitted */ |
| 25 | void ieee80211_led_tx(struct ieee80211_local *local, int q) |
| 26 | { |
| 27 | if (unlikely(!local->tx_led)) |
| 28 | return; |
| 29 | /* not sure how this is supposed to work ... */ |
| 30 | local->tx_led_counter += 2*q-1; |
| 31 | if (local->tx_led_counter % 2 == 0) |
| 32 | led_trigger_event(local->tx_led, LED_OFF); |
| 33 | else |
| 34 | led_trigger_event(local->tx_led, LED_FULL); |
| 35 | } |
| 36 | |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 37 | void ieee80211_led_assoc(struct ieee80211_local *local, bool associated) |
| 38 | { |
| 39 | if (unlikely(!local->assoc_led)) |
| 40 | return; |
| 41 | if (associated) |
| 42 | led_trigger_event(local->assoc_led, LED_FULL); |
| 43 | else |
| 44 | led_trigger_event(local->assoc_led, LED_OFF); |
| 45 | } |
| 46 | |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 47 | void ieee80211_led_radio(struct ieee80211_local *local, bool enabled) |
| 48 | { |
| 49 | if (unlikely(!local->radio_led)) |
| 50 | return; |
| 51 | if (enabled) |
| 52 | led_trigger_event(local->radio_led, LED_FULL); |
| 53 | else |
| 54 | led_trigger_event(local->radio_led, LED_OFF); |
| 55 | } |
| 56 | |
Johannes Berg | fe67c91 | 2010-11-27 20:02:59 +0100 | [diff] [blame^] | 57 | void ieee80211_led_names(struct ieee80211_local *local) |
| 58 | { |
| 59 | snprintf(local->rx_led_name, sizeof(local->rx_led_name), |
| 60 | "%srx", wiphy_name(local->hw.wiphy)); |
| 61 | snprintf(local->tx_led_name, sizeof(local->tx_led_name), |
| 62 | "%stx", wiphy_name(local->hw.wiphy)); |
| 63 | snprintf(local->assoc_led_name, sizeof(local->assoc_led_name), |
| 64 | "%sassoc", wiphy_name(local->hw.wiphy)); |
| 65 | snprintf(local->radio_led_name, sizeof(local->radio_led_name), |
| 66 | "%sradio", wiphy_name(local->hw.wiphy)); |
| 67 | } |
| 68 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 69 | void ieee80211_led_init(struct ieee80211_local *local) |
| 70 | { |
| 71 | local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 72 | if (local->rx_led) { |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 73 | local->rx_led->name = local->rx_led_name; |
| 74 | if (led_trigger_register(local->rx_led)) { |
| 75 | kfree(local->rx_led); |
| 76 | local->rx_led = NULL; |
| 77 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 81 | if (local->tx_led) { |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 82 | local->tx_led->name = local->tx_led_name; |
| 83 | if (led_trigger_register(local->tx_led)) { |
| 84 | kfree(local->tx_led); |
| 85 | local->tx_led = NULL; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); |
| 90 | if (local->assoc_led) { |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 91 | local->assoc_led->name = local->assoc_led_name; |
| 92 | if (led_trigger_register(local->assoc_led)) { |
| 93 | kfree(local->assoc_led); |
| 94 | local->assoc_led = NULL; |
| 95 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 96 | } |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 97 | |
| 98 | local->radio_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); |
| 99 | if (local->radio_led) { |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 100 | local->radio_led->name = local->radio_led_name; |
| 101 | if (led_trigger_register(local->radio_led)) { |
| 102 | kfree(local->radio_led); |
| 103 | local->radio_led = NULL; |
| 104 | } |
| 105 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void ieee80211_led_exit(struct ieee80211_local *local) |
| 109 | { |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 110 | if (local->radio_led) { |
| 111 | led_trigger_unregister(local->radio_led); |
| 112 | kfree(local->radio_led); |
| 113 | } |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 114 | if (local->assoc_led) { |
| 115 | led_trigger_unregister(local->assoc_led); |
| 116 | kfree(local->assoc_led); |
| 117 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 118 | if (local->tx_led) { |
| 119 | led_trigger_unregister(local->tx_led); |
| 120 | kfree(local->tx_led); |
| 121 | } |
| 122 | if (local->rx_led) { |
| 123 | led_trigger_unregister(local->rx_led); |
| 124 | kfree(local->rx_led); |
| 125 | } |
| 126 | } |
| 127 | |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 128 | char *__ieee80211_get_radio_led_name(struct ieee80211_hw *hw) |
| 129 | { |
| 130 | struct ieee80211_local *local = hw_to_local(hw); |
| 131 | |
Johannes Berg | fe67c91 | 2010-11-27 20:02:59 +0100 | [diff] [blame^] | 132 | return local->radio_led_name; |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 133 | } |
| 134 | EXPORT_SYMBOL(__ieee80211_get_radio_led_name); |
| 135 | |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 136 | char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw) |
| 137 | { |
| 138 | struct ieee80211_local *local = hw_to_local(hw); |
| 139 | |
Johannes Berg | fe67c91 | 2010-11-27 20:02:59 +0100 | [diff] [blame^] | 140 | return local->assoc_led_name; |
Michael Buesch | 47f0c50 | 2007-09-27 15:10:44 +0200 | [diff] [blame] | 141 | } |
| 142 | EXPORT_SYMBOL(__ieee80211_get_assoc_led_name); |
| 143 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 144 | char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw) |
| 145 | { |
| 146 | struct ieee80211_local *local = hw_to_local(hw); |
| 147 | |
Johannes Berg | fe67c91 | 2010-11-27 20:02:59 +0100 | [diff] [blame^] | 148 | return local->tx_led_name; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 149 | } |
| 150 | EXPORT_SYMBOL(__ieee80211_get_tx_led_name); |
| 151 | |
| 152 | char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw) |
| 153 | { |
| 154 | struct ieee80211_local *local = hw_to_local(hw); |
| 155 | |
Johannes Berg | fe67c91 | 2010-11-27 20:02:59 +0100 | [diff] [blame^] | 156 | return local->rx_led_name; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 157 | } |
| 158 | EXPORT_SYMBOL(__ieee80211_get_rx_led_name); |