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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
#!/bin/bash
# Network Interface Configuration System
# Copyright (c) 1996-2009 Red Hat, Inc. all rights reserved.
#
# Based on PCMCIA wireless script by (David Hinds/Jean Tourrilhes)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Configure wireless network device options. See iw(8) for more info.
# Mageia prefixes the following variables with WIRELESS_ prefix.
# Valid variables:
# MODE: Ad-Hoc, Managed, etc.
# ESSID: Name of the wireless network
# NWID: Name of this machine on the network. Hostname is default
# FREQ: Frequency to operate on. See CHANNEL
# CHANNEL: Numbered frequency to operate on. See FREQ
# SENS: Sensitivity threshold for packet rejection.
# RATE: Transfer rate. Usually one of Auto, 11, 5, 2, or 1.
# RTS: Explicit RTS handshake. Usually not specified (auto)
# FRAG: Fragmentation threshold to split packets. Usually not specified.
# IWCONFIG: Extra parameters to pass directly to IWCONFIG
# IWPRIV: Extra parameters to pass directly to IWPRIV
#
# redhat-only variables:
# KEY: Encryption key for WEP.
# KEY[1-4]: Encryption key for WEP in position [1-4]
# SECURITYMODE: Security mode, e.g: 'open' or 'restricted'
# SPYIPS: List of IP addresses to "spy" on for link performance stats.
#
# mandriva-only variables:
# WIRELESS_NICK: nickname for wireless connection
# WIRELESS_ENC_KEY: Encryption key for WEP.
# WIRELESS_ENC_MODE: Security mode, e.g: 'open' or 'restricted'
# WIRELESS_XSUPPLICANT: Enabling xsupplicant support
# WIRELESS_XSUPPLICANT_FILE: Custom location for xsupplicant.conf file
# Only meant to be called from ifup.
# unify variables common to RH and Mageia-style ifcfg
MODE=${MODE:-$WIRELESS_MODE}
ESSID=${ESSID:-$WIRELESS_ESSID}
NWID=${NWID:-$WIRELESS_NWID}
FREQ=${FREQ:-$WIRELESS_FREQ}
CHANNEL=${CHANNEL:-$WIRELESS_CHANNEL}
SENS=${SENS:-$WIRELESS_SENS}
RATE=${RATE:-$WIRELESS_RATE}
POWER=${POWER:-$WIRELESS_POWER}
RTS=${RTS:-$WIRELESS_RTS}
FRAG=${FRAG:-$WIRELESS_FRAG}
IWCONFIG=${IWCONFIG:-$WIRELESS_IWCONFIG}
IWSPY=${IWSPY:-$WIRELESS_IWSPY}
IWPRIV=${IWPRIV:-$WIRELESS_IWPRIV}
# Mode need to be first : some settings apply only in a specific mode !
if [ -n "$MODE" ] ; then
# for some cards, the mode can only be set with the card is down
# so we bring the card down (and suspending ifplugd if it is running)
# in order to do so (mdv bug #43166)
ifplugd -S -i $DEVICE 2>/dev/null
/sbin/ip link set dev $DEVICE down
iwconfig $DEVICE mode $MODE
ifplugd -R -i $DEVICE 2>/dev/null
fi
# Set link up (some cards require this.)
/sbin/ip link set dev ${DEVICE} up
# Setup the card nickname
# This is a bit hackish, but should do the job right...
if [ -n "$ESSID" -o -n "$MODE" ] ; then
NICKNAME=$(/bin/hostname)
iwconfig $DEVICE nick "$NICKNAME" >/dev/null 2>&1
fi
if [ -n "$WIRELESS_NICK" ] ; then
iwconfig $DEVICE nick $WIRELESS_NICK >/dev/null 2>&1
elif [ -n "$ESSID" ] || [ -n "$MODE" ] ; then
# This is a bit hackish, but should do the job right...
NICKNAME=`/bin/hostname`
iwconfig $DEVICE nick $NICKNAME >/dev/null 2>&1
fi
# Regular stuff...
# network id
if [ -n "$NWID" ] ; then
iwconfig $DEVICE nwid $NWID
fi
# frequency and channel
if [ -n "$FREQ" -a "$MODE" != "Managed" ] ; then
iwconfig $DEVICE freq $FREQ
elif [ -n "$CHANNEL" -a "$MODE" != "Managed" ] ; then
iwconfig $DEVICE channel $CHANNEL
fi
# sensitivity
if [ -n "$SENS" ] ; then
iwconfig $DEVICE sens $SENS
fi
# rate
if [ -n "$RATE" ] ; then
iwconfig $DEVICE rate "$RATE"
fi
# encryption
# for redhat-style ifcfg
if [ -n "$KEY" -o -n "$KEY1" -o -n "$KEY2" -o -n "$KEY3" -o -n "$KEY4" ] ; then
[ -n "$KEY1" ] && iwconfig $DEVICE key "[1]" $KEY1
[ -n "$KEY2" ] && iwconfig $DEVICE key "[2]" $KEY2
[ -n "$KEY3" ] && iwconfig $DEVICE key "[3]" $KEY3
[ -n "$KEY4" ] && iwconfig $DEVICE key "[4]" $KEY4
[ -n "$DEFAULTKEY" ] && iwconfig $DEVICE key "[${DEFAULTKEY}]"
[ -n "$KEY" ] && iwconfig $DEVICE key $KEY
else
iwconfig $DEVICE key off
fi
# for mandriva-style ifcfg
if [ -n "$WIRELESS_ENC_KEY" -o "$WIRELESS_ENC_MODE" ] ; then
if [ -n "$WIRELESS_ENC_MODE" ]; then
iwconfig $DEVICE key $WIRELESS_ENC_MODE "$WIRELESS_ENC_KEY"
else
# compatibility for older config files
# that used to contain enc mode in key
echo "$WIRELESS_ENC_KEY" | egrep -q '^(open|restricted) '
if [ $? == 0 ]; then
iwconfig $DEVICE key $WIRELESS_ENC_KEY
else
iwconfig $DEVICE key "$WIRELESS_ENC_KEY"
fi
fi
fi
# security mode
if [ -n "$SECURITYMODE" ]; then
iwconfig $DEVICE enc $SECURITYMODE
fi
# power
if [ -n "$POWER" ] ; then
iwconfig $DEVICE power $POWER
fi
# rts
if [ -n "$RTS" ] ; then
iwconfig $DEVICE rts $RTS
fi
# fragmentation
if [ -n "$FRAG" ] ; then
iwconfig $DEVICE frag $FRAG
fi
# More specific parameters passed directly to IWCONFIG
if [ -n "$IWCONFIG" ] ; then
iwconfig $DEVICE $IWCONFIG
fi
# iwspy settings
if [ -n "$SPYIPS" ] ; then
for IP in $SPYIPS; do
iwspy $DEVICE + $IP
done
fi
if [ -n "$IWSPY" ] ; then
/sbin/iwspy $DEVICE $IWSPY
fi
# private options
if [ -n "$IWPRIV" ] ; then
IFS=$'\n' echo "$IWPRIV" | while read priv; do
[ -n -n "$priv" ] && eval "/sbin/iwpriv $DEVICE $priv"
done
fi
# ESSID need to be last : most device re-perform the scanning/discovery
# when this is set, and things like encryption keys are better be
# defined if we want to discover the right set of APs/nodes.
if [ -n "$ESSID" ] ; then
iwconfig $DEVICE essid "$ESSID"
else
# use any essid
iwconfig $DEVICE essid any >/dev/null 2>&1
fi
|