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

[RFC] [PATCH 2/7] Add WPA support to netcfg



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

wireless.c, add functions for selecting WPA secured network and
entering passphrase, then starting wpasupplicant.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIEszUV8GyuTwyskMRApRjAJwK3GkFreGF406nl4hj2kGacKN6fgCeOJty
oZZdwksYEeKtq0HVDhJG9bU=
=/PVr
-----END PGP SIGNATURE-----

diff --git a/packages/netcfg/wireless.c b/packages/netcfg/wireless.c
index ed07b8a..d1a4bac 100644
--- a/packages/netcfg/wireless.c
+++ b/packages/netcfg/wireless.c
@@ -19,6 +19,7 @@ wifimode_t mode = MANAGED;
 /* wireless config */
 char* wepkey = NULL;
 char* essid = NULL;
+char* passphrase = NULL;
 
 #ifdef WIRELESS
 
@@ -189,6 +190,25 @@ static void unset_wep_key (char* iface)
     ret = iw_set_basic_config (wfd, iface, &wconf);
 }
 
+int netcfg_wireless_set_security (struct debconfclient *client, char *iface)
+{
+  int ret = 0 ;
+  debconf_subst (client, "netcfg/wireless_security_type", "iface", iface);
+  debconf_input (client, "high", "netcfg/wireless_security_type");
+  ret = debconf_go(client);
+
+  if (ret == 30)
+    return GO_BACK;
+
+  debconf_get (client, "netcfg/wireless_security_type");
+
+  if (!strcmp(client->value, "WEP/Open Network"))
+     return REPLY_WEP;
+  else
+     return REPLY_WPA;
+
+}
+
 int netcfg_wireless_set_wep (struct debconfclient * client, char* iface)
 {
     wireless_config wconf;
@@ -250,6 +270,50 @@ int netcfg_wireless_set_wep (struct debconfclient * client, char* iface)
     return 0;
 }
 
+int netcfg_set_passphrase (struct debconfclient *client, char *iface)
+{
+  wireless_config wconf;
+  int ret;
+
+  iw_get_basic_config (wfd, iface, &wconf);
+
+  unset_wep_key (iface);
+
+  debconf_subst (client, "netcfg/wireless_wpa", "iface", iface);
+  debconf_input (client, "high", "netcfg/wireless_wpa");
+  ret = debconf_go (client);
+
+  if (ret == 30)
+    return GO_BACK;
+
+  debconf_get (client, "netcfg/wireless_wpa");
+  passphrase = client->value;
+
+  while (strlen (passphrase) < WPA_MIN || strlen (passphrase) > WPA_MAX) {
+      debconf_subst (client, "netcfg/invalid_pass", "passphrase", passphrase);
+      debconf_input (client, "critical", "netcfg/invalid_pass");
+      debconf_go (client);
+
+      debconf_input (client, "high", "netcfg/wireless_wpa");
+      ret = debconf_go (client);
+
+
+      if (ret == 30)
+        return GO_BACK;
+
+      debconf_get (client, "netcfg/wireless_wpa");
+      passphrase = client->value;
+    }
+
+  if (netcfg_write_wpa (essid, passphrase))
+    return -1;
+
+  if (start_wpa_supplicant (client))
+    return -1;
+
+  return 0;
+}
+
 #else
 
 int is_wireless_iface (const char *iface)

Reply to: