+ # All interfaces must have unique mac addresses
+ # which can either be explicitly set in the device
+ # section, or automatically generated
+ config_get macaddr "$device" macaddr
+ local mac_1="${macaddr%%:*}"
+ local mac_2="${macaddr#*:}"
+
+ config_get vif_mac "$vif" macaddr
+ [ -n "$vif_mac" ] || {
+ if [ "$macidx" -gt 0 ]; then
+ offset="$(( 2 + $macidx * 4 ))"
+ else
+ offset="0"
+ fi
+ vif_mac="$( printf %02x $((0x$mac_1 + $offset)) ):$mac_2"
+ macidx="$(($macidx + 1))"
+ }
+ ifconfig "$ifname" hw ether "$vif_mac"
+
+ # We attempt to set teh channel for all interfaces, although
+ # mac80211 may not support it or the driver might not yet
+ [ -n "$fixed" -a -n "$channel" ] && iw dev "$ifname" set channel "$channel"
+
+ local key keystring
+
+ # Valid values are:
+ # wpa / wep / none
+ #
+ # !! ap !!
+ #
+ # ALL ap functionality will be passed to hostapd
+ #
+ # !! mesh / adhoc / station !!
+ # none -> NO encryption
+ #
+ # wep + keymgmt = '' -> we use iw to connect to the
+ # network.
+ #
+ # wep + keymgmt = 'NONE' -> wpa_supplicant will be
+ # configured to handle the wep connection
+ if [ ! "$mode" = "ap" ]; then
+ case "$enc" in
+ *wep*)
+ config_get keymgmt "$vif" keymgmt
+ if [ -z "$keymgmt" ]; then
+ config_get key "$vif" key
+ key="${key:-1}"
+ case "$key" in
+ [1234])
+ for idx in 1 2 3 4; do
+ local zidx
+ zidx=$(($idx - 1))
+ config_get ckey "$vif" "key${idx}"
+ if [ -n "$ckey" ]; then
+ [ $idx -eq $key ] && zidx="d:${zidx}"
+ append keystring "${zidx}:$(prepare_key_wep "$ckey")"
+ fi
+ done
+ ;;
+ *)
+ keystring="d:0:$(prepare_key_wep "$key")"
+ ;;
+ esac
+ fi
+ ;;
+ *psk*|*wpa*)
+ config_get key "$vif" key
+ ;;
+ esac