From: Michael Tremer Date: Tue, 26 Aug 2014 17:51:53 +0000 (+0200) Subject: Introduce "network device ap0 monitor" command X-Git-Tag: 007~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a38ea84a7e5122e9b38581c2413ad27b1bd9912;p=network.git Introduce "network device ap0 monitor" command This enables the user to monitor all 802.11 frames that traverse the wireless interface. --- diff --git a/src/functions/functions.wireless b/src/functions/functions.wireless index f33419e3..9090056d 100644 --- a/src/functions/functions.wireless +++ b/src/functions/functions.wireless @@ -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} +} diff --git a/src/network b/src/network index a0f393a9..0425d7af 100644 --- a/src/network +++ b/src/network @@ -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