Swifer: simple wifi connector tool with auto-connect features

I've just got the newest incarnation of my wifi tool ready for testing.

It is available on github. As there have been a few nibbles, I've added swifer-git to the AUR.

I readily admit this may be partially reinventing the wheel of tools like netcfg. I've never used netcfg, but there seems to be a lot to it. There is very little to swifer.

Swifer, ran without parameters, will present a ncurses list of available networks (manual mode) and connect you to the one you select. If you select an unsecure/open network wifi will do this silently. If you select a secure and unknown (see "add" below) swifer will prompt you for a passphrase to pass to wpa_supplicant. If you select a secure and known network swifer will also handle this silently requiring no further input.

Parameters: (each can be invoked with the first two letters):autoAutomatic connect mode will not present the ncurses menu. Instead wifi will automatically detect the strongest signal available among known (see "add") networks and connect to it.anyAny is like auto (and implies auto), except that it will select the strongest connection from among any known networks and any unsecure/open unknown networks. Effectively this gets you the best available connection without requiring any further input.addAdd will add the network selected (either from the menu or from the auto-detect) to the list of known networks so it can be automaticaly connected to in the future.

Other options in various states of usability:reconnect (INCOMPLETE)Reconnect will keep wifi alive and monitor the network connection. If it disconnects or drops below a signal threshold, wifi will reconnect to the best available network.verboseVerbose is not particularly useful yet as it only disinhibits dhcpcd output for troubleshooting purposes. Verbose is disabled in any automatic mode.

Limitations:- Wifi is only a wifi tool and does not manage any wired connections.- Wifi is for automating simple but repetitive manual connection steps. Wifi will *break* complex setups with mutliple connections. For example, wifi kills any active dhcpcd or wpa_supplicant process before it starts a new one. If you want dhcpcd active on eth0 AND you try to use wifi for wlan0, you will lose your eth0 connection. I do not consider this a problem as I define the scope of use of wifi as a tool for more "common use" to just get a wireless connection. Those with more advanced needs should not use this tool.- With the above, wifi's management of WPA networks is very "vanilla". It simply calls wpa_passphrase and wpa_supplicant. If you have advanced security needs you may need to customize these (just once) in your wpa_supplicant.conf. After that wifi should connect to your network well.

Optional configuration:/etc/swifer.conf will be created when you "add" the first network. You can also create this manually and add either of the following options to the top (above "[NETWORKS]") of the file to change the defaults to use an alternate interface or a drop-in replacement for dhcpcd (such as dhclient).INTERFACEINTERFACE = wlan0DHCPDHCP = dhcpcd

Potential advantages: (over other connection tools)- Wifi is simple. The code is (I hope) simple. The configuration is simple (all automated). Use is simple.- Unless invoked in "reconnect" mode, wifi does not run as a daemon. It just sets up your connection then gets out of your way.

Future directions:- A systemd service file for auto modes is coming soon. With this you will be able to have wifi automatically connect to the best available network at boot (if you enable the service). (done)- Finish the reconnect modes.- Put together a man page. For now see the README, or just ask here.

Re: Swifer: simple wifi connector tool with auto-connect features

Please, if it's not too late, consider changing the name. Using a completely generic name for something like this will cause immense frustration when searching for issues, even more so with a name that refers to something that is likely to be sought in conjunction with the application (cf. "maxima" for a computer algebra system that does calculus).

Re: Swifer: simple wifi connector tool with auto-connect features

Sounds interesting, I'll give it a shot!

About the name, Xyne is definitely right. How about "swinct" (simple wireless network connection tool)? Or "cnwt" (chuck norris wifi tool)? I'm just fooling around, but maybe I'll come up with a better idea, who knows

Re: Swifer: simple wifi connector tool with auto-connect features

EDIT: This post can now be ignored - this issue is solved.

If anyone more familiar with systemd than I am can point me in the right direction as to why the service file fails, I'd appreciate it.

I have a couple known networks set up, so if I run `wifi auto` wifi connects to a known network and launches dhcpcd and I am connected. If the same command is executed from a service file it did not seem to do anything. By some exploring I found that it did, in fact, execute just as it should, but the dhcpcd process was killed after wifi finished.

There is some difference in how systemd executes commands in a service file and how they are run from the command line. So I even tried a service file with an exec line of "/bin/bash -c 'wifi auto'" and it failed in the same way: it ran, but dhcpcd was killed afterwards.

Re: Swifer: simple wifi connector tool with auto-connect features

I tried the different types, and the remain after is only for systemd's record keeping. But I think I have a solution. I was using simple "system(...)" calls in the code instead of forking, and using execvp. I'm testing the new set up now.

These changes seemed to do it. Though it could be the service file to as "Type=forking" is not the same as "Type=Forking" ... what's the forking difference!

Re: Swifer: simple wifi connector tool with auto-connect features

Last week I was contacted about a problem in swifer. Aparently I forgot to implement part of the configurable dhcpcd/dhclient option. Swifer would read the config, but then (try to) launch dhcpcd regardless of the setting.

This was quickly fixed on git and should be working now. But all my replies to that email have been returned as undeliverable even after I looked up that users website, double checked the email address, and tried again.

So, please report all bugs and or requests here or in the AUR comments. This way we will have a functioning line of communication, I wont have to hunt for email addresses, and everyone can benefit from any progress made.

Re: Swifer: simple wifi connector tool with auto-connect features

Yup. I wasn't going to name names. I got your email and replied that day and it bounced back immediately as undeliverable. So I came here, and got your email link, and that looked like it went through ... but several days later I got the undeliverable notice.

I am interested if this works as intended with dhclient as I have not tested it myself, so do keep me posted.

Re: Swifer: simple wifi connector tool with auto-connect features

I just did a git clone and ran make && sudo make install clean. I enabled swifer.service via systemctl. I then rebooted. swifer did not connect to my network. It used to at least get the name of the right network, and I would then manually use dhclient to actually connect to the network, but this no longer seems to work.

Re: Swifer: simple wifi connector tool with auto-connect features

Interesting. Running swifer manually has no effect at all. This makes me think I'm about to have egg on my face because I am missing something horribly obvious, but I can't think of what it is.

None of 'swifer auto', 'swifer any', 'swifer autoconnect' or 'swifer verbose' produce much in the way of output and nothing in the way of results. 'any' and 'verbose' ask me to choose a network from the ncurses menu, but they don't seem to be doing anything at all to connect to networks; 'ip addr' shows no ip address, and conky doesn't show either the network name or an ip address. 'ping google.ca' of course outputs 'ping: unknown host google.ca'.

Re: Swifer: simple wifi connector tool with auto-connect features

As is, no it probably doesn't. I have virtually no experience with WEP so I wouldn't know where to start. But if you make it easy for me by outlining the steps you would take to manually connect to WEP networks, I'd be happy to implement options for those steps in swifer.

Re: Swifer: simple wifi connector tool with auto-connect features

Trilby wrote:

As is, no it probably doesn't. I have virtually no experience with WEP so I wouldn't know where to start. But if you make it easy for me by outlining the steps you would take to manually connect to WEP networks, I'd be happy to implement options for those steps in swifer.

Re: Swifer: simple wifi connector tool with auto-connect features

I'm not really sure what to make of that example - how was it generated, where do those values come from? The only documentation I can find for WEP are lines that say not to use it. I'm sure I could search harder, but I don't have any need for it myself.

Again, I would be happy to build it in to swifer, but I'd need the actual steps one would take to connect manually. Using wpa_supplicant with an existing configuration entry such as that one would only be the last step. Swifier will already do that step quite well: just use `swifer add` then select the network, then manually edit the network config file for that network in /usr/share/swifer/. From then on swifer would connect properly.

But to automate the generation of such a config file I'd need to know how it should be generated.

Re: Swifer: simple wifi connector tool with auto-connect features

I'm not sure if I have ncurses issues or what, but the text is invisible when I run 'swifer any'. I've tried this with both a ssh terminal from another Linux host (Fedora) and an ssh terminal from Putty (Windows). I can do a copy/paste and pull the text into a text editor and it is there, but I see nothing on the ssh window.

For the record, I compiled and am running this on a pogoplug (ARM) and had no indication that there was a problem during the compile. Obviously I have no organic video available so the only way I can see anything is via ssh. I use other tools like lynx all the time over ssh and they all appear to display fine.

Re: Swifer: simple wifi connector tool with auto-connect features

Interesting. I went in again just now to do a copy/paste and it pulls up the list of access points in glorious color. Everything appears to be working fine now. I'm trying to remember if I did a reboot after I installed it last time....

Anyway, 'swifer' and 'swifer any' appear to do the same thing: pulls up a list of access points with the percentages next to them. 'swifer auto' returns: [swifer] no suitable networks found. This is what I'd expect as I have saved no SSID/password pairs.

CTRL-C does not appear to work. The only way I can bail out is to select one of the APs and then hit CTRL-C when it asks for the password.

Re: Swifer: simple wifi connector tool with auto-connect features

Question - is the 'reconnect' mode working yet? I noticed that in the service file the 'reconnect' lines are all commented out. That's the one thing netcfg never was able to do...automatically reconnect to a different network when I put the laptop to sleep then wake it up in a different location.

Re: Swifer: simple wifi connector tool with auto-connect features

No. Not quite. (edit: not in a way that has been tested).

All that's missing is an efficent way of checking whether the connection is still good. I could do a popen("ping ...") and read the results - but this would just be ugly. I've meant to look into a way of doing this - if anyone knows, let me know.

I can have it trigger a reconnect based on signal strength pretty easily. But signal strength and connectivity are not the same. One could have a strong signal from the router, but the router's network connection could be down.

EDIT: I just grabbed a bit of code from one of my other projects that should do the job well. I just pushed the changes to git - but be warned, until I wander around with my netbook, I can't make any promises that this will work - nor can I promise it will not break in really ugly ways.

Reconnect only works in auto modes - it doesn't make much sense to reconnect in manual modes ... it'd have to open a terminal, display the menu, etc. That will never happen.

Re: Swifer: simple wifi connector tool with auto-connect features

I'm at home with a wired connection - so I can't do any of my own testing until tomorrow - but if you wish to do some testing, I'd suggest taking the service out of the equation - first see if swifer will reconnect.

Just do "swifer auto reconnect" from a terminal (as root or w/ sudo). Then see if there is a swifer process after it is connected. If there is turn off one of the networks and see if it switches.

As is, the problem could be service-file related, suspend-resume related, or process forking related. My first goal would be to pinpoint which of the three is the problem.

EDIT: one likely issue is that swifer may currently exit if there are no suitable networks found during a rescan. To check whether this is the issue, you could look in the stderr output. Does stderr from service-file-launched programs go to journalctl?

EDIT: as an only partly related aside "reconnect auto" is no longer needed, the reconnect keyword implies auto, as it makes no sense to have a manual reconnect mode.

EDIT: I just pushed a change that fixed a foolish mistake in the execvp call. I'd be surprised if this was the only problem preventing reconnect from currently working, but it was certainly one of them. As a bonus (mistake in hindsight) I replaced two system() calls with execvp - I feel much better not opening a root shell just to stop current dhcp or wpa_supplicant processes.