2007-09-12 Dan Williams <dcbw@redhat.com>

Wireless connections can be made with config data from the applet now.
	
	Yay.

	* src/supplicant-manager/nm-supplicant-config.h
	  src/supplicant-manager/nm-supplicant-config.c
		- (nm_supplicant_config_new): kill unused init parameter 'iface'
		- (nm_supplicant_config_add_setting_wireless,
		   nm_supplicant_config_add_setting_wireless_security): new functions;
			add key/value pairs from the settings objects to the supplicant
			config

	* src/nm-device-802-11-wireless.c
		- (cull_scan_list): fix check to not prune currently associated AP
		- (build_supplicant_config, real_act_stage2_config): call the functions
			of the NMSupplicantConfig that parse settings objects rather than
			doing it manually here



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2796 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2007-09-12 04:53:23 +00:00
parent 7d0e13919c
commit 594dd3f208
4 changed files with 214 additions and 66 deletions

View file

@ -1,3 +1,23 @@
2007-09-12 Dan Williams <dcbw@redhat.com>
Wireless connections can be made with config data from the applet now.
Yay.
* src/supplicant-manager/nm-supplicant-config.h
src/supplicant-manager/nm-supplicant-config.c
- (nm_supplicant_config_new): kill unused init parameter 'iface'
- (nm_supplicant_config_add_setting_wireless,
nm_supplicant_config_add_setting_wireless_security): new functions;
add key/value pairs from the settings objects to the supplicant
config
* src/nm-device-802-11-wireless.c
- (cull_scan_list): fix check to not prune currently associated AP
- (build_supplicant_config, real_act_stage2_config): call the functions
of the NMSupplicantConfig that parse settings objects rather than
doing it manually here
2007-09-12 Dan Williams <dcbw@redhat.com>
* src/supplicant-manager/nm-supplicant-interface.c

View file

@ -1723,32 +1723,32 @@ cull_scan_list (NMDevice80211Wireless * self)
GTimeVal cur_time;
GSList * outdated_list = NULL;
GSList * elt;
NMAccessPoint * cur_ap = NULL;
NMActRequest * req;
const char * cur_ap_path = NULL;
g_return_if_fail (self != NULL);
g_get_current_time (&cur_time);
req = nm_device_get_act_request (NM_DEVICE (self));
if (req)
cur_ap_path = nm_act_request_get_specific_object (req);
/* Walk the access point list and remove any access points older than
* three times the inactive scan interval.
*/
for (elt = self->priv->ap_list; elt; elt = g_slist_next (elt)) {
NMAccessPoint * outdated_ap = NM_AP (elt->data);
const glong ap_time = nm_ap_get_last_seen (outdated_ap);
gboolean keep_around = FALSE;
guint prune_interval_s = SCAN_INTERVAL_MAX * 3;
const GByteArray * ssid;
const GByteArray * cur_ssid;
NMAccessPoint * ap = NM_AP (elt->data);
const glong ap_time = nm_ap_get_last_seen (ap);
gboolean keep = FALSE;
const guint prune_interval_s = SCAN_INTERVAL_MAX * 3;
/* Don't ever prune the AP we're currently associated with */
ssid = nm_ap_get_ssid (outdated_ap);
// FIXME: get cur_ap somehow
cur_ssid = cur_ap ? nm_ap_get_ssid (cur_ap) : NULL;
if (ssid && nm_utils_same_ssid (cur_ssid, ssid, TRUE))
keep_around = TRUE;
if (cur_ap_path && !strcmp (cur_ap_path, nm_ap_get_dbus_path (ap)))
keep = TRUE;
if (!keep_around && (ap_time + prune_interval_s < cur_time.tv_sec))
outdated_list = g_slist_append (outdated_list, outdated_ap);
if (!keep && (ap_time + prune_interval_s < cur_time.tv_sec))
outdated_list = g_slist_append (outdated_list, ap);
}
/* Remove outdated APs */
@ -2336,61 +2336,41 @@ remove_supplicant_timeouts (NMDevice80211Wireless *self)
remove_link_timeout (self);
}
static NMSupplicantConfig *
build_supplicant_config (NMDevice80211Wireless *self)
build_supplicant_config (NMDevice80211Wireless *self,
NMConnection *connection,
NMAccessPoint *ap)
{
NMSupplicantConfig * config = NULL;
NMAccessPoint * ap = NULL;
const GByteArray * ssid;
gboolean is_adhoc;
gboolean is_adhoc = FALSE;
NMSettingWireless * s_wireless;
NMSettingWirelessSecurity *s_wireless_sec;
g_return_val_if_fail (self != NULL, NULL);
ap = nm_device_802_11_wireless_get_activation_ap (self);
g_assert (ap);
s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, "802-11-wireless");
g_return_val_if_fail (s_wireless != NULL, NULL);
config = nm_supplicant_config_new (nm_device_get_iface (NM_DEVICE (self)));
if (config == NULL)
goto out;
config = nm_supplicant_config_new ();
if (!config)
return NULL;
/* Use "AP_SCAN 2" if the wireless network is non-broadcast or Ad-Hoc */
is_adhoc = (nm_ap_get_mode(ap) == IW_MODE_ADHOC);
if (!nm_ap_get_broadcast (ap) || is_adhoc) {
nm_supplicant_config_set_ap_scan (config, 2);
}
ssid = nm_ap_get_ssid (ap);
if (!ssid) {
nm_warning ("can't add null ssid to config.");
if (!nm_supplicant_config_add_setting_wireless (config,
s_wireless,
nm_ap_get_broadcast (ap))) {
nm_warning ("Couldn't add 802-11-wireless setting to supplicant config.");
goto error;
}
nm_supplicant_config_add_option (config, "ssid", (const char *) ssid->data, ssid->len);
/* For non-broadcast networks, we need to set "scan_ssid 1" to scan with probe request frames.
* However, don't try to probe Ad-Hoc networks.
*/
if (!nm_ap_get_broadcast (ap) && !is_adhoc) {
if (!nm_supplicant_config_add_option (config, "scan_ssid", "1", -1))
goto error;
}
/* Ad-Hoc ? */
if (is_adhoc) {
if (!nm_supplicant_config_add_option (config, "mode", "1", -1))
goto error;
}
#if 0
// FIXME: send nm-802-11-wireless & nm-802-11-wireless-security
// settings objects to the supplicant
if (!nm_ap_security_write_supplicant_config (nm_ap_get_security (ap),
config,
is_adhoc))
s_wireless_sec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, "802-11-wireless-security");
if ( s_wireless_sec
&& !nm_supplicant_config_add_setting_wireless_security (config,
s_wireless_sec)) {
nm_warning ("Couldn't add 802-11-wireless-security setting to supplicant config.");
goto error;
#endif
}
out:
return config;
error:
@ -2471,6 +2451,7 @@ real_act_stage2_config (NMDevice *dev)
NMSupplicantConfig * config = NULL;
gulong id = 0;
NMActRequest * req;
NMAccessPoint * ap;
NMConnection * connection;
NMSettingConnection * s_connection;
const char * setting_name;
@ -2480,6 +2461,9 @@ real_act_stage2_config (NMDevice *dev)
req = nm_device_get_act_request (dev);
g_assert (req);
ap = nm_device_802_11_wireless_get_activation_ap (self);
g_assert (ap);
connection = nm_act_request_get_connection (req);
g_assert (connection);
@ -2504,7 +2488,7 @@ real_act_stage2_config (NMDevice *dev)
iface, s_connection->name);
}
config = build_supplicant_config (self);
config = build_supplicant_config (self, connection, ap);
if (config == NULL) {
nm_warning ("Activation (%s/wireless): couldn't build wireless "
"configuration.", iface);

View file

@ -28,7 +28,8 @@
#include "nm-supplicant-settings-verify.h"
#include "nm-utils.h"
#include "dbus-dict-helpers.h"
#include "cipher.h"
#include "nm-setting.h"
#include "NetworkManagerUtils.h"
#define NM_SUPPLICANT_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_SUPPLICANT_CONFIG, \
@ -44,23 +45,17 @@ typedef struct {
typedef struct
{
char * ifname;
GHashTable *config;
guint32 ap_scan;
gboolean dispose_has_run;
} NMSupplicantConfigPrivate;
NMSupplicantConfig *
nm_supplicant_config_new (const char *ifname)
nm_supplicant_config_new (void)
{
NMSupplicantConfig * scfg;
g_return_val_if_fail (ifname != NULL, NULL);
scfg = g_object_new (NM_TYPE_SUPPLICANT_CONFIG, NULL);
NM_SUPPLICANT_CONFIG_GET_PRIVATE (scfg)->ifname = g_strdup (ifname);
return scfg;
return g_object_new (NM_TYPE_SUPPLICANT_CONFIG, NULL);
}
static void
@ -135,6 +130,12 @@ nm_supplicant_config_add_option (NMSupplicantConfig *self,
opt->len = len;
opt->type = type;
{
char buf[255];
memset (&buf[0], 0, sizeof (buf));
memcpy (&buf[0], opt->value, opt->len > 254 ? 254 : opt->len);
nm_info ("Config: added '%s' value '%s'", key, &buf[0]);
}
g_hash_table_insert (priv->config, g_strdup (key), opt);
return TRUE;
@ -246,3 +247,138 @@ nm_supplicant_config_get_hash (NMSupplicantConfig * self)
return hash;
}
gboolean
nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self,
NMSettingWireless * setting,
gboolean is_broadcast)
{
NMSupplicantConfigPrivate *priv;
gboolean is_adhoc;
g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), FALSE);
g_return_val_if_fail (setting != NULL, FALSE);
priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self);
is_adhoc = (setting->mode && !strcmp (setting->mode, "adhoc")) ? TRUE : FALSE;
if (!is_broadcast || is_adhoc)
priv->ap_scan = 2;
if (!nm_supplicant_config_add_option (self, "ssid",
setting->ssid->data,
setting->ssid->len)) {
nm_warning ("Error adding SSID to supplicant config.");
return FALSE;
}
if (is_adhoc) {
if (!nm_supplicant_config_add_option (self, "mode", "1", -1)) {
nm_warning ("Error adding mode to supplicant config.");
return FALSE;
}
}
/* For non-broadcast networks, we need to set "scan_ssid 1" to scan with
* probe request frames. However, don't try to probe Ad-Hoc networks.
*/
if (!is_broadcast && !is_adhoc) {
if (!nm_supplicant_config_add_option (self, "scan_ssid", "1", -1))
return FALSE;
}
if (setting->bssid) {
if (!nm_supplicant_config_add_option (self, "bssid",
setting->bssid->data,
setting->bssid->len)) {
nm_warning ("Error adding BSSID to supplicant config.");
return FALSE;
}
}
// FIXME: band & channel config items
return TRUE;
}
#define ADD_STRING_VAL(field, name, ucase, unhexify) \
if (field) { \
if (ucase) \
value = g_ascii_strup (field, -1); \
else if (unhexify) { \
value = nm_utils_hexstr2bin (field, strlen (field)); \
} else \
value = g_strdup (field); \
success = nm_supplicant_config_add_option (self, name, value, -1); \
g_free (value); \
if (!success) { \
nm_warning ("Error adding %s to supplicant config.", name); \
return FALSE; \
} \
}
#define ADD_STRING_LIST_VAL(field, name) \
if (field) { \
GSList *elt; \
GString *str = g_string_new (NULL); \
for (elt = field; elt; elt = g_slist_next (elt)) { \
if (!str->len) { \
g_string_append (str, elt->data); \
} else { \
g_string_append_c (str, ' '); \
g_string_append (str, elt->data); \
} \
} \
success = nm_supplicant_config_add_option (self, name, str->str, -1); \
g_string_free (str, TRUE); \
if (!success) { \
nm_warning ("Error adding %s to supplicant config.", name); \
return FALSE; \
} \
}
gboolean
nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig * self,
NMSettingWirelessSecurity * setting)
{
NMSupplicantConfigPrivate *priv;
char * value;
gboolean success;
g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), FALSE);
g_return_val_if_fail (setting != NULL, FALSE);
priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self);
ADD_STRING_VAL (setting->key_mgmt, "key_mgmt", TRUE, FALSE);
ADD_STRING_VAL (setting->auth_alg, "auth_alg", TRUE, FALSE);
ADD_STRING_VAL (setting->proto, "proto", TRUE, FALSE);
ADD_STRING_VAL (setting->identity, "identity", FALSE, FALSE);
ADD_STRING_VAL (setting->anonymous_identity, "anonymous_identity", FALSE, FALSE);
ADD_STRING_VAL (setting->nai, "nai", FALSE, FALSE);
ADD_STRING_VAL (setting->wep_key0, "wep_key0", FALSE, TRUE);
ADD_STRING_VAL (setting->wep_key1, "wep_key1", FALSE, TRUE);
ADD_STRING_VAL (setting->wep_key2, "wep_key2", FALSE, TRUE);
ADD_STRING_VAL (setting->wep_key3, "wep_key3", FALSE, TRUE);
ADD_STRING_VAL (setting->psk, "psk", FALSE, TRUE);
ADD_STRING_VAL (setting->password, "password", FALSE, TRUE);
ADD_STRING_VAL (setting->pin, "pin", FALSE, FALSE);
ADD_STRING_VAL (setting->eappsk, "eappsk", FALSE, TRUE);
ADD_STRING_VAL (setting->private_key_passwd, "private_key_passwd", FALSE, FALSE);
ADD_STRING_VAL (setting->phase2_private_key_passwd, "phase2_private_key_passwd", FALSE, FALSE);
ADD_STRING_LIST_VAL (setting->pairwise, "pairwise");
ADD_STRING_LIST_VAL (setting->group, "group");
ADD_STRING_LIST_VAL (setting->eap, "eap");
value = g_strdup_printf ("%d", setting->wep_tx_keyidx);
success = nm_supplicant_config_add_option (self, "wep_tx_keyidx", value, -1);
g_free (value);
if (!success) {
nm_warning ("Error adding wep_tx_keyidx to supplicant config.");
return FALSE;
}
return TRUE;
}

View file

@ -24,6 +24,7 @@
#include <glib-object.h>
#include "nm-supplicant-types.h"
#include "nm-setting.h"
G_BEGIN_DECLS
@ -47,7 +48,7 @@ typedef struct
GType nm_supplicant_config_get_type (void);
NMSupplicantConfig * nm_supplicant_config_new (const char *ifname);
NMSupplicantConfig * nm_supplicant_config_new (void);
gboolean nm_supplicant_config_add_option (NMSupplicantConfig *scfg,
const char * key,
@ -64,6 +65,13 @@ void nm_supplicant_config_set_ap_scan (NMSupplicantConfig * self,
GHashTable *nm_supplicant_config_get_hash (NMSupplicantConfig * self);
gboolean nm_supplicant_config_add_setting_wireless (NMSupplicantConfig * self,
NMSettingWireless * setting,
gboolean is_broadcast);
gboolean nm_supplicant_config_add_setting_wireless_security (NMSupplicantConfig * self,
NMSettingWirelessSecurity * setting);
G_END_DECLS
#endif /* NM_SUPPLICANT_CONFIG_H */