]> git.ipfire.org Git - people/stevee/network.git/blob - functions.wpa_supplicant
Move wpa_supplicant functions into their own file.
[people/stevee/network.git] / functions.wpa_supplicant
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 function wpa_supplicant_config_write() {
23 local device=${1}
24 shift
25
26 assert isset device
27
28 local ssid
29 local encryption
30 local key
31
32 while [ $# -gt 0 ]; do
33 case "${1}" in
34 --ssid=*)
35 ssid=${1#--ssid=}
36 ;;
37 --encryption=*)
38 encryption=${1#--encryption=}
39 ;;
40 --key=*)
41 key=${1#--key=}
42 ;;
43 esac
44 shift
45 done
46
47 assert isset ssid
48 assert isset encryption
49 assert isset key
50
51 cat <<EOF
52 # WPA supplicant configuration for ${device}.
53 # DO NOT EDIT.
54
55 network={
56 ssid="${ssid}"
57 proto=RSN
58 key_mgmt=${encryption}
59 pairwise=CCMP
60 group=TKIP
61 psk="${key}"
62 }
63
64 EOF
65 }
66
67 function wpa_supplicant_config_dir() {
68 local device=${1}
69
70 assert isset device
71
72 echo "${RUN_DIR}/wireless/${device}"
73 }
74
75 function wpa_supplicant_start() {
76 local device=${1}
77 shift
78
79 assert device_exists ${device}
80
81 local config_dir=$(wpa_supplicant_config_dir ${device})
82 mkdir -p ${config_dir}
83
84 local config_file=${config_dir}/config
85 wpa_supplicant_config_write ${device} $@ > ${config_file}
86
87 wpa_supplicant -i ${device} -D wext -B -c ${config_file} \
88 -P ${config_dir}/pid
89 }
90
91 function wpa_supplicant_stop() {
92 local device=${1}
93
94 assert isset device
95
96 local pid=$(wpa_supplicant_get_pid ${device})
97
98 if isset pid; then
99 process_kill ${pid}
100 else
101 warning_log "Could not find pid file for wpa_supplicant process running for ${device}."
102 fi
103
104 rm -rf $(wpa_supplicant_config_dir ${device})
105 }
106
107 function wpa_supplicant_get_pid() {
108 local device=${1}
109
110 assert isset device
111
112 local pid_file="$(wpa_supplicant_config_dir ${device})/pid"
113
114 [ -e "${pid_file}" ] || return ${EXIT_ERROR}
115
116 cat ${pid_file} 2>/dev/null
117 return ${EXIT_OK}
118 }
119
120 function wpa_supplicant_is_running() {
121 local device=${1}
122
123 assert isset device
124
125 local pid=$(wpa_supplicant_get_pid ${device})
126
127 if isset pid && [ -d "/proc/${pid}" ]; then
128 return ${EXIT_OK}
129 fi
130
131 return ${EXIT_ERROR}
132 }
133
134 function wpa_supplicant_get_pid() {
135 local zone=${1}
136 shift
137
138
139 }
140
141 function wpa_supplicant_stop() {
142 local zone=${1}
143 shift
144
145 killall wpa_supplicant
146 }