Friday, December 15, 2017

Life Tips

Create plans from dreams

Great ideas are great. It is surely a good feeling to dwell on future possibilities. But strive to realize your dreams: plan on how you can reach your goals, no matter how impossible they might seem. (Want to be an astronaut? Research your options: how to get hired at NASA / SpaceX, establish your own space-travel agency or set a goal to gather enough money to become a space tourist.)


Where you are now matters less than where you are headed

Think on the long term, see the trajectories of where you're going; extrapolate.


Sharing is caring

If you solve a hard problem, make sure to post it somewhere people can find it. Eg, post to forums that you came across while searching for the solution. Write a blog post. Like this one ;)


Bitching is unprofessional

What do you think of people who cannot stop complaining? Let me tell you what I think: they cannot solve the situation. They are unlucky. They do not know how to deal with the problem. Of course, if you meet a sub-par service or product, leave a review, give feedback, make a mental note you would never go back. But complaining for complaint's sake is very unprofessional.


Be an efficiency fanatic

This might be a personality trait, that is, might not suit everyone.

The only limited resource you have is time. Time ticks away, inevitably - so make the most of it. Grow a habit of being an efficiency fanatic: if you see a shorter path, choose it. If you see a way to achieve things faster, go for it! (geek example: learn keyboard shortcuts! Does Alt-TAB ring a bell? How about pressing Enter instead of clicking OK / Go / Submit buttons?)

This habit will help you everywhere, and the tiny bits and pieces will grow into hours saved. Hours you can spend with your family, hobbies, or anything you want.

Monday, August 7, 2017

Hungarian Telenor's D-Link DWM-222 4G Mobile Broadband Modem on Ubuntu 16.04 Linux

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

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:

$ lsusb
...
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.
...


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

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? :)