#!/bin/bash -x


pkill hostapd

rmmod mac80211_hwsim
echo "" >prova.pcap
chmod a+w prova.pcap

sleep 1
modprobe mac80211_hwsim radios=3

nmcli device set wlan0 managed false
nmcli device set wlan1 managed false
nmcli device set wlan2 managed false

ip link set dev hwsim0 up
# tshark -i hwsim0 -l -w prova.pcap &
sleep 1

read -r mac1 _ < /sys/class/net/wlan1/address
read -r mac2 _ < /sys/class/net/wlan2/address

sed "s/MACWLAN1/$mac1/g" hostapd.wlan2.template >hostapd.wlan2
sed "s/MACWLAN2/$mac2/g" hostapd.wlan1.template >hostapd.wlan1

hostapd -B hostapd.wlan1 
hostapd -B hostapd.wlan2

wpa_supplicant -Dnl80211 -iwlan0 -ddd -f /var/run/wpa_supplicant.log -O /var/run/wpa_supplicant  -B

#nmcli device set wlan0 managed true
#sleep 10
#nmcli device wifi list ifname wlan0
#sleep 5
#pkill tshark
#tshark -r prova.pcap  -Y 'wlan.fc.type_subtype == 0x0004 || wlan.fc.type_subtype == 0x0005'
#nmcli device set wlan0 managed false


