3 # Usage: gen-rules.tcl [--set-version <date>]
5 # <date> should be in the form YYYYMMDD
7 # A config file is expected to have one comment line containing
8 # a model name or other concise device specifications
11 # Default version string
12 set version
"20130807"
14 if {[lindex $argv 0] == "--set-version" && [regexp {\d
\d
\d
\d
\d
\d
\d
\d
} [lindex $argv 1]]} {
15 set version
[lindex $argv 1]
18 set template
{ATTR
{idVendor
}=="+##+", ATTR
{idProduct
}=="#++#", RUN
+="usb_modeswitch '%b/%k'"}
20 if {![file isdirectory usb_modeswitch.d
]} {
21 puts "No \"usb_modeswitch.d\" subfolder found"
25 set filelist
[glob -nocomplain .
/usb_modeswitch.d
/*]
26 if {[llength $filelist] == 0} {
27 puts "The \"usb_modeswitch.d\" subfolder is empty"
31 set wc
[open "40-usb_modeswitch.rules" w
]
33 # Writing file header with given version
35 puts -nonewline $wc {# Part of usb-modeswitch-data, version }
38 # Recommended use with USB_ModeSwitch >= 1.2.5, works with versions >= 1.0.3
39 # (New style, interface class check moved to dispatcher)
41 ACTION
!="add|change", GOTO
="modeswitch_rules_end"
43 # Adds a symlink "gsmmodem[n]" to the lowest ttyUSB port with interrupt
44 # transfer; checked against a list of known modems, or else no action
45 KERNEL
=="ttyUSB*", ATTRS
{bNumConfigurations
}=="*", PROGRAM
="usb_modeswitch --symlink-name %p %s{idVendor} %s{idProduct} %E{PRODUCT}", SYMLINK
+="%c"
47 SUBSYSTEM
!="usb", GOTO
="modeswitch_rules_end"
49 # Adds the device ID to the "option" driver after a warm boot
50 # in cases when the device is yet unknown to the driver; checked
51 # against a list of known modems, or else no action
52 ATTR
{bInterfaceClass
}=="ff", ATTR
{bInterfaceNumber
}=="00", ATTRS
{bNumConfigurations
}=="*", RUN
+="usb_modeswitch --driver-bind %p %s{idVendor} %s{idProduct} %E{PRODUCT}"
55 # Don't continue on "change" event, prevent trigger by changed configuration
56 ACTION
!="add", GOTO
="modeswitch_rules_end"
62 foreach idfile
$filelist {
63 if {![regexp -nocase {.
/([0-9A-F
]{4}:[0-9A-F
]{4})} $idfile d id
]} {continue}
64 if [info exists
entry($id)] {
65 append entry($id) ", "
67 set rc
[open $idfile r
]
70 foreach line
[split $buffer \n] {
72 regexp {# (.*)} $line d comment
73 if {[string length
$comment] > 0} {
74 append entry($id) [string trim
$comment]
79 foreach id_entry
[lsort [array names
entry]] {
80 set id
[split $id_entry :]
81 set rule
[regsub {\+##\+} $template [lindex $id 0]]
82 set rule
[regsub {#\+\+#} $rule [lindex $id 1]]
83 puts $wc "\n# $entry($id_entry)\n$rule"
87 LABEL
="modeswitch_rules_end"}