From 7ae6819f31530b74bf021f0c65a68acb538aa484 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Dec 2005 20:48:08 +0000 Subject: [PATCH] 2005-12-14 Dan Williams * include/NetworkManager.h src/NetworkManagerWireless.c - Rearrange 802.11 wireless-specific capabilities again * src/Makefile.am - Forgot to add wpa.c/wpa.h to the makefiles * src/NetworkManagerAP.[ch] - Implement access point capabilities and parse the WPA/RSN IEs into the capability bitfield - Switch the "encrypted" attribute to utilize the bitfield and capabilities rather than being independent * src/NetworkManagerDevice.c - (nm_device_wireless_get_activation_ap): break it horribly until we can push NMAPSecurity objects into access point objects and through the activation chain - Stuff WPA & RSN IEs into AP capabilities * src/nm-dbus-nm.c - Take a shot at actually making setActiveDevice work * src/wpa.[ch] - Make the API a bit saner git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1191 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 27 +++++++++ include/NetworkManager.h | 20 +++---- src/Makefile.am | 4 +- src/NetworkManagerAP.c | 104 ++++++++++++++--------------------- src/NetworkManagerAP.h | 10 +--- src/NetworkManagerDevice.c | 21 ++++--- src/NetworkManagerDevice.h | 3 +- src/NetworkManagerWireless.c | 20 +++++-- src/nm-dbus-nm.c | 72 +++++++++++------------- src/wpa.c | 34 +++++++----- src/wpa.h | 6 +- 11 files changed, 163 insertions(+), 158 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6bd3480568..ca9a10f418 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2005-12-14 Dan Williams + + * include/NetworkManager.h + src/NetworkManagerWireless.c + - Rearrange 802.11 wireless-specific capabilities again + + * src/Makefile.am + - Forgot to add wpa.c/wpa.h to the makefiles + + * src/NetworkManagerAP.[ch] + - Implement access point capabilities and parse the + WPA/RSN IEs into the capability bitfield + - Switch the "encrypted" attribute to utilize the bitfield + and capabilities rather than being independent + + * src/NetworkManagerDevice.c + - (nm_device_wireless_get_activation_ap): break it horribly + until we can push NMAPSecurity objects into access point + objects and through the activation chain + - Stuff WPA & RSN IEs into AP capabilities + + * src/nm-dbus-nm.c + - Take a shot at actually making setActiveDevice work + + * src/wpa.[ch] + - Make the API a bit saner + 2005-12-14 Dan Williams * include/NetworkManager.h diff --git a/include/NetworkManager.h b/include/NetworkManager.h index e0541ac226..bda9e7642e 100644 --- a/include/NetworkManager.h +++ b/include/NetworkManager.h @@ -105,22 +105,18 @@ typedef enum NMEncKeyType /* 802.11 wireless-specific device capability bits */ #define NM_802_11_CAP_NONE 0x00000000 -#define NM_802_11_CAP_KEY_MGMT_WPA 0x00000001 -#define NM_802_11_CAP_KEY_MGMT_WPA_PSK 0x00000002 -#define NM_802_11_CAP_KEY_MGMT_WPA2 0x00000004 -#define NM_802_11_CAP_KEY_MGMT_WPA2_PSK 0x00000008 -#define NM_802_11_CAP_KEY_MGMT_IEEE8021X 0x00000010 -#define NM_802_11_CAP_KEY_MGMT_RESERVED1 0x00000020 -#define NM_802_11_CAP_KEY_MGMT_RESERVED2 0x00000040 -#define NM_802_11_CAP_KEY_MGMT_RESERVED3 0x00000080 +#define NM_802_11_CAP_PROTO_WEP 0x00000001 +#define NM_802_11_CAP_PROTO_WPA 0x00000002 +#define NM_802_11_CAP_PROTO_WPA2 0x00000004 +#define NM_802_11_CAP_RESERVED1 0x00000008 +#define NM_802_11_CAP_KEY_MGMT_PSK 0x00000010 +#define NM_802_11_CAP_KEY_MGMT_802_1X 0x00000020 +#define NM_802_11_CAP_RESERVED2 0x00000040 +#define NM_802_11_CAP_RESERVED3 0x00000080 #define NM_802_11_CAP_CIPHER_WEP40 0x00000100 #define NM_802_11_CAP_CIPHER_WEP104 0x00000200 #define NM_802_11_CAP_CIPHER_TKIP 0x00000400 #define NM_802_11_CAP_CIPHER_CCMP 0x00000800 -#define NM_802_11_CAP_CIPHER_RESERVED1 0x00001000 -#define NM_802_11_CAP_CIPHER_RESERVED2 0x00002000 -#define NM_802_11_CAP_CIPHER_RESERVED3 0x00004000 -#define NM_802_11_CAP_CIPHER_RESERVED4 0x00008000 /* diff --git a/src/Makefile.am b/src/Makefile.am index 5b3512692a..b0414c5573 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,7 +54,9 @@ NetworkManager_SOURCES = \ nm-ap-security-wep.c \ nm-ap-security-wep.h \ nm-ap-security-wpa-psk.c \ - nm-ap-security-wpa-psk.h + nm-ap-security-wpa-psk.h \ + wpa.c \ + wpa.h NetworkManager_CPPFLAGS = \ $(DBUS_CFLAGS) \ diff --git a/src/NetworkManagerAP.c b/src/NetworkManagerAP.c index 35386c8909..e4771f3df4 100644 --- a/src/NetworkManagerAP.c +++ b/src/NetworkManagerAP.c @@ -23,6 +23,7 @@ #include "NetworkManagerUtils.h" #include "nm-utils.h" #include "NetworkManagerWireless.h" +#include "nm-ap-security.h" #include @@ -40,15 +41,8 @@ struct NMAccessPoint gint8 strength; double freq; guint16 rate; - gboolean encrypted; guint32 capabilities; - /* WPA auxiliary information */ - guint8 * wpa_ie; - guint32 wpa_ie_len; - guint8 * rsn_ie; - guint32 rsn_ie_len; - /* Non-scanned attributes */ gboolean invalid; gboolean matched; /* used in ap list diffing */ @@ -58,11 +52,14 @@ struct NMAccessPoint /* Things from user prefs/NetworkManagerInfo */ gboolean trusted; + NMAPSecurity * security; + GTimeVal timestamp; + GSList * user_addresses; + + /* Soon to be banished */ char * enc_key; NMEncKeyType enc_type; int auth_method; /* from wireless.h; -1 is unknown, zero is none */ - GTimeVal timestamp; - GSList * user_addresses; }; /* This is a controlled list. Want to add to it? Stop. Ask first. */ @@ -134,7 +131,7 @@ NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *src_ap) new_ap->strength = src_ap->strength; new_ap->freq = src_ap->freq; new_ap->rate = src_ap->rate; - new_ap->encrypted = src_ap->encrypted; + new_ap->capabilities = src_ap->capabilities; if (src_ap->enc_key && (strlen (src_ap->enc_key) > 0)) new_ap->enc_key = g_strdup (src_ap->enc_key); @@ -286,14 +283,17 @@ gboolean nm_ap_get_encrypted (const NMAccessPoint *ap) { g_return_val_if_fail (ap != NULL, FALSE); - return (ap->encrypted); + return (ap->capabilities & NM_802_11_CAP_PROTO_WEP); } -void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean encrypted) +void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy) { g_return_if_fail (ap != NULL); - ap->encrypted = encrypted; + if (privacy) + ap->capabilities |= NM_802_11_CAP_PROTO_WEP; + else + ap->capabilities &= ~NM_802_11_CAP_PROTO_WEP; } @@ -652,65 +652,41 @@ gboolean nm_ap_has_manufacturer_default_essid (NMAccessPoint *ap) } -const guint8 * nm_ap_get_wpa_ie (NMAccessPoint *ap, guint32 *length) +static void set_capabilities_from_cipher (NMAccessPoint *ap, int cipher) { - g_return_val_if_fail (ap != NULL, NULL); - g_return_val_if_fail (length != NULL, NULL); - - *length = ap->wpa_ie_len; - return ap->wpa_ie; + if (cipher & IW_AUTH_CIPHER_WEP40) + ap->capabilities |= NM_802_11_CAP_CIPHER_WEP40; + if (cipher & IW_AUTH_CIPHER_WEP104) + ap->capabilities |= NM_802_11_CAP_CIPHER_WEP104; + if (cipher & IW_AUTH_CIPHER_TKIP) + ap->capabilities |= NM_802_11_CAP_CIPHER_TKIP; + if (cipher & IW_AUTH_CIPHER_CCMP) + ap->capabilities |= NM_802_11_CAP_CIPHER_CCMP; } -void nm_ap_set_wpa_ie (NMAccessPoint *ap, const char *wpa_ie, guint32 length) +void nm_ap_set_capabilities_from_wpa_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length) { + wpa_ie_data * cap_data; + g_return_if_fail (ap != NULL); - if (wpa_ie) - g_return_if_fail ((length > 0) && (length <= WPA_MAX_IE_LEN)); + if (!(cap_data = wpa_parse_wpa_ie (wpa_ie, length))) + return; - if (ap->wpa_ie) - { - g_free (ap->wpa_ie); - ap->wpa_ie = NULL; - ap->wpa_ie_len = 0; - } + ap->capabilities = NM_802_11_CAP_NONE; - if (wpa_ie) - { - ap->wpa_ie = g_malloc0 (length); - ap->wpa_ie_len = length; - memcpy (ap->wpa_ie, wpa_ie, length); - } + if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA) + ap->capabilities |= NM_802_11_CAP_PROTO_WPA; + if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA2) + ap->capabilities |= NM_802_11_CAP_PROTO_WPA2; + + set_capabilities_from_cipher (ap, cap_data->pairwise_cipher); + set_capabilities_from_cipher (ap, cap_data->group_cipher); + + if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_802_1X) + ap->capabilities |= NM_802_11_CAP_KEY_MGMT_802_1X; + if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_PSK) + ap->capabilities |= NM_802_11_CAP_KEY_MGMT_PSK; } -const guint8 * nm_ap_get_rsn_ie (NMAccessPoint *ap, guint32 *length) -{ - g_return_val_if_fail (ap != NULL, NULL); - g_return_val_if_fail (length != NULL, NULL); - - *length = ap->rsn_ie_len; - return ap->rsn_ie; -} - -void nm_ap_set_rsn_ie (NMAccessPoint *ap, const char *rsn_ie, guint32 length) -{ - g_return_if_fail (ap != NULL); - - if (rsn_ie) - g_return_if_fail ((length > 0) && (length <= WPA_MAX_IE_LEN)); - - if (ap->rsn_ie) - { - g_free (ap->rsn_ie); - ap->rsn_ie = NULL; - ap->rsn_ie_len = 0; - } - - if (rsn_ie) - { - ap->rsn_ie = g_malloc0 (length); - ap->rsn_ie_len = length; - memcpy (ap->rsn_ie, rsn_ie, length); - } -} diff --git a/src/NetworkManagerAP.h b/src/NetworkManagerAP.h index 661edbfbe8..da3cbd8b06 100644 --- a/src/NetworkManagerAP.h +++ b/src/NetworkManagerAP.h @@ -51,9 +51,9 @@ int nm_ap_get_auth_method (const NMAccessPoint *ap); void nm_ap_set_auth_method (NMAccessPoint *ap, int auth_method); gboolean nm_ap_get_encrypted (const NMAccessPoint *ap); -void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean encrypted); +void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy); -const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap); +const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap); void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr); int nm_ap_get_mode (const NMAccessPoint *ap); @@ -93,11 +93,7 @@ void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list); gboolean nm_ap_is_enc_key_valid (NMAccessPoint *ap); gboolean nm_is_enc_key_valid (const char *key, NMEncKeyType key_type); -const guint8 * nm_ap_get_wpa_ie (NMAccessPoint *ap, guint32 *length); -void nm_ap_set_wpa_ie (NMAccessPoint *ap, const char *wpa_ie, guint32 length); - -const guint8 * nm_ap_get_rsn_ie (NMAccessPoint *ap, guint32 *length); -void nm_ap_set_rsn_ie (NMAccessPoint *ap, const char *rsn_ie, guint32 length); +void nm_ap_set_capabilities_from_wpa_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length); /* * NOTE: diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index 431ebc513a..4d0ec530cd 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -3777,7 +3777,7 @@ NMAccessPoint * nm_device_get_best_ap (NMDevice *dev) * request. * */ -NMAccessPoint * nm_device_wireless_get_activation_ap (NMDevice *dev, const char *essid, const char *key, NMEncKeyType key_type) +NMAccessPoint * nm_device_wireless_get_activation_ap (NMDevice *dev, const char *essid, NMAPSecurity *security) { gboolean encrypted = FALSE; NMAccessPoint *ap = NULL; @@ -3789,6 +3789,7 @@ NMAccessPoint * nm_device_wireless_get_activation_ap (NMDevice *dev, const char nm_debug ("Forcing AP '%s'", essid); +#if 0 if ( key && strlen (key) && (key_type != NM_ENC_TYPE_UNKNOWN) @@ -3834,6 +3835,7 @@ NMAccessPoint * nm_device_wireless_get_activation_ap (NMDevice *dev, const char /* Use the encryption key and type the user sent us if its valid */ if (encrypted) nm_ap_set_enc_key_source (ap, key, key_type); +#endif return ap; } @@ -4610,7 +4612,7 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin /* New AP with some defaults */ ap = nm_ap_new (); nm_ap_set_address (ap, (const struct ether_addr *)(iwe->u.ap_addr.sa_data)); - nm_ap_set_auth_method (ap, 0); + nm_ap_set_auth_method (ap, IW_AUTH_ALG_OPEN_SYSTEM); nm_ap_set_mode (ap, IW_MODE_INFRA); break; case SIOCGIWMODE: @@ -4656,10 +4658,7 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin break; case SIOCGIWENCODE: if (!(iwe->u.data.flags & IW_ENCODE_DISABLED)) - { nm_ap_set_encrypted (ap, TRUE); - nm_ap_set_auth_method (ap, IW_AUTH_ALG_OPEN_SYSTEM); - } break; #if 0 case SIOCGIWRATE: @@ -4688,9 +4687,9 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin nm_warning ("get_scan_results(): IWEVGENIE overflow."); break; } - while ((gpos + 1 < gend) && (gpos + 2 + (u8) gpos[1] <= gend)) + while ((gpos + 1 < gend) && (gpos + 2 + (guint8) gpos[1] <= gend)) { - u8 ie = gpos[0], ielen = gpos[1] + 2; + guint8 ie = gpos[0], ielen = gpos[1] + 2; if (ielen > WPA_MAX_IE_LEN) { gpos += ielen; @@ -4701,10 +4700,10 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin case WPA_GENERIC_INFO_ELEM: if ((ielen < 2 + 4) || (memcmp (&gpos[2], "\x00\x50\xf2\x01", 4) != 0)) break; - nm_ap_set_wpa_ie (ap, gpos, ielen); + nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)gpos, ielen); break; case WPA_RSN_INFO_ELEM: - nm_ap_set_rsn_ie (ap, gpos, ielen); + nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)gpos, ielen); break; } gpos += ielen; @@ -4733,9 +4732,9 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin ie_buf = g_malloc0 (bytes); hexstr2bin (spos, ie_buf, bytes); if (strncmp (custom, "wpa_ie=", 7) == 0) - nm_ap_set_wpa_ie (ap, ie_buf, bytes); + nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)ie_buf, bytes); else if (strncmp (custom, "rsn_ie=", 7) == 0) - nm_ap_set_rsn_ie (ap, ie_buf, bytes); + nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)ie_buf, bytes); g_free (ie_buf); } break; diff --git a/src/NetworkManagerDevice.h b/src/NetworkManagerDevice.h index d9092fd81b..a98b4ce6c1 100644 --- a/src/NetworkManagerDevice.h +++ b/src/NetworkManagerDevice.h @@ -27,6 +27,7 @@ #include "NetworkManager.h" #include "NetworkManagerMain.h" #include "nm-ip4-config.h" +#include "nm-ap-security.h" #if 0 #define IOCTL_DEBUG @@ -112,7 +113,7 @@ gboolean nm_device_is_activating (NMDevice *dev); gboolean nm_device_deactivate_quickly (NMDevice *dev); gboolean nm_device_deactivate (NMDevice *dev); -NMAccessPoint *nm_device_wireless_get_activation_ap (NMDevice *dev, const char *essid, const char *key, NMEncKeyType key_type); +NMAccessPoint *nm_device_wireless_get_activation_ap (NMDevice *dev, const char *essid, NMAPSecurity *security); void nm_device_set_user_key_for_network (NMActRequest *req, const char *key, const NMEncKeyType enc_type); diff --git a/src/NetworkManagerWireless.c b/src/NetworkManagerWireless.c index e1ac1170cd..b4bbad2ff3 100644 --- a/src/NetworkManagerWireless.c +++ b/src/NetworkManagerWireless.c @@ -286,10 +286,10 @@ guint32 nm_802_11_wireless_discover_capabilities (NMDevice *dev, iwrange * range /* A test wireless device is a pro at everything */ if (nm_device_is_test_device (dev)) { - caps |= NM_802_11_CAP_KEY_MGMT_WPA - | NM_802_11_CAP_KEY_MGMT_WPA2 - | NM_802_11_CAP_KEY_MGMT_WPA_PSK - | NM_802_11_CAP_KEY_MGMT_WPA2_PSK + caps |= NM_802_11_CAP_PROTO_WPA + | NM_802_11_CAP_PROTO_WPA2 + | NM_802_11_CAP_KEY_MGMT_PSK + | NM_802_11_CAP_KEY_MGMT_802_1X | NM_802_11_CAP_CIPHER_WEP40 | NM_802_11_CAP_CIPHER_WEP104 | NM_802_11_CAP_CIPHER_TKIP @@ -303,9 +303,17 @@ guint32 nm_802_11_wireless_discover_capabilities (NMDevice *dev, iwrange * range if ((data_len >= minlen) && range->we_version_compiled >= 18) { if (range->enc_capa & IW_ENC_CAPA_WPA) - caps |= NM_802_11_CAP_KEY_MGMT_WPA | NM_802_11_CAP_KEY_MGMT_WPA_PSK; + { + caps |= NM_802_11_CAP_PROTO_WPA + | NM_802_11_CAP_KEY_MGMT_PSK + | NM_802_11_CAP_KEY_MGMT_802_1X; + } if (range->enc_capa & IW_ENC_CAPA_WPA2) - caps |= NM_802_11_CAP_KEY_MGMT_WPA2 | NM_802_11_CAP_KEY_MGMT_WPA2_PSK; + { + caps |= NM_802_11_CAP_PROTO_WPA2 + | NM_802_11_CAP_KEY_MGMT_PSK + | NM_802_11_CAP_KEY_MGMT_802_1X; + } if (range->enc_capa & IW_ENC_CAPA_CIPHER_TKIP) caps |= NM_802_11_CAP_CIPHER_TKIP; diff --git a/src/nm-dbus-nm.c b/src/nm-dbus-nm.c index cdbcdc79f1..2939717ba9 100644 --- a/src/nm-dbus-nm.c +++ b/src/nm-dbus-nm.c @@ -190,9 +190,6 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB DBusMessage * reply = NULL; char * dev_path; char * unescaped_dev_path = NULL; - char * essid = NULL; - char * key = NULL; - int key_type = -1; NMAccessPoint * ap = NULL; DBusMessageIter iter; @@ -205,8 +202,7 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_OBJECT_PATH) { - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "InvalidArguments", - "NetworkManager::setActiveDevice called with invalid arguments."); + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE); goto out; } @@ -225,51 +221,47 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB if (nm_device_is_802_11_wireless (dev)) { - NMAPSecurity * security = NULL; + NMAPSecurity * security = NULL; + char * essid = NULL; - if (dbus_message_iter_next (&iter)) - { - dbus_message_iter_get_basic (&iter, &essid); - - if (dbus_message_iter_next (&iter)) - { - security = nm_ap_security_new_from_dbus_message (&iter); - } - } - } - else if (nm_device_is_802_3_ethernet (dev)) - { - } -// DEBUG -return reply; - - /* Try to grab both device _and_ network first, and if that fails then just the device. */ - if (!dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &dev_path, - DBUS_TYPE_STRING, &essid, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID)) - { - /* So if that failed, try getting just the device */ - if (!dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &dev_path, DBUS_TYPE_INVALID)) + if (!dbus_message_iter_next (&iter)) { reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE); goto out; - } else nm_info ("FORCE: device '%s'", dev_path); - } else nm_info ("FORCE: device '%s', network '%s'", dev_path, essid); + } - /* Make sure network is valid and device is wireless */ - if (nm_device_is_802_11_wireless (dev) && !essid) + /* grab ssid and ensure validity */ + dbus_message_iter_get_basic (&iter, &essid); + if (!essid || (strlen (essid) <= 0)) + { + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE); + goto out; + } + + if (!dbus_message_iter_next (&iter)) + { + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE); + goto out; + } + + if (!(security = nm_ap_security_new_from_dbus_message (&iter))) + { + reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE); + goto out; + } + + /* Set up the wireless-specific activation request properties */ + ap = nm_device_wireless_get_activation_ap (dev, essid, security); + + nm_info ("User Switch: %s / %s", dev_path, essid); + } + else if (nm_device_is_802_3_ethernet (dev)) { - reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE); - goto out; + nm_info ("User Switch: %s", dev_path); } nm_device_deactivate (dev); - nm_schedule_state_change_signal_broadcast (data->data); - - if (nm_device_is_802_11_wireless (dev)) - ap = nm_device_wireless_get_activation_ap (dev, essid, key, (NMEncKeyType)key_type); nm_policy_schedule_device_activation (nm_act_request_new (data->data, dev, ap, TRUE)); out: diff --git a/src/wpa.c b/src/wpa.c index 3b37da6a43..03131e49d7 100644 --- a/src/wpa.c +++ b/src/wpa.c @@ -14,6 +14,7 @@ #include #include +#include #include "wpa.h" #include "nm-utils.h" @@ -93,14 +94,6 @@ static const u8 RSN_KEY_DATA_STAKEY[] = { 0x00, 0x0f, 0xac, 2 }; static const u8 RSN_KEY_DATA_MAC_ADDR[] = { 0x00, 0x0f, 0xac, 3 }; static const u8 RSN_KEY_DATA_PMKID[] = { 0x00, 0x0f, 0xac, 4 }; -/* 1/4: PMKID - * 2/4: RSN IE - * 3/4: one or two RSN IEs + GTK IE (encrypted) - * 4/4: empty - * 1/2: GTK IE (encrypted) - * 2/2: empty - */ - /* RSN IE version 1 * 0x01 0x00 (version; little endian) * (all following fields are optional:) @@ -436,16 +429,31 @@ static int wpa_parse_wpa_ie_rsn(const u8 *rsn_ie, size_t rsn_ie_len, * @wpa_ie: Pointer to WPA or RSN IE * @wpa_ie_len: Length of the WPA/RSN IE * @data: Pointer to data area for parsing results - * Returns: 0 on success, -1 on failure + * Returns: parsed results on success, NULL on failure * * Parse the contents of WPA or RSN IE and write the parsed data into data. */ -int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len, - struct wpa_ie_data *data) +wpa_ie_data * wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len) { + wpa_ie_data * data = NULL; + int err = -1; + + if (!wpa_ie || wpa_ie_len <= 0) + return NULL; + + data = g_malloc0 (sizeof (wpa_ie_data)); + if (wpa_ie_len >= 1 && wpa_ie[0] == WPA_RSN_INFO_ELEM) - return wpa_parse_wpa_ie_rsn(wpa_ie, wpa_ie_len, data); + err = wpa_parse_wpa_ie_rsn(wpa_ie, wpa_ie_len, data); else - return wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, data); + err = wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, data); + + if (err != 0) + { + g_free (data); + data = NULL; + } + + return data; } diff --git a/src/wpa.h b/src/wpa.h index 2f5035193e..18d1dbee9b 100644 --- a/src/wpa.h +++ b/src/wpa.h @@ -22,7 +22,7 @@ #define WPA_MAX_IE_LEN 40 -struct wpa_ie_data { +typedef struct wpa_ie_data { int proto; int pairwise_cipher; int group_cipher; @@ -30,9 +30,9 @@ struct wpa_ie_data { int capabilities; int num_pmkid; const uint8_t *pmkid; -}; +} wpa_ie_data; -int wpa_parse_wpa_ie(const uint8_t *wpa_ie, size_t wpa_ie_len, struct wpa_ie_data *data); +wpa_ie_data * wpa_parse_wpa_ie (const uint8_t *wpa_ie, size_t wpa_ie_len); #endif /* WPA_H */