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