Re: wifind(8) find your wifi

2016-06-05 Thread Alexander Hall
On June 4, 2016 11:11:13 AM GMT+02:00, Benjamin Baier  
wrote:
>On Fri, 3 Jun 2016 00:26:12 +0800
>Ray Lai  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  }
> 
>
>[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



Re: wifind(8) find your wifi

2016-06-04 Thread Craig Skinner
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.



Re: wifind(8) find your wifi

2016-06-04 Thread Benjamin Baier
On Fri, 3 Jun 2016 00:26:12 +0800
Ray Lai  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 

Re: wifind(8) find your wifi

2016-06-03 Thread Stefan Sperling
On Sat, Jun 04, 2016 at 02:38:06AM +0800, Ray Lai wrote:
> On Fri, 3 Jun 2016 15:52:34 +0200
> Stefan Sperling  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.



Re: wifind(8) find your wifi

2016-06-03 Thread Ray Lai
> On Jun 3, 2016, at 8:42 PM, Erling Westenvik 
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



Re: wifind(8) find your wifi

2016-06-03 Thread Ray Lai
On Fri, 3 Jun 2016 10:33:47 +0100
skin...@britvault.co.uk (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



Re: wifind(8) find your wifi

2016-06-03 Thread Ray Lai
On Fri, 3 Jun 2016 15:52:34 +0200
Stefan Sperling  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?



Re: wifind(8) find your wifi

2016-06-03 Thread Ray Lai
> On Jun 3, 2016, at 8:59 PM, 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

Check apmd(8)



Re: wifind(8) find your wifi

2016-06-03 Thread Etienne

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.



Re: wifind(8) find your wifi

2016-06-03 Thread Stefan Sperling
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.



Re: wifind(8) find your wifi

2016-06-03 Thread Raf Czlonka
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



Re: wifind(8) find your wifi

2016-06-03 Thread Kamil Cholewiński
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.



Re: wifind(8) find your wifi

2016-06-03 Thread Etienne

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



Re: wifind(8) find your wifi

2016-06-03 Thread Erling Westenvik
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  wrote:
> >> On Thu, 02 Jun 2016, Ray Lai  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



Re: wifind(8) find your wifi

2016-06-03 Thread Craig Skinner
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



Re: wifind(8) find your wifi

2016-06-02 Thread Ray Lai
> On Jun 3, 2016, at 6:17 AM, Gleydson Soares  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



Re: wifind(8) find your wifi

2016-06-02 Thread Ray Lai
> On Jun 3, 2016, at 2:36 AM, Kamil Cholewiński  wrote:
>> On Thu, 02 Jun 2016, Ray Lai  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



Re: wifind(8) find your wifi

2016-06-02 Thread Kamil Cholewiński
On Thu, 02 Jun 2016, Ray Lai  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.