wifind(8) find your wifi

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

wifind(8) find your wifi

Ray Lai-3
Hi all,

I got tired of configuring my wifi every time I had to move my laptop.
Here's a script a whipped up. It scans the wifi for known networks and
writes the strongest one to /etc/hostname.if. Then it runs netstart.
Easy to use, simple config file, no arguments needed, perfect
for /etc/apm/resume.

Oh, and it uses pledge for good measure.

I hope this is helpful!

Ray



wifind(8)                   System Manager's Manual
wifind(8)

NAME
     wifind – connect to known wifi networks

SYNOPSIS
     wifind

DESCRIPTION
     The wifind utility scans for the strongest recognized wifi networks,
     writes an appropriate hostname.if(5) file, and starts the network with
     /etc/netstart(8).

FILES
     /etc/wifind.conf

EXIT STATUS
     Exits 0 on success, 1 if no network found.

EXAMPLES
     Add the following line to your /etc/apm/resume:

     wifind

SEE ALSO
     hostname.if(5)

HISTORY
     I got really tired of editing hostname.if(5) every time I moved my
     laptop.

AUTHORS
     Ray Lai <[hidden email]>

CAVEATS
     Please avoid nwid or wpakey with quotes, dollar signs, or backslashes.

     I'm sorry if you dislike Perl, but it comes stock with OpenBSD.

OpenBSD 6.0                      June 3, 2016                      OpenBSD
6.0

======
wifind
======
#!/usr/bin/env perl
# Written by Ray Lai <[hidden email]>.
# Public domain.

use JSON::PP;
use OpenBSD::Pledge;
use strict;
use warnings;

my $ifconfig = '/sbin/ifconfig';
my $tmp = "/etc/wifind.tmp";
my $head = "lladdr random\n" .
    "-chan -bssid -wpakey\n";
my $tail = "dhcp\n";

sub slurp
{
        my $file = shift;
        open F, '<', $file or die "Can't read $file: $!";
        local $/; # enable slurp mode, locally.
        my $data = <F>;
        close F;
        $data;
}

sub write_hostname_if
{
        my ($if, $ap) = @_;
        my $hostname_if = "/etc/hostname.$if";

        umask 077;
        open TMP, '>', $tmp or die "Unable to open $tmp: $!";

        print TMP $head;
        # set nwid, bssid, chan
        printf TMP 'nwid "%s"', $ap->{nwid};
        printf TMP ' bssid "%s"', $ap->{bssid} if $ap->{bssid};
        printf TMP ' chan "%s"', $ap->{chan} if $ap->{chan};
        print TMP "\n";
        # wpa needs to be set after nwid
        printf TMP "wpakey \"%s\"\n", $ap->{wpakey} if $ap->{wpakey};
        print TMP $tail;
        close TMP;

        rename $hostname_if, "$hostname_if.orig" or die "rename failed: $!";
        rename $tmp, $hostname_if or die "rename failed: $!";

        print STDERR "found $ap->{nwid}, wrote $hostname_if\n";
}

# we only need rpath to read config file
pledge(qw( rpath wpath cpath proc exec )) || die "Unable to pledge: $!";

my $conf = decode_json(slurp '/etc/wifind.conf');
my $wlan = $conf->{wlan};
my $if = $conf->{if};

# initial scan
open L, '-|', $ifconfig, $if, 'scan' or die "Can't open pipe: $!";

pledge(qw( rpath wpath cpath exec )) || die "Unable to pledge: $!";
for (<L>) {
        if (/^\s+nwid (.+) chan (\d+) bssid ([0-9a-f:]+) (-\d+)dBm ([\w-]+)
([\w,-]+)\s*$/) {
                my ($nwid, $chan, $bssid, $dbm, $mystery, $csv) =
                    ($1, $2, $3, $4, $5, $6);
                my %cap = map { $_ => 1 } split(/,/, $csv);

                # remove quotes from nwid, if any
                $nwid =~ s/^"(.*)"$/$1/;

                # reject hostile characters
                if ($nwid =~ /["\\\$]/) {
                        print STDERR "malformed nwid: $nwid\n";
                        next;
                }
                # check for recognized access points
                # i assume we will match the strongest signal first
                for my $ap (@$wlan) {
                        next if $ap->{nwid} ne $nwid ||
                            ($ap->{bssid} && $ap->{bssid} ne $bssid) ||
                            ($ap->{chan} && $ap->{chan} ne $chan) ||
                            ($ap->{wpakey} && !$cap{wpa2});

                        # reject hostile characters
                        if ($ap->{wpakey} =~ /["\\\$]/) {
                                print STDERR "malformed wpakey\n";
                                next;
                        }

                        write_hostname_if $if, $ap;
                        exec '/bin/sh', '/etc/netstart', $if
                            or die "exec failed: $!";
                }
        }
}

print STDERR "no network found\n";
exit 1;


=============
wifind.conf.5
=============
.\" $OpenBSD$
.\"
.\" Written by Ray Lai <[hidden email]>.
.\" Public domain.
.\"
.Dd $Mdocdate$
.Dt WIFIND.CONF 5
.Os
.Sh NAME
.Nm wifind.conf
.Nd wifind configuration file
.Sh SYNOPSIS
.Nm /etc/wifind.conf
.Sh DESCRIPTION
The
.Nm
file contains details of wifi networks to connect to
(for example, nwid, bssid, chan, wpakey).
It also specifies the interface with which to scan and connect.
.Sh EXAMPLES
.Bd -literal -offset indent
{
   "if" : "iwn0",
   "wlan" : [
      {
         "nwid" : "openwireless.org"
      },
      {
         "nwid" : "Corporate Network",
         "bssid" : "f8:03:0d:72:9e:f0",
         "chan" : "1",
         "wpakey" : "j839fzjieJrRjf"
      }
   ]
}
.Ed
.Sh SEE ALSO
.Xr wifind 8
.Sh HISTORY
Ray was really tired of editing
.Xr hostname.if 5
and running
.Xr netstart 8
every time he resumed my laptop.
.Sh AUTHORS
Ray Lai <[hidden email]> wrote
.Xr wifind 8 ,
but he did not invent JSON.
.Sh CAVEATS
Please avoid nwid or wpakey with quotes, dollar signs, or backslashes.
.Pp
I'm sorry if you dislike JSON, but it comes stock with Perl.



========
wifind.8
========
.\" $OpenBSD$
.\"
.\" Written by Ray Lai <[hidden email]>.
.\" Public domain.
.\"
.Dd $Mdocdate$
.Dt wifind 8
.Os
.Sh NAME
.Nm wifind
.Nd connect to known wifi networks
.Sh SYNOPSIS
.Nm wifind
.Sh DESCRIPTION
The
.Nm
utility scans for the strongest recognized wifi networks,
writes an appropriate
.Xr hostname.if 5
file,
and starts the network with
.Xr /etc/netstart 8 .
.Sh FILES
.Pa /etc/wifind.conf
.Sh EXIT STATUS
Exits 0 on success, 1 if no network found.
.Sh EXAMPLES
Add the following line to your /etc/apm/resume:
.Pp
wifind
.Sh SEE ALSO
.Xr hostname.if 5
.Sh HISTORY
I got really tired of editing
.Xr hostname.if 5
every time I moved my laptop.
.Sh AUTHORS
Ray Lai <[hidden email]>
.Sh CAVEATS
Please avoid nwid or wpakey with quotes, dollar signs, or backslashes.
.Pp
I'm sorry if you dislike Perl, but it comes stock with
.Ox .

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Kamil Cholewiński
On Thu, 02 Jun 2016, Ray Lai <[hidden email]> wrote:
> use JSON::PP;

That's just my personal opinion, but JSON sucks for configuration files.
It's more of a human-readable data interchange format.

It feels like the same functionality can be achieved with something much
simpler, getent or CSV style.

> my $tmp = "/etc/wifind.tmp";

mkstemp?

> Please avoid nwid or wpakey with quotes, dollar signs, or backslashes.

Without knowing or assuming much about how WiFi works, why would this be
a concern in a well-designed program?

<3,K.

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Ray Lai-3
> On Jun 3, 2016, at 2:36 AM, Kamil Cholewiński <[hidden email]> wrote:
>> On Thu, 02 Jun 2016, Ray Lai <[hidden email]> wrote:
>> use JSON::PP;
>
> That's just my personal opinion, but JSON sucks for configuration files.
> It's more of a human-readable data interchange format.
>
> It feels like the same functionality can be achieved with something much
> simpler, getent or CSV style.

I agree. All I need are hashes and arrays. Any examples would be welcome, I'm
open to changing the file format. But as wifind.conf(5) says, I chose json
because it's included in Perl. I was more concerned with having a
set-it-and-forget-it solution. The config file is a minor detail that can be
changed.
>
>> my $tmp = "/etc/wifind.tmp";
>
> mkstemp?

Will fix

>> Please avoid nwid or wpakey with quotes, dollar signs, or backslashes.
>
> Without knowing or assuming much about how WiFi works, why would this be
> a concern in a well-designed program?

Currently wifind parses 'ifconfig if scan' output, which, according to my
reading of the code, simply adds "double quotes" around any nwid with white
space when printing. (I've not tested my theory that nwid with " in the name
would cause problem. )

Likewise, netstart takes nwid and wpakey, which could include spaces, but as
netstart is a shell script, I have not tested what happens when the values
contain backslashes, dollar signs, or double quotes. Caveat emptor!


Thanks for your feedback, I appreciate it!

Ray

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Ray Lai-3
In reply to this post by Ray Lai-3
> On Jun 3, 2016, at 6:17 AM, Gleydson Soares <[hidden email]> wrote:
>
> I usually just use a small script that lives in ~/bin
>
> cat ~/bin/wifi
>
> #!/bin/sh
>
> if [[ $1 == "home" ]]; then
>    doas ifconfig run0 nwid foonet wpa wpakey ultrasecret
>    doas dhclient run0
> fi

Yup. The goal of wifind is to do exactly this, the moment I resume my laptop,
without my interaction.

Ray

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Craig Skinner-3
In reply to this post by Ray Lai-3
Hi Ray,

On 2016-06-03 Fri 00:26 AM |, Ray Lai wrote:
>
> I got tired of configuring my wifi every time I had to move my laptop.
> Here's a script a whipped up.

port it up: http://www.OpenBSD.Org/faq/ports/guide.html

Cheers!
--
I know not with what weapons World War III will be fought,
but World War IV will be fought with sticks and stones.
                -- Albert Einstein

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Erling Westenvik-2
In reply to this post by Ray Lai-3
As much as I endorse and approve of any effort to create a good solution
for handling wifi's, I must say I find the use of perl and json
unnecessary for such a project. I've been using a "pure ksh" solution
named wiconfig since 2013 and which was posted here at @misc back in
2011 or 2012:

http://openbsd-archive.7691.n7.nabble.com/wiconfig-simplifies-the-configuration-of-wireless-interfaces-td89829.html

It is available on github:

https://github.com/devious/wiconfig/blob/master/wiconfig

wiconfig:
- Works great with apm/resume, including trunk(4) interfaces.
- Has no dependencies. Just pure old fashioned ksh.
- Stores (accepted) connections in plain text format. (/etc/wiconfig.db)
- Handles quoted nwids.
- Does not require writing to /etc/hostname.if-files.

Not sure how/if it handles potentially unsafe nwid names, though.

Regards.

--
Erling Westenvik
,_____,
|_|_|_|
|_|X|_|
|_|_|_|

On Fri, Jun 03, 2016 at 11:58:05AM +0800, Ray Lai wrote:

> > On Jun 3, 2016, at 2:36 AM, Kamil Cholewiński <[hidden email]> wrote:
> >> On Thu, 02 Jun 2016, Ray Lai <[hidden email]> wrote:
> >> use JSON::PP;
> >
> > That's just my personal opinion, but JSON sucks for configuration files.
> > It's more of a human-readable data interchange format.
> >
> > It feels like the same functionality can be achieved with something much
> > simpler, getent or CSV style.
>
> I agree. All I need are hashes and arrays. Any examples would be welcome, I'm
> open to changing the file format. But as wifind.conf(5) says, I chose json
> because it's included in Perl. I was more concerned with having a
> set-it-and-forget-it solution. The config file is a minor detail that can be
> changed.
> >
> >> my $tmp = "/etc/wifind.tmp";
> >
> > mkstemp?
>
> Will fix
>
> >> Please avoid nwid or wpakey with quotes, dollar signs, or backslashes.
> >
> > Without knowing or assuming much about how WiFi works, why would this be
> > a concern in a well-designed program?
>
> Currently wifind parses 'ifconfig if scan' output, which, according to my
> reading of the code, simply adds "double quotes" around any nwid with white
> space when printing. (I've not tested my theory that nwid with " in the name
> would cause problem. )
>
> Likewise, netstart takes nwid and wpakey, which could include spaces, but as
> netstart is a shell script, I have not tested what happens when the values
> contain backslashes, dollar signs, or double quotes. Caveat emptor!
>
>
> Thanks for your feedback, I appreciate it!
>
> Ray

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Etienne
In reply to this post by Ray Lai-3
On 06/03/16 05:12, Ray Lai wrote:

>>
>> #!/bin/sh
>>
>> if [[ $1 == "home" ]]; then
>>     doas ifconfig run0 nwid foonet wpa wpakey ultrasecret
>>     doas dhclient run0
>> fi
> Yup. The goal of wifind is to do exactly this, the moment I resume my laptop,
> without my interaction.
>
May I know what's triggering it? I have something similar, but I need to
click on a button to run it.

Cheers,

--
Étienne

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Kamil Cholewiński
In reply to this post by Erling Westenvik-2
Perhaps it's time that the best tool be chosen and made a part of the
base install? I've already seen like a 100 different OBSD WiFi scripts
floating around the 'net, and naturally I also have a DIY one.

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Raf Czlonka-2
In reply to this post by Etienne
On Fri, Jun 03, 2016 at 01:59:08PM BST, Etienne wrote:

> On 06/03/16 05:12, Ray Lai wrote:
> > >
> > > #!/bin/sh
> > >
> > > if [[ $1 == "home" ]]; then
> > >     doas ifconfig run0 nwid foonet wpa wpakey ultrasecret
> > >     doas dhclient run0
> > > fi
> > Yup. The goal of wifind is to do exactly this, the moment I resume my laptop,
> > without my interaction.
> >
> May I know what's triggering it? I have something similar, but I need to
> click on a button to run it.

/etc/apm/resume I presume :^)

man 8 apmd

Regards,

Raf

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Stefan Sperling-5
In reply to this post by Kamil Cholewiński
On Fri, Jun 03, 2016 at 03:22:19PM +0200, Kamil Cholewiński wrote:
> Perhaps it's time that the best tool be chosen and made a part of the
> base install? I've already seen like a 100 different OBSD WiFi scripts
> floating around the 'net, and naturally I also have a DIY one.

No scripts for this, please.

We need a well engineered to make the kernel handle this, perhaps with some
help from userland. Various ideas have been porposed (not always on list,
but mostly during face-to-face discussions at hackathons).

What we need is someone who wants to sit down and drive the project home,
i.e. wrap up the design discussion within the community and write the code.
I'm up for helping people through this, but it really needs someone else
dedicated to take responsibility for this project and the implementation.

One thing we should probably fix first is roaming support in the kernel.

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Etienne
In reply to this post by Raf Czlonka-2
On 06/03/16 14:31, Raf Czlonka wrote:
>
>> May I know what's triggering it? I have something similar, but I need to
>> click on a button to run it.
> /etc/apm/resume I presume :^)
>
> man 8 apmd
>
Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Ray Lai-3
In reply to this post by Etienne
> On Jun 3, 2016, at 8:59 PM, Etienne <[hidden email]> wrote:
> On 06/03/16 05:12, Ray Lai wrote:
>>>
>>> #!/bin/sh
>>>
>>> if [[ $1 == "home" ]]; then
>>>    doas ifconfig run0 nwid foonet wpa wpakey ultrasecret
>>>    doas dhclient run0
>>> fi
>> Yup. The goal of wifind is to do exactly this, the moment I resume my
laptop,
>> without my interaction.
> May I know what's triggering it? I have something similar, but I need to
click on a button to run it.

/etc/apm/resume

Check apmd(8)

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Ray Lai-3
In reply to this post by Craig Skinner-3
On Fri, 3 Jun 2016 10:33:47 +0100
[hidden email] (Craig Skinner) wrote:

> Hi Ray,
>
> On 2016-06-03 Fri 00:26 AM |, Ray Lai wrote:
> >
> > I got tired of configuring my wifi every time I had to move my laptop.
> > Here's a script a whipped up.  
>
> port it up: http://www.OpenBSD.Org/faq/ports/guide.html
>
> Cheers!

Done: http://permalink.gmane.org/gmane.os.openbsd.ports/80223

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Ray Lai-3
In reply to this post by Stefan Sperling-5
On Fri, 3 Jun 2016 15:52:34 +0200
Stefan Sperling <[hidden email]> wrote:

> On Fri, Jun 03, 2016 at 03:22:19PM +0200, Kamil Cholewiński wrote:
> > Perhaps it's time that the best tool be chosen and made a part of the
> > base install? I've already seen like a 100 different OBSD WiFi scripts
> > floating around the 'net, and naturally I also have a DIY one.
>
> No scripts for this, please.
>
> We need a well engineered to make the kernel handle this, perhaps with some
> help from userland. Various ideas have been porposed (not always on list,
> but mostly during face-to-face discussions at hackathons).
>
> What we need is someone who wants to sit down and drive the project home,
> i.e. wrap up the design discussion within the community and write the code.
> I'm up for helping people through this, but it really needs someone else
> dedicated to take responsibility for this project and the implementation.
>
> One thing we should probably fix first is roaming support in the kernel.

Do you mean 802.11r support?

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Stefan Sperling-5
On Sat, Jun 04, 2016 at 02:38:06AM +0800, Ray Lai wrote:
> On Fri, 3 Jun 2016 15:52:34 +0200
> Stefan Sperling <[hidden email]> wrote:
> > One thing we should probably fix first is roaming support in the kernel.
>
> Do you mean 802.11r support?

No, that extension seems to be about moving fast across a huge range.
It addresses a special case of roaming.

AFAIK the standard doesn't specify how roaming should be done in general.

I mean just something like watching for beacon signal strength, counting
missed beacons, or whatever heuristic is possible with the given hardware,
and then retriggering a scan when the AP can be considered "gone" or a
"better" AP is available.
And get this working with as many drivers as possible.

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Ray Lai-3
In reply to this post by Erling Westenvik-2
> On Jun 3, 2016, at 8:42 PM, Erling Westenvik <[hidden email]>
wrote:
> As much as I endorse and approve of any effort to create a good solution
> for handling wifi's, I must say I find the use of perl and json
> unnecessary for such a project. I've been using a "pure ksh" solution
> named wiconfig since 2013 and which was posted here at @misc back in
> 2011 or 2012:

I've checked out wiconfig prior to wifind, but I couldn't figure out how to
use it, and couldn't figure it out from the 500-line shell script.

This script, for now, merely parses a config file and ifconfig scan output and
writes a new hostname.if. I understand it.

>
http://openbsd-archive.7691.n7.nabble.com/wiconfig-simplifies-the-configurati
on-of-wireless-interfaces-td89829.html
>
> It is available on github:
>
> https://github.com/devious/wiconfig/blob/master/wiconfig
>
> wiconfig:
> - Works great with apm/resume, including trunk(4) interfaces.
> - Has no dependencies. Just pure old fashioned ksh.

This is a nice benefit, as it can be run even when upgrading, theoretically.

> - Stores (accepted) connections in plain text format. (/etc/wiconfig.db)

I couldn't figure this out from the documentation and code, unfortunately.

> - Handles quoted nwids.

Does it handle nwids with quotes within, eg "network "name""?

> - Does not require writing to /etc/hostname.if-files.

The reason I chose to write hostname.if files is upgrades. I don't expect this
program to be functional during upgrades, nor any other non-base solution. So
the simplest solution was to save the latest best-known network configuration
so that the network would have a decent chance of being usable during
upgrades.

Cheers,
Ray

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Benjamin Baier
In reply to this post by Ray Lai-3
On Fri, 3 Jun 2016 00:26:12 +0800
Ray Lai <[hidden email]> wrote:

> Hi all,
>
> I got tired of configuring my wifi every time I had to move my laptop.
> Here's a script a whipped up. It scans the wifi for known networks and
> writes the strongest one to /etc/hostname.if. Then it runs netstart.
> Easy to use, simple config file, no arguments needed, perfect
> for /etc/apm/resume.
>
> Oh, and it uses pledge for good measure.
>
> I hope this is helpful!

Hi and thanks,
please let me share my modifications for wifi handling, too.

This patch to /etc/netstart [0] cycles through different configurations
in hostname.if [1] until the link status becomes "active".

It's not bulletproof nor as fast as it could be...

Greetings Ben


[0] diff -u /etc/netstart.orig /etc/netstart
--- /etc/netstart.orig  Fri Jun  3 23:09:40 2016
+++ /etc/netstart       Sat Jun  4 11:05:03 2016
@@ -40,6 +40,8 @@
        fi
        # Check for ifconfig'able interface.
        (ifconfig $if || ifconfig $if create) >/dev/null 2>&1 || return
+       # Check for wifi, so we can treat it special
+       [ "$(ifconfig $if | grep groups:.*wlan)" ] && wifi=yes
 
        # Now parse the hostname.* file.
        while :; do
@@ -66,6 +68,11 @@
                "!"*) # Parse commands.
                        cmd="${af#*!} ${name} ${mask} ${bcaddr} ${ext1} ${ext2}"
                        ;;
+               "TRYNEXT")
+                       [ "$wifi" ] && wifi=checkactive || continue
+                       [ "$name" = "NONE" ] && checkdelay="" || checkdelay="$name"
+                       cmd=
+                       ;;
                "dhcp")
                        [ "$name" = "NONE" ] && name=
                        [ "$mask" = "NONE" ] && mask=
@@ -127,6 +134,13 @@
                        ;;
                esac
                eval "$cmd"
+               if [ "X$wifi" = "Xcheckactive" ]
+               then
+                       # delay to let the status catch up
+                       [ "$checkdelay" ] && sleep $checkdelay || sleep 1
+                       [ "$(ifconfig $if | grep status:.*active)" ] && break
+                       wifi=retry
+               fi
        done </etc/hostname.$if
 }
 

[1] cat /etc/hostname.iwn0
nwid APhop1 nwkey 0x1234567890abcdefabcdef1234
inet 192.168.1.10 255.255.255.0
up

TRYNEXT 10

nwid APhop2 nwkey 0x1234567890abcdefabcdef1234
dhcp

TRYNEXT

nwid APhop3 nwkey 0x1234567890abcdefabcdef1234
dhcp

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Craig Skinner-3
In reply to this post by Erling Westenvik-2
Hello Erling,

On 2016-06-03 Fri 14:42 PM |, Erling Westenvik wrote:
>
> It is available on github:
>

Port it too, with your README or man page.

Packaged as /usr/local/sbin/wiconfig instead of /etc/wiconfig

# sh /etc/wiconfig iwi0

Becomes:

# wiconfig iwi0

... and /etc/apmd/resume is simpler too:
#!/bin/sh
wiconfig -qs iwi0


>
> wiconfig:
> - Works great with apm/resume, including trunk(4) interfaces.
> - Has no dependencies. Just pure old fashioned ksh.

Superb.

> - Stores (accepted) connections in plain text format. (/etc/wiconfig.db)

How about moving that to /var/db/ ? (Like the plain text dhcpd.leases)

When creating the db, you could do it with 1 command:
[[ -e $wiconfigdb ]] || install -b -m 640 /dev/null $wiconfigdb

This can be done in the port, so it never needs to be done at run time,
and you can remove createdb() as it is created at package install.

> - Handles quoted nwids.
> - Does not require writing to /etc/hostname.if-files.
>

Cool.
--
A beer delayed is a beer denied.

Reply | Threaded
Open this post in threaded view
|

Re: wifind(8) find your wifi

Alexander Hall
In reply to this post by Benjamin Baier
On June 4, 2016 11:11:13 AM GMT+02:00, Benjamin Baier <[hidden email]> wrote:

>On Fri, 3 Jun 2016 00:26:12 +0800
>Ray Lai <[hidden email]> wrote:
>
>> Hi all,
>>
>> I got tired of configuring my wifi every time I had to move my
>laptop.
>> Here's a script a whipped up. It scans the wifi for known networks
>and
>> writes the strongest one to /etc/hostname.if. Then it runs netstart.
>> Easy to use, simple config file, no arguments needed, perfect
>> for /etc/apm/resume.
>>
>> Oh, and it uses pledge for good measure.
>>
>> I hope this is helpful!
>
>Hi and thanks,
>please let me share my modifications for wifi handling, too.
>
>This patch to /etc/netstart [0] cycles through different configurations
>in hostname.if [1] until the link status becomes "active".

I don't like the syntax, and in general I'd like hostname.if over time become a list of arguments to pass on to ifconfig with no magic whatsoever attached, but I like the relative KISS approach of this.

Alternatively, one could pass sth like "linkless" or "nolink" (or probably something better), as a parameter to ifconfig, causing it to not process any further arguments if the interface already has link status active.

/Alexander

>
>It's not bulletproof nor as fast as it could be...
>
>Greetings Ben
>
>
>[0] diff -u /etc/netstart.orig /etc/netstart
>--- /etc/netstart.orig  Fri Jun  3 23:09:40 2016
>+++ /etc/netstart       Sat Jun  4 11:05:03 2016
>@@ -40,6 +40,8 @@
>        fi
>        # Check for ifconfig'able interface.
>        (ifconfig $if || ifconfig $if create) >/dev/null 2>&1 || return
>+       # Check for wifi, so we can treat it special
>+       [ "$(ifconfig $if | grep groups:.*wlan)" ] && wifi=yes
>
>        # Now parse the hostname.* file.
>        while :; do
>@@ -66,6 +68,11 @@
>                "!"*) # Parse commands.
>               cmd="${af#*!} ${name} ${mask} ${bcaddr} ${ext1} ${ext2}"
>                        ;;
>+               "TRYNEXT")
>+                       [ "$wifi" ] && wifi=checkactive || continue
>+                       [ "$name" = "NONE" ] && checkdelay="" ||
>checkdelay="$name"
>+                       cmd=
>+                       ;;
>                "dhcp")
>                        [ "$name" = "NONE" ] && name=
>                        [ "$mask" = "NONE" ] && mask=
>@@ -127,6 +134,13 @@
>                        ;;
>                esac
>                eval "$cmd"
>+               if [ "X$wifi" = "Xcheckactive" ]
>+               then
>+                       # delay to let the status catch up
>+                       [ "$checkdelay" ] && sleep $checkdelay || sleep
>1
>+                       [ "$(ifconfig $if | grep status:.*active)" ] &&
>break
>+                       wifi=retry
>+               fi
>        done </etc/hostname.$if
> }
>
>
>[1] cat /etc/hostname.iwn0
>nwid APhop1 nwkey 0x1234567890abcdefabcdef1234
>inet 192.168.1.10 255.255.255.0
>up
>
>TRYNEXT 10
>
>nwid APhop2 nwkey 0x1234567890abcdefabcdef1234
>dhcp
>
>TRYNEXT
>
>nwid APhop3 nwkey 0x1234567890abcdefabcdef1234
>dhcp