Moved  WPS code to new function

The WPS implementation is going to have a bigger code base which
justifies a dedicated function with less indentation levels.

Signed-off-by: Lorenzo Cappelletti <lorenzo.cappelle...@gmail.com>

---

Hi everyone,

I'm a senior embedded C programmer and I'd like to contribute with my
2 cents to this great project.

My final goal consists in implementing a WPS
(http://en.wikipedia.org/wiki/Wi-Fi_Protected_Setup) based guest
network which my friends coming by can connect to and have access to
my entire network resources.  Of course, without compromising on
security.

I already started documenting the code on the wiki last month.  My
next step was preparing the ground for a couple of new WPS methods,
label and keypad.  What I'm submitting here is the result of this
first effort.  I hope you'll accept it in the trunk.

Next, I'll move on to implement the keypad method which requires user
inputs.  I think I'll create a dynamic web page here.  Not sure
because I'm new to this.

diff --git a/hostapd/files/hostapd.sh b/hostapd/files/hostapd.sh
--- a/hostapd/files/hostapd.sh
+++ b/hostapd/files/hostapd.sh
@@ -1,3 +1,29 @@
+hostapd_set_wps_options() {
+       local config_methods device_name device_type manufacturer\
+             wps_label wps_pbc
+
+       config_get_bool wps_pbc "$vif" wps_pushbutton 0
+       config_get_bool wps_label "$vif" wps_label 0
+
+       config_get config_methods "$vif" wps_config
+       [ "$wps_pbc" -gt 0 ] && append config_methods push_button
+
+       [ -z "$config_methods" ] && return
+
+       # common options
+       config_get device_type "$vif" wps_device_type "6-0050F204-1"
+       config_get device_name "$vif" wps_device_name "OpenWrt AP"
+       config_get manufacturer "$vif" wps_manufacturer "openwrt.org"
+
+       append "$var" "eap_server=1" "$N"
+       append "$var" "wps_state=2" "$N"
+       append "$var" "ap_setup_locked=1" "$N"
+       append "$var" "device_type=$device_type" "$N"
+       append "$var" "device_name=$device_name" "$N"
+       append "$var" "manufacturer=$manufacturer" "$N"
+       append "$var" "config_methods=$config_methods" "$N"
+}
+
 hostapd_set_bss_options() {
        local var="$1"
        local vif="$2"
@@ -159,25 +185,7 @@
        config_get ieee80211d "$vif" ieee80211d
        config_get iapp_interface "$vif" iapp_interface

-       config_get_bool wps_pbc "$vif" wps_pushbutton 0
-       config_get_bool wps_label "$vif" wps_label 0
-
-       config_get config_methods "$vif" wps_config
-       [ "$wps_pbc" -gt 0 ] && append config_methods push_button
-
-       [ -n "$wps_possible" -a -n "$config_methods" ] && {
-               config_get device_type "$vif" wps_device_type "6-0050F204-1"
-               config_get device_name "$vif" wps_device_name "OpenWrt AP"
-               config_get manufacturer "$vif" wps_manufacturer "openwrt.org"
-
-               append "$var" "eap_server=1" "$N"
-               append "$var" "wps_state=2" "$N"
-               append "$var" "ap_setup_locked=1" "$N"
-               append "$var" "device_type=$device_type" "$N"
-               append "$var" "device_name=$device_name" "$N"
-               append "$var" "manufacturer=$manufacturer" "$N"
-               append "$var" "config_methods=$config_methods" "$N"
-       }
+       [ -n "$wps_possible" ] && hostapd_set_wps_options

        append "$var" "ssid=$ssid" "$N"
        [ -n "$bridge" ] && append "$var" "bridge=$bridge" "$N"
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to