]> git.ipfire.org Git - people/stevee/network.git/blame - functions.wireless
firewall: Stop for unrecognized command line arguments.
[people/stevee/network.git] / functions.wireless
CommitLineData
d76f5107 1#!/bin/bash
1578dae9
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
0e035311 5# Copyright (C) 2012 IPFire Network Development Team #
1578dae9
MT
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###############################################################################
d76f5107 21
d76f5107
MT
22function wireless_create() {
23 local device=${1}
d76f5107 24 assert isset device
22a61046 25 shift
d76f5107 26
22a61046
MT
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
d76f5107 53
d76f5107 54 assert isoneof type managed __ap
22a61046
MT
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=$?
d76f5107 60
22a61046
MT
61 if [ ${ret} -eq ${EXIT_OK} ]; then
62 log DEBUG "created wireless device '${device}' (${type})"
d76f5107 63
22a61046
MT
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}"
d76f5107
MT
69 fi
70
22a61046 71 return ${ret}
d76f5107
MT
72}
73
74function wireless_remove() {
75 local device=${1}
22a61046 76 assert isset device
d76f5107 77
22a61046
MT
78 if ! device_exists ${device}; then
79 return ${EXIT_OK}
80 fi
d76f5107 81
22a61046 82 # Tear down the device (if necessary).
d76f5107
MT
83 device_set_down ${device}
84
22a61046
MT
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}
d76f5107
MT
96}
97
98function wireless_set_channel() {
99 local device=${1}
d76f5107 100 assert isset device
22a61046
MT
101
102 local channel=${2}
d76f5107
MT
103 assert isset channel
104
22a61046
MT
105 device_exists ${device} || return ${EXIT_ERROR}
106
107 cmd_quiet iw dev ${device} set channel ${channel}
d76f5107 108}