#!/bin/sh
MAX_LOG_LEN=8192
LOG_FILE=/var/log/udev.log
VID_STR=0x`echo $PRODUCT|/bin/awk -F '/' '{print $1}'`
PID_STR=0x`echo $PRODUCT|/bin/awk -F '/' '{print $2}'`
case $1 in
MMC)
echo $(date) >> ${LOG_FILE}
DATE=$(date "+%s")
if [ $ACTION = "add" ]; then
env_key=${2//:/_}
/sbin/hal_event --pd_$ACTION dev_sys_id=$env_key,time=${DATE}
echo "[/sbin/hal_event --pd_$ACTION dev_sys_id=$env_key,time=${DATE}]...$?" >> ${LOG_FILE}
elif [ $ACTION = "remove" ]; then
env_key=${2//:/_}
env_var=$(eval echo "\$$env_key")
/sbin/hal_event --pd_$ACTION dev_sys_id=$env_key,enc_sys_id=$env_var,time=${DATE}
/sbin/udevadm control --env=$env_key=NULL
echo "[/sbin/hal_event --pd_$ACTION dev_sys_id=$env_key,enc_sys_id=$env_var,time=${DATE}]...$?" >> ${LOG_FILE}
fi
;;
SJBOD)
#ADD
echo $(date) >> ${LOG_FILE}
DATE=$(date "+%s")
/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}
echo "[/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}]...$?" >> ${LOG_FILE}
;;
TJBOD)
#ADD
echo $(date) >> ${LOG_FILE}
DATE=$(date "+%s")
/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}
echo "[/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}]...$?" >> ${LOG_FILE}
;;
UJBOD)
echo $(date) >> ${LOG_FILE}
DATE=$(date "+%s")
/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}
echo "[/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}]...$?" >> ${LOG_FILE}
;;
DISK_CHANGE)
DATE=$(date "+%s")
BEFORE_SIZE=$(cat /sys/block/$2/size)
/bin/dd if=/dev/$2 of=/dev/null count=1 >& /dev/null
AFTER_SIZE=$(cat /sys/block/$2/size)
dev_name=$(cat /sys/block/$2/device/generic/dev)
dev_name=sg${dev_name##*:}
env_var=$(eval echo "\$$dev_name")
if [ $AFTER_SIZE -gt $BEFORE_SIZE ];then
echo $(date) >> ${LOG_FILE}
/sbin/hal_event --pd_add dev_sys_id=$dev_name,time=${DATE}
echo "[/sbin/hal_event --pd_add dev_sys_id=$dev_name,time=${DATE}]...$?" >> ${LOG_FILE}
elif [ $AFTER_SIZE -lt $BEFORE_SIZE ];then
echo $(date) >> ${LOG_FILE}
/sbin/hal_event --pd_change dev_sys_id=$dev_name,enc_sys_id=$env_var,time=${DATE}
echo "[/sbin/hal_event --pd_change dev_sys_id=$dev_namec,enc_sys_id=$env_var,time=${DATE}]...$?" >> ${LOG_FILE}
fi
;;
DISK)
#ADD
echo $(date) >> ${LOG_FILE}
DATE=$(date "+%s")
/sbin/hal_event --pd_$ACTION dev_sys_id=$2,time=${DATE}
echo "[/sbin/hal_event --pd_$ACTION dev_sys_id=$2,time=${DATE}]...$?" >> ${LOG_FILE}
;;
SJBOD_DISK)
#REMOVE
echo $(date) >> ${LOG_FILE}
DATE=$(date "+%s")
env_var=$(eval echo "\$$2")
if [ $env_var = "enc" ]
then
/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}
/sbin/udevadm control --env=$2=NULL
echo "[/sbin/hal_event --se_$ACTION enc_sys_id=$2,time=${DATE}]...$?" >> ${LOG_FILE}
elif [ $env_var != "NULL" ]
then
/sbin/hal_event --pd_$ACTION dev_sys_id=$2,enc_sys_id=$env_var,time=${DATE}
/sbin/udevadm control --env=$2=NULL
echo "[/sbin/hal_event --pd_$ACTION dev_sys_id=$2,enc_sys_id=$env_var,time=${DATE}]...$?" >> ${LOG_FILE}
else
echo "[Ignore evnet:env_var == NULL, dev_sys_id = $2 ,time=${DATE}]" >> ${LOG_FILE}
fi
;;
PRT)
echo $(date) >> ${LOG_FILE}
/sbin/hal_event --prt_$ACTION dev_sys_id=$2
echo "[/sbin/hal_event --prt_$ACTION dev_sys_id=$2]...$?" >> ${LOG_FILE}
;;
WIFI_RT2500)
#ADD
echo $(date) >> ${LOG_FILE}
env_key=${2//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
/sbin/insmod /usr/local/modules/led-class.ko
/sbin/insmod /usr/local/modules/wifi/rt2x00lib.ko
/sbin/insmod /usr/local/modules/wifi/rt2x00usb.ko
/sbin/insmod /usr/local/modules/wifi/rt2500usb.ko
if [ "$?" = "0" ]; then
/bin/sleep 1
/etc/init.d/wireless.sh auto_connect
fi
;;
GIGAETH_AX88179)
#ADD
echo $(date) >> ${LOG_FILE}
env_key=${2//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
/sbin/insmod /lib/modules/misc/mii.ko
/sbin/insmod /lib/modules/misc/usbnet.ko
/sbin/insmod /lib/modules/misc/ax88179_178a.ko
;;
WIFI_RT2870 | WIFI_RT3070 | WIFI_RT3572 | WIFI_RT3573 | WIFI_RT5572 | WIFI_RTL8712 | WIFI_RT5370 | WIFI_RTL8192CU | WIFI_AR9170 | WIFI_AR9271 | WIFI_MT7610U | WIFI_RTL8192DU | WIFI_RTL8188EU | WIFI_RTL8812AU | WIFI_RT3572ASUS | WIFI_MT7601U)
#ADD
echo $(date) >> ${LOG_FILE}
env_key=${2//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
/etc/init.d/wireless_modules.sh start $1
;;
USB_GENERAL_REMOVE)
#REMOVE
env_key=${2//-/_}
env_key=USB_${env_key//./_}
env_var=$(eval echo "\$$env_key")
case $env_var in
WIFI_RT2500)
echo $(date) >> ${LOG_FILE}
echo "Run dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
/etc/init.d/wireless.sh stop
/bin/sleep 1
/sbin/rmmod /usr/local/modules/wifi/rt2500usb.ko
/sbin/rmmod /usr/local/modules/wifi/rt2x00usb.ko
/sbin/rmmod /usr/local/modules/wifi/rt2x00lib.ko
/sbin/rmmod /usr/local/modules/led-class.ko
/sbin/udevadm control --env=$env_key=NULL
;;
WIFI_RT2870 | WIFI_RT3070 | WIFI_RT3572 | WIFI_RT3573 | WIFI_RT5572 | WIFI_RTL8712 | WIFI_RT5370 | WIFI_RTL8192CU | WIFI_AR9170 | WIFI_AR9271 | WIFI_MT7610U | WIFI_RTL8192DU | WIFI_RTL8188EU | WIFI_RTL8812AU | WIFI_RT3572ASUS | WIFI_MT7601U)
echo $(date) >> ${LOG_FILE}
echo "Run dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
/etc/init.d/wireless_modules.sh stop $env_var
/sbin/udevadm control --env=$env_key=NULL
;;
UPS_HID)
echo $(date) >> ${LOG_FILE}
echo "Run dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
/etc/init.d/usb_ups.sh stop
/sbin/udevadm control --env=$env_key=NULL
;;
UPS_BLAZER)
echo $(date) >> ${LOG_FILE}
echo "Run dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
/etc/init.d/usb_ups.sh stop
/sbin/udevadm control --env=$env_key=NULL
;;
UPS_OMRON)
echo $(date) >> ${LOG_FILE}
echo "Run dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
/etc/init.d/usb_ups.sh stop
/sbin/udevadm control --env=$env_key=NULL
;;
UPS_YEC)
echo $(date) >> ${LOG_FILE}
echo "Run dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
/sbin/daemon_mgr ups_yec stop "/sbin/ups_yec &"
/sbin/rm /tmp/ups_temp
/sbin/rmmod ftdi_sio
/sbin/udevadm control --env=$env_key=NULL
;;
UPS_GENERAL)
echo $(date) >> ${LOG_FILE}
echo "Run dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
QVID=`printf "%.4x" $VID_STR`
QPID=`printf "%.4x" $PID_STR`
/etc/init.d/usb_ups.sh stop "$QVID" "$QPID"
/sbin/udevadm control --env=$env_key=NULL
;;
*)
# echo "Unknown usb device dev_sys_id=$2 model=$env_var $ACTION" >> ${LOG_FILE}
;;
esac
;;
UPS_HID)
#ADD
echo $(date) >> ${LOG_FILE}
env_key=${2//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
/etc/init.d/usb_ups.sh start usbhid-ups
;;
UPS_BLAZER)
#ADD
echo $(date) >> ${LOG_FILE}
env_key=${2//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
/etc/init.d/usb_ups.sh start blazer_usb
;;
UPS_OMRON)
#ADD
echo $(date) >> ${LOG_FILE}
env_key=${2//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
/etc/init.d/usb_ups.sh start omron_usb
;;
UPS_YEC)
#ADD
echo $(date) >> ${LOG_FILE}
env_key=${2//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
/sbin/insmod /lib/modules/others/ftdi_sio.ko
if [ "$?" = "0" ]
then
/sbin/daemon_mgr ups_yec start "/sbin/ups_yec &"
fi
;;
UPS_GENERAL)
#ADD
echo $(date) >> ${LOG_FILE}
ups_bus=${2%:*}
env_key=${ups_bus//-/_}
env_key=USB_${env_key//./_}
/sbin/udevadm control --env=$env_key=$1
echo "Run dev_sys_id=$2 model=$1 $ACTION" >> ${LOG_FILE}
idVendor=0x$(/bin/cat /sys/bus/usb/devices/$ups_bus/idVendor)
idProduct=0x$(/bin/cat /sys/bus/usb/devices/$ups_bus/idProduct)
not_ups_vid_list=(1d6b 05e3 046d 1005 0b05 1c05 1c05)
not_ups_pid_list=(xxxx 0608 0826 b155 17ba 3074 2074)
not_ups_count=${#not_ups_vid_list[@]}
for ((i=0; i<$not_ups_count; i++)); do
if [ "$idVendor" = "${not_ups_vid_list[i]}" ]; then
if [ "${not_ups_pid_list[i]}" = "xxxx" ]; then
exit 0
fi
if [ "$idProduct" = "${not_ups_pid_list[i]}" ]; then
exit 0
fi
fi
done
/etc/init.d/usb_ups.sh start "" "$idVendor" "$idProduct"
;;
LOAD_FIRMWARE)
#ADD
echo $(date) >> ${LOG_FILE}
if [ -e /usr/local/modules/$FIRMWARE ]; then
echo "Upload firmware $2 ${FIRMWARE}" >> ${LOG_FILE}
echo 1 > /sys${DEVPATH}/loading
cat "/usr/local/modules/$FIRMWARE" > /sys${DEVPATH}/data
echo 0 > /sys${DEVPATH}/loading
else
echo "firmware ${FIRMWARE} not found" >> ${LOG_FILE}
fi
;;
USB_SPEAKER)
# If NAS has audio jack, it will not support usb speaker.
CAP=$(/sbin/getcfg "System Enclosure" "CAP" -d 0 -f /etc/model.conf)
CAP_AUDIO_JACK=$((!!($CAP & 0x10000000)))
if [ $CAP_AUDIO_JACK -ne 1 ] && [ -f /proc/asound/cards ]; then
devnum=`expr $(cat /proc/asound/cards | grep USB-Audio | cut -d "[" -f 1) 2>/dev/null`
if [ ! -z $devnum ]; then
/bin/chown 0:0 /dev/audio$devnum
/bin/chmod 666 /dev/audio$devnum
/bin/chown 0:0 /dev/mixer$devnum
/bin/chmod 666 /dev/mixer$devnum
/bin/chown 0:0 /dev/dsp$devnum
/bin/chmod 666 /dev/dsp$devnum
/bin/chown 0:0 /dev/adsp$devnum
/bin/chmod 666 /dev/adsp$devnum
[ ! -f /var/.system.info ] && touch /var/.system.info
[ ! -f /tmp/aumix.conf ] && touch /tmp/aumix.conf
/sbin/setcfg System usbAudio "/dev/audio$devnum" -f /var/.system.info
/sbin/setcfg System usbAudioDevNum $devnum -f /var/.system.info
fi
fi
;;
esac
if [ $(wc -c < ${LOG_FILE}) -ge $MAX_LOG_LEN ];then
$(mv ${LOG_FILE} ${LOG_FILE}.bak)
fi