Modifying scripts to let UCI interface accomodate advanced hostapd options, i.e....
[lede.git] / package / network / services / hostapd / files / hostapd.sh
index 04ee9e21b769d13e98f4454667991c7034e0bb73..534e49e0b4c4b5af8af8940387bcf51763bfcb1a 100644 (file)
@@ -262,13 +262,24 @@ hostapd_set_bss_options() {
                ;;
                psk)
                        json_get_vars key wpa_psk_file
-                       if [ ${#key} -lt 8 ]; then
-                               wireless_setup_vif_failed INVALID_WPA_PSK
-                               return 1
-                       elif [ ${#key} -eq 64 ]; then
-                               append bss_conf "wpa_psk=$key" "$N"
-                       else
-                               append bss_conf "wpa_passphrase=$key" "$N"
+                       # -- SENTINEL CHANGE --
+                       # We just check if the default key is defined.
+                       # If it is undefined, the script will check if /etc/config/wireless
+                       # specifies "option wpa_psk_file '<file_name>'"
+                       # e.g. option wpa_psk_file '/etc/config/hostapd-psk'.
+                       # When "option key '<key>'" is defined, together with 
+                       # "option wpa_psk_file '<file_name>'",
+                       # it will be the default key for any devices.
+                       # Both options can be defined independently.
+                       if [ -e "$key" ]; then
+                               if [ ${#key} -lt 8 ]; then
+                                       wireless_setup_vif_failed INVALID_WPA_PSK
+                                       return 1
+                               elif [ ${#key} -eq 64 ]; then
+                                       append bss_conf "wpa_psk=$key" "$N"
+                               else
+                                       append bss_conf "wpa_passphrase=$key" "$N"
+                               fi
                        fi
                        [ -n "$wpa_psk_file" ] && {
                                [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file"