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

Re: [RFC] [PATCH 1/7] Add WPA support to netcfg



Glenn Saberton <gsaberton@foomagic.org> writes:

> Hello list,
>     Here is a new patchset that is hopefully easier for people to
> digest and thus comment on, broken down per file. Nothing much has
> changed since the last patch except a couple of cleanups and
> suggestions from the last patch.

Since you're using GIT I suggest you to take a look at git send-email
and git format-patch commands since they will make your life easier.

> netcfg, remove the nested satan machine, add reconfigure-wifi function
> and add wpa options during configuration.
>
> diff --git a/packages/netcfg/netcfg.c b/packages/netcfg/netcfg.c
> index 710327b..1e5745a 100644
> --- a/packages/netcfg/netcfg.c
> +++ b/packages/netcfg/netcfg.c
> @@ -33,6 +33,7 @@
>  #endif
>  #include "netcfg.h"
>  
> +int requested_wpa_supplicant = 0;
>  static method_t netcfg_method = DHCP;
>  
>  response_t netcfg_get_method(struct debconfclient *client)
> @@ -61,7 +62,21 @@ response_t netcfg_get_method(struct debconfclient *client)
>  int main(int argc, char *argv[])
>  {
>      int num_interfaces = 0;
> -    enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_METHOD, GET_DHCP, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT } state = GET_INTERFACE;
> +    enum { BACKUP, \
> +           GET_INTERFACE, \
> +           GET_HOSTNAME_ONLY, \
> +           GET_METHOD, \
> +           GET_DHCP, \
> +           GET_STATIC, \
> +           WCONFIG, \
> +           WCONFIG_ESSID, \
> +           WCONFIG_SECURITY, \
> +           WCONFIG_WEP, \
> +           WCONFIG_WPA, \
> +           QUIT } 
> +
> +     state = GET_INTERFACE;
> +

This reformating could be done in another patch to leave the WPA
specific changes on the patch.

>      static struct debconfclient *client;
>      static int requested_wireless_tools = 0;
>      char **ifaces;
> @@ -237,23 +252,49 @@ int main(int argc, char *argv[])
>              }
>              state = WCONFIG_ESSID;
>              break;
> -            
> +
>          case WCONFIG_ESSID:
> -            if (netcfg_wireless_set_essid (client, interface, NULL) == GO_BACK)
> +            if (netcfg_wireless_set_essid(client, interface, "high") == GO_BACK)
>                  state = BACKUP;
>              else
> -                state = WCONFIG_WEP;
> +                state = WCONFIG_SECURITY;
>              break;
>              
> +        case WCONFIG_SECURITY:
> +            {
> +                int ret;
> +                ret = netcfg_wireless_set_security(client, interface);
> +                if (ret == GO_BACK)
> +                    state = WCONFIG_ESSID;
> +                else if (ret == REPLY_WPA)
> +                    state = WCONFIG_WPA;
> +                else
> +                    state = WCONFIG_WEP;
> +                break;
> +            }
> +
>          case WCONFIG_WEP:
> -            if (netcfg_wireless_set_wep (client, interface) == GO_BACK)
> -                state = WCONFIG_ESSID;
> +            if (netcfg_wireless_set_wep(client, interface) == GO_BACK)
> +                state = WCONFIG_SECURITY;
>              else
>                  state = GET_METHOD;
>              break;
> -            
> +
> +        case WCONFIG_WPA:
> +            if (requested_wpa_supplicant == 0) {
> +                di_exec_shell_log("apt-install wpasupplicant");
> +                requested_wpa_supplicant = 1;
> +            }
> +
> +            if (netcfg_set_passphrase(client, interface) == GO_BACK)
> +                state = WCONFIG_SECURITY;
> +            else
> +                state = GET_METHOD;
> +            break;
> +
>          case QUIT:
>              return 0;
>          }
>      }
>  }
> +
> diff --git a/packages/netcfg/netcfg.h b/packages/netcfg/netcfg.h
> index 5016870..f2aeccb 100644
> --- a/packages/netcfg/netcfg.h
> +++ b/packages/netcfg/netcfg.h
> @@ -10,11 +10,15 @@
>  #define DHCLIENT3_CONF	"/etc/dhcp3/dhclient.conf"
>  #define DOMAIN_FILE     "/tmp/domain_name"
>  #define NTP_SERVER_FILE "/tmp/dhcp-ntp-servers"
> +#define WPASUPP_FILE    "/etc/wpa_supplicant/wpa_supplicant.conf"
>  
>  #define DEVNAMES	"/etc/network/devnames"
>  #define DEVHOTPLUG	"/etc/network/devhotplug"
>  #define STAB		"/var/run/stab"
>  
> +#define WPA_MIN         8
> +#define WPA_MAX         64
> +
>  #define _GNU_SOURCE
>  
>  #include <sys/types.h>
> @@ -41,7 +45,7 @@
>  "ff02::2 ip6-allrouters\n" \
>  "ff02::3 ip6-allhosts\n"
>  
> -typedef enum { NOT_ASKED = 30, GO_BACK } response_t;
> +typedef enum { NOT_ASKED = 30, GO_BACK, REPLY_WEP, REPLY_WPA } response_t;
>  typedef enum { DHCP, STATIC, DUNNO } method_t;
>  typedef enum { ADHOC = 1, MANAGED = 2 } wifimode_t;
>  
> @@ -49,6 +53,7 @@ extern int netcfg_progress_displayed;
>  extern int wfd, skfd;
>  extern int input_result;
>  extern int have_domain;
> +extern int requested_wpa_supplicant;
>  
>  /* network config */
>  extern char *interface;
> @@ -64,7 +69,7 @@ extern struct in_addr gateway;
>  extern struct in_addr pointopoint;
>  
>  /* wireless */
> -extern char *essid, *wepkey;
> +extern char *essid, *wepkey, *passphrase;
>  extern wifimode_t mode;
>  
>  /* common functions */
> @@ -111,7 +116,11 @@ extern int is_wireless_iface (const char* iface);
>  
>  extern int netcfg_wireless_set_essid (struct debconfclient *client, char* iface, char* priority);
>  extern int netcfg_wireless_set_wep (struct debconfclient *client, char* iface);
> +extern int netcfg_wireless_set_security (struct debconfclient *client, char* iface);
> +extern int netcfg_set_passphrase (struct debconfclient *client, char* iface);
>  
> +extern int netcfg_write_wpa (char *essid, char *passphrase);
> +extern int start_wpa_supplicant (struct debconfclient *client);
>  extern int iface_is_hotpluggable(const char *iface);
>  extern short find_in_stab (const char *iface);
>  extern void deconfigure_network(void);
>

-- 
        O T A V I O    S A L V A D O R
---------------------------------------------
 E-mail: otavio@debian.org      UIN: 5906116
 GNU/Linux User: 239058     GPG ID: 49A5F855
 Home Page: http://otavio.ossystems.com.br
---------------------------------------------
"Microsoft sells you Windows ... Linux gives
 you the whole house."


Reply to: