void nm_ap_update_from_properties (NMAccessPoint *ap, const char *supplicant_path, GVariant *properties) { NMAccessPointPrivate *priv; char *addr; const guint8 *bytes; GVariant *v; gsize len; gboolean b = FALSE; const char *s; gint16 i16; guint16 u16; g_return_if_fail (ap != NULL); g_return_if_fail (properties != NULL); priv = NM_AP_GET_PRIVATE (ap); g_object_freeze_notify (G_OBJECT (ap)); if (g_variant_lookup (properties, "Privacy", "b", &b) && b) nm_ap_set_flags (ap, priv->flags | NM_802_11_AP_FLAGS_PRIVACY); if (g_variant_lookup (properties, "Mode", "&s", &s)) { if (!g_strcmp0 (s, "infrastructure")) nm_ap_set_mode (ap, NM_802_11_MODE_INFRA); else if (!g_strcmp0 (s, "ad-hoc")) nm_ap_set_mode (ap, NM_802_11_MODE_ADHOC); } if (g_variant_lookup (properties, "Signal", "n", &i16)) nm_ap_set_strength (ap, nm_ap_utils_level_to_quality (i16)); if (g_variant_lookup (properties, "Frequency", "q", &u16)) nm_ap_set_freq (ap, u16); v = g_variant_lookup_value (properties, "SSID", G_VARIANT_TYPE_BYTESTRING); if (v) { bytes = g_variant_get_fixed_array (v, &len, 1); len = MIN (32, len); /* Stupid ieee80211 layer uses <hidden> */ if ( bytes && len && !(((len == 8) || (len == 9)) && !memcmp (bytes, "<hidden>", 8)) && !nm_utils_is_empty_ssid (bytes, len)) nm_ap_set_ssid (ap, bytes, len); g_variant_unref (v); } v = g_variant_lookup_value (properties, "BSSID", G_VARIANT_TYPE_BYTESTRING); if (v) { bytes = g_variant_get_fixed_array (v, &len, 1); if (len == ETH_ALEN) { addr = nm_utils_hwaddr_ntoa (bytes, len); nm_ap_set_address (ap, addr); g_free (addr); } g_variant_unref (v); } v = g_variant_lookup_value (properties, "Rates", G_VARIANT_TYPE ("au")); if (v) { const guint32 *rates = g_variant_get_fixed_array (v, &len, sizeof (guint32)); guint32 maxrate = 0; int i; /* Find the max AP rate */ for (i = 0; i < len; i++) { if (rates[i] > maxrate) { maxrate = rates[i]; nm_ap_set_max_bitrate (ap, rates[i] / 1000); } } g_variant_unref (v); } v = g_variant_lookup_value (properties, "WPA", G_VARIANT_TYPE_VARDICT); if (v) { nm_ap_set_wpa_flags (ap, priv->wpa_flags | security_from_vardict (v)); g_variant_unref (v); } v = g_variant_lookup_value (properties, "RSN", G_VARIANT_TYPE_VARDICT); if (v) { nm_ap_set_rsn_flags (ap, priv->rsn_flags | security_from_vardict (v)); g_variant_unref (v); } if (!priv->supplicant_path) priv->supplicant_path = g_strdup (supplicant_path); nm_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); priv->fake = FALSE; g_object_thaw_notify (G_OBJECT (ap)); }
static void foreach_property_cb (gpointer key, gpointer value, gpointer user_data) { GValue *variant = (GValue *) value; NMAccessPoint *ap = (NMAccessPoint *) user_data; if (G_VALUE_HOLDS_BOXED (variant)) { GArray *array = g_value_get_boxed (variant); if (!strcmp (key, "SSID")) { guint32 len = MIN (32, array->len); GByteArray *ssid; /* Stupid ieee80211 layer uses <hidden> */ if (((len == 8) || (len == 9)) && (memcmp (array->data, "<hidden>", 8) == 0)) return; if (nm_utils_is_empty_ssid ((const guint8 *) array->data, len)) return; ssid = g_byte_array_sized_new (len); 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")) { struct ether_addr addr; if (array->len != ETH_ALEN) return; 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")) { NM80211ApSecurityFlags flags = nm_ap_get_wpa_flags (ap); flags |= security_from_dict (g_value_get_boxed (variant)); nm_ap_set_wpa_flags (ap, flags); } else if (!strcmp (key, "RSN")) { NM80211ApSecurityFlags flags = nm_ap_get_rsn_flags (ap); flags |= security_from_dict (g_value_get_boxed (variant)); 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); 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 (val && !strcmp (key, "Mode")) { if (strcmp (val, "infrastructure") == 0) nm_ap_set_mode (ap, NM_802_11_MODE_INFRA); else if (strcmp (val, "ad-hoc") == 0) 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) { NM80211ApFlags flags = nm_ap_get_flags (ap); nm_ap_set_flags (ap, flags | NM_802_11_AP_FLAGS_PRIVACY); } } } }