4 |
- |
1 |
#!/bin/bash
|
|
|
2 |
# Network Interface Configuration System
|
|
|
3 |
# Copyright (c) 1996-2009 Red Hat, Inc. all rights reserved.
|
|
|
4 |
#
|
|
|
5 |
# Based on PCMCIA wireless script by (David Hinds/Jean Tourrilhes)
|
|
|
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, version 2,
|
|
|
9 |
# as published by the Free Software Foundation.
|
|
|
10 |
#
|
|
|
11 |
# This program is distributed in the hope that it will be useful,
|
|
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
14 |
# GNU General Public License for more details.
|
|
|
15 |
#
|
|
|
16 |
# You should have received a copy of the GNU General Public License
|
|
|
17 |
# along with this program; if not, write to the Free Software
|
|
|
18 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
19 |
#
|
|
|
20 |
# Configure wireless network device options. See iwconfig(8) for more info.
|
|
|
21 |
# Valid variables:
|
|
|
22 |
# MODE: Ad-Hoc, Managed, etc.
|
|
|
23 |
# ESSID: Name of the wireless network
|
|
|
24 |
# NWID: Name of this machine on the network. Hostname is default
|
|
|
25 |
# FREQ: Frequency to operate on. See CHANNEL
|
|
|
26 |
# CHANNEL: Numbered frequency to operate on. See FREQ
|
|
|
27 |
# SENS: Sensitivity threshold for packet rejection.
|
|
|
28 |
# RATE: Transfer rate. Usually one of Auto, 11, 5, 2, or 1.
|
|
|
29 |
# KEY: Encryption key for WEP.
|
|
|
30 |
# RTS: Explicit RTS handshake. Usually not specified (auto)
|
|
|
31 |
# FRAG: Fragmentation threshold to split packets. Usually not specified.
|
|
|
32 |
# SPYIPS: List of IP addresses to "spy" on for link performance stats.
|
|
|
33 |
# IWCONFIG: Extra parameters to pass directly to IWCONFIG
|
|
|
34 |
# SECURITYMODE: Security mode, e.g: 'open' or 'restricted'
|
|
|
35 |
# IWPRIV: Extra parameters to pass directly to IWPRIV
|
|
|
36 |
|
|
|
37 |
# Only meant to be called from ifup.
|
|
|
38 |
|
|
|
39 |
# Mode need to be first : some settings apply only in a specific mode !
|
|
|
40 |
if [ -n "$MODE" ] ; then
|
|
|
41 |
iwconfig $DEVICE mode $MODE
|
|
|
42 |
fi
|
|
|
43 |
|
|
|
44 |
# Set link up (some cards require this.)
|
|
|
45 |
/sbin/ip link set dev ${DEVICE} up
|
|
|
46 |
|
|
|
47 |
# This is a bit hackish, but should do the job right...
|
|
|
48 |
if [ -n "$ESSID" -o -n "$MODE" ] ; then
|
|
|
49 |
NICKNAME=$(/bin/hostname)
|
|
|
50 |
iwconfig $DEVICE nick "$NICKNAME" >/dev/null 2>&1
|
|
|
51 |
fi
|
|
|
52 |
# Regular stuff...
|
|
|
53 |
if [ -n "$NWID" ] ; then
|
|
|
54 |
iwconfig $DEVICE nwid $NWID
|
|
|
55 |
fi
|
|
|
56 |
if [ -n "$FREQ" -a "$MODE" != "Managed" ] ; then
|
|
|
57 |
iwconfig $DEVICE freq $FREQ
|
|
|
58 |
elif [ -n "$CHANNEL" -a "$MODE" != "Managed" ] ; then
|
|
|
59 |
iwconfig $DEVICE channel $CHANNEL
|
|
|
60 |
fi
|
|
|
61 |
if [ -n "$SENS" ] ; then
|
|
|
62 |
iwconfig $DEVICE sens $SENS
|
|
|
63 |
fi
|
|
|
64 |
if [ -n "$RATE" ] ; then
|
|
|
65 |
iwconfig $DEVICE rate "$RATE"
|
|
|
66 |
fi
|
|
|
67 |
if [ -n "$KEY" -o -n "$KEY1" -o -n "$KEY2" -o -n "$KEY3" -o -n "$KEY4" ] ; then
|
|
|
68 |
[ -n "$KEY1" ] && iwconfig $DEVICE key "[1]" $KEY1
|
|
|
69 |
[ -n "$KEY2" ] && iwconfig $DEVICE key "[2]" $KEY2
|
|
|
70 |
[ -n "$KEY3" ] && iwconfig $DEVICE key "[3]" $KEY3
|
|
|
71 |
[ -n "$KEY4" ] && iwconfig $DEVICE key "[4]" $KEY4
|
|
|
72 |
[ -n "$DEFAULTKEY" ] && iwconfig $DEVICE key "[${DEFAULTKEY}]"
|
|
|
73 |
[ -n "$KEY" ] && iwconfig $DEVICE key $KEY
|
|
|
74 |
else
|
|
|
75 |
iwconfig $DEVICE key off
|
|
|
76 |
fi
|
|
|
77 |
if [ -n "$SECURITYMODE" ]; then
|
|
|
78 |
iwconfig $DEVICE enc $SECURITYMODE
|
|
|
79 |
fi
|
|
|
80 |
if [ -n "$RTS" ] ; then
|
|
|
81 |
iwconfig $DEVICE rts $RTS
|
|
|
82 |
fi
|
|
|
83 |
if [ -n "$FRAG" ] ; then
|
|
|
84 |
iwconfig $DEVICE frag $FRAG
|
|
|
85 |
fi
|
|
|
86 |
|
|
|
87 |
# More specific parameters passed directly to IWCONFIG
|
|
|
88 |
if [ -n "$IWCONFIG" ] ; then
|
|
|
89 |
iwconfig $DEVICE $IWCONFIG
|
|
|
90 |
fi
|
|
|
91 |
|
|
|
92 |
if [ -n "$SPYIPS" ] ; then
|
|
|
93 |
for IP in $SPYIPS; do
|
|
|
94 |
iwspy $DEVICE + $IP
|
|
|
95 |
done
|
|
|
96 |
fi
|
|
|
97 |
if [ -n "$IWPRIV" ] ; then
|
|
|
98 |
iwpriv $DEVICE $IWPRIV
|
|
|
99 |
fi
|
|
|
100 |
|
|
|
101 |
# ESSID need to be last : most device re-perform the scanning/discovery
|
|
|
102 |
# when this is set, and things like encryption keys are better be
|
|
|
103 |
# defined if we want to discover the right set of APs/nodes.
|
|
|
104 |
if [ -n "$ESSID" ] ; then
|
|
|
105 |
iwconfig $DEVICE essid "$ESSID"
|
|
|
106 |
else
|
|
|
107 |
# use any essid
|
|
|
108 |
iwconfig $DEVICE essid any >/dev/null 2>&1
|
|
|
109 |
fi
|