#!/bin/sh
#
# $Author: ylee $
# $Revision: 1.11 $  
# $Date: 2004/06/30 19:53:54 $  
#
# Name: ath_helper
# 
# COPYRIGHT NOTICE:
#   This software is protected as an unpublished work under the
#   Copyright Act of 1976.
#
# PROPRIETARY RIGHTS of Stellcom Technologies are involved in
# the subject matter of this material and all manufacturing,
# reproduction, use and sales rights pertaining to such subject
# matter are expressly reserved.  This material is submitted in
# confidence for a specified purpose, and the recipient, by
# accepting this material, agrees that this material will not be
# used, copied or reproduced in whole or in part, nor its
# contents revealed in any manner, or to any person, except for
# the purpose delivered.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
# Use, duplication or disclosure by the Government is subject to
# restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph
# (c)(1)(ii) of the Rights in Technical Data and Computer Software clause
# at DFARS 252.227-7013 and/or in similar or successor clauses in the
# FAR, or the DOD or NASA FAR Supplement. Contractor/manufacturer is
# Stellcom, 12670 High Bluff Drive, San Diego, CA 92130-2013.
#
# Description:
#
#	User space helper function for the Atheros device driver
#
#
# Usage:
#
#	ath_helper load_config
#		Loads the saved driver configuration data file
#
#	ath_helper save_config
#		Saves the driver configuration file
#
#	ath_helper reboot
#		Reboots the Atheros access point driver
#
#-----------------------------------------------------------------------------


#
# Setup the constant strings
#

ap_cfg_proc="/proc/net/ath/ap_cfg"
ap_cfg_save="/etc/ath/ap_cfg.save"
ap_helper_done="/proc/net/ath/ap_helper_done"

#
# Load saved driver configuration
#
if [ "$1" = "load_config" ] ; then
    cp $ap_cfg_save $ap_cfg_proc
fi

echo "done"

#
# Save driver configuration to file
#
if [ "$1" = "save_config" ] ; then
    cp $ap_cfg_proc $ap_cfg_save
fi


#
# Initialize the bridge
#
if [ "$1" = "bridge_init" ] ; then
    brctl addbr br0
    brctl sethello br0 1000000000
    brctl setfd br0 1
    ifconfig br0 up $2 netmask $3 promisc
fi

#
# Add a virtual port to the bridge
#
if [ "$1" = "bridge_add" ] ; then
    brctl addif br0 $2
fi

#
# Remove a virtual port from the bridge
#
if [ "$1" = "bridge_remove" ] ; then
    brctl delif br0 $2
fi

                      
#
# Start a virtual port
#                      
if [ "$1" = "vport_start" ] ; then
    brctl addif br0 $2
    ifconfig $2 up
fi


#
# Stop a virtual port
#
if [ "$1" = "vport_stop" ] ; then
    ifconfig $2 down
    brctl delif br0 $2
fi

#
# Display cli proc message 
#
if [ "$1" = "display_climsg" ] ; then
    TTY=$(ps ax | grep ath_cli | awk '{print $2}' | grep 1)
    cat  "/proc/net/ath/ap_cli"  1>/dev/$TTY 2>/dev/$TTY
fi

#
# Try ping 
#
if [ "$1" = "ping" ] ; then
    TTY=$(ps ax | grep ath_cli | awk '{print $2}' | grep 1)
    ping $2 -c$3 1>/dev/$TTY 2>/dev/$TTY
fi

#
# Reboot operation requested
#
if [ "$1" = "reboot" ] ; then
    init 6
fi

#
# Let the access point driver know that the
# userspace helper function is done
#
echo -n $1 > $ap_helper_done
