usb-modeswitch: Fix a condition to compare default product id and switched product...
[openwrt/svn-archive/archive.git] / utils / usb-modeswitch / files / modeswitch.hotplug
index eebaf13..8042451 100644 (file)
@@ -92,7 +92,7 @@ if [ "$ACTION" = add ]; then
        [ -d "/etc/usb_modeswitch.d" ] && [ -x "$modeswitch" ] && {
                case "$DEVICENAME" in
                        *-*:*.*) : ;;
-                       *) log "Not handling $DEVICENAME"; exit 0 ;;
+                       *) exit 0 ;;
                esac
 
                find_usb_attrs
@@ -120,9 +120,20 @@ if [ "$ACTION" = add ]; then
                # If a candidate is remaining, start usb-modeswitch
                [ -n "$configs" ] && {
                        log "$DEVICENAME: Selecting ${configs%% *} for mode switching"
-                       $modeswitch -c "${configs%% *}"
-               } || {
-                       log "$DEVICENAME: Device does not seem to need mode switching"
+                       # ugly workaround, but working for all hw we got for testing
+                       switching_done=0
+                       switching_tries=0
+                       local usb_dir="/sys/$DEVPATH"       
+                       [ -f "$usb_dir/idVendor" ] || usb_dir="${usb_dir%/*}"
+                       while [ $switching_done -lt 1 -a $switching_tries -le 6 ]; do
+                               $modeswitch -I -D -n -s 30 -c "${configs%% *}"
+                               if [ $(sanitize "$usb_dir/idProduct") = $uPid ]; then
+                                       log "switching seemingly failed"
+                               else
+                                       switching_done=1
+                               fi
+                               switching_tries=$(( $switching_tries + 1 ))
+                       done
                }
        }
 fi