summaryrefslogtreecommitdiff
path: root/recipes-kernel/rs9113/files/rs9113/wpa_supplicant
blob: 6aa645641daa2d1d0b6e75af61e96d26ca852c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#! /bin/sh
# wpa_supplicant
# Example for /etc/init.d
# MTS 
#
PATH=/sbin:/bin:/usr/bin:/usr/sbin
PIDFILE=/var/run/wpa_suplicant
CONF=/etc/wpa_supplicant/psk5g.conf 
TIMELIMIT=60
DRIVERNAME=wifi0
upinterface() {
    ((loopcount=1))
    while ((loopcount < TIMELIMIT)) ; do
        if [[ $(iw dev ${DRIVERNAME} link) =~ "Connected to " ]] ; then
	    break;
	fi
	sleep 1
        ((loopcount++))
    done
    ((loopcount=1))
    while ((loopcount < TIMELIMIT)) ; do
        ldifs="$IFS"
        IFS=$'\n'
        result=($(ifup wifi0 2>&1))
        oldifs="$IFS"
	show=$(ip addr show)
	if [[ ${show} =~ [[:space:]]+inet[[:space:]]*[0-9].*[[:space:]]+global[[:space:]]+wifi0[[:space:]] ]] ; then
	    break
	fi
	ifdown wifi0
	sleep 1
        ((loopcount++))
    done
    for (( i=0; i < ${#result[@]}; i++ )); do 
	if [[ ${result[i]} =~ ^[[:space:]]*$ ]] ; then
	    continue;
	fi
        logger -t ifup -p daemon.info "${result[i]}"
    done
}

# ntpd	init.d script for ntpdc from ntp.isc.org
test -x /usr/sbin/wpa_supplicant -a -r $CONF || exit 0
if ! [[ -r $CONF ]] ; then
    logger -s -t wpa_supplicant -p daemon.err "Cannot find configuration file $CONF"
fi
test -r /etc/default/rcS && . /etc/default/rcS

# Functions to do individual actions
startdaemon(){
	echo -n "Starting wpa_supplicant: "
	/opt/rs9113/onebox_util rpine0 enable_protocol 1 
	/opt/rs9113/onebox_util rpine0 set_country 840
	/opt/rs9113/onebox_util rpine0 create_vap ${DRIVERNAME} sta sw_bmiss >/dev/null 2>&1
	start-stop-daemon --start -x wpa_supplicant -- -i ${DRIVERNAME} -D nl80211 -P $PIDFILE /var/run/ -B -c $CONF
}
stopdaemon(){
	echo -n "Stopping ntpd: "
	start-stop-daemon --stop -p $PIDFILE
	echo "done"
}

case "$1" in
  start)
	if ! [[ -f ${CONF} ]] ; then
		echo "Skipping.  Configuration file ${CONF} not found."
		exit 1
	fi
	startdaemon
	{ upinterface & }
	;;
  stop)
	ifdown ${DRIVERNAME} >/dev/null 2>&1
  	stopdaemon
	;;
  force-reload)
  	stopdaemon
	startdaemon
	;;
  restart)
  	# Don't reset the tick here
	stopdaemon
	startdaemon
	;;
  reload)
	stopdaemon
	startdaemon
	;;
  *)
	echo "Usage: wpa_supplicant { start | stop | restart | reload }" >&2
	exit 1
	;;
esac

exit 0