A clone of Aleksander Morgado's libqmi code with a few tweaks