Please note: This project is no longer active. The website is kept online for historic purposes only.
If you´re looking for a Linux driver for your Atheros WLAN device, you should continue here .

UserDocs/EnableLEDs: ath_led.sh

File ath_led.sh, 3.4 kB (added by anonymous, 11 years ago)
Line 
1 #!/bin/bash
2 ## $Id$
3 ## vim:ts=4:sw=4:nu:ai:nowrap:
4 ##
5 ## Created by Wolfram Schlich <wschlich@gentoo.org>
6 ## Licensed under the GNU GPLv2 or later
7 ##
8 ## Script for being called by udev to activate power and activity LEDs on Atheros cards
9 ##
10 ## Intended to be placed at /lib/udev/ath_led.sh
11 ##
12 ## Example udev rules for a Philips SNN6500 PCMCIA card (802.11abg)
13 ## (e.g. update your /etc/udev/rules.d/70-persistent-net.rules):
14 ## --8<--[ snip ]--8<--
15 ## SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:12:bf:12:ab:cd", \
16 ##   ATTR{type}=="1", NAME="ath0"
17 ## SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:12:bf:12:ab:cd", \
18 ##   ATTR{type}=="801", RUN+="ath_led.sh -p 1 -a 0"
19 ## --8<--[ snap ]--8<--
20 ## Please note you might change the -p and -a options depending on your card!
21 ##
22
23 ##
24 ## functions
25 ##
26
27 ## logs via syslog and optionally stderr
28 function log() {
29         local log_syslog_facility="user"
30         local log_syslog_level="${1}"; shift
31         local log_syslog_pri="${log_syslog_facility}.${log_syslog_level}"
32         local log_syslog_tag="${0##*/}[${$}]" # scriptname[PID]
33         local logger_args=
34         case "${log_syslog_level}" in
35                 err|crit|alert|emerg)
36                         ## log err|crit|alert|emerg messages to stderr as well
37                         logger_args='-s'
38                         ;;
39                 *)
40                         ;;
41         esac
42         logger ${logger_args} -p "${log_syslog_pri}" -t "${log_syslog_tag}" <<-EOF
43                 ${@}
44                 EOF
45 }
46
47 ## exits and optionally logs a message
48 function die() {
49         local retval=${1:-1}; shift
50         if [[ ${#} -gt 0 ]]; then
51                 if [[ ${retval} -ne 0 ]]; then
52                         log crit "${@}"
53                 else
54                         log notice "${@}"
55                 fi
56         fi
57         exit ${retval}
58 }
59
60 ##
61 ## parse command line options
62 ##
63
64 #
65 # -a: activity LED pin (e.g. 0)
66 # -g: power LED pin (e.g. 1)
67 #
68
69 declare -i act_led_pin=-1 pwr_led_pin=-1
70 while getopts ':a:p:' opt; do
71         case "${opt}" in
72                 ## device data
73                 a)      declare -i act_led_pin=${OPTARG};;
74                 p)      declare -i pwr_led_pin=${OPTARG};;
75                 ## option without a required argument
76                 :)      die 1 "option -${OPTARG} requires an argument";;
77                 ## unknown option
78                 \?)     die 1 "unknown option -${OPTARG}";;
79                 ## this should never happen
80                 *)      die 1 "there's an error in the matrix!";;
81         esac
82 done; opt_idx=${OPTIND}; unset OPTIND
83
84 ##
85 ## main()
86 ##
87
88 ## check if command line options were given at all
89 if [[ ${opt_idx} -eq 1 ]]; then
90         die 1 "no command line options specified"
91 fi
92
93 ## shift options + arguments off the positional parameters
94 ## and process remaining positional parameters
95 let opt_idx--; shift ${opt_idx}; unset opt_idx
96 set -- "${@}"
97
98 ## check for udev environment variable
99 if [[ -z ${INTERFACE} ]]; then
100         die 1 "udev environment variable INTERFACE missing (wifi device)"
101 fi
102
103 ## check for required arguments
104 if [[ -z ${act_led_pin} ]]; then
105         die 1 "${INTERFACE}: no activity LED pin specified"
106 fi
107 if [[ -z ${pwr_led_pin} ]]; then
108         die 1 "${INTERFACE}: no power LED pin specified"
109 fi
110
111 ## first, configure power LED
112 if [[ ${pwr_led_pin} -gt -1 ]]; then
113         log info "${INTERFACE}: enabling power LED on pin #${pwr_led_pin}"
114         sysctl -q -e -w dev.${INTERFACE}.ledpin=${pwr_led_pin}
115         sysctl -q -e -w dev.${INTERFACE}.softled=1
116         sysctl -q -e -w dev.${INTERFACE}.softled=0
117 fi
118
119 ## second, configure activity LED
120 if [[ ${act_led_pin} -gt -1 ]]; then
121         log info "${INTERFACE}: enabling activity LED on pin #${act_led_pin}"
122         sysctl -q -e -w dev.${INTERFACE}.ledpin=${act_led_pin}
123         sysctl -q -e -w dev.${INTERFACE}.softled=1
124 fi
125
126 exit 0
127