From f24bcb8ae9ca429fffacb17e38463c09ca6e8deb Mon Sep 17 00:00:00 2001 From: albfan Date: Fri, 1 May 2015 21:57:28 +0200 Subject: [PATCH] polish device tester script closes #22 --- README.md | 4 +- res/miracle-utils.sh | 125 ++++++++++++++++++++++++++++++++++ res/test-wifi-capabilities.sh | 44 +++++++++++- 3 files changed, 170 insertions(+), 3 deletions(-) create mode 100755 res/miracle-utils.sh mode change 100644 => 100755 res/test-wifi-capabilities.sh diff --git a/README.md b/README.md index 3f6f7a3..7669acc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MiracleCast - Wifi-Display/Miracast Implementation -The MiracleCast project provides software to connect external monitors to your system via Wifi. It is compatible to the Wifi-Display specification also known as Miracast. MiracleCast implements the Display-Source as well as Display-Sink side. +The MiracleCast project provides software to connect external monitors to your system via Wi-Fi. It is compatible to the Wifi-Display specification also known as Miracast. MiracleCast implements the Display-Source as well as Display-Sink side. The Display-Source side allows you to connect external displays to your system and stream local content to the device. A lot of effort is put into making this as easy as connecting external displays via HDMI. @@ -22,6 +22,8 @@ The MiracleCast projects requires the following software to be installed: - **gstreamer**: MiracleCast relay on gstreamer to show cast its output. You can test if all needed is installed launching [res/test-viewer.sh](https://github.com/albfan/miraclecast/blob/master/res/test-viewer.sh) + - **P2P Wi-Fi device** Although widespread this days, there are some devices not compatible with [Wi-Fi Direct](http://en.wikipedia.org/wiki/Wi-Fi_Direct) (prior know as Wi-Fi P2P). Test yours with [res/test-wifi-capabilities.sh](https://github.com/albfan/miraclecast/blob/master/res/test_wifi-capabilities.sh) + - copy the dbus policy **res/org.freedesktop.miracle.conf** to `/etc/dbus-1/system.d/` ## Install diff --git a/res/miracle-utils.sh b/res/miracle-utils.sh new file mode 100755 index 0000000..1d9ff4d --- /dev/null +++ b/res/miracle-utils.sh @@ -0,0 +1,125 @@ +#http://lxr.linux.no/linux+v3.0/include/linux/if_arp.h#L67 +ARPHRD_LOOPBACK=772 + +# +# Find all interfaces except loopback one +# +function find_choosable_networknames { + for i in $( ls /sys/class/net ) + do + if [ $( cat /sys/class/net/$i/type ) != $ARPHRD_LOOPBACK ] + then + echo $i + fi + done +} + +# +# find wireless interfaces +# +function find_wireless_network_interfaces { + for i in $( find_choosable_networknames ) + do + if [ -d /sys/class/net/$i/wireless ] + then + echo $i + fi + done +} + +# +# test if interface is connected +# +function is_interface_connected { + test x$( cat /sys/class/net/$1/carrier 2>/dev/null) = x1 +} + +# +# find wireless connected interfaces +# +function find_wireless_connected_network_interfaces { + for i in $( find_wireless_network_interfaces ) + do + if is_interface_connected $i + then + echo $i + fi + done +} + +# +# find physical for interface if exists +# +function find_physical_for_network_interface { + PHY_INDEX=$(iw dev $1 info | grep wiphy | awk '{print $2}') + if [ -n $PHY_INDEX ] + then + echo phy$PHY_INDEX + fi +} + +# +# Check interface for P2P capabilities +# +function search_p2p_capabilities { + WI_DEVICE=$1 + PHY_DEVICE=$(find_physical_for_network_interface $WI_DEVICE) + + if iw phy $PHY_DEVICE info | grep -Pzo "(?s)Supported interface modes.*Supported commands" | grep "P2P" &> /dev/null + then + echo $WI_DEVICE supports P2P + else + echo Sorry, $WI_DEVICE do not support P2P + exit 1 + fi +} + +# +# show wpa_supplicant command +# +function show_wpa_supplicant_process { + ps -ef | grep wpa_supplican[t] +} + +# +# show wpa_supplicant command +# +function show_wpa_supplicant_command { + show_wpa_supplicant_process | awk '{print substr($0, index($0,$8))}' +} + +# +# find wpa_supplicant pid +# +function find_wpa_supplicant_pid { + show_wpa_supplicant_process | awk '{print $2}' +} + +# +# checking if distro is ubuntu +# +function check_ubuntu_distro { + cat /proc/version | grep -i ubuntu +} + +# +# ubuntu manager restarts automatically wpa_supplicant +# +function kill_ubuntu_network_manager { + if check_ubuntu_distro + then + echo stopping NetworkManager + sudo service NetworkManager stop + fi +} + +# +# start ubuntu manager +# +function start_ubuntu_network_manager { + if check_ubuntu_distro + then + echo starting NetworkManager + sudo service NetworkManager start + fi +} diff --git a/res/test-wifi-capabilities.sh b/res/test-wifi-capabilities.sh old mode 100644 new mode 100755 index 9ee9932..61244cf --- a/res/test-wifi-capabilities.sh +++ b/res/test-wifi-capabilities.sh @@ -1,5 +1,45 @@ #/bin/bash -echo You must see P2P-Go and P2P-Client below this line for a valid miraclecast device: +. miracle-utils.sh + +WIFI_NAMES=$(find_wireless_network_interfaces) +WIFI_COUNT=$(echo "$WIFI_NAMES" | wc -l) + +if [ 0 = $WIFI_COUNT ] +then + echo There is no wireless devices avaliable + exit 1 +elif [ 1 = $WIFI_COUNT ] +then + WIFI_NAME="$WIFI_NAMES" +elif [ 2 -ge $WIFI_COUNT ] +then + echo Choose wireless device: + PS3="device: " + QUIT="exit" + select wi_name in $WIFI_NAMES $QUIT + do + case $wi_name + in + "$QUIT") + exit + ;; + "") + if [ "$REPLY" = $QUIT ] + then + exit + else + echo unknow $REPLY + fi + ;; + *) + WIFI_NAME=$wi_name + break + ;; + esac + done +fi + +search_p2p_capabilities $WIFI_NAME + -iw list | grep -P "(?s)Supported interface.*Supported commands" | grep "P2P"