]> git.ipfire.org Git - people/ms/network.git/blob - functions.wireless
wireless: Enhance hook to handle encrypted connections.
[people/ms/network.git] / functions.wireless
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 wireless_create() {
23 local device=${1}
24 assert isset device
25 shift
26
27 local address
28 local phy
29 local type="managed"
30
31 while [ $# -gt 0 ]; do
32 case "${1}" in
33 --address=*)
34 address=$(cli_get_val ${1})
35 ;;
36 --phy=*)
37 phy=$(cli_get_val ${1})
38 phy=$(phy_get ${phy})
39 ;;
40 --type=*)
41 type=$(cli_get_val ${1})
42
43 # ap --> __ap
44 [ "${type}" = "ap" ] && type="__ap"
45 ;;
46 *)
47 error "Unrecognized argument: ${1}"
48 return ${EXIT_ERROR}
49 ;;
50 esac
51 shift
52 done
53
54 assert isoneof type managed __ap
55 assert phy_exists ${phy}
56 isset address || address=$(mac_generate)
57
58 cmd_quiet iw phy ${phy} interface add ${device} type ${type}
59 local ret=$?
60
61 if [ ${ret} -eq ${EXIT_OK} ]; then
62 log DEBUG "created wireless device '${device}' (${type})"
63
64 if isset address; then
65 device_set_address ${device} ${address}
66 fi
67 else
68 log ERROR "could not create wireless device '${device}' (${type}): ${ret}"
69 fi
70
71 return ${ret}
72 }
73
74 function wireless_remove() {
75 local device=${1}
76 assert isset device
77
78 if ! device_exists ${device}; then
79 return ${EXIT_OK}
80 fi
81
82 # Tear down the device (if necessary).
83 device_set_down ${device}
84
85 # Remove it.
86 cmd_quiet iw dev ${device} del
87 local ret=$?
88
89 if [ ${ret} -eq ${EXIT_OK} ]; then
90 log DEBUG "removed wireless device '${device}'"
91 else
92 log ERROR "could not remove wireless device '${device}': ${ret}"
93 fi
94
95 return ${ret}
96 }
97
98 function wireless_set_channel() {
99 local device=${1}
100 assert isset device
101
102 local channel=${2}
103 assert isset channel
104
105 device_exists ${device} || return ${EXIT_ERROR}
106
107 cmd_quiet iw dev ${device} set channel ${channel}
108 }