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