[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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Turns on the capture interface
|
# Switches the capture interface to monitor mode, on the channel in
|
||||||
iface_up()
|
# argument
|
||||||
|
iface_set_channel()
|
||||||
{
|
{
|
||||||
echo -n "Turning up interface $IFACE... "
|
iface_down
|
||||||
ifconfig $IFACE up && echo "OK." \
|
|
||||||
|| error "Cannot turn the interface up!"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Shuts down the capture interface
|
echo -n "Setting interface $IFACE on channel $1... "
|
||||||
iface_down()
|
case $OS in
|
||||||
{
|
Linux)
|
||||||
echo -n "Shuting down interface $IFACE... "
|
iwconfig $IFACE mode managed channel $1
|
||||||
ifconfig $IFACE down && echo "OK." \
|
;;
|
||||||
|| error "Cannot shut down the interface!"
|
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
|
# Switches the capture interface to monitor mode
|
||||||
iface_monitor()
|
iface_monitor()
|
||||||
{
|
{
|
||||||
|
iface_down
|
||||||
|
|
||||||
echo -n "Switching interface $IFACE to monitor mode... "
|
echo -n "Switching interface $IFACE to monitor mode... "
|
||||||
case $OS in
|
case $OS in
|
||||||
Linux)
|
Linux)
|
||||||
|
@ -108,25 +119,24 @@ iface_monitor()
|
||||||
esac \
|
esac \
|
||||||
&& echo "OK." \
|
&& echo "OK." \
|
||||||
|| error "Cannot switch the interface to monitor mode!"
|
|| error "Cannot switch the interface to monitor mode!"
|
||||||
|
|
||||||
|
iface_up
|
||||||
}
|
}
|
||||||
|
|
||||||
# Switches the capture interface on the channel in argument
|
# Shuts down the capture interface
|
||||||
iface_set_channel()
|
iface_down()
|
||||||
{
|
{
|
||||||
echo -n "Setting interface $IFACE on channel $1... "
|
echo -n "Shuting down interface $IFACE... "
|
||||||
case $OS in
|
ifconfig $IFACE down && echo "OK." \
|
||||||
Linux)
|
|| error "Cannot shut down the interface!"
|
||||||
iwconfig $IFACE channel $1
|
}
|
||||||
;;
|
|
||||||
NetBSD)
|
# Turns on the capture interface
|
||||||
ifconfig $IFACE chan $1
|
iface_up()
|
||||||
;;
|
{
|
||||||
*)
|
echo -n "Turning up interface $IFACE... "
|
||||||
error "Your OS is not supported."
|
ifconfig $IFACE up && echo "OK." \
|
||||||
;;
|
|| error "Cannot turn the interface up!"
|
||||||
esac \
|
|
||||||
&& echo "OK." \
|
|
||||||
|| error "Cannot set the channel!"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Invokes tcpdump and returns the number of packets captured
|
# Invokes tcpdump and returns the number of packets captured
|
||||||
|
@ -210,13 +220,10 @@ FILE="$DESTDIR/$FILE"
|
||||||
|
|
||||||
check_dependencies
|
check_dependencies
|
||||||
|
|
||||||
iface_down
|
|
||||||
iface_monitor
|
|
||||||
iface_up
|
|
||||||
|
|
||||||
echo "Trying to capture $NB_PKT packets..."
|
echo "Trying to capture $NB_PKT packets..."
|
||||||
CAPTURED=0
|
CAPTURED=0
|
||||||
while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
|
while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
|
||||||
|
echo
|
||||||
iface_set_channel $CHANNEL
|
iface_set_channel $CHANNEL
|
||||||
wait_tcpdump $TIMEOUT &
|
wait_tcpdump $TIMEOUT &
|
||||||
invoke_tcpdump
|
invoke_tcpdump
|
||||||
|
@ -226,6 +233,7 @@ while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
|
||||||
CHANNEL=`expr $CHANNEL + 1`
|
CHANNEL=`expr $CHANNEL + 1`
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
[ $CAPTURED -gt 0 ] \
|
[ $CAPTURED -gt 0 ] \
|
||||||
&& echo "Capture file \"$FILE\" created with $CAPTURED packets." \
|
&& echo "Capture file \"$FILE\" created with $CAPTURED packets." \
|
||||||
|| error "Failed to capture any packet!"
|
|| error "Failed to capture any packet!"
|
||||||
|
|
Loading…
Reference in New Issue