2004-06-24 14:18:37 +00:00
|
|
|
/* 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 2004 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <iwlib.h>
|
2004-08-29 05:10:16 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
#ifdef HAVE_GCRYPT
|
|
|
|
|
#include <gcrypt.h>
|
|
|
|
|
#else
|
|
|
|
|
#include "gnome-keyring-md5.h"
|
|
|
|
|
#endif
|
2004-06-24 14:18:37 +00:00
|
|
|
#include "NetworkManager.h"
|
|
|
|
|
#include "NetworkManagerDevice.h"
|
|
|
|
|
#include "NetworkManagerWireless.h"
|
|
|
|
|
#include "NetworkManagerPolicy.h"
|
|
|
|
|
#include "NetworkManagerUtils.h"
|
|
|
|
|
|
|
|
|
|
|
2004-09-08 18:14:42 +00:00
|
|
|
/*
|
|
|
|
|
* nm_wireless_md5_digest_to_ascii
|
|
|
|
|
*
|
|
|
|
|
* Convert an MD5 digest into an ascii string suitable for use
|
|
|
|
|
* as a WEP key.
|
|
|
|
|
*
|
|
|
|
|
* Code originally by Alex Larsson <alexl@redhat.com> and
|
|
|
|
|
* copyright Red Hat, Inc. under terms of the LGPL.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static char *nm_wireless_md5_digest_to_ascii (unsigned char digest[16])
|
2004-08-29 05:10:16 +00:00
|
|
|
{
|
2004-09-08 18:14:42 +00:00
|
|
|
static char hex_digits[] = "0123456789abcdef";
|
|
|
|
|
unsigned char *res;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
res = g_malloc (33);
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
res[2*i] = hex_digits[digest[i] >> 4];
|
|
|
|
|
res[2*i+1] = hex_digits[digest[i] & 0xf];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We chomp it at byte 26, since WEP keys only use 104 bits */
|
|
|
|
|
res[26] = 0;
|
|
|
|
|
|
|
|
|
|
return (res);
|
2004-08-29 05:10:16 +00:00
|
|
|
}
|
2004-06-24 14:18:37 +00:00
|
|
|
|
2004-09-08 18:14:42 +00:00
|
|
|
|
2004-07-28 02:49:33 +00:00
|
|
|
/*
|
|
|
|
|
* nm_wireless_128bit_key_from_passphrase
|
|
|
|
|
*
|
|
|
|
|
* From a passphrase, generate a standard 128-bit WEP key using
|
|
|
|
|
* MD5 algorithm.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
char *nm_wireless_128bit_key_from_passphrase (char *passphrase)
|
|
|
|
|
{
|
2004-09-08 18:14:42 +00:00
|
|
|
char md5_data[65];
|
|
|
|
|
unsigned char digest[16];
|
|
|
|
|
int passphrase_len;
|
|
|
|
|
int i;
|
2004-07-28 02:49:33 +00:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (passphrase != NULL, NULL);
|
2004-08-26 02:27:02 +00:00
|
|
|
|
2004-07-28 02:49:33 +00:00
|
|
|
passphrase_len = strlen (passphrase);
|
2004-08-26 02:27:02 +00:00
|
|
|
if (passphrase_len < 1)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
/* Get at least 64 bits */
|
2004-07-28 02:49:33 +00:00
|
|
|
for (i = 0; i < 64; i++)
|
2004-09-08 18:14:42 +00:00
|
|
|
md5_data [i] = passphrase [i % passphrase_len];
|
|
|
|
|
|
|
|
|
|
/* Null terminate md5 data-to-hash and hash it */
|
|
|
|
|
md5_data[64] = 0;
|
|
|
|
|
#ifdef HAVE_GCRYPT
|
|
|
|
|
gcry_md_hash_buffer (GCRY_MD_MD5, digest, md5_data, 64);
|
|
|
|
|
#else
|
|
|
|
|
gnome_keyring_md5_string (md5_data, digest);
|
|
|
|
|
#endif
|
2004-07-28 02:49:33 +00:00
|
|
|
|
2004-09-08 18:14:42 +00:00
|
|
|
return (nm_wireless_md5_digest_to_ascii (digest));
|
2004-07-28 02:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-06-24 14:18:37 +00:00
|
|
|
/*
|
|
|
|
|
* nm_wireless_scan_monitor
|
|
|
|
|
*
|
|
|
|
|
* Called every 10s to get a list of access points.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
gboolean nm_wireless_scan_monitor (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMData *data = (NMData *)user_data;
|
2004-09-09 20:02:59 +00:00
|
|
|
GSList *element;
|
|
|
|
|
NMDevice *dev;
|
2004-06-24 14:18:37 +00:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (data != NULL, TRUE);
|
2004-07-06 01:34:10 +00:00
|
|
|
|
|
|
|
|
/* Attempt to acquire mutex so that data->active_device sticks around.
|
2004-06-24 14:18:37 +00:00
|
|
|
* If the acquire fails, just ignore the scan completely.
|
|
|
|
|
*/
|
2004-09-09 20:02:59 +00:00
|
|
|
if (!nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
2004-06-24 14:18:37 +00:00
|
|
|
{
|
2004-09-09 20:02:59 +00:00
|
|
|
syslog (LOG_ERR, "nm_wireless_scan_monitor() could not acquire device list mutex." );
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|
2004-06-24 14:18:37 +00:00
|
|
|
|
2004-09-09 20:02:59 +00:00
|
|
|
element = data->dev_list;
|
|
|
|
|
while (element)
|
|
|
|
|
{
|
|
|
|
|
if ((dev = (NMDevice *)(element->data)) && nm_device_is_wireless (dev))
|
|
|
|
|
nm_device_do_wireless_scan (dev);
|
|
|
|
|
element = g_slist_next (element);
|
2004-06-24 14:18:37 +00:00
|
|
|
}
|
2004-09-09 20:02:59 +00:00
|
|
|
|
|
|
|
|
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
2004-06-24 14:18:37 +00:00
|
|
|
|
|
|
|
|
return (TRUE);
|
|
|
|
|
}
|