#!/bin/bash # set -xv source /opt/scripts/mesh/freq.sh # get center frequency of channel like this: ${chan2g["1"]} 'OR' ${chan5g["149"]} ### === INPUT ARGUMENTS === PHYNAME=$1 MON_INTERFACE=$2 # CHANNEL=${chan[$3]} CHANNEL=$3 shift 3 NODES=($@) ### === NODE IDENTIFICATION === HOSTNAME=$(uname -n | cut -d. -f1) NODE_ID=$(echo "$HOSTNAME" | sed -E 's/[^0-9]*([0-9]+)$/\1/') NODE_ID=$((10#$NODE_ID)) # Check if this node is in the NODES list NODE_INDEX=-1 for idx in "${!NODES[@]}"; do [[ ${NODES[$idx]} -eq $NODE_ID ]] && NODE_INDEX=$idx && break done if [[ $NODE_INDEX -lt 0 ]]; then echo "Node ID $NODE_ID ($HOSTNAME) is not in the monitor list. Exiting." exit 0 fi echo "Node ID $NODE_ID is in the list — setting up monitoring interface." ### === MONITOR INTERFACE SETUP === PHY_PATH="/sys/kernel/debug/ieee80211/${PHYNAME}" # Check if PHY exists if [[ ! -d "$PHY_PATH" ]]; then echo "PHY $PHYNAME does not exist at $PHY_PATH" exit 1 fi #!/bin/bash # Usage: ./remove_all_wireless.sh # Removes all interfaces on phy0 and phy1 echo "Removing all wireless interfaces on $PHYNAME..." INTERFACES=$(iw dev | awk -v phy="${PHYNAME//[!0-9]/}" ' $1 == "phy#"phy {getline; while ($1 == "Interface") {print $2; getline}}') for IFACE in $INTERFACES; do echo " - Deleting $IFACE on $PHYNAME" ip link set "$IFACE" down 2>/dev/null iw dev "$IFACE" del done echo "All wireless interfaces removed." # # Remove old monitor interface if it exists # if ip link show "$MON_INTERFACE" &>/dev/null; then # echo "Removing existing $MON_INTERFACE" # ip link set "$MON_INTERFACE" down # iw dev "$MON_INTERFACE" del # fi # Create and enable monitor interface echo "Creating monitor interface $MON_INTERFACE on $PHYNAME" iw phy "$PHYNAME" interface add "$MON_INTERFACE" type monitor sleep 2 # iw dev "$MON_INTERFACE" set channel $CHANNEL HT40+ # echo "channel=$CHANNEL / freq=$FREQ" ip link set "$MON_INTERFACE" up iw dev "$MON_INTERFACE" set channel $CHANNEL HT40+ echo "Monitor interface $MON_INTERFACE is now active." set +x