# etc/wlan/shared.NSD
#
# Copyright (C) 2002 AbsoluteValue Systems, Inc.  All Rights Reserved.
# --------------------------------------------------------------------
#
# linux-wlan
#
#   The contents of this file are subject to the Mozilla Public
#   License Version 1.1 (the "License"); you may not use this file
#   except in compliance with the License. You may obtain a copy of
#   the License at http://www.mozilla.org/MPL/
#
#   Software distributed under the License is distributed on an "AS
#   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
#   implied. See the License for the specific language governing
#   rights and limitations under the License.
#
#   Alternatively, the contents of this file may be used under the
#   terms of the GNU Public License version 2 (the "GPL"), in which
#   case the provisions of the GPL are applicable instead of the
#   above.  If you wish to allow the use of your version of this file
#   only under the terms of the GPL and not to allow others to use
#   your version of this file under the MPL, indicate your decision
#   by deleting the provisions above and replace them with the notice
#   and other provisions required by the GPL.  If you do not delete
#   the provisions above, a recipient may use your version of this
#   file under either the MPL or the GPL.
#
# --------------------------------------------------------------------
#
# Inquiries regarding the linux-wlan Open Source project can be
# made directly to:
#
# AbsoluteValue Systems Inc.
# info@linux-wlan.com
# http://www.linux-wlan.com
#
# --------------------------------------------------------------------
# This file contains NSD specific shell routines called from the 
# global shell routines found in linux-wlan/etc.
# --------------------------------------------------------------------

PRISM2DL=/sbin/prism2dl

prism2_fwload ()
{
	# $1 == wlandev
	# Perform NSD specific actions for loading f/w

	if [ ! -x $PRISM2DL ]; then
		$ECHO $PRISM2DL not found, aborting firmware download.
		return 0
	fi

	# figure out hwtype 
	initnichw="0007" # pci, 1x16 SRAM
	source_procfile /proc/net/p80211/$1/nsd

	cp $FIRMWARE_DIR/prism2_ssf.pda /tmp
	echo "2 0400 $initnichw" >> /tmp/prism2_ssf.pda
	oldhw=$initnichw
	
	# figure out firmware image and dump it over.

	$WLANCTL $1 lnxreq_ifstate ifstate=fwload
	HARDWARE=`$PRISM2DL -s $1 | grep 0x0008 | cut -c26-29`
	case "$HARDWARE" in
	8002|8003|8004|8008)  # (3841)
		$PRISM2DL -r $FIRMWARE_DIR/prism2_r1.hex $1
		;;
	800a|800b|8012|8016|801a|8021) # AMD Parallel Flash (3842)
		$PRISM2DL -r $FIRMWARE_DIR/prism2_af.hex -r $FIRMWARE_DIR/prism2_rf.hex $1
		;;
	800c|8013|8017|801b|8022)   # SST Parallel Flash (3842)
		$PRISM2DL -r $FIRMWARE_DIR/prism2_ak.hex -r $FIRMWARE_DIR/prism2_rf.hex $1
		;;
	800e|8015|8019|801d|8024)  # AT24C08 Small Serial Flash (3842)
 		$PRISM2DL -r $FIRMWARE_DIR/prism2_pm.hex -r $FIRMWARE_DIR/prism2_rf.hex $1
		;;
	800d|800e|8014|8015|8019|801c|801d|8023|8024)
		$PRISM2DL -r $FIRMWARE_DIR/prism2_rf.hex $1
	;;
	800a|800f|8010|8011|801e|801f|8020|8025|8026|8027)  # USB
		$PRISM2DL -r $FIRMWARE_DIR/prism2_ru.hex $1
		;;
	*)
		$ECHO "Unknown prism2 hardware type $HARDWARE ($hwtype), assuming SSF"
		$PRISM2DL -p /tmp/prism2_ssf.pda -r $FIRMWARE_DIR/prism2_pm.hex $1

		# double-check the hwtype
		source_procfile /proc/net/p80211/$1/nsd
		# if it doesn't line up, fix the PDA and try again.
		if [ ! "$initnichw" = "$oldhw" ] ; then
			cp $FIRMWARE_DIR/prism2_ssf.pda /tmp
			echo "2 0400 $initnichw" >> /tmp/prism2_ssf.pda
			$PRISM2DL -p tmp/prism2_ssf.pda -r $FIRMWARE_DIR/prism2_pm.hex $1
		fi

		$PRISM2DL -r $FIRMWARE_DIR/prism2_pm.hex -r $FIRMWARE_DIR/prism2_rf.hex $1
		;;
	esac

	return $?
}

prism2_mibset ()
{
	# $1 == wlandev
	# Global (always performed) NSD specific MIB settings.
	return 0
}

