]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Introduce "network device ap0 monitor" command
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Aug 2014 17:51:53 +0000 (19:51 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Aug 2014 17:51:53 +0000 (19:51 +0200)
This enables the user to monitor all 802.11 frames
that traverse the wireless interface.

src/functions/functions.wireless
src/network

index f33419e3018076ce23b27e1bbcc8ae5c4177df88..9090056d670dde547fe543041dcb5aa9f3022507 100644 (file)
@@ -55,7 +55,7 @@ function wireless_create() {
                shift
        done
 
-       assert isoneof type ibss managed __ap
+       assert isoneof type ibss managed monitor __ap
        assert phy_exists ${phy}
        isset address || address=$(mac_generate)
 
@@ -182,6 +182,7 @@ function wireless_set_channel() {
 
        device_exists ${device} || return ${EXIT_ERROR}
 
+       log DEBUG "Setting wireless channel on device '${device}' to channel '${channel}'"
        cmd_quiet iw dev ${device} set channel ${channel}
 }
 
@@ -242,3 +243,35 @@ function wireless_is_radar_frequency() {
 
        [[ ${frequency} -ge 5260 ]] && [[ ${frequency} -le 5700 ]]
 }
+
+function wireless_monitor() {
+       local device="${1}"
+       assert isset device
+       shift
+
+       local monitor_device="mon$$"
+
+       # Create an 802.11 monitoring device
+       wireless_create "${monitor_device}" --phy="${device}" --type="monitor"
+       local ret=$?
+
+       case "${ret}" in
+               0)
+                       # Bring up the device
+                       device_set_up "${monitor_device}"
+
+                       # Starting tcpdump
+                       tcpdump -i "${monitor_device}" "$@"
+
+                       # Remove the monitoring interface.
+                       wireless_remove "${monitor_device}"
+                       ;;
+
+               *)
+                       log ERROR "Could not create a monitoring interface on ${device}"
+                       return ${EXIT_ERROR}
+                       ;;
+       esac
+
+       return ${EXIT_OK}
+}
index a0f393a923ce7f56343b1fa0122f15674b9d9a5f..0425d7af1e19fb64d1782ee82725954845f1a3c3 100644 (file)
@@ -73,6 +73,9 @@ function cli_device() {
                discover)
                        cli_device_discover ${device} $@
                        ;;
+               monitor)
+                       cli_device_monitor "${device}" $@
+                       ;;
                status)
                        cli_device_status ${device}
                        ;;
@@ -421,6 +424,19 @@ function cli_device_send_ussd_command() {
        exit $?
 }
 
+function cli_device_monitor() {
+       local device="${1}"
+       assert isset device
+
+       if ! device_is_wireless "${device}"; then
+               error "This action only works with wireless devices. Exiting."
+               exit ${EXIT_ERROR}
+       fi
+
+       wireless_monitor "${device}"
+       exit $?
+}
+
 function cli_hostname() {
        if cli_help_requested $@; then
                cli_show_man network