WiFi GUI management tool

来源:互联网 发布:彼得潘大叔 知乎 编辑:程序博客网 时间:2024/06/06 21:42

In my new embedded device,I use wpa_supplicant as the wifi backend management daemon.So,

for user's convenience use,I need to write a GUI configuration tool. I don't want to know more

about the wpa commands. I have a good idea,I dump the WiFi's ssid and password to a config file,

and restart the wpa_supplicant daemon,to let it autoconnect at startup time.To better control,I should

kill the old wpa_supplicant daemon. The wpa_supplicant supplies some useful command arguments

-B

-c

-i

-P pid file

I start the daemon use the following arguments:

wpa_supplicant -i wlan0 -B -c /etc/wpa_supplicant.conf -P /var/run/wpa_supplicant.pid

The config file contains the following parts:

ctrl_interface=/var/run/wpa_supplicant

network={

           ssid="zhangshaoyan"

           psk="yantai"

}

When the user operates in the GUI,then kill the previous daemon with this command:

cat /var/run/wpa_supplicant | kill -9.


yantai:/home/shell.albert/tools # wpa_supplicant

Successfully initialized wpa_supplicant
wpa_supplicant v2.2
Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/)

usage:
  wpa_supplicant [-BddhKLqqtuvW] [-P<pid file>] [-g<global ctrl>] \
        [-G<group>] \
        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
        [-b<br_ifname>] [-e<entropy file>] [-f<debug file>] \
        [-o<override driver>] [-O<override ctrl>] \
        [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
        [-m<P2P Device config file>] \
        [-p<driver_param>] [-b<br_ifname>] [-I<config file>] ...]

drivers:
  nl80211 = Linux nl80211/cfg80211
  wext = Linux wireless extensions (generic)
  wired = Wired Ethernet driver
options:
  -b = optional bridge interface name
  -B = run daemon in the background
  -c = Configuration file
  -C = ctrl_interface parameter (only used if -c is not)
  -i = interface name
  -I = additional configuration file
  -d = increase debugging verbosity (-dd even more)
  -D = driver name (can be multiple drivers: nl80211,wext)
  -e = entropy file
  -f = log output to debug file instead of stdout
  -g = global ctrl_interface
  -G = global ctrl_interface group
  -K = include keys (passwords, etc.) in debug output
  -t = include timestamp in debug messages
  -h = show this help text
  -L = show license (BSD)
  -o = override driver parameter for new interfaces
  -O = override ctrl_interface parameter for new interfaces
  -p = driver parameters
  -P = PID file
  -q = decrease debugging verbosity (-qq even less)
  -u = enable DBus control interface
  -v = show version
  -W = wait for a control interface monitor before starting
  -m = Configuration file for the P2P Device interface
  -N = start describing new interface
example:
  wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf
yantai:/home/shell.albert/tools #



必须要跟上-B参数放到后台运行,才会生成PID文件。

yantai:/home/shell.albert # wpa_supplicant  -i wlp5s0 -c /etc/wpa_supplicant/wpa_supplicant.conf -P /home/shell.albert/wpa.pid -B
Successfully initialized wpa_supplicant
yantai:/home/shell.albert # 

yantai:/home/shell.albert # ls -l *.pid
-rw-r--r-- 1 root root 6 May 26 15:03 wpa.pid
yantai:/home/shell.albert # cat wpa.pid
11727
yantai:/home/shell.albert # ps aux | grep wpa
root       948  0.0  0.0  30836  3772 ?        Ss   08:37   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root     11727  0.0  0.0  31048  2016 ?        Ss   15:03   0:00 wpa_supplicant -i wlp5s0 -c /etc/wpa_supplicant/wpa_supplicant.conf -P /home/shell.albert/wpa.pid -B
root     11743  0.0  0.0  10524  1528 pts/4    S+   15:04   0:00 grep --color=auto wpa
yantai:/home/shell.albert # kill 11727
yantai:/home/shell.albert # ps aux | grep wpa
root       948  0.0  0.0  30836  3772 ?        Ss   08:37   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root     11750  0.0  0.0  10524  1624 pts/4    S+   15:04   0:00 grep --color=auto wpa
yantai:/home/shell.albert #

yantai:/home/shell.albert # kill `cat wpa.pid`
yantai:/home/shell.albert # ps aux | grep wpa
root       948  0.0  0.0  30836  3772 ?        Ss   08:37   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root     11807  0.0  0.0  10524  1624 pts/4    S+   15:06   0:00 grep --color=auto wpa
yantai:/home/shell.albert #





0 0