mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 07:10:33 +01:00
First dump of wpa_supplicant-related code. It's not hooked up to anything yet though. Thanks to Kay Sievers for wpa_supplicant_wrapper.c, which formed the basis for this work, and to Jouni Malinen for writing wpa_ctrl.c and wpa_ctrl.h. * src/Makefile.am src/wpa_ctrl.[ch] - Add wpa_ctrl stuff from wpa_supplicant so we can talk to it * src/NetworkManagerUtils.[ch] - (nm_utils_supplicant_request, nm_utils_supplicant_request_with_check): Add convenience functions for talking to wpa_supplicant * src/nm-ap-security.[ch] src/nm-ap-security-wep.c src/nm-ap-security-wpa-psk.[ch] - Update and implement real_write_supplicant_config functions in all security types - (nm_ap_security_wpa_psk_new_from_ap): implement in nm-ap-security-wpa-psk.c * src/nm-device-802-11-wireless.c - (supplicant_cleanup, supplicant_watch_cb, supplicant_monitor_status_cb, wpa_supplicant_start, wpa_supplicant_interface_init, wpa_supplicant_send_network_config): add functions to talk to wpa_supplicant and write network config to it git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1267 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
207 lines
5.9 KiB
C
207 lines
5.9 KiB
C
/* NetworkManager -- Network link manager
|
|
*
|
|
* Dan Williams <dcbw@redhat.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*
|
|
* (C) Copyright 2005 Red Hat, Inc.
|
|
*/
|
|
|
|
#include <glib.h>
|
|
#include <glib/gi18n.h>
|
|
#include <dbus/dbus.h>
|
|
#include <iwlib.h>
|
|
|
|
#include "nm-ap-security.h"
|
|
#include "nm-ap-security-wep.h"
|
|
#include "nm-ap-security-private.h"
|
|
#include "dbus-helpers.h"
|
|
#include "nm-device-802-11-wireless.h"
|
|
#include "nm-utils.h"
|
|
#include "NetworkManagerUtils.h"
|
|
|
|
#define NM_AP_SECURITY_WEP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WEP, NMAPSecurityWEPPrivate))
|
|
|
|
struct _NMAPSecurityWEPPrivate
|
|
{
|
|
int auth_algorithm;
|
|
};
|
|
|
|
static void set_description (NMAPSecurityWEP *security)
|
|
{
|
|
NMAPSecurity * parent = NM_AP_SECURITY (security);
|
|
|
|
if (nm_ap_security_get_we_cipher (parent) == IW_AUTH_CIPHER_WEP40)
|
|
nm_ap_security_set_description (parent, _("40-bit WEP"));
|
|
else
|
|
nm_ap_security_set_description (parent, _("104-bit WEP"));
|
|
|
|
}
|
|
|
|
NMAPSecurityWEP *
|
|
nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher)
|
|
{
|
|
NMAPSecurityWEP * security = NULL;
|
|
char * key = NULL;
|
|
int key_len;
|
|
int auth_algorithm;
|
|
DBusMessageIter subiter;
|
|
|
|
g_return_val_if_fail (iter != NULL, NULL);
|
|
g_return_val_if_fail ((we_cipher == IW_AUTH_CIPHER_WEP40) || (we_cipher == IW_AUTH_CIPHER_WEP104), NULL);
|
|
|
|
if (!nmu_security_deserialize_wep (iter, &key, &key_len, &auth_algorithm))
|
|
goto out;
|
|
|
|
/* Success, build up our security object */
|
|
security = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL);
|
|
nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher);
|
|
if (key)
|
|
nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len);
|
|
security->priv->auth_algorithm = auth_algorithm;
|
|
|
|
set_description (security);
|
|
|
|
out:
|
|
return security;
|
|
}
|
|
|
|
NMAPSecurityWEP *
|
|
nm_ap_security_wep_new_from_ap (NMAccessPoint *ap, int we_cipher)
|
|
{
|
|
NMAPSecurityWEP * security = NULL;
|
|
|
|
g_return_val_if_fail (ap != NULL, NULL);
|
|
g_return_val_if_fail ((we_cipher == IW_AUTH_CIPHER_WEP40) || (we_cipher == IW_AUTH_CIPHER_WEP104), NULL);
|
|
|
|
security = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL);
|
|
nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher);
|
|
security->priv->auth_algorithm = IW_AUTH_ALG_OPEN_SYSTEM;
|
|
|
|
set_description (security);
|
|
|
|
return security;
|
|
}
|
|
|
|
static int
|
|
real_serialize (NMAPSecurity *instance, DBusMessageIter *iter)
|
|
{
|
|
NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance);
|
|
|
|
if (!nmu_security_serialize_wep (iter,
|
|
nm_ap_security_get_key (instance),
|
|
self->priv->auth_algorithm))
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
static gboolean
|
|
real_write_supplicant_config (NMAPSecurity *instance,
|
|
struct wpa_ctrl *ctrl,
|
|
int nwid)
|
|
{
|
|
NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance);
|
|
gboolean success = FALSE;
|
|
char * msg = NULL;
|
|
const char * key = nm_ap_security_get_key (instance);
|
|
|
|
/* WEP network setup */
|
|
if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL,
|
|
"SET_NETWORK %i key_mgmt NONE", nwid))
|
|
goto out;
|
|
|
|
msg = g_strdup_printf ("SET_NETWORK %i wep_key0 <key>", nwid);
|
|
if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, msg,
|
|
"SET_NETWORK %i wep_key0 %s", nwid, key))
|
|
{
|
|
g_free (msg);
|
|
goto out;
|
|
}
|
|
g_free (msg);
|
|
|
|
if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL,
|
|
"SET_NETWORK %i wep_tx_keyidx 0", nwid))
|
|
goto out;
|
|
|
|
success = TRUE;
|
|
|
|
out:
|
|
return success;
|
|
}
|
|
|
|
static int
|
|
real_device_setup (NMAPSecurity *instance, NMDevice80211Wireless * dev)
|
|
{
|
|
NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance);
|
|
|
|
nm_device_802_11_wireless_set_wep_enc_key (dev, nm_ap_security_get_key (instance),
|
|
self->priv->auth_algorithm);
|
|
return 0;
|
|
}
|
|
|
|
static NMAPSecurity *
|
|
real_copy_constructor (NMAPSecurity *instance)
|
|
{
|
|
NMAPSecurityWEP * dst = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL);
|
|
NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance);
|
|
|
|
dst->priv->auth_algorithm = self->priv->auth_algorithm;
|
|
nm_ap_security_copy_properties (NM_AP_SECURITY (self), NM_AP_SECURITY (dst));
|
|
return NM_AP_SECURITY (dst);
|
|
}
|
|
|
|
static void
|
|
nm_ap_security_wep_init (NMAPSecurityWEP * self)
|
|
{
|
|
self->priv = NM_AP_SECURITY_WEP_GET_PRIVATE (self);
|
|
self->priv->auth_algorithm = IW_AUTH_ALG_OPEN_SYSTEM;
|
|
}
|
|
|
|
static void
|
|
nm_ap_security_wep_class_init (NMAPSecurityWEPClass *klass)
|
|
{
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
NMAPSecurityClass *par_class = NM_AP_SECURITY_CLASS (klass);
|
|
|
|
par_class->copy_constructor_func = real_copy_constructor;
|
|
par_class->serialize_func = real_serialize;
|
|
par_class->write_supplicant_config_func = real_write_supplicant_config;
|
|
par_class->device_setup_func = real_device_setup;
|
|
|
|
g_type_class_add_private (object_class, sizeof (NMAPSecurityWEPPrivate));
|
|
}
|
|
|
|
GType
|
|
nm_ap_security_wep_get_type (void)
|
|
{
|
|
static GType type = 0;
|
|
if (type == 0) {
|
|
static const GTypeInfo info = {
|
|
sizeof (NMAPSecurityWEPClass),
|
|
NULL, /* base_init */
|
|
NULL, /* base_finalize */
|
|
(GClassInitFunc) nm_ap_security_wep_class_init,
|
|
NULL, /* class_finalize */
|
|
NULL, /* class_data */
|
|
sizeof (NMAPSecurityWEP),
|
|
0, /* n_preallocs */
|
|
(GInstanceInitFunc) nm_ap_security_wep_init
|
|
};
|
|
type = g_type_register_static (NM_TYPE_AP_SECURITY,
|
|
"NMAPSecurityWEP",
|
|
&info, 0);
|
|
}
|
|
return type;
|
|
}
|