#!/bin/sh

[ -z "$ROOT" ] && ROOT=/www
CONFIG=$ROOT/config
SCRIPT=$ROOT/script

source $CONFIG/ap.conf
source $CONFIG/ng.conf

source $SCRIPT/utils/wifi.sh

ssid="$1"
[ -z "$ssid" -o "$ssid" -gt "$NO_SSID" ] && echo "Invalid SSID $ssid" && exit

uciKey="network.wifi${ssid}"
uci -q del $uciKey

if [ `isSsidEnabled $ssid` ] && [ ! `isSsidInBridgeMode $ssid` ] ; then
  eval netmask="\$SSID${ssid}_NETMASK"
  [ -z "$netmask" ] && netmask="255.255.255.0"

  eval ssidIp="\$SSID${ssid}_IP"

  uci set $uciKey=interface
  uci set $uciKey.type=bridge
  uci set $uciKey.proto=static
  uci set $uciKey.ipaddr="$ssidIp"
  uci set $uciKey.netmask="$netmask"
fi
