[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[[RFC] Netcfg add WPA support 2/4] Create reconfigure_wifi function.



This function takes some of the confusion out of the dhcp switch. Especially once we add more cases to it for WPA.
---
 packages/netcfg/dhcp.c |   66 +++++++++++++++++++++++++----------------------
 1 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/packages/netcfg/dhcp.c b/packages/netcfg/dhcp.c
index d58119c..d8dc17d 100644
--- a/packages/netcfg/dhcp.c
+++ b/packages/netcfg/dhcp.c
@@ -263,6 +263,8 @@ int poll_dhcp_client (struct debconfclient *client)
 #define REPLY_DONT_CONFIGURE         3
 #define REPLY_RECONFIGURE_WIFI       4
 #define REPLY_LOOP_BACK              5
+#define REPLY_CHECK_DHCP             6
+#define REPLY_ASK_OPTIONS            7
 
 int ask_dhcp_options (struct debconfclient *client)
 {
@@ -302,8 +304,30 @@ int ask_dhcp_options (struct debconfclient *client)
         return REPLY_DONT_CONFIGURE;
 }
 
+int reconfigure_wifi (struct debconfclient *client)
+{
+    enum { ABORT, DONE, ESSID, WEP } wifistate = ESSID;
+    for (;;) {
+        switch (wifistate) {
+        case ESSID:
+            wifistate = ( netcfg_wireless_set_essid(client, interface, "high") == GO_BACK ) ?
+                ABORT : WEP;
+            break;
+        case WEP:
+            wifistate = ( netcfg_wireless_set_wep (client, interface) == GO_BACK ) ?
+                ESSID : DONE;
+            break;
+        case ABORT:
+            return REPLY_ASK_OPTIONS;
+            break;
+        case DONE:
+            return REPLY_CHECK_DHCP;
+            break;
+	}
+    }
+}
+
 
-/* Here comes another Satan machine. */
 int netcfg_activate_dhcp (struct debconfclient *client)
 {
     char* dhostname = NULL;
@@ -472,37 +496,17 @@ int netcfg_activate_dhcp (struct debconfclient *client)
                 }
                 break;
             case REPLY_RECONFIGURE_WIFI:
-                {
-                    /* oh god - a NESTED satan machine */
-                    enum { ABORT, DONE, ESSID, WEP } wifistate = ESSID;
-                    for (;;) {
-                        switch (wifistate) {
-                        case ESSID:
-                            wifistate = ( netcfg_wireless_set_essid(client, interface, "high") == GO_BACK ) ?
-                                ABORT : WEP;
-                            break;
-                        case WEP:
-                            wifistate = ( netcfg_wireless_set_wep (client, interface) == GO_BACK ) ?
-                                ESSID : DONE;
-                            break;
-                        case ABORT:
-                            state = ASK_OPTIONS;
-                            break;
-                        case DONE:
-                            if (dhcp_pid > 0)
-                                state = POLL;
-                            else {
-                                kill_dhcp_client();
-                                state = START;
-                            }
-                            break;
-                        }
-                        if (wifistate == DONE || wifistate == ABORT)
-                            break;
-                    }
-                }
+        	if (reconfigure_wifi(client) == REPLY_CHECK_DHCP)
+            	    if (dhcp_pid > 0)
+            		state = POLL;
+            	    else {
+            		kill_dhcp_client();
+            		state = START;
+            	    }
+            	else
+            	    state = ASK_OPTIONS;
                 break;
-            }
+    	    }
             break;
 
         case DHCP_HOSTNAME:
-- 
1.5.5.1


Reply to: