#!/bin/sh
. /lib/functions.sh

maclist="AA:BB:CC:DD:EE:FF 00:11:22:33:44:55 66:77:88:99:00:11"
ifnames="ra0 ra1 rax0 rax1"

add_blacklist() {
    local s="$1"
    uci set wireless.$s.macfilter=deny
    uci -q del wireless.$s.maclist
    for mac in $maclist; do
        uci add_list wireless.$s.maclist="$mac"
    done
}

del_blacklist() {
    local s="$1"
    uci set wireless.$s.macfilter=""
    uci -q del wireless.$s.maclist
}


start_blacklist() {
    action=2

    for ifname in $ifnames; do
        iwpriv $ifname set AccessPolicy=$action
        iwpriv $ifname set ACLAddEntry="${maclist// /;}"
    done

    config_load wireless

    config_foreach add_blacklist wifi-iface
    uci commit wireless
}

stop_blacklist() {
    action=0

    for ifname in $ifnames; do
        iwpriv $ifname set AccessPolicy=$action
        iwpriv $ifname set ACLClearAll=1
    done
    config_load wireless

    config_foreach del_blacklist wifi-iface
    uci commit wireless
}
 

cmd=$1

case $cmd in
    start)
        echo "Starting blacklist"
        start_blacklist
        ;;
    stop)
        echo "Stopping blacklist"
        stop_blacklist
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac


