#!/bin/sh # Made for Acer Aspire 9110 Series # Load the IPWRAW Wifi module for using the Wifi device to do packet injection # Author: Advhertz aka Carlo Avversari - advhertz@gmail.com DEVICE=eth2 module=ipwraw debug="debug=0x104021" prog=$0 [ "${prog/*load/load}" = "load" ] || { echo "This script must not be sourced." return 1 } || return 1 function die() { ret=$1 shift echo $@ >&2 exit $ret } function is_loaded() { (lsmod | egrep -q -e "^$module[[:space:]]+") && return 0 return 1 } function unload() { is_loaded || return 0 echo -n "Unloading '$module'.." modprobe -r $module echo ".done." is_loaded || return 0 die 1 "Module unload failed." } function load() { echo -n "Loading '$module'.." modprobe $module $debug is_loaded && echo ".done." && return 0 echo ".failed." die 2 "Module load failed." } function check_root() { [ $(whoami) != "root" ] && die 1 "You must be root to run this script." return 0 } function wait_for_file() { echo -n "Waiting for $2 to appear." elapsed=0 i=$1 i=$((i*2)) while [[ $elapsed<$i ]]; do [ -e $2 ] && echo ".done." && return 0 echo -n "." sleep 0.5 elapsed=$((elapsed+1)) done echo "time out." return 1 } function set_channel() { channel=$1 band=$2 printf "Setting channel to %d..." $channel echo $channel > /sys/class/net/${DEVICE}/device/channel tmp=$(cat /sys/class/net/${DEVICE}/device/channel) || die 1 "failed." (( $tmp == $channel )) || die 2 "did not work." echo "done." [ $band ] && { printf "Setting band to %d..." $band echo $band > /sys/class/net/${DEVICE}/device/band tmp=$(cat /sys/class/net/${DEVICE}/device/band) || die 1 "failed." (( $tmp == $band )) || die 2 "did not work." echo "done." } || true } check_root unload load (( $# > 0 )) && { channel=$1 shift } || channel=1 (( $# > 0 )) && { band=$2 shift } wait_for_file 10 /sys/class/net/${DEVICE}/device/rtap_iface || die 3 "Could not find ${DEVICE} interface." (echo 1 > /sys/class/net/${DEVICE}/device/rtap_iface) || die 4 "Could not write to rtap_iface to create rtap interface." iface=$(cat /sys/class/net/${DEVICE}/device/rtap_iface) || die 5 "Could not read from rtap_iface to determine rtap interface." [ "$iface" != "-1" ] || die 6 "Could not create rtap interface." ifconfig $iface up || die 7 "Could not bring up rtap interface." set_channel $channel $band|| die 5 "Could not tune to channel $channel." cat << EOM Interface up as $iface and ready for application connection. EOM