minidlna support now Samsung TV C550/C650 (thx amir909)
[tomato.git] / release / src / router / usbmodeswitch / usb_modeswitch.sh
blob8cea87abdcd71577e25349b881049191fd7fb61d
1 #!/bin/sh
2 # part of usb_modeswitch 1.1.7
3 device_in()
5 if [ ! -e /var/lib/usb_modeswitch/$1 ]; then
6 return 0
7 fi
8 while read line
9 do
10 if [ $(expr "$line" : "$2:$3") != 0 ]; then
11 return 1
13 done </var/lib/usb_modeswitch/$1
14 if [ $(expr "$line" : "$2:$3") != 0 ]; then
15 return 1
17 return 0
20 p_id=$4
21 if [ -z $p_id ]; then
22 prod=$5
23 if [ -z $prod ]; then
24 prod=$3
26 prod=${prod%/*}
27 v_id=0x${prod%/*}
28 v_id=$(printf %04x $(($v_id)) )
29 p_id=0x${prod#*/}
30 p_id=$(printf %04x $(($p_id)) )
31 else
32 v_id=$3
34 case "$1" in
35 --driver-bind)
37 dir=$(ls -d /sys$2/ttyUSB* 2>/dev/null)
38 if [ ! -z "$dir" ]; then
39 exit 0
41 set +e
42 device_in "bind_list" $v_id $p_id
43 if [ "$?" = "1" ]; then
44 id_attr="/sys/bus/usb-serial/drivers/option1/new_id"
45 if [ ! -e "$id_attr" ]; then
46 /sbin/modprobe option 2>/dev/null || true
48 if [ -e "$id_attr" ]; then
49 echo "$v_id $p_id" > $id_attr
50 else
51 /sbin/modprobe -r usbserial
52 /sbin/modprobe usbserial vendor=0x$v_id product=0x$p_id
55 ) &
56 exit 0
58 --symlink-name)
59 device_in "link_list" $v_id $p_id
60 if [ "$?" = "1" ]; then
61 if [ -e "/usr/bin/tclsh" ]; then
62 exec /usr/bin/tclsh /usr/sbin/usb_modeswitch_dispatcher $1 $2 $v_id $p_id 2>/dev/null
65 exit 0
67 esac
69 count=120
70 while [ $count != 0 ]; do
71 if [ ! -e "/usr/bin/tclsh" ]; then
72 sleep 1
73 count=$(($count - 1))
74 else
75 exec /usr/bin/tclsh /usr/sbin/usb_modeswitch_dispatcher "$@" 2>/dev/null &
76 exit 0
78 done
79 ) &