Search This Blog

Sunday, March 6, 2011

Plasma NM: small feature

In the last days I have been trying to figure out how to "enable" Mobile Broadband modems by default. By "enable" I mean make the modem powers up when it is attached to the computer. NetworkManager and ModemManager require the modem to be "enabled" before using it.

I have always thought it should be something simple like modem = Solid::Control::ModemManager::findModemInterface(...); modem->enable(true). Actually that sample code works... for root only. ModemManager protects most of its DBus interface through policy-kit, so I had to figure out how to do it for normal users without asking for a password. As you probably know, Plasma NM run as normal user, not root. Time to take a look at how nm-applet does that.

After some digging in nm-applet source code I found this function nm_client_wwan_set_enabled. I have never seen that "wwan" interface in NetworkManager specification, the public specification did not mention it some days ago. In the end I figured out wwan is a synonym for mobile broadband. Today I have looked at the specification site again and now there is a 0.9 specification that mentions wwan, although NetworkManager 0.8 supports wwan but the 0.8 specification does not mention that, cool, huh?

Anyway, now that I know those functions are there, I have updated Solid::Control::NetworkManager to make use of them. The changes are already in kde://kde-workspace and kde://networkmanagement, they are going to be available in KDE SC 4.7. The visual changes in Plasma NM are very small, just a new checkbox called "Enable mobile broadband". The checkbox is visible only when there is at least one Gsm/Cdma modem attached. Following the same idea, I have changed the "Enable wireless" checkbox to also be visible only when there is at least one wireless card attached.

When you attach a modem to your computer ModemManager disables it by default. NetworkManager disables wwan if all modems are disabled, which means everytime you attach a modem NM will disable wwan. Even worse, if you have two modems, attach the first, enable wwan, attach the second modem, NM will disable wwan because the last modem is disabled. Nm-applet also demonstrates the same behavior in my tests. I think that explains why sometimes when my notebook is connected through 3G and I attach my cellphone in "PCSuite mode" to my notebook the 3G connection drops. To workaround the enable/disable problem I am using a QTimer::singleShot(...) to enable wwan after NM disables it if the mobile broadband checkbox is checked. Seems to work.

Now that I can enable/disable wwan the next thing to implement is saving the plasmoid configuration. Plasma NM is splitted into two parts, one plasmoid and a kded module. The kded module already saves its configuration, it is responsible to talk to NetworkManager and ModemManager and manages all interfaces. Of course the plasmoid is the user interface, it does not save its configuration yet, that is why everytime you resume from ram or disk the wireless state is on, it is on because your computer's BIOS set it to on, not Plasma NM. Plasma NM just reads the wireless state from NetworkManager.

The plasmoid state is just those three checkbox (Networking, Wireless and Mobile Broadband). I plan to save those three state to a configuration file and restore them when Plasma NM is started or resumes from ram/disk. So if the user set wwan to enable and attaches a modem to his/her computer, the modem will be be enabled after a short flux of DBus calls. Use dbus-monitor to see what I am talking about :-)

8 comments:

Anonymous said...

Great news, really :)
I couldn't use network-manager at all with my mobile broadband stick (or Wireless Wide Area Network in nm terms) because it was doing nothing. I used my own tool to enter the PIN for the UMTS card and used pppd to connect. What is not clear is the possible danger! Note that the PIN code is specific for a card but you cannot know in advance which card is inserted. Thus NM may try the wrong PIN and 3 times is enough to disable it.

Unknown said...

Hi Lamarque,

Similarly to how you hide the checkboxes for enabling/disabling wwan and wifi, have you thought of the following:

Hide the networkmanager plasmoid from the system tray if: wwan/wifi are unplugged or hardblocked and the network cable is unplugged. This would be similar to how the bluetooth plasmoid works (hidden if it cannot possibly be of any use).

Thanks for your work!

Cheers,

Tom

Lamarque said...

The show/hide feature hides the checkbox when there is no hardware for that network interface type attached to the computer. It is very rare to have a computer without ethernet card these days, so it would not work as you expected.

Hiding the plasmoid when the cable is unplugged is not a good idea either. The ethernet card can enter the unplug state when there is a glitch in the ethernet hub, wall power goes down, etc. The plasmoid also shows information about the interfaces. With the plasmoid hidden the user could not get the ethernet MAC address to configure a firewall for example.

Another problem is that sometimes NetworkManager state gets stuck in "no networking" (sleep state) when resuming from ram/disk. In that state wifi and wwan are disabled. If I hide the plasmoid when ethernet cable is unplugged I could not click in the "Enable networking" to get NetworkManager from sleep state. I would have to use command line for that.

Lamarque said...

@Anonymous, that is a known bug, we are trying to solving it.

Sauron said...

Hi!

1) regarding the bug about wwan being disabled when you plug the second device, I hope you reported it right ?

2) gnome's network manager back in 2005 already provided me a list of countries, then mobile operators to easily configure my 3g connection without any efforts. It uses the mobile-broadband-provider-info package in ubuntu which contains the data from http://live.gnome.org/NetworkManager/MobileBroadband/ServiceProviders
I really really wish for this to be supported. Do you know if anything is being done ?

3)
outside the scope of mobile broadband, to configure a vpn connection I first need to install network-manager-pptp-kde, network-manager-openvpn-kde or network-manager-vpnc-kde. But last time I tried, the NM UI did not inform me about it. Could it provide an easy way to install these missing dependencies when configuring the vpn connection ?

Thank you.

Lamarque said...

1) No, but I am using an old NetworkManager version, probably the newer ones have this bug fixed. I have not had time to test a newer NetworkManager version.

2) I implemented that feature in October of last year, probably your distribution is using an old Plasma NM version.

3) Using package names are not a good decision since they change from distribution to distribution. I have never used VPN until today, I am trying to setup a VPN connection to do some tests, no lucky so far :-(

Luiz Angelo Daros de Luca said...

Hello Lamarque,

Thanks for the great work in NM-plasma!

I installed kubuntu11.10 yesterday and tried to use a ZTE 3g modem with plasma-nm. The first problem was its vendor:product wasn't in usb_modeswitch list. After solving that, I could see it in plasma-nm.

However, the checkbox for wwan is really "non intuitive". With the checkbox unchecked, I can see the modem, I can ask it to connect but it just does down after less than a second. If I enable the checkbox, everything is ok.

Is there any way to enable wwan "by default"? The "connect automatically" does not help and plasma is still not saving the last state. The "connect automatically" really does not make any sense if the device is never enabled when plugged.

Also, I would suggest that the modems, when wwan is disable, should be shown as "disabled". Alternatively, if the user click to connect a wwan device, the "wwan enabled" flag in nm should be set.

I don't know if there is a version/patch that fixes these issues but, if it exist, I could suggest to kubuntu to release an update with it.

Lamarque said...

@Luiz Angelo, NM does not support enabling wwan by default nor auto-connect for mobile broadband (https://bugzilla.gnome.org/show_bug.cgi?id=554538). Modems are disabled by default to save power, specially in notebooks.

Probably your modem is blocked by rfkill. When you click on "Enable Mobile Broadband" NM unblocks it. If you set rfkill to not block your modem when you click on a mobile broadband connection NM will be able to activate the connection right away.

As for modem still be listed even with "Enable Mobile Broadband" disabled that is the intended NM behaviour (https://bugzilla.gnome.org/show_bug.cgi?id=616285).

I do not agree with showing modems as disable when wwan is disabled. The correct behaviour is your second suggestion: enable wwan when clicking on a mobile broadband connection. But what should be done by NM itself not by Plasma NM in my oppinion.