|
|
@ -9,8 +9,8 @@
|
|
|
|
# the mode switching program with the matching parameter
|
|
|
|
# the mode switching program with the matching parameter
|
|
|
|
# file from /usr/share/usb_modeswitch
|
|
|
|
# file from /usr/share/usb_modeswitch
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Part of usb-modeswitch-2.4.0 package
|
|
|
|
# Part of usb-modeswitch-2.5.0 package
|
|
|
|
# (C) Josua Dietze 2009-2016
|
|
|
|
# (C) Josua Dietze 2009-2017
|
|
|
|
|
|
|
|
|
|
|
|
set arg0 [lindex $argv 0]
|
|
|
|
set arg0 [lindex $argv 0]
|
|
|
|
if [regexp {\.tcl$} $arg0] {
|
|
|
|
if [regexp {\.tcl$} $arg0] {
|
|
|
@ -40,6 +40,11 @@ global scsi usb config match device flags setup devdir loginit
|
|
|
|
set flags(config) ""
|
|
|
|
set flags(config) ""
|
|
|
|
Log "[ParseGlobalConfig]"
|
|
|
|
Log "[ParseGlobalConfig]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if {$flags(stordelay) > 0} {
|
|
|
|
|
|
|
|
SetStorageDelay $flags(stordelay)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# The facility to add a symbolic link pointing to the
|
|
|
|
# The facility to add a symbolic link pointing to the
|
|
|
|
# ttyUSB port which provides interrupt transfer, i.e.
|
|
|
|
# ttyUSB port which provides interrupt transfer, i.e.
|
|
|
|
# the port to connect through.
|
|
|
|
# the port to connect through.
|
|
|
@ -55,74 +60,47 @@ if {[lindex $argv 0] == "--symlink-name"} {
|
|
|
|
SafeExit
|
|
|
|
SafeExit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if {[lindex $argv 0] == "--switch-systemd"} {
|
|
|
|
# arg0: the bus id for the device (udev: %b), now deprecated
|
|
|
|
set argList [split [lindex $argv 1] _]
|
|
|
|
# arg1: the "kernel name" for the device (udev: %k)
|
|
|
|
Log "\nStarted via systemd"
|
|
|
|
#
|
|
|
|
} else {
|
|
|
|
# From version 2.5.0 upward %b is removed by udev sh script
|
|
|
|
if {[lindex $argv 0] == "--switch-upstart"} {
|
|
|
|
# which can handle old and new udev params ('%b/%k' and '%k')
|
|
|
|
Log "\nStarted via upstart"
|
|
|
|
|
|
|
|
|
|
|
|
Log "Raw parameters: $argv"
|
|
|
|
|
|
|
|
set device "noname"
|
|
|
|
|
|
|
|
if {[lindex $argv 0] == "--switch-mode"} {
|
|
|
|
|
|
|
|
if [string length [lindex $argv 1]] {
|
|
|
|
|
|
|
|
set arg1 [lindex $argv 1]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log "\nNo data from udev. Exit"
|
|
|
|
|
|
|
|
SafeExit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set argList [split [lindex $argv 1] /]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if [string length [lindex $argList 1]] {
|
|
|
|
|
|
|
|
set device [lindex $argList 1]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
set device "noname"
|
|
|
|
Log "\nNo command given. Exit"
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$flags(stordelay) > 0} {
|
|
|
|
|
|
|
|
SetStorageDelay $flags(stordelay)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log "Raw args from udev: [lindex $argv 1]\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if {$device == "noname"} {
|
|
|
|
|
|
|
|
Log "\nNo data from udev. Exit"
|
|
|
|
|
|
|
|
SafeExit
|
|
|
|
SafeExit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if {![regexp -- {--switch-} [lindex $argv 0]]} {
|
|
|
|
if {![regexp {(.*?):.*$} $arg1 d device]} {
|
|
|
|
Log "\nNo command given. Exit"
|
|
|
|
if {![regexp {([0-9]+-[0-9]+\.?[0-9]*.*)} $arg1 d device]} {
|
|
|
|
SafeExit
|
|
|
|
Log "Could not determine device dir from udev values! Exit"
|
|
|
|
|
|
|
|
SafeExit
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set flags(logwrite) 1
|
|
|
|
|
|
|
|
|
|
|
|
set setup(dbdir) /usr/share/usb_modeswitch
|
|
|
|
set setup(dbdir) /usr/share/usb_modeswitch
|
|
|
|
set setup(dbdir_etc) /etc/usb_modeswitch.d
|
|
|
|
set setup(dbdir_etc) /etc/usb_modeswitch.d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if {![file exists $setup(dbdir)] && ![file exists $setup(dbdir_etc)]} {
|
|
|
|
if {![file exists $setup(dbdir)] && ![file exists $setup(dbdir_etc)]} {
|
|
|
|
Log "\nError: no config database found in /usr/share or /etc. Exit"
|
|
|
|
Log "\nError: no config database found in /usr/share or /etc. Exit"
|
|
|
|
SafeExit
|
|
|
|
SafeExit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set bindir /usr/sbin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set bindir /usr/sbin
|
|
|
|
set devList1 {}
|
|
|
|
set devList1 {}
|
|
|
|
set devList2 {}
|
|
|
|
set devList2 {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# arg 0: the bus id for the device (udev: %b), often ommitted
|
|
|
|
|
|
|
|
# arg 1: the "kernel name" for the device (udev: %k)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Used to determine the top directory for the device in sysfs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set ifChk 0
|
|
|
|
set ifChk 0
|
|
|
|
if {[string length [lindex $argList 0]] == 0} {
|
|
|
|
|
|
|
|
if {[string length [lindex $argList 1]] == 0} {
|
|
|
|
|
|
|
|
Log "No device number values given from udev! Exit"
|
|
|
|
|
|
|
|
SafeExit
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if {![regexp {(.*?):} [lindex $argList 1] d dev_top]} {
|
|
|
|
|
|
|
|
if {![regexp {([0-9]+-[0-9]+\.?[0-9]*.*)} [lindex $argList 1] d dev_top]} {
|
|
|
|
|
|
|
|
Log "Could not determine device dir from udev values! Exit"
|
|
|
|
|
|
|
|
SafeExit
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
set dev_top [lindex $argList 0]
|
|
|
|
|
|
|
|
regexp {(.*?):} $dev_top d dev_top
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set devdir /sys/bus/usb/devices/$dev_top
|
|
|
|
set devdir /sys/bus/usb/devices/$device
|
|
|
|
if {![file isdirectory $devdir]} {
|
|
|
|
if {![file isdirectory $devdir]} {
|
|
|
|
Log "Top device directory not found ($devdir)! Exit"
|
|
|
|
Log "Top device directory not found ($devdir)! Exit"
|
|
|
|
SafeExit
|
|
|
|
SafeExit
|
|
|
@ -141,8 +119,6 @@ Log " Interface 0 class is $config(class)."
|
|
|
|
set ifdir [file tail [IfDir $iface $devdir]]
|
|
|
|
set ifdir [file tail [IfDir $iface $devdir]]
|
|
|
|
regexp {:([0-9]+\.[0-9]+)$} $ifdir d iface
|
|
|
|
regexp {:([0-9]+\.[0-9]+)$} $ifdir d iface
|
|
|
|
|
|
|
|
|
|
|
|
set flags(logwrite) 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Mapping of the short string identifiers (in the config
|
|
|
|
# Mapping of the short string identifiers (in the config
|
|
|
|
# file names) to the long name used here
|
|
|
|
# file names) to the long name used here
|
|
|
|
#
|
|
|
|
#
|
|
|
@ -228,13 +204,10 @@ if $scsiNeeded {
|
|
|
|
Log "SCSI attributes not needed, move on"
|
|
|
|
Log "SCSI attributes not needed, move on"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# General wait - some devices need this
|
|
|
|
|
|
|
|
after 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Now check for a matching config file. Matching is done
|
|
|
|
# Now check for a matching config file. Matching is done
|
|
|
|
# by MatchDevice
|
|
|
|
# by MatchDevice
|
|
|
|
|
|
|
|
|
|
|
|
set report {}
|
|
|
|
set report ""
|
|
|
|
foreach mconfig $configList {
|
|
|
|
foreach mconfig $configList {
|
|
|
|
|
|
|
|
|
|
|
|
# skipping installer leftovers like "*.rpmnew"
|
|
|
|
# skipping installer leftovers like "*.rpmnew"
|
|
|
@ -243,74 +216,89 @@ foreach mconfig $configList {
|
|
|
|
Log "Check config: $mconfig"
|
|
|
|
Log "Check config: $mconfig"
|
|
|
|
if [MatchDevice $mconfig] {
|
|
|
|
if [MatchDevice $mconfig] {
|
|
|
|
Log "! matched. Read config data"
|
|
|
|
Log "! matched. Read config data"
|
|
|
|
# set flags(config) $mconfig
|
|
|
|
|
|
|
|
if [string length $usb(busnum)] {
|
|
|
|
|
|
|
|
set busParam "-b [string trimleft $usb(busnum) 0]"
|
|
|
|
|
|
|
|
set devParam "-g [string trimleft $usb(devnum) 0]"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
set busParam ""
|
|
|
|
|
|
|
|
set devParam ""
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set flags(config) [ConfigGet conffile $mconfig]
|
|
|
|
set flags(config) [ConfigGet conffile $mconfig]
|
|
|
|
ParseDeviceConfig $flags(config)
|
|
|
|
break
|
|
|
|
if [regexp -nocase {/[0-9a-f]+:#} $flags(config)] {
|
|
|
|
} else {
|
|
|
|
Log "Note: Using generic manufacturer configuration for \"$flags(os)\""
|
|
|
|
Log "* no match, don't use this config"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if $flags(nombim) {
|
|
|
|
}
|
|
|
|
set config(NoMBIMCheck) 1
|
|
|
|
if {$flags(config) == ""} {
|
|
|
|
}
|
|
|
|
Log "No matching config file found. Exit"
|
|
|
|
if {$config(WaitBefore) != ""} {
|
|
|
|
SafeExit
|
|
|
|
Log "Delay time of $config(WaitBefore) seconds"
|
|
|
|
}
|
|
|
|
append config(WaitBefore) "000"
|
|
|
|
|
|
|
|
after $config(WaitBefore)
|
|
|
|
ParseDeviceConfig $flags(config)
|
|
|
|
Log " wait is over, start mode switch"
|
|
|
|
|
|
|
|
}
|
|
|
|
if [regexp -nocase {0x([0-9a-f]+)} $config(TargetClass) d tc] {
|
|
|
|
if {$config(NoMBIMCheck)==0 && $usb(bNumConfigurations) > 1} {
|
|
|
|
if {$tc == $config(class)} {
|
|
|
|
Log "Device may have an MBIM configuration, check driver ..."
|
|
|
|
Log "Class of interface 0 matches target. Do nothing"
|
|
|
|
if [CheckMBIM] {
|
|
|
|
set report "ok:busdev"
|
|
|
|
Log " driver for MBIM devices is available"
|
|
|
|
}
|
|
|
|
Log "Find MBIM configuration number ..."
|
|
|
|
}
|
|
|
|
if [catch {set cfgno [exec /usr/sbin/usb_modeswitch -j -Q $busParam $devParam -v $usb(idVendor) -p $usb(idProduct)]} err] {
|
|
|
|
|
|
|
|
Log "Error when trying to find MBIM configuration, switch to legacy modem mode"
|
|
|
|
if [string length $usb(busnum)] {
|
|
|
|
} else {
|
|
|
|
set busParam "-b [string trimleft $usb(busnum) 0]"
|
|
|
|
set cfgno [string trim $cfgno]
|
|
|
|
set devParam "-g [string trimleft $usb(devnum) 0]"
|
|
|
|
if {$cfgno > 0} {
|
|
|
|
} else {
|
|
|
|
set config(Configuration) $cfgno
|
|
|
|
set busParam ""
|
|
|
|
set flags(config) "Configuration=$cfgno"
|
|
|
|
set devParam ""
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
Log " No MBIM configuration found, switch to legacy modem mode"
|
|
|
|
if [regexp -nocase $flags(os) $flags(config)] {
|
|
|
|
}
|
|
|
|
Log "Note: Using generic manufacturer configuration for \"$flags(os)\""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if $flags(nombim) {
|
|
|
|
|
|
|
|
set config(NoMBIMCheck) 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$config(NoMBIMCheck)==0 && $usb(bNumConfigurations) > 1} {
|
|
|
|
|
|
|
|
Log "Device may have an MBIM configuration, check driver ..."
|
|
|
|
|
|
|
|
if [CheckMBIM] {
|
|
|
|
|
|
|
|
Log " driver for MBIM devices is available"
|
|
|
|
|
|
|
|
Log "Find MBIM configuration number ..."
|
|
|
|
|
|
|
|
if [catch {set cfgno [exec /usr/sbin/usb_modeswitch -j -Q $busParam $devParam -v $usb(idVendor) -p $usb(idProduct)]} err] {
|
|
|
|
|
|
|
|
Log "Error when trying to find MBIM configuration, switch to legacy modem mode"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
set cfgno [string trim $cfgno]
|
|
|
|
|
|
|
|
if {$cfgno > 0} {
|
|
|
|
|
|
|
|
set config(Configuration) $cfgno
|
|
|
|
|
|
|
|
set flags(config) "Configuration=$cfgno"
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Log " no MBIM driver found, switch to legacy modem mode"
|
|
|
|
Log " No MBIM configuration found, switch to legacy modem mode"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if [PantechAutoSwitch] {
|
|
|
|
|
|
|
|
Log "Waiting for Pantech auto-modeswitch"
|
|
|
|
|
|
|
|
set report "ok:busdev"
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$config(Configuration) == 0} {
|
|
|
|
|
|
|
|
Log "Config file contains dummy method, do nothing. Exit"
|
|
|
|
|
|
|
|
SafeExit
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UnbindDriver $devdir $ifdir
|
|
|
|
|
|
|
|
# Now we are actually switching
|
|
|
|
|
|
|
|
if $flags(logging) {
|
|
|
|
|
|
|
|
Log "Command to be run:\nusb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f \$flags(config)"
|
|
|
|
|
|
|
|
set report [exec /usr/sbin/usb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]
|
|
|
|
|
|
|
|
Log "\nVerbose debug output of usb_modeswitch and libusb follows"
|
|
|
|
|
|
|
|
Log "(Note that some USB errors are to be expected in the process)"
|
|
|
|
|
|
|
|
Log "--------------------------------"
|
|
|
|
|
|
|
|
Log $report
|
|
|
|
|
|
|
|
Log "--------------------------------"
|
|
|
|
|
|
|
|
Log "(end of usb_modeswitch output)\n"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
set report [exec /usr/sbin/usb_modeswitch -Q -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Log "* no match, don't use this config"
|
|
|
|
Log " no MBIM driver found, switch to legacy modem mode"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if [PantechAutoSwitch] {
|
|
|
|
|
|
|
|
Log "Waiting for Pantech auto-modeswitch"
|
|
|
|
|
|
|
|
set report "ok:busdev"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$config(Configuration) == 0} {
|
|
|
|
|
|
|
|
Log "Config file contains dummy method, do nothing. Exit"
|
|
|
|
|
|
|
|
SafeExit
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# General wait - some devices need this
|
|
|
|
|
|
|
|
after 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if {$config(WaitBefore) != ""} {
|
|
|
|
|
|
|
|
Log "Delay time of $config(WaitBefore) seconds"
|
|
|
|
|
|
|
|
append config(WaitBefore) "000"
|
|
|
|
|
|
|
|
after $config(WaitBefore)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if {$report == ""} {
|
|
|
|
|
|
|
|
# Now we are actually switching
|
|
|
|
|
|
|
|
if $flags(logging) {
|
|
|
|
|
|
|
|
Log "Command line:\nusb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f \$flags(config)"
|
|
|
|
|
|
|
|
catch {set report [exec /usr/sbin/usb_modeswitch -W -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]} report
|
|
|
|
|
|
|
|
Log "\nVerbose debug output of usb_modeswitch and libusb follows"
|
|
|
|
|
|
|
|
Log "(Note that some USB errors are to be expected in the process)"
|
|
|
|
|
|
|
|
Log "--------------------------------"
|
|
|
|
|
|
|
|
Log $report
|
|
|
|
|
|
|
|
Log "--------------------------------"
|
|
|
|
|
|
|
|
Log "(end of usb_modeswitch output)\n"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
catch {set report [exec /usr/sbin/usb_modeswitch -Q -D $configParam $busParam $devParam -v $usb(idVendor) -p $usb(idProduct) -f "$flags(config)" 2>@1]} report
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -976,16 +964,6 @@ if {$config(PantechMode) == 1} {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
proc UnbindDriver {devdir ifdir} {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set att $devdir/$ifdir/driver/unbind
|
|
|
|
|
|
|
|
if [file exists $att] {
|
|
|
|
|
|
|
|
Log "Unbinding driver"
|
|
|
|
|
|
|
|
exec echo -n "$ifdir" > $att
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc {LogAttributes} {} {
|
|
|
|
proc {LogAttributes} {} {
|
|
|
|
|
|
|
|
|
|
|
|
global flags usb
|
|
|
|
global flags usb
|
|
|
|