Ejemplo n.º 1
0
static gint
compare_aps (gconstpointer a, gconstpointer b, gpointer user_data)
{
	const char *bssid1, *bssid2;
	guint8 strength1, strength2;

	NMAccessPoint * ap1 = NM_ACCESS_POINT (* ((gconstpointer *) a));
	NMAccessPoint * ap2 = NM_ACCESS_POINT (* ((gconstpointer *) b));
	NMAccessPoint * active_ap;

	/* sort by signal strength, but put active ap first */
	if (user_data) {
		active_ap = NM_ACCESS_POINT (user_data);
		bssid1 = nm_access_point_get_hw_address (ap1);
		bssid2 = nm_access_point_get_hw_address (active_ap);
		if (!g_strcmp0 (bssid1, bssid2))
			return -1;
		bssid1 = nm_access_point_get_hw_address (ap2);
		if (!g_strcmp0 (bssid1, bssid2))
			return 1;
	}

	strength1 = nm_access_point_get_strength(ap1);
	strength2 = nm_access_point_get_strength(ap2);

	if (strength1 < strength2)
		return 1;
	else if (strength1 == strength2)
		return 0;
	else return -1;

}
Ejemplo n.º 2
0
static GPtrArray *
get_strongest_unique_aps (const GPtrArray *aps)
{
  const GByteArray *ssid;
  const GByteArray *ssid_tmp;
  GPtrArray *unique = NULL;
  gboolean add_ap;
  guint i;
  guint j;
  NMAccessPoint *ap;
  NMAccessPoint *ap_tmp;

  /* we will have multiple entries for typical hotspots,
   * just keep the one with the strongest signal
   */
  unique = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
  if (aps == NULL)
    goto out;

  for (i = 0; i < aps->len; i++) {
    ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
    ssid = nm_access_point_get_ssid (ap);
    add_ap = TRUE;

    /* get already added list */
    for (j = 0; j < unique->len; j++) {
      ap_tmp = NM_ACCESS_POINT (g_ptr_array_index (unique, j));
      ssid_tmp = nm_access_point_get_ssid (ap_tmp);

      /* is this the same type and data? */
      if (nm_utils_same_ssid (ssid, ssid_tmp, TRUE)) {
        /* the new access point is stronger */
        if (nm_access_point_get_strength (ap) >
            nm_access_point_get_strength (ap_tmp)) {
          g_ptr_array_remove (unique, ap_tmp);
          add_ap = TRUE;
        } else {
          add_ap = FALSE;
        }
        break;
      }
    }
    if (add_ap) {
      g_ptr_array_add (unique, g_object_ref (ap));
    }
  }

 out:
  return unique;
}
Ejemplo n.º 3
0
static void
clean_up_aps (NMDeviceWifi *self, gboolean in_dispose)
{
	NMDeviceWifiPrivate *priv;
	GPtrArray *aps;
	int i;

	g_return_if_fail (NM_IS_DEVICE_WIFI (self));

	priv = NM_DEVICE_WIFI_GET_PRIVATE (self);

	if (priv->active_ap) {
		g_object_unref (priv->active_ap);
		priv->active_ap = NULL;
	}

	aps = priv->aps;

	if (in_dispose)
		priv->aps = NULL;
	else {
		priv->aps = g_ptr_array_new ();

		for (i = 0; i < aps->len; i++) {
			NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));

			g_signal_emit (self, signals[ACCESS_POINT_REMOVED], 0, ap);
		}
	}

	g_ptr_array_unref (aps);
}
Ejemplo n.º 4
0
static void
clean_up_aps (NMDeviceWifi *self, gboolean notify)
{
	NMDeviceWifiPrivate *priv;

	g_return_if_fail (NM_IS_DEVICE_WIFI (self));

	priv = NM_DEVICE_WIFI_GET_PRIVATE (self);

	if (priv->active_ap) {
		g_object_unref (priv->active_ap);
		priv->active_ap = NULL;
	}

	if (priv->aps) {
		while (priv->aps->len) {
			NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (priv->aps, 0));

			if (notify)
				g_signal_emit (self, signals[ACCESS_POINT_REMOVED], 0, ap);
			g_ptr_array_remove (priv->aps, ap);
			g_object_unref (ap);
		}
		g_ptr_array_free (priv->aps, TRUE);
		priv->aps = NULL;
	}
}
Ejemplo n.º 5
0
static void
access_point_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
{
	NMDeviceWifi *self = NM_DEVICE_WIFI (user_data);
	NMDeviceWifiPrivate *priv;
	GObject *ap;

	g_return_if_fail (self != NULL);

	ap = G_OBJECT (nm_device_wifi_get_access_point_by_path (self, path));
	if (!ap) {
		DBusGConnection *connection = nm_object_get_connection (NM_OBJECT (self));

		priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
		ap = G_OBJECT (_nm_object_cache_get (path));
		if (ap) {
			g_ptr_array_add (priv->aps, g_object_ref (ap));
		} else {
			ap = G_OBJECT (nm_access_point_new (connection, path));
			if (ap)
				g_ptr_array_add (priv->aps, ap);
		}
	}

	if (ap)
		g_signal_emit (self, signals[ACCESS_POINT_ADDED], 0, NM_ACCESS_POINT (ap));
}
Ejemplo n.º 6
0
static void
detail_access_point (gpointer data, gpointer user_data)
{
	NMAccessPoint *ap = NM_ACCESS_POINT (data);
	const char *active_bssid = (const char *) user_data;
	GString *str;
	gboolean active = FALSE;
	guint32 flags, wpa_flags, rsn_flags;
	const GByteArray * ssid;
	char *tmp;

	flags = nm_access_point_get_flags (ap);
	wpa_flags = nm_access_point_get_wpa_flags (ap);
	rsn_flags = nm_access_point_get_rsn_flags (ap);

	if (active_bssid) {
		const char *current_bssid = nm_access_point_get_hw_address (ap);
		if (current_bssid && !strcmp (current_bssid, active_bssid))
			active = TRUE;
	}

	str = g_string_new (NULL);
	g_string_append_printf (str,
	                        "%s, %s, Freq %d MHz, Rate %d Mb/s, Strength %d",
	                        (nm_access_point_get_mode (ap) == NM_802_11_MODE_INFRA) ? "Infra" : "Ad-Hoc",
	                        nm_access_point_get_hw_address (ap),
	                        nm_access_point_get_frequency (ap),
	                        nm_access_point_get_max_bitrate (ap) / 1000,
	                        nm_access_point_get_strength (ap));

	if (   !(flags & NM_802_11_AP_FLAGS_PRIVACY)
	    &&  (wpa_flags != NM_802_11_AP_SEC_NONE)
	    &&  (rsn_flags != NM_802_11_AP_SEC_NONE))
		g_string_append (str, ", Encrypted: ");

	if (   (flags & NM_802_11_AP_FLAGS_PRIVACY)
	    && (wpa_flags == NM_802_11_AP_SEC_NONE)
	    && (rsn_flags == NM_802_11_AP_SEC_NONE))
		g_string_append (str, " WEP");
	if (wpa_flags != NM_802_11_AP_SEC_NONE)
		g_string_append (str, " WPA");
	if (rsn_flags != NM_802_11_AP_SEC_NONE)
		g_string_append (str, " WPA2");
	if (   (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
	    || (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
		g_string_append (str, " Enterprise");

	/* FIXME: broadcast/hidden */

	ssid = nm_access_point_get_ssid (ap);
	tmp = g_strdup_printf ("  %s%s", active ? "*" : "",
	                       ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)");

	print_string (tmp, str->str);

	g_string_free (str, TRUE);
	g_free (tmp);
}
Ejemplo n.º 7
0
static void
constructed (GObject *object)
{
	NMAccessPointPrivate *priv;

	G_OBJECT_CLASS (nm_access_point_parent_class)->constructed (object);

	priv = NM_ACCESS_POINT_GET_PRIVATE (object);
	priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_ACCESS_POINT);
	register_properties (NM_ACCESS_POINT (object));
}
Ejemplo n.º 8
0
static gboolean
demarshal_active_ap (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
	const char *path;
	NMAccessPoint *ap = NULL;
	DBusGConnection *connection;

	if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
		return FALSE;

	priv->null_active_ap = FALSE;

	path = g_value_get_boxed (value);
	if (path) {
		if (!strcmp (path, "/"))
			priv->null_active_ap = TRUE;
		else {
			ap = NM_ACCESS_POINT (_nm_object_cache_get (path));
			if (ap)
				ap = g_object_ref (ap);
			else {
				connection = nm_object_get_connection (object);
				ap = NM_ACCESS_POINT (nm_access_point_new (connection, path));
			}
		}
	}

	if (priv->active_ap) {
		g_object_unref (priv->active_ap);
		priv->active_ap = NULL;
	}

	if (ap)
		priv->active_ap = ap;

	_nm_object_queue_notify (object, NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT);
	return TRUE;
}
Ejemplo n.º 9
0
static void
get_property (GObject *object,
              guint prop_id,
              GValue *value,
              GParamSpec *pspec)
{
	NMAccessPoint *ap = NM_ACCESS_POINT (object);

	_nm_object_ensure_inited (NM_OBJECT (object));

	switch (prop_id) {
	case PROP_FLAGS:
		g_value_set_uint (value, nm_access_point_get_flags (ap));
		break;
	case PROP_WPA_FLAGS:
		g_value_set_uint (value, nm_access_point_get_wpa_flags (ap));
		break;
	case PROP_RSN_FLAGS:
		g_value_set_uint (value, nm_access_point_get_rsn_flags (ap));
		break;
	case PROP_SSID:
		g_value_set_boxed (value, nm_access_point_get_ssid (ap));
		break;
	case PROP_FREQUENCY:
		g_value_set_uint (value, nm_access_point_get_frequency (ap));
		break;
	case PROP_HW_ADDRESS:
		g_value_set_string (value, nm_access_point_get_bssid (ap));
		break;
	case PROP_BSSID:
		g_value_set_string (value, nm_access_point_get_bssid (ap));
		break;
	case PROP_MODE:
		g_value_set_uint (value, nm_access_point_get_mode (ap));
		break;
	case PROP_MAX_BITRATE:
		g_value_set_uint (value, nm_access_point_get_max_bitrate (ap));
		break;
	case PROP_STRENGTH:
		g_value_set_uchar (value, nm_access_point_get_strength (ap));
		break;
	case PROP_LAST_SEEN:
		g_value_set_int (value, nm_access_point_get_last_seen (ap));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
Ejemplo n.º 10
0
static void
set_property (GObject *object, guint prop_id,
              const GValue *value, GParamSpec *pspec)
{
    NMWifiItem *self = NM_WIFI_ITEM (object);

    switch (prop_id) {
    case PROP_AP:
        /* Construct only */
        nm_wifi_item_add_ap (self, NM_ACCESS_POINT (g_value_dup_object (value)));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}
static void
access_point_removed (NMObject *self_obj, NMObject *ap_obj)
{
	NMDeviceWifi *self = NM_DEVICE_WIFI (self_obj);
	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
	NMAccessPoint *ap = NM_ACCESS_POINT (ap_obj);

	if (ap == priv->active_ap) {
		g_object_unref (priv->active_ap);
		priv->active_ap = NULL;
		_nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT);

		priv->rate = 0;
		_nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_BITRATE);
	}

	g_signal_emit (self, signals[ACCESS_POINT_REMOVED], 0, ap);
}
Ejemplo n.º 12
0
static void
dump_wireless (NMDeviceWifi *device)
{
	const char *str;
	const GPtrArray *aps;
	int i;

	g_print ("Mode: %d\n", nm_device_wifi_get_mode (device));
	g_print ("Bitrate: %d\n", nm_device_wifi_get_bitrate (device));

	str = nm_device_wifi_get_hw_address (device);
	g_print ("MAC: %s\n", str);

	g_print ("AccessPoints:\n");
	aps = nm_device_wifi_get_access_points (device);
	for (i = 0; aps && (i < aps->len); i++) {
		dump_access_point (NM_ACCESS_POINT (g_ptr_array_index (aps, i)));
		g_print ("\n");
	}
}
Ejemplo n.º 13
0
static void
refresh_wireless_list (GisNetworkPage *page)
{
  GisNetworkPagePrivate *priv = gis_network_page_get_instance_private (page);
  NMAccessPoint *active_ap = NULL;
  NMAccessPoint *ap;
  const GPtrArray *aps;
  GPtrArray *unique_aps;
  guint i;
  GList *children, *l;

  priv->refreshing = TRUE;

  g_assert (NM_IS_DEVICE_WIFI (priv->nm_device));

  if (priv->refresh_timeout_id != 0)
    {
      g_source_remove (priv->refresh_timeout_id);
      priv->refresh_timeout_id = 0;
    }

  active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (priv->nm_device));

  children = gtk_container_get_children (GTK_CONTAINER (priv->network_list));
  for (l = children; l; l = l->next)
    gtk_container_remove (GTK_CONTAINER (priv->network_list), l->data);
  g_list_free (children);

  aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (priv->nm_device));

  if (aps == NULL || aps->len == 0) {
    gboolean enabled, hw_enabled;

    enabled = nm_client_wireless_get_enabled (priv->nm_client);
    hw_enabled = nm_client_wireless_hardware_get_enabled (priv->nm_client);

    if (!enabled || !hw_enabled) {
      gtk_label_set_text (GTK_LABEL (priv->no_network_label), _("Wireless networking is disabled"));
      gtk_widget_show (priv->no_network_label);
      gtk_widget_hide (priv->no_network_spinner);

      gtk_widget_set_visible (priv->turn_on_label, hw_enabled);
      gtk_widget_set_visible (priv->turn_on_switch, hw_enabled);
    } else {
      gtk_label_set_text (GTK_LABEL (priv->no_network_label), _("Checking for available wireless networks"));
      gtk_widget_show (priv->no_network_spinner);
      gtk_widget_show (priv->no_network_label);
      gtk_widget_hide (priv->turn_on_label);
      gtk_widget_hide (priv->turn_on_switch);
    }

    gtk_widget_hide (priv->scrolled_window);
    priv->refresh_timeout_id = g_timeout_add_seconds (1, refresh_again, page);
    goto out;

  } else {
    gtk_widget_hide (priv->no_network_spinner);
    gtk_widget_hide (priv->no_network_label);
    gtk_widget_hide (priv->turn_on_label);
    gtk_widget_hide (priv->turn_on_switch);
    gtk_widget_show (priv->scrolled_window);
  }

  unique_aps = get_strongest_unique_aps (aps);
  for (i = 0; i < unique_aps->len; i++) {
    ap = NM_ACCESS_POINT (g_ptr_array_index (unique_aps, i));
    add_access_point (page, ap, active_ap);
  }
  g_ptr_array_unref (unique_aps);
  add_access_point_other (page);

 out:
  priv->refreshing = FALSE;
}