#!/bin/bash
# $Id: firmware.agent 308 2005-01-20 11:02:49Z hare $
#
# Firmware-specific hotplug policy agent.
#
# Kernel firmware hotplug params include:
#
#       ACTION=%s [add or remove]
#       DEVPATH=%s [in 2.5 kernels, /sys/$DEVPATH]
#       FIRMWARE=%s
#
# HISTORY:
#
# 24-Jul-2003   Initial version of "new" hotplug agent.
#
#

SYSFS=needed
cd /etc/hotplug
. ./hotplug.functions

# directories with the firmware files
FIRMWARE_DIRS="/lib/firmware /usr/local/lib/firmware /usr/lib/hotplug/firmware"

#
# What to do with this firmware hotplug event?
#
case "$ACTION" in

add)
    if [ ! -e $SYSFS/$DEVPATH/loading ]; then
	debug_mesg "loading of firmware is not supported"
        exit 0
    fi

    for DIR in $FIRMWARE_DIRS; do
        [ -e "$DIR/$FIRMWARE" ] || continue
        echo 1 > $SYSFS/$DEVPATH/loading
        cat "$DIR/$FIRMWARE" > $SYSFS/$DEVPATH/data
        echo 0 > $SYSFS/$DEVPATH/loading
        exit
    done

    # the firmware was not found
    echo -1 > $SYSFS/$DEVPATH/loading

    ;;

remove)
    ;;

*)
    mesg "Firmware '$ACTION' event not supported"
    exit 1
    ;;

esac
