#! /bin/sh # /etc/rc.d/rc.ath # This script brings up the ath* interfaces for Atheros networking devices. # Just one interface for now. Most of this is from rc.inet1 ## set this here to make it easier to change DHCP_TIMEOUT=10 ############################ # READ NETWORK CONFIG FILE # ############################ ## set the config variables here ATH_IPADDR[0]="" ATH_NETMASK[0]="" ATH_USE_DHCP[0]="yes" ATH_DHCP_HOSTNAME[0]="" ## set debug options DEBUG_ATH_UP="yes" ########### # LOGGING # ########### ## same as rc.inet1 # If possible, log events in /var/log/messages: if [ /var/run/syslogd.pid -a -x /usr/bin/logger ]; then LOGGER=/usr/bin/logger else # output to stdout/stderr: LOGGER=/bin/cat fi ##################### # ATHEROS FUNCTIONS # ##################### ## copied from eth_up in rc.inet1, with modifications ath_up() { # If the interface isn't in the kernel yet (but there's an alias for it in # modules.conf), then it should be loaded first: if ! grep ath${1}: /proc/net/dev 1> /dev/null ; then # no interface yet if /sbin/modprobe -c | grep -w "alias ath${1}" | grep -vw "alias ath${1} off" > /dev/null ; then ## I don't know what the module is for non-pci cards echo "/etc/rc.d/rc.ath: /sbin/modprobe ath_pci" | $LOGGER /sbin/modprobe ath_pci fi fi if grep ath${1}: /proc/net/dev 1> /dev/null ; then # interface exists if ! /sbin/ifconfig | grep -w "ath${1}" 1>/dev/null || \ ! /sbin/ifconfig ath${1} | grep "inet addr" 1> /dev/null ; then # interface not up or not configured if [ -x /etc/rc.d/rc.wireless ]; then . /etc/rc.d/rc.wireless ath${1} # Initialize any wireless parameters fi if [ "${ATH_USE_DHCP[$1]}" = "yes" ]; then # use DHCP to bring interface up if [ ! "${ATH_DHCP_HOSTNAME[$1]}" = "" ]; then echo "/etc/rc.d/rc.ath: /sbin/dhcpcd -d -t $DHCP_TIMEOUT -h ${ATH_DHCP_HOSTNAME[$1]} ath${1}" | $LOGGER /sbin/dhcpcd -d -t 10 -h ${ATH_DHCP_HOSTNAME[$1]} ath${1} else echo "/etc/rc.d/rc.ath: /sbin/dhcpcd -d -t $DHCP_TIMEOUT ath${1}" | $LOGGER /sbin/dhcpcd -d -t 10 ath${1} fi else # bring up interface using a static IP address if [ ! "${ATH_IPADDR[$1]}" = "" ]; then # skip unconfigured interfaces # Determine broadcast address from the IP address and netmask: BROADCAST=`/bin/ipmask ${ATH_NETMASK[$1]} ${ATH_IPADDR[$1]} | cut -f 1 -d ' '` # Set up the ethernet card: echo "/etc/rc.d/rc.ath: /sbin/ifconfig ath${1} ${ATH_IPADDR[$1]} broadcast ${BROADCAST} netmask ${ATH_NETMASK[$1]}" | $LOGGER /sbin/ifconfig ath${1} ${ATH_IPADDR[$1]} broadcast ${BROADCAST} netmask ${ATH_NETMASK[$1]} else if [ "$DEBUG_ATH_UP" = "yes" ]; then echo "/etc/rc.d/rc.ath: ath${1} interface is not configured in /etc/rc.d/rc.inet1.conf" | $LOGGER fi fi fi else if [ "$DEBUG_ATH_UP" = "yes" ]; then echo "/etc/rc.d/rc.ath: ath${1} is already up, skipping" | $LOGGER fi fi else if [ "$DEBUG_ATH_UP" = "yes" ]; then echo "/etc/rc.d/rc.ath: ath${1} interface does not exist (yet)" | $LOGGER fi fi } # Function to take down an Atheros interface: (same as eth_down in rc.inet1) ath_down() { if grep ath${1}: /proc/net/dev 1> /dev/null ; then if [ "${ATH_USE_DHCP[$1]}" = "yes" ]; then echo "/etc/rc.d/rc.ath: /sbin/dhcpcd -k -d ath${1}" | $LOGGER /sbin/dhcpcd -k -d ath${1} || /sbin/ifconfig ath${1} down sleep 1 else echo "/etc/rc.d/rc.ath: /sbin/ifconfig ath${1} down" | $LOGGER /sbin/ifconfig ath${1} down fi fi } ############ ### MAIN ### ############ ## this is copied from rc.inet1 but eth is replaced with ath case "$1" in 'start') # "start" brings up all Atheros interfaces: ath_up 0 ;; 'stop') # "stop" takes down all existing interfaces: ath_down 0 ;; ath?_start) # "ath?_start" will start the specified interface INUM=`echo $1 | /bin/cut -c 4` ath_up $INUM ;; ath?_stop) # "ath?_stop" will stop the specified interface INUM=`echo $1 | /bin/cut -c 4` ath_down $INUM ;; ath?_restart) # "ath?_restart" will take the specified interface down and up again INUM=`echo $1 | /bin/cut -c 4` ath_down $INUM ath_up $INUM ;; *) # The default is to bring up all interfaces: ath_up 0 esac # End of /etc/rc.d/rc.ath