#!/bin/sh
# MAB self-announce on the dot1x interface (no 802.1X supplicant). DHCP DISCOVER triggers
# hostapd wired station detection → EAPOL-timeout → MAC-Authentication-Bypass at the NAS.
IFACE=${DOT1X_IF:-$(ip -o link show 2>/dev/null | awk -F': ' '$2!="lo" && $2!~/^eth0/ {print $2; exit}')}
IFACE=${IFACE:-eth1}
pkill -f "wpa_supplicant -i $IFACE" 2>/dev/null || true
ip link set "$IFACE" up 2>/dev/null
sleep 2
# DHCP DISCOVER (hostapd-snoopable station detection) — silent endpoint, no supplicant
udhcpc -i "$IFACE" -n -q -t 5 -T 2 2>/dev/null || true
# keep the station visible through the capture/auth window
( for i in $(seq 1 40); do
    arping -c1 -w1 -I "$IFACE" 192.168.100.1 >/dev/null 2>&1 || \
    ping  -c1 -W1 -I "$IFACE" 192.168.100.1 >/dev/null 2>&1
    sleep 2
  done ) >/dev/null 2>&1 &
echo "[mab-trigger] announced on $IFACE (MAB expected at the NAS)"
