I've used usb_modeswitch on FreeBSD for a Huawei dongle where I realized that things were not as plug and play as they are on Linux. I ended up learning way more about udev, the usb-modeswitch-data package, udev rules etc. than initially wanted, but now I'm (trying) to hack a port of the missing pieces. FreeBSD has has devd, so making devd(8) rules out of the -data package might once day become possible, but first I saw most of the "magic" was happening in usb_modeswitch.tcl aka usb_modeswitch_dispatcher.
I've tried to understand all what this script does - which is definitely specific to Linux - but since it does quite a lot of things (1205 LoC) and there aren't that many comments inside, I wanted to ask whether there is a document somewhere that would explain what it all does. Maybe someone is willing to point out the major tasks this script does - I see things like detecting the device ID etc but also an awful lot more.
The current idea is to stay with Tcl since that is what usb_modeswitch uses there and make a FreeBSD port of that script that might be invoked by devd rules. Since DragonflyBSD has devd too (inherited & shared mostly with FreeBSD) it may even be portable to this OS as well (just maybe). Actually getting things like the USB bus numbers, device id and product id are pretty easy with devd since they are available through variables in devd rules so they can be passed out to a BSD-ish usb_modedeswitch_dispatcher. Apparently udev gives way less information (on my Ubuntu laptop) to the dispatcher script so it has to figure out quite a bit on its own (true?).
Don't expect quick advances though, but I've come this far as to understand a bit more about the mechanics behind the scenes have started bastardizing one line after the usb_modeswitch.tcl for a possible BSD port.
Looking forward for some feedback, so I don't forget/missunderstand the Linux version. Maybe there is documentation around that I haven't yet catched