summaryrefslogtreecommitdiff
path: root/src/nm-wifi-ap.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-04-21 10:42:53 +0200
committerMichael Biebl <biebl@debian.org>2011-04-21 10:42:53 +0200
commit8baa1aca8dfd35e3190d7d5655eb83b5b901e263 (patch)
treea9ac1e67d0c22a48330c76f08fc5291f85307055 /src/nm-wifi-ap.c
parentf75dd6fd1975146623052b843b182dc32c3fbe46 (diff)
Imported Upstream version 0.8.4.0upstream/0.8.4.0
Diffstat (limited to 'src/nm-wifi-ap.c')
-rw-r--r--src/nm-wifi-ap.c193
1 files changed, 70 insertions, 123 deletions
diff --git a/src/nm-wifi-ap.c b/src/nm-wifi-ap.c
index 5fbdcea6a..7770b8bc4 100644
--- a/src/nm-wifi-ap.c
+++ b/src/nm-wifi-ap.c
@@ -22,10 +22,8 @@
#include "wireless-helper.h"
#include <string.h>
-#include <stdlib.h>
#include "nm-wifi-ap.h"
-#include "nm-wifi-ap-utils.h"
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
#include "nm-logging.h"
@@ -371,69 +369,10 @@ NMAccessPoint *nm_ap_new (void)
return (NMAccessPoint *) object;
}
-static guint32
-pair_to_flags (const char *str)
-{
- g_return_val_if_fail (str != NULL, NM_802_11_AP_SEC_NONE);
-
- if (strcmp (str, "wep40") == 0)
- return NM_802_11_AP_SEC_PAIR_WEP40;
- if (strcmp (str, "wep104") == 0)
- return NM_802_11_AP_SEC_PAIR_WEP104;
- if (strcmp (str, "tkip") == 0)
- return NM_802_11_AP_SEC_PAIR_TKIP;
- if (strcmp (str, "ccmp") == 0)
- return NM_802_11_AP_SEC_PAIR_CCMP;
- return NM_802_11_AP_SEC_NONE;
-}
-
-static guint32
-group_to_flags (const char *str)
-{
- g_return_val_if_fail (str != NULL, NM_802_11_AP_SEC_NONE);
-
- if (strcmp (str, "wep40") == 0)
- return NM_802_11_AP_SEC_GROUP_WEP40;
- if (strcmp (str, "wep104") == 0)
- return NM_802_11_AP_SEC_GROUP_WEP104;
- if (strcmp (str, "tkip") == 0)
- return NM_802_11_AP_SEC_GROUP_TKIP;
- if (strcmp (str, "ccmp") == 0)
- return NM_802_11_AP_SEC_GROUP_CCMP;
- return NM_802_11_AP_SEC_NONE;
-}
-static guint32
-security_from_dict (GHashTable *security)
-{
- GValue *value;
- guint32 flags = NM_802_11_AP_SEC_NONE;
- const char **items, **iter;
-
- value = g_hash_table_lookup (security, "KeyMgmt");
- if (value) {
- items = g_value_get_boxed (value);
- for (iter = items; iter && *iter; iter++) {
- if (strcmp (*iter, "wpa-psk") == 0)
- flags |= NM_802_11_AP_SEC_KEY_MGMT_PSK;
- else if (strcmp (*iter, "wpa-eap") == 0)
- flags |= NM_802_11_AP_SEC_KEY_MGMT_802_1X;
- }
- }
-
- value = g_hash_table_lookup (security, "Pairwise");
- if (value) {
- items = g_value_get_boxed (value);
- for (iter = items; iter && *iter; iter++)
- flags |= pair_to_flags (*iter);
- }
-
- value = g_hash_table_lookup (security, "Group");
- if (value)
- flags |= group_to_flags (g_value_get_string (value));
-
- return flags;
-}
+#define IEEE80211_CAP_ESS 0x0001
+#define IEEE80211_CAP_IBSS 0x0002
+#define IEEE80211_CAP_PRIVACY 0x0010
static void
foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
@@ -444,9 +383,9 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
if (G_VALUE_HOLDS_BOXED (variant)) {
GArray *array = g_value_get_boxed (variant);
- if (!strcmp (key, "SSID")) {
+ if (!strcmp (key, "ssid")) {
guint32 len = MIN (IW_ESSID_MAX_SIZE, array->len);
- GByteArray *ssid;
+ GByteArray * ssid;
/* Stupid ieee80211 layer uses <hidden> */
if (((len == 8) || (len == 9))
@@ -460,7 +399,7 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
g_byte_array_append (ssid, (const guint8 *) array->data, len);
nm_ap_set_ssid (ap, ssid);
g_byte_array_free (ssid, TRUE);
- } else if (!strcmp (key, "BSSID")) {
+ } else if (!strcmp (key, "bssid")) {
struct ether_addr addr;
if (array->len != ETH_ALEN)
@@ -468,54 +407,43 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
memset (&addr, 0, sizeof (struct ether_addr));
memcpy (&addr, array->data, ETH_ALEN);
nm_ap_set_address (ap, &addr);
- } else if (!strcmp (key, "Rates")) {
- guint32 maxrate = 0;
- int i;
-
- /* Find the max AP rate */
- for (i = 0; i < array->len; i++) {
- guint32 r = g_array_index (array, guint32, i);
-
- if (r > maxrate) {
- maxrate = r;
- nm_ap_set_max_bitrate (ap, r / 1000);
- }
- }
- } else if (!strcmp (key, "WPA")) {
+ } else if (!strcmp (key, "wpaie")) {
+ guint8 * ie = (guint8 *) array->data;
guint32 flags = nm_ap_get_wpa_flags (ap);
- flags |= security_from_dict (g_value_get_boxed (variant));
+ if (array->len <= 0 || array->len > WPA_MAX_IE_LEN)
+ return;
+ flags = nm_ap_add_security_from_ie (flags, ie, array->len);
nm_ap_set_wpa_flags (ap, flags);
- } else if (!strcmp (key, "RSN")) {
+ } else if (!strcmp (key, "rsnie")) {
+ guint8 * ie = (guint8 *) array->data;
guint32 flags = nm_ap_get_rsn_flags (ap);
- flags |= security_from_dict (g_value_get_boxed (variant));
+ if (array->len <= 0 || array->len > WPA_MAX_IE_LEN)
+ return;
+ flags = nm_ap_add_security_from_ie (flags, ie, array->len);
nm_ap_set_rsn_flags (ap, flags);
}
- } else if (G_VALUE_HOLDS_UINT (variant)) {
- guint32 val = g_value_get_uint (variant);
-
- if (!strcmp (key, "Frequency"))
- nm_ap_set_freq (ap, val);
} else if (G_VALUE_HOLDS_INT (variant)) {
- gint val = g_value_get_int (variant);
+ gint32 int_val = g_value_get_int (variant);
- if (!strcmp (key, "Signal"))
- nm_ap_set_strength (ap, nm_ap_utils_level_to_quality (val));
- } else if (G_VALUE_HOLDS_STRING (variant)) {
- const char *val = g_value_get_string (variant);
+ if (!strcmp (key, "frequency")) {
+ nm_ap_set_freq (ap, (guint32) int_val);
+ } else if (!strcmp (key, "maxrate")) {
+ /* Supplicant reports as b/s, we use Kb/s internally */
+ nm_ap_set_max_bitrate (ap, int_val / 1000);
+ }
+ } else if (G_VALUE_HOLDS_UINT (variant)) {
+ guint32 val = g_value_get_uint (variant);
- if (val && !strcmp (key, "Mode")) {
- if (strcmp (val, "infrastructure") == 0)
+ if (!strcmp (key, "capabilities")) {
+ if (val & IEEE80211_CAP_ESS) {
nm_ap_set_mode (ap, NM_802_11_MODE_INFRA);
- else if (strcmp (val, "ad-hoc") == 0)
+ } else if (val & IEEE80211_CAP_IBSS) {
nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC);
- }
- } else if (G_VALUE_HOLDS_BOOLEAN (variant)) {
- gboolean val = g_value_get_boolean (variant);
+ }
- if (strcmp (key, "Privacy") == 0) {
- if (val) {
+ if (val & IEEE80211_CAP_PRIVACY) {
guint32 flags = nm_ap_get_flags (ap);
nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY);
}
@@ -523,6 +451,7 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
}
}
+
NMAccessPoint *
nm_ap_new_from_properties (GHashTable *properties)
{
@@ -1241,6 +1170,45 @@ void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list)
}
+guint32
+nm_ap_add_security_from_ie (guint32 flags,
+ const guint8 *wpa_ie,
+ guint32 length)
+{
+ wpa_ie_data * cap_data;
+
+ if (!(cap_data = wpa_parse_wpa_ie (wpa_ie, length)))
+ return NM_802_11_AP_SEC_NONE;
+
+ /* Pairwise cipher flags */
+ if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_WEP40)
+ flags |= NM_802_11_AP_SEC_PAIR_WEP40;
+ if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_WEP104)
+ flags |= NM_802_11_AP_SEC_PAIR_WEP104;
+ if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_TKIP)
+ flags |= NM_802_11_AP_SEC_PAIR_TKIP;
+ if (cap_data->pairwise_cipher & IW_AUTH_CIPHER_CCMP)
+ flags |= NM_802_11_AP_SEC_PAIR_CCMP;
+
+ /* Group cipher flags */
+ if (cap_data->group_cipher & IW_AUTH_CIPHER_WEP40)
+ flags |= NM_802_11_AP_SEC_GROUP_WEP40;
+ if (cap_data->group_cipher & IW_AUTH_CIPHER_WEP104)
+ flags |= NM_802_11_AP_SEC_GROUP_WEP104;
+ if (cap_data->group_cipher & IW_AUTH_CIPHER_TKIP)
+ flags |= NM_802_11_AP_SEC_GROUP_TKIP;
+ if (cap_data->group_cipher & IW_AUTH_CIPHER_CCMP)
+ flags |= NM_802_11_AP_SEC_GROUP_CCMP;
+
+ if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_802_1X)
+ flags |= NM_802_11_AP_SEC_KEY_MGMT_802_1X;
+ if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_PSK)
+ flags |= NM_802_11_AP_SEC_KEY_MGMT_PSK;
+
+ g_slice_free (wpa_ie_data, cap_data);
+ return flags;
+}
+
gboolean
nm_ap_check_compatible (NMAccessPoint *self,
NMConnection *connection)
@@ -1307,27 +1275,6 @@ nm_ap_check_compatible (NMAccessPoint *self,
nm_ap_get_mode (self));
}
-gboolean
-nm_ap_complete_connection (NMAccessPoint *self,
- NMConnection *connection,
- gboolean lock_bssid,
- GError **error)
-{
- NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (self);
-
- g_return_val_if_fail (connection != NULL, FALSE);
-
- return nm_ap_utils_complete_connection (priv->ssid,
- priv->address.ether_addr_octet,
- priv->mode,
- priv->flags,
- priv->wpa_flags,
- priv->rsn_flags,
- connection,
- lock_bssid,
- error);
-}
-
static gboolean
capabilities_compatible (guint32 a_flags, guint32 b_flags)
{