3 local uVid uPid uMa uPr uSe
6 local modeswitch
="/usr/bin/usb_modeswitch"
10 logger
-t "usb-modeswitch" "$@"
14 sed -e 's/[[:space:]]\+$//; s/[[:space:]]\+/_/g' "$@"
18 [ -n "$DEVPATH" ] && [ -d /sys
/$DEVPATH/host* ] && {
19 log
"$DEVICENAME is a SCSI device, waiting for it to settle..."
21 while [ $
((--timeout)) -ge 0 ]; do
22 [ -d /sys
/$DEVPATH/host*/target
* ] && {
24 for scsi_dir
in /sys
/$DEVPATH/host*/target
*/*; do
25 [ -d "$scsi_dir" ] ||
break
27 */host*/target
*/*:*:*:*)
28 sVe
=$
(sanitize
"$scsi_dir/vendor")
29 sMo
=$
(sanitize
"$scsi_dir/model")
30 sRe
=$
(sanitize
"$scsi_dir/rev")
32 log
"$DEVICENAME: Vendor=${sVe:-?} Model=${sMo:-?} Revision=${sRe:-?}"
41 log
"$DEVICENAME: Failed to get SCSI attributes!"
48 local usb_dir
="/sys/$DEVPATH"
49 [ -f "$usb_dir/idVendor" ] || usb_dir
="${usb_dir%/*}"
51 uVid
=$
(cat "$usb_dir/idVendor")
52 uPid
=$
(cat "$usb_dir/idProduct")
53 uMa
=$
(sanitize
"$usb_dir/manufacturer")
54 uPr
=$
(sanitize
"$usb_dir/product")
55 uSe
=$
(sanitize
"$usb_dir/serial")
57 log
"$DEVICENAME: Manufacturer=${uMa:-?} Product=${uPr:-?} Serial=${uSe:-?}"
66 local cmp; eval "cmp=\$$tag"
67 local pat
="${conf#*:$tag=}"; pat
="${pat%%:*}"
82 for tag
in uMa uPr uSe sVe sMo sRe
; do
83 match_config_tag
"$conf" "$tag" ||
return 1
91 if [ "$ACTION" = add
]; then
92 [ -d "/etc/usb_modeswitch.d" ] && [ -x "$modeswitch" ] && {
102 for conf
in /etc
/usb_modeswitch.d
/$uVid:$uPid*; do
103 [ -f "$conf" ] ||
break
104 configs
="${configs:+$configs }$conf"
108 # Found more than one candidate, read SCSI attributes and find the best match
109 [ $candidates -gt 1 ] && {
111 for conf
in $configs; do
112 match_config
"$conf" && {
120 # If a candidate is remaining, start usb-modeswitch
121 [ -n "$configs" ] && {
122 log
"$DEVICENAME: Selecting ${configs%% *} for mode switching"
123 # ugly workaround, but working for all hw we got for testing
126 local usb_dir
="/sys/$DEVPATH"
127 [ -f "$usb_dir/idVendor" ] || usb_dir
="${usb_dir%/*}"
128 while [ $switching_done -lt 1 -a $switching_tries -le 6 ]; do
129 $modeswitch -v $uVid -p $uPid -I -D -n -s 30 -c "${configs%% *}"
130 if [ $
(sanitize
"$usb_dir/idProduct") = $uPid ]; then
131 log
"$DEVICENAME: Switching seemingly failed"
136 switching_tries
=$
(( $switching_tries + 1 ))