/* * Copyright 2006, Johannes Berg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ /* just for IFNAMSIZ */ #include #include #include #include "led.h" #define MAC80211_BLINK_DELAY 50 /* ms */ void ieee80211_led_rx(struct ieee80211_local *local) { unsigned long led_delay = MAC80211_BLINK_DELAY; if (unlikely(!local->rx_led)) return; led_trigger_blink_oneshot(local->rx_led, &led_delay, &led_delay, 0); } void ieee80211_led_tx(struct ieee80211_local *local) { unsigned long led_delay = MAC80211_BLINK_DELAY; if (unlikely(!local->tx_led)) return; led_trigger_blink_oneshot(local->tx_led, &led_delay, &led_delay, 0); } void ieee80211_led_assoc(struct ieee80211_local *local, bool associated) { if (unlikely(!local->assoc_led)) return; if (associated) led_trigger_event(local->assoc_led, LED_FULL); else led_trigger_event(local->assoc_led, LED_OFF); } void ieee80211_led_radio(struct ieee80211_local *local, bool enabled) { if (unlikely(!local->radio_led)) return; if (enabled) led_trigger_event(local->radio_led, LED_FULL); else led_trigger_event(local->radio_led, LED_OFF); } void ieee80211_led_names(struct ieee80211_local *local) { snprintf(local->rx_led_name, sizeof(local->rx_led_name), "%srx", wiphy_name(local->hw.wiphy)); snprintf(local->tx_led_name, sizeof(local->tx_led_name), "%stx", wiphy_name(local->hw.wiphy)); snprintf(local->assoc_led_name, sizeof(local->assoc_led_name), "%sassoc", wiphy_name(local->hw.wiphy)); snprintf(local->radio_led_name, sizeof(local->radio_led_name), "%sradio", wiphy_name(local->hw.wiphy)); } void ieee80211_led_init(struct ieee80211_local *local) { local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->rx_led) { local->rx_led->name = local->rx_led_name; if (led_trigger_register(local->rx_led)) { kfree(local->rx_led); local->rx_led = NULL; } } local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->tx_led) { local->tx_led->name = local->tx_led_name; if (led_trigger_register(local->tx_led)) { kfree(local->tx_led); local->tx_led = NULL; } } local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->assoc_led) { local->assoc_led->name = local->assoc_led_name; if (led_trigger_register(local->assoc_led)) { kfree(local->assoc_led); local->assoc_led = NULL; } } local->radio_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->radio_led) { local->radio_led->name = local->radio_led_name; if (led_trigger_register(local->radio_led)) { kfree(local->radio_led); local->radio_led = NULL; } } if (local->tpt_led_trigger) { if (led_trigger_register(&local->tpt_led_trigger->trig)) { kfree(local->tpt_led_trigger); local->tpt_led_trigger = NULL; } } } void ieee80211_led_exit(struct ieee80211_local *local) { if (local->radio_led) { led_trigger_unregister(local->radio_led); kfree(local->radio_led); } if (local->assoc_led) { led_trigger_unregister(local->assoc_led); kfree(local->assoc_led); } if (local->tx_led) { led_trigger_unregister(local->tx_led); kfree(local->tx_led); } if (local->rx_led) { led_trigger_unregister(local->rx_led); kfree(local->rx_led); } if (local->tpt_led_trigger) { led_trigger_unregister(&local->tpt_led_trigger->trig); kfree(local->tpt_led_trigger); } } char *__ieee80211_get_radio_led_name(struct ieee80211_hw *hw) { struct ieee80211_local *local = hw_to_local(hw); return local->radio_led_name; } EXPORT_SYMBOL(__ieee80211_get_radio_led_name); char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw) { struct ieee80211_local *local = hw_to_local(hw); return local->assoc_led_name; } EXPORT_SYMBOL(__ieee80211_get_assoc_led_name); char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw) { struct ieee80211_local *local = hw_to_local(hw); return local->tx_led_name; } EXPORT_SYMBOL(__ieee80211_get_tx_led_name); char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw) { struct ieee80211_local *local = hw_to_local(hw); return local->rx_led_name; } EXPORT_SYMBOL(__ieee80211_get_rx_led_name); static unsigned long tpt_trig_traffic(struct ieee80211_local *local, struct tpt_led_trigger *tpt_trig) { unsigned long traffic, delta; traffic = tpt_trig->tx_bytes + tpt_trig->rx_bytes; delta = traffic - tpt_trig->prev_traffic; tpt_trig->prev_traffic = traffic; return DIV_ROUND_UP(delta, 1024 / 8); } static void tpt_trig_timer(unsigned long data) { struct ieee80211_local *local = (void *)data; struct tpt_led_trigger *tpt_trig = local->tpt_led_trigger; struct led_classdev *led_cdev; unsigned long on, off, tpt; int i; if (!tpt_trig->running) return; mod_timer(&tpt_trig->timer, round_jiffies(jiffies + HZ)); tpt = tpt_trig_traffic(local, tpt_trig); /* default to just solid on */ on = 1; off = 0; for (i = tpt_trig->blink_table_len - 1; i >= 0; i--) { if (tpt_trig->blink_table[i].throughput < 0 || tpt > tpt_trig->blink_table[i].throughput) { off = tpt_trig->blink_table[i].blink_time / 2; on = tpt_trig->blink_table[i].blink_time - off; break;