D-Link DWM-222 on Linux
I recently had to use the D-Link DWM-222 modem sold by Telenor in Hungary. Of course plugging in and waiting did not bring nothing... so here you go step-by-step instructions for setting it up.
USB Mode Switch
The way these dongles work is that first they pretend to be a flash drive, containing the drivers. First, it must be non-standard, as Linux does not mount it automatically. Second, the drivers are Windows only... very helpful.
On Windows, after having the driver installed, it instructs the dongle to switch from being a flash drive ("USB Mass Storage" device) into an USB-to-Serial device, from which point it becomes a simple modem. Yes, you heard correctly, back to the 90's, when modems (remember the sound? :) were accessible on a serial port, with AT commands, using ppp interface! Guess what. We still have to use AT commands. Oh, the nostalgia....
So, we just need to give the instruction to the modem to do the switch. USB_ModeSwitch to the rescue!
Installation
Thankfully to Josua Dietze (make sure to visit his Draisberghof!), we have the utility right at hand. Ubuntu 16.04 does not have the most recent version supporting the DWM-222, so we need to download, compile and install it:
First, the dependencies (on Ubuntu I only needed this):
$ sudo apt install libusb-1.0-0-dev
Download and install -- check http://www.draisberghof.de/usb_modeswitch/#download for recent link:
$ wget http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-2.5.1.tar.bz2
...
2017-08-07 12:51:38 (634 KB/s) - ‘usb-modeswitch-2.5.1.tar.bz2’ saved [259123/259123]
$ tar xfj usb-modeswitch-2.5.1.tar.bz2
$ cd usb-modeswitch-2.5.1/
$ make
cc -o usb_modeswitch usb_modeswitch.c -Wall `pkg-config --libs --cflags libusb-1.0`
sed 's_!/usr/bin/tclsh_!'"/usr/bin/tclsh"'_' < usb_modeswitch.tcl > usb_modeswitch_dispatcher
$ sudo make install
...
2017-08-07 12:51:38 (634 KB/s) - ‘usb-modeswitch-2.5.1.tar.bz2’ saved [259123/259123]
$ tar xfj usb-modeswitch-2.5.1.tar.bz2
$ cd usb-modeswitch-2.5.1/
$ make
cc -o usb_modeswitch usb_modeswitch.c -Wall `pkg-config --libs --cflags libusb-1.0`
sed 's_!/usr/bin/tclsh_!'"/usr/bin/tclsh"'_' < usb_modeswitch.tcl > usb_modeswitch_dispatcher
$ sudo make install
Verifying the Switch
Having usb_modeswitch installed, the switch should occur automatically whenever the modem is plugged in.
Before the switch, the operating system sees USB device 2001:ab00 listed:
Before the switch, the operating system sees USB device 2001:ab00 listed:
$ lsusb
...
Bus 001 Device 002: ID 2001:ab00 D-Link Corp.
...
...
Bus 001 Device 002: ID 2001:ab00 D-Link Corp.
...
...after the switch, this should turn into 2001:7e35:
$ lsusb
...
Bus 001 Device 002: ID 2001:7e35 D-Link Corp.
...
...
Bus 001 Device 002: ID 2001:7e35 D-Link Corp.
...
Registering the Serial Interface
After having the switch done, we still do not see the new serial ports (/dev/ttyUSB* devices). As far as I get it, this is because Linux kernel's usbserial module still does not recognize this USB device as a serial port provider. Rectification is easy, we need the option kernel module to tell the Linux kernel that hey, this is a serial port provider! Easy-peasy, lemon squeezy:
$ modprobe option
$ echo 2001 7e35 > /sys/bus/usb-serial/drivers/option1/new_id
$ echo 2001 7e35 > /sys/bus/usb-serial/drivers/option1/new_id
Automating the Registration
Oh, it would be so great if we could just have a way to tell Linux to run these commands anytime the device is detected... but hey!! This is what udev is for! Let's get to it:
$ cat > /etc/udev/rules.d/99-dlink-mobile-connect.rules
ACTION=="add", ATTRS{idVendor}=="2001", ATTRS{idProduct}=="7e35", RUN+="/sbin/modprobe option" RUN+="/bin/sh -c 'echo 2001 7e35 > /sys/bus/usb-serial/drivers/option1/new_id'"(press ctrl-d here to end the input)
If you did everything correctly, you should have your broadband modem detected everytime you plug it in. Don't you just love Linux? :)