[wifi] capture: fix channel setting
At least on NetBSD with the ath driver, it is impossible to change the channel when the interface is in monitor mode (actually it is possible, but when the interface is turned up again the channel is set back to its prior value). Therefore, to set the interface in monitor mode on a given channel, we must: - shut down, - switch to managed mode (media autoselect) with the wanted channel, - turn up, - shut down again, - switch to monitor mode, - turn up again. I implemented the same behaviour for Linux, maybe it's useless but it can't hurt.
This commit is contained in:
parent
81611af216
commit
9a5853d48a
|
@ -75,25 +75,36 @@ check_dependencies()
|
|||
fi
|
||||
}
|
||||
|
||||
# Turns on the capture interface
|
||||
iface_up()
|
||||
# Switches the capture interface to monitor mode, on the channel in
|
||||
# argument
|
||||
iface_set_channel()
|
||||
{
|
||||
echo -n "Turning up interface $IFACE... "
|
||||
ifconfig $IFACE up && echo "OK." \
|
||||
|| error "Cannot turn the interface up!"
|
||||
}
|
||||
iface_down
|
||||
|
||||
# Shuts down the capture interface
|
||||
iface_down()
|
||||
{
|
||||
echo -n "Shuting down interface $IFACE... "
|
||||
ifconfig $IFACE down && echo "OK." \
|
||||
|| error "Cannot shut down the interface!"
|
||||
echo -n "Setting interface $IFACE on channel $1... "
|
||||
case $OS in
|
||||
Linux)
|
||||
iwconfig $IFACE mode managed channel $1
|
||||
;;
|
||||
NetBSD)
|
||||
ifconfig $IFACE media autoselect chan $1
|
||||
;;
|
||||
*)
|
||||
error "Your OS is not supported."
|
||||
;;
|
||||
esac \
|
||||
&& echo "OK." \
|
||||
|| error "Cannot set the channel!"
|
||||
|
||||
iface_up
|
||||
iface_monitor
|
||||
}
|
||||
|
||||
# Switches the capture interface to monitor mode
|
||||
iface_monitor()
|
||||
{
|
||||
iface_down
|
||||
|
||||
echo -n "Switching interface $IFACE to monitor mode... "
|
||||
case $OS in
|
||||
Linux)
|
||||
|
@ -108,25 +119,24 @@ iface_monitor()
|
|||
esac \
|
||||
&& echo "OK." \
|
||||
|| error "Cannot switch the interface to monitor mode!"
|
||||
|
||||
iface_up
|
||||
}
|
||||
|
||||
# Switches the capture interface on the channel in argument
|
||||
iface_set_channel()
|
||||
# Shuts down the capture interface
|
||||
iface_down()
|
||||
{
|
||||
echo -n "Setting interface $IFACE on channel $1... "
|
||||
case $OS in
|
||||
Linux)
|
||||
iwconfig $IFACE channel $1
|
||||
;;
|
||||
NetBSD)
|
||||
ifconfig $IFACE chan $1
|
||||
;;
|
||||
*)
|
||||
error "Your OS is not supported."
|
||||
;;
|
||||
esac \
|
||||
&& echo "OK." \
|
||||
|| error "Cannot set the channel!"
|
||||
echo -n "Shuting down interface $IFACE... "
|
||||
ifconfig $IFACE down && echo "OK." \
|
||||
|| error "Cannot shut down the interface!"
|
||||
}
|
||||
|
||||
# Turns on the capture interface
|
||||
iface_up()
|
||||
{
|
||||
echo -n "Turning up interface $IFACE... "
|
||||
ifconfig $IFACE up && echo "OK." \
|
||||
|| error "Cannot turn the interface up!"
|
||||
}
|
||||
|
||||
# Invokes tcpdump and returns the number of packets captured
|
||||
|
@ -210,13 +220,10 @@ FILE="$DESTDIR/$FILE"
|
|||
|
||||
check_dependencies
|
||||
|
||||
iface_down
|
||||
iface_monitor
|
||||
iface_up
|
||||
|
||||
echo "Trying to capture $NB_PKT packets..."
|
||||
CAPTURED=0
|
||||
while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
|
||||
echo
|
||||
iface_set_channel $CHANNEL
|
||||
wait_tcpdump $TIMEOUT &
|
||||
invoke_tcpdump
|
||||
|
@ -226,6 +233,7 @@ while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
|
|||
CHANNEL=`expr $CHANNEL + 1`
|
||||
done
|
||||
|
||||
echo
|
||||
[ $CAPTURED -gt 0 ] \
|
||||
&& echo "Capture file \"$FILE\" created with $CAPTURED packets." \
|
||||
|| error "Failed to capture any packet!"
|
||||
|
|
Loading…
Reference in New Issue