]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/mac80211/led.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[net-next-2.6.git] / net / mac80211 / led.c
CommitLineData
f0706e82
JB
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>
5a0e3ad6 11#include <linux/slab.h>
2c8dccc7 12#include "led.h"
f0706e82
JB
13
14void 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 */
25void 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
47f0c502
MB
37void 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
cdcb006f
ID
47void 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
f0706e82
JB
57void ieee80211_led_init(struct ieee80211_local *local)
58{
59 local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
47f0c502
MB
60 if (local->rx_led) {
61 snprintf(local->rx_led_name, sizeof(local->rx_led_name),
62 "%srx", wiphy_name(local->hw.wiphy));
63 local->rx_led->name = local->rx_led_name;
64 if (led_trigger_register(local->rx_led)) {
65 kfree(local->rx_led);
66 local->rx_led = NULL;
67 }
f0706e82
JB
68 }
69
70 local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
47f0c502
MB
71 if (local->tx_led) {
72 snprintf(local->tx_led_name, sizeof(local->tx_led_name),
73 "%stx", wiphy_name(local->hw.wiphy));
74 local->tx_led->name = local->tx_led_name;
75 if (led_trigger_register(local->tx_led)) {
76 kfree(local->tx_led);
77 local->tx_led = NULL;
78 }
79 }
80
81 local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
82 if (local->assoc_led) {
83 snprintf(local->assoc_led_name, sizeof(local->assoc_led_name),
84 "%sassoc", wiphy_name(local->hw.wiphy));
85 local->assoc_led->name = local->assoc_led_name;
86 if (led_trigger_register(local->assoc_led)) {
87 kfree(local->assoc_led);
88 local->assoc_led = NULL;
89 }
f0706e82 90 }
cdcb006f
ID
91
92 local->radio_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
93 if (local->radio_led) {
94 snprintf(local->radio_led_name, sizeof(local->radio_led_name),
95 "%sradio", wiphy_name(local->hw.wiphy));
96 local->radio_led->name = local->radio_led_name;
97 if (led_trigger_register(local->radio_led)) {
98 kfree(local->radio_led);
99 local->radio_led = NULL;
100 }
101 }
f0706e82
JB
102}
103
104void ieee80211_led_exit(struct ieee80211_local *local)
105{
cdcb006f
ID
106 if (local->radio_led) {
107 led_trigger_unregister(local->radio_led);
108 kfree(local->radio_led);
109 }
47f0c502
MB
110 if (local->assoc_led) {
111 led_trigger_unregister(local->assoc_led);
112 kfree(local->assoc_led);
113 }
f0706e82
JB
114 if (local->tx_led) {
115 led_trigger_unregister(local->tx_led);
116 kfree(local->tx_led);
117 }
118 if (local->rx_led) {
119 led_trigger_unregister(local->rx_led);
120 kfree(local->rx_led);
121 }
122}
123
cdcb006f
ID
124char *__ieee80211_get_radio_led_name(struct ieee80211_hw *hw)
125{
126 struct ieee80211_local *local = hw_to_local(hw);
127
128 if (local->radio_led)
129 return local->radio_led_name;
130 return NULL;
131}
132EXPORT_SYMBOL(__ieee80211_get_radio_led_name);
133
47f0c502
MB
134char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw)
135{
136 struct ieee80211_local *local = hw_to_local(hw);
137
138 if (local->assoc_led)
139 return local->assoc_led_name;
140 return NULL;
141}
142EXPORT_SYMBOL(__ieee80211_get_assoc_led_name);
143
f0706e82
JB
144char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
145{
146 struct ieee80211_local *local = hw_to_local(hw);
147
148 if (local->tx_led)
149 return local->tx_led_name;
150 return NULL;
151}
152EXPORT_SYMBOL(__ieee80211_get_tx_led_name);
153
154char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
155{
156 struct ieee80211_local *local = hw_to_local(hw);
157
158 if (local->rx_led)
159 return local->rx_led_name;
160 return NULL;
161}
162EXPORT_SYMBOL(__ieee80211_get_rx_led_name);