- # setup wifi-dhcp interface or alias
-
- # Setup alias for $net
-
- if [ "$vap" == 1 ]; then
- echo " + Setup interface ${netrenamed}dhcp."
- uci set network.${netrenamed}dhcp=interface
+ # If we use VAP and also offer dhcp on the adhoc interface then cut the dhcp
+ # range in two halves. one for the adhoc, one for the managed VAP interface
+ ahdhcp_when_vap="$(uci get profile_$community.profile.adhoc_dhcp_when_vap)"
+
+ if [ "$supports_vap" = 1 -a "$vap" = 1 -a "$ahdhcp_when_vap" = 1 ]; then
+ # VAPs are enabled for this interface, supported and we want to
+ # also use DHCP on the adhoc interface
+ local network
+ local mask
+ network=${dhcprange%%/*}
+ mask=${dhcprange##*/}
+ # Divide network size by adding 1 to the netmask
+ mask=$(($mask + 1))
+ # Get first ip and netmask for the adhoc dhcp network
+ eval $(sh $dir/helpers/ipcalc-cidr.sh ${network}/${mask} 1 0)
+ STARTADHOC=$START
+ NETMASKADHOC=$NETMASK
+ # Get first ip and netmask for the managed dhcp network
+ eval $(sh $dir/helpers/ipcalc-cidr.sh ${NEXTNET}/${mask} 1 0)
+ STARTVAP=$START
+ NETMASKVAP=$NETMASK
+ # Add dhcp interface
+ uci batch <<- EOF
+ set network.${netrenamed}dhcp=interface
+ set network.${netrenamed}dhcp.proto=static
+ set network.${netrenamed}dhcp.ipaddr="$STARTVAP"
+ set network.${netrenamed}dhcp.netmask="$NETMASKVAP"
+ EOF
+ uci_commitverbose "Setup interface for ${netrenamed}dhcp" network