Пример #1
0
void NMListener::run() {
  NMDevice *dev = nm_client_get_device_by_iface(nm, "wlan0");
  context = g_main_context_default();
  //context = g_main_context_new();
  loop = g_main_loop_new(context, false);
  //g_main_context_invoke(context, initialize_in_context, status);

  g_signal_connect_swapped(nm, "notify::" NM_CLIENT_WIRELESS_ENABLED,
    G_CALLBACK(handle_wireless_enabled), wifiStatus);

  g_signal_connect_swapped(dev, "notify::" NM_DEVICE_STATE,
    G_CALLBACK(handle_wireless_connected), wifiStatus);

  g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "notify::" NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT,
    G_CALLBACK(handle_active_access_point), wifiStatus);

  g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "access-point-added",
    G_CALLBACK(handle_changed_access_points), wifiStatus);

  g_signal_connect_swapped(NM_DEVICE_WIFI(dev), "access-point-removed",
    G_CALLBACK(handle_changed_access_points), wifiStatus);

  while (!threadShouldExit()) {
    {
      const MessageManagerLock mmLock;
      bool dispatched = g_main_context_iteration(context, false);
    }
    wait(LIBNM_ITERATION_PERIOD);
  }

  g_main_loop_unref(loop);
  g_main_context_unref(context);
}
Пример #2
0
static void
refresh_wireless_list (GisNetworkPage *page)
{
  GisNetworkPagePrivate *priv = page->priv;
  NMDeviceState state = NM_DEVICE_STATE_UNAVAILABLE;
  NMAccessPoint *active_ap = NULL;
  NMAccessPoint *ap;
  const GPtrArray *aps;
  GPtrArray *unique_aps;
  guint i;
  GtkWidget *label;
  GtkWidget *spinner;
  GtkWidget *swin;

  priv->refreshing = TRUE;

  if (NM_IS_DEVICE_WIFI (priv->nm_device)) {
    state = nm_device_get_state (priv->nm_device);

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

    gtk_tree_view_set_model (OBJ(GtkTreeView*, "network-list"), NULL);
    gtk_list_store_clear (priv->ap_list);
    if (priv->row) {
      gtk_tree_row_reference_free (priv->row);
      priv->row = NULL;
    }

    aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (priv->nm_device));
  }
Пример #3
0
static void
dispose (GObject *object)
{
	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
	GError *error = NULL;

	if (priv->scan_call) {
		g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN,
		                     "Wi-Fi device was destroyed");
		if (priv->scan_info) {
			if (priv->scan_info->callback)
				priv->scan_info->callback (NULL, error, priv->scan_info->user_data);
			g_slice_free (RequestScanInfo, priv->scan_info);
			priv->scan_info = NULL;
		}
		g_clear_error (&error);

		dbus_g_proxy_cancel_call (priv->proxy, priv->scan_call);
		priv->scan_call = NULL;
	}

	if (priv->aps)
		clean_up_aps (NM_DEVICE_WIFI (object), TRUE);
	g_clear_object (&priv->proxy);

	G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
}
static void
access_point_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
{
	NMDeviceWifi *self = NM_DEVICE_WIFI (user_data);
	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
	NMAccessPoint *ap;

	g_return_if_fail (self != NULL);

	ap = nm_device_wifi_get_access_point_by_path (self, path);
	if (ap) {
		if (ap == priv->active_ap) {
			g_object_unref (priv->active_ap);
			priv->active_ap = NULL;
			priv->null_active_ap = FALSE;

			_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);
		g_ptr_array_remove (priv->aps, ap);
		g_object_unref (G_OBJECT (ap));
	}
}
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));
}
Пример #6
0
static void
dump_device (NMDevice *device)
{
	const char *str;
	NMDeviceState state;

	str = nm_device_get_iface (device);
	g_print ("Interface: %s\n", str);

	str = nm_device_get_udi (device);
	g_print ("Udi: %s\n", str);

	str = nm_device_get_driver (device);
	g_print ("Driver: %s\n", str);

	str = nm_device_get_vendor (device);
	g_print ("Vendor: %s\n", str);

	str = nm_device_get_product (device);
	g_print ("Product: %s\n", str);

	state = nm_device_get_state (device);
	g_print ("State: %d\n", state);

	if (state == NM_DEVICE_STATE_ACTIVATED)
		dump_ip4_config (nm_device_get_ip4_config (device));

	if (NM_IS_DEVICE_ETHERNET (device))
		dump_wired (NM_DEVICE_ETHERNET (device));
	else if (NM_IS_DEVICE_WIFI (device))
		dump_wireless (NM_DEVICE_WIFI (device));

	dump_dhcp4_config (nm_device_get_dhcp4_config (device));
}
Пример #7
0
OwnedArray<WifiAccessPoint> WifiStatusNM::nearbyAccessPoints() {
  NMDeviceWifi *wdev;
  const GPtrArray *ap_list;
  OwnedArray<WifiAccessPoint> accessPoints;

  wdev = NM_DEVICE_WIFI(nmdevice);
  //nm_device_wifi_request_scan(wdev, NULL, NULL);

  ap_list =  nm_device_wifi_get_access_points(wdev);
  if (ap_list != NULL) {
    std::map<String, WifiAccessPoint *> uniqueAPs;
    for (int i = 0; i < ap_list->len; i++) {
      NMAccessPoint *ap = (NMAccessPoint *) g_ptr_array_index(ap_list, i);
      auto created_ap = createNMWifiAccessPoint(ap);

      /*FIXME: dropping hidden (no ssid) networks until gui supports it*/
      if (created_ap->ssid.length() == 0)
        continue;

      if (uniqueAPs.find(created_ap->hash) == uniqueAPs.end())
        uniqueAPs[created_ap->hash] = created_ap;
      else
        if (uniqueAPs[created_ap->hash]->signalStrength < created_ap->signalStrength)
	  uniqueAPs[created_ap->hash] = created_ap;
    }
    for (const auto entry : uniqueAPs)
      accessPoints.add(entry.second);
  }

  DBG(__func__ << ": found " << accessPoints.size() << " AccessPoints");
  return accessPoints;
}
Пример #8
0
static void
state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
{
	NMDeviceWifi *self = NM_DEVICE_WIFI (device);
	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);

	switch (nm_device_get_state (device)) {
	case NM_DEVICE_STATE_UNKNOWN:
	case NM_DEVICE_STATE_UNMANAGED:
	case NM_DEVICE_STATE_UNAVAILABLE:
	case NM_DEVICE_STATE_DISCONNECTED:
	case NM_DEVICE_STATE_FAILED:
		/* Just clear active AP; don't clear the AP list unless wireless is disabled completely */
		if (priv->active_ap) {
			g_object_unref (priv->active_ap);
			priv->active_ap = NULL;
		}
		_nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT);
		priv->rate = 0;
		_nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIFI_BITRATE);
		break;
	default:
		break;
	}
}
Пример #9
0
static void
get_property (GObject *object,
              guint prop_id,
              GValue *value,
              GParamSpec *pspec)
{
	NMDeviceWifi *self = NM_DEVICE_WIFI (object);

	switch (prop_id) {
	case PROP_HW_ADDRESS:
		g_value_set_string (value, nm_device_wifi_get_hw_address (self));
		break;
	case PROP_PERM_HW_ADDRESS:
		g_value_set_string (value, nm_device_wifi_get_permanent_hw_address (self));
		break;
	case PROP_MODE:
		g_value_set_uint (value, nm_device_wifi_get_mode (self));
		break;
	case PROP_BITRATE:
		g_value_set_uint (value, nm_device_wifi_get_bitrate (self));
		break;
	case PROP_ACTIVE_ACCESS_POINT:
		g_value_set_object (value, nm_device_wifi_get_active_access_point (self));
		break;
	case PROP_WIRELESS_CAPABILITIES:
		g_value_set_uint (value, nm_device_wifi_get_capabilities (self));
		break;
	case PROP_ACCESS_POINTS:
		g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_wifi_get_access_points (self)));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
Пример #10
0
void WifiStatusNM::handleConnectedAccessPoint() {
  DBG("WifiStatusNM::" << __func__ << " changed active AP");
  connectedAP = getNMConnectedAP(NM_DEVICE_WIFI(nmdevice));
  if (connectedAP)
    DBG("WifiStatusNM::" << __func__ << " ssid = " << connectedAP->ssid);
  else
    DBG("WifiStatusNM::" << __func__ << " connectedAP = NULL");
}
static void
add_connections_for_aps (NmtConnectDevice *nmtdev,
                         const GPtrArray  *connections)
{
	NmtConnectConnection *nmtconn;
	NMConnection *conn;
	NMAccessPoint *ap;
	const GPtrArray *aps;
	GHashTable *seen_ssids;
	GBytes *ssid;
	char *ap_hash;
	int i, c;

	aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nmtdev->device));
	if (!aps->len)
		return;

	seen_ssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

	for (i = 0; i < aps->len; i++) {
		ap = aps->pdata[i];

		if (!nm_access_point_get_ssid (ap))
			continue;

		ap_hash = hash_ap (ap);
		if (g_hash_table_contains (seen_ssids, ap_hash)) {
			g_free (ap_hash);
			continue;
		}
		g_hash_table_add (seen_ssids, ap_hash);

		nmtconn = g_slice_new0 (NmtConnectConnection);
		nmtconn->device = nmtdev->device;
		nmtconn->ap = g_object_ref (ap);
		ssid = nm_access_point_get_ssid (ap);
		if (ssid)
			nmtconn->ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL),
			                                       g_bytes_get_size (ssid));

		for (c = 0; c < connections->len; c++) {
			conn = connections->pdata[c];
			if (   nm_device_connection_valid (nmtdev->device, conn)
			    && nm_access_point_connection_valid (ap, conn)) {
				nmtconn->name = nm_connection_get_id (conn);
				nmtconn->conn = g_object_ref (conn);
				break;
			}
		}

		if (!nmtconn->name)
			nmtconn->name = nmtconn->ssid ? nmtconn->ssid : "<unknown>";

		nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn);
	}

	g_hash_table_unref (seen_ssids);
}
Пример #12
0
static const char *
wifi_get_hw_address (NMDeviceItem *item)
{
    NMDeviceWifi *device;

    device = NM_DEVICE_WIFI (nm_device_item_get_device (NM_DEVICE_ITEM (item)));

    return nm_device_wifi_get_hw_address (device);
}
Пример #13
0
static void
show_wifi_specific_info (NMDevice * dev)
{
	NMDeviceWifi * device = NM_DEVICE_WIFI (dev);

	const char * hw_address;
	NM80211Mode mode;
	guint32 bitrate;
	guint32 capas;
	NMAccessPoint * active_ap;
	const GPtrArray * aps;

	gchar * capa_strs[6]; /* Currently six capabilities is defined */
	gint capas_num, i;

	hw_address = nm_device_wifi_get_hw_address (device);
	mode = nm_device_wifi_get_mode (device);
	bitrate = nm_device_wifi_get_bitrate (device);
	capas = nm_device_wifi_get_capabilities (device);
	active_ap = nm_device_wifi_get_active_access_point (device);
	aps = nm_device_wifi_get_access_points (device);

	capas_num = 0;
	if (capas & NM_WIFI_DEVICE_CAP_CIPHER_WEP40)
		capa_strs[capas_num++] = "wep40";
	if (capas & NM_WIFI_DEVICE_CAP_CIPHER_WEP104)
		capa_strs[capas_num++] = "wep104";
	if (capas & NM_WIFI_DEVICE_CAP_CIPHER_TKIP)
		capa_strs[capas_num++] = "tkip";
	if (capas & NM_WIFI_DEVICE_CAP_CIPHER_CCMP)
		capa_strs[capas_num++] = "ccmp";
	if (capas & NM_WIFI_DEVICE_CAP_WPA)
		capa_strs[capas_num++] = "wpa";
	if (capas & NM_WIFI_DEVICE_CAP_RSN)
		capa_strs[capas_num++] = "rsn";

	g_print ("%-9s HWaddr:%s  Mode:%s", "", hw_address,
			wifi_mode_to_string(mode));
	if (bitrate > 0)
		g_print ("  Bitrate:%.1fMb/s\n", bitrate/1000.0);
	else
		g_print ("\n");

	g_print ("%-9s Capabilities:", "");
	for (i = 0; i < capas_num; i++) {
		g_print ("%s", capa_strs[i]);
		if (i != capas_num - 1)
			g_print (" ");
	}
	if (capas_num == 0) {
		g_print ("none");
	}
	g_print ("\n");

	list_wifi_access_points (aps, active_ap, capas);
}
static void
dispose (GObject *object)
{
	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);

	clean_up_aps (NM_DEVICE_WIFI (object), FALSE);
	g_clear_object (&priv->proxy);

	G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
}
static void
add_connections_for_aps (NmtConnectDevice *nmtdev,
                         GSList           *connections)
{
	NmtConnectConnection *nmtconn;
	NMConnection *conn;
	NMAccessPoint *ap;
	const GPtrArray *aps;
	GHashTable *seen_ssids;
	char *ap_hash;
	GSList *iter;
	int i;

	aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nmtdev->device));
	if (!aps)
		return;

	seen_ssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

	for (i = 0; i < aps->len; i++) {
		ap = aps->pdata[i];

		if (!nm_access_point_get_ssid (ap))
			continue;

		ap_hash = hash_ap (ap);
		if (g_hash_table_contains (seen_ssids, ap_hash)) {
			g_free (ap_hash);
			continue;
		}
		g_hash_table_add (seen_ssids, ap_hash);

		nmtconn = g_slice_new0 (NmtConnectConnection);
		nmtconn->device = nmtdev->device;
		nmtconn->ap = g_object_ref (ap);
		nmtconn->ssid = nm_utils_ssid_to_utf8 (nm_access_point_get_ssid (ap));

		for (iter = connections; iter; iter = iter->next) {
			conn = iter->data;
			if (   nm_device_connection_valid (nmtdev->device, conn)
			    && nm_access_point_connection_valid (ap, conn)) {
				nmtconn->name = nm_connection_get_id (conn);
				nmtconn->conn = g_object_ref (conn);
				break;
			}
		}

		if (!iter)
			nmtconn->name = nmtconn->ssid;

		nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn);
	}

	g_hash_table_unref (seen_ssids);
}
Пример #16
0
static void
show_wifi_device_info (NMDevice *device)
{
	NMAccessPoint *active_ap = NULL;
	const GPtrArray *aps;
	const char *iface;
	const char *driver;
	guint32 speed;
	const GByteArray *active_ssid; 
	char *active_ssid_str = NULL;
	int i;

	/* Get active AP */
	if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
		if ((active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device)))) {
			active_ssid = nm_access_point_get_ssid (active_ap);
			active_ssid_str = nm_utils_ssid_to_utf8 (active_ssid);
		}
	}

        iface = nm_device_get_iface (device);
        driver = nm_device_get_driver (device);
	speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device));
	speed /= 1000;

	printf ("Device: %s  ----  Driver: %s  ----  Speed: %d MB/s  ----  Active AP: %s\n",
	         iface, driver, speed, active_ssid_str ? active_ssid_str : "none");
	printf ("=================================================================================\n");
	g_free (active_ssid_str);

	/* Get all APs of the Wi-Fi device */
	aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));

	/* Print AP details */
	for (i = 0; aps && (i < aps->len); i++) {
		NMAccessPoint *ap = g_ptr_array_index (aps, i);
		show_access_point_info (ap);
	}
}
Пример #17
0
static void
bitrate_changed_cb (GObject *device, GParamSpec *pspec, gpointer user_data)
{
	GtkWidget *speed_label = GTK_WIDGET (user_data);
	guint32 bitrate = 0;
	char *str = NULL;

	bitrate = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device)) / 1000;
	if (bitrate)
		str = g_strdup_printf (_("%u Mb/s"), bitrate);

	gtk_label_set_text (GTK_LABEL (speed_label), str ? str : _("Unknown"));
	g_free (str);
}
Пример #18
0
static gboolean
is_companion (NMDeviceOlpcMesh *self, NMDevice *other)
{
	NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
	struct ether_addr their_addr;
	NMManager *manager;

	if (!NM_IS_DEVICE_WIFI (other))
		return FALSE;

	nm_device_wifi_get_address (NM_DEVICE_WIFI (other), &their_addr);

	if (memcmp (priv->hw_addr.ether_addr_octet,
		their_addr.ether_addr_octet, ETH_ALEN) != 0) {
		return FALSE;
	}

	/* FIXME detect when our companion leaves */
	priv->companion = other;

	/* When we've found the companion, stop listening for other devices */
	manager = nm_manager_get ();
	if (priv->device_added_id) {
		g_signal_handler_disconnect (manager, priv->device_added_id);
		priv->device_added_id = 0;
	}
	g_object_unref (manager);

	nm_device_state_changed (NM_DEVICE (self),
	                         NM_DEVICE_STATE_DISCONNECTED,
	                         NM_DEVICE_STATE_REASON_NONE);

	nm_log_info (LOGD_OLPC_MESH, "(%s): found companion WiFi device %s",
	             nm_device_get_iface (NM_DEVICE (self)),
	             nm_device_get_iface (other));

	g_signal_connect (G_OBJECT (other), "state-changed",
	                  G_CALLBACK (companion_state_changed_cb), self);
	g_signal_connect (G_OBJECT (other), "notify::scanning",
	                  G_CALLBACK (companion_notify_cb), self);
	g_signal_connect (G_OBJECT (other), "scanning-allowed",
	                  G_CALLBACK (companion_scan_allowed_cb), self);
	g_signal_connect (G_OBJECT (other), "autoconnect-allowed",
	                  G_CALLBACK (companion_autoconnect_allowed_cb), self);

	g_object_notify (G_OBJECT (self), NM_DEVICE_OLPC_MESH_COMPANION);

	return TRUE;
}
Пример #19
0
static void
dispose (GObject *object)
{
	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);

	if (priv->disposed) {
		G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
		return;
	}

	priv->disposed = TRUE;

	clean_up_aps (NM_DEVICE_WIFI (object), FALSE);
	g_object_unref (priv->proxy);

	G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
}
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);
}
static gboolean
nm_device_is_connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
	g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);

	if (NM_IS_DEVICE_ETHERNET (device))
		return check_ethernet_compatible (NM_DEVICE_ETHERNET (device), connection, error);
	else if (NM_IS_DEVICE_WIFI (device))
		return check_wifi_compatible (NM_DEVICE_WIFI (device), connection, error);
	else if (NM_IS_DEVICE_BT (device))
		return check_bt_compatible (NM_DEVICE_BT (device), connection, error);
//      else if (NM_IS_DEVICE_OLPC_MESH (device))
//              return check_olpc_mesh_compatible (NM_DEVICE_OLPC_MESH (device), connection, error);

	g_set_error (error, 0, 0, "unhandled device type '%s'", G_OBJECT_TYPE_NAME (device));
	return FALSE;
}
Пример #22
0
static GObject*
constructor (GType type,
		   guint n_construct_params,
		   GObjectConstructParam *construct_params)
{
	GObject *object;
	NMDeviceWifiPrivate *priv;

	object = G_OBJECT_CLASS (nm_device_wifi_parent_class)->constructor (type,
																    n_construct_params,
																    construct_params);
	if (!object)
		return NULL;

	priv = NM_DEVICE_WIFI_GET_PRIVATE (object);

	priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
											NM_DBUS_SERVICE,
											nm_object_get_path (NM_OBJECT (object)),
											NM_DBUS_INTERFACE_DEVICE_WIRELESS);

	dbus_g_proxy_add_signal (priv->proxy, "AccessPointAdded",
	                         DBUS_TYPE_G_OBJECT_PATH,
	                         G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (priv->proxy, "AccessPointAdded",
						    G_CALLBACK (access_point_added_proxy),
						    object, NULL);

	dbus_g_proxy_add_signal (priv->proxy, "AccessPointRemoved",
	                         DBUS_TYPE_G_OBJECT_PATH,
	                         G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (priv->proxy, "AccessPointRemoved",
						    G_CALLBACK (access_point_removed_proxy),
						    object, NULL);

	register_for_property_changed (NM_DEVICE_WIFI (object));

	g_signal_connect (NM_DEVICE (object),
	                  "notify::" NM_DEVICE_STATE,
	                  G_CALLBACK (state_changed_cb),
	                  NULL);

	return object;
}
Пример #23
0
void WifiStatusNM::initializeStatus() {
  connectedAP = nullptr;
  connected = false;

  if (!this->connectToNetworkManager())
    DBG("WifiStatusNM: failed to connect to nmclient over dbus");

  nmlistener = new NMListener();
  nmlistener->initialize(this, nmclient);
  nmlistener->startThread();

  enabled = nm_client_wireless_get_enabled(nmclient);

  if (!enabled)
    return;

  connected = nm_device_get_state(nmdevice) == NM_DEVICE_STATE_ACTIVATED;

  if (connected)
    connectedAP = getNMConnectedAP(NM_DEVICE_WIFI(nmdevice));
}
static void
constructed (GObject *object)
{
	NMDeviceWifiPrivate *priv;

	G_OBJECT_CLASS (nm_device_wifi_parent_class)->constructed (object);

	priv = NM_DEVICE_WIFI_GET_PRIVATE (object);

	priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
											NM_DBUS_SERVICE,
											nm_object_get_path (NM_OBJECT (object)),
											NM_DBUS_INTERFACE_DEVICE_WIRELESS);

	register_properties (NM_DEVICE_WIFI (object));

	g_signal_connect (NM_DEVICE (object),
	                  "notify::" NM_DEVICE_STATE,
	                  G_CALLBACK (state_changed_cb),
	                  NULL);
}
Пример #25
0
/* return value must not be freed! */
static const gchar *
get_mac_address_of_device (NMDevice *device)
{
  const gchar *mac = NULL;
  switch (nm_device_get_device_type (device))
    {
    case NM_DEVICE_TYPE_WIFI:
      {
        NMDeviceWifi *device_wifi = NM_DEVICE_WIFI (device);
        mac = nm_device_wifi_get_hw_address (device_wifi);
        break;
      }
    case NM_DEVICE_TYPE_ETHERNET:
      {
        NMDeviceEthernet *device_ethernet = NM_DEVICE_ETHERNET (device);
        mac = nm_device_ethernet_get_hw_address (device_ethernet);
        break;
      }
    case NM_DEVICE_TYPE_WIMAX:
      {
        NMDeviceWimax *device_wimax = NM_DEVICE_WIMAX (device);
        mac = nm_device_wimax_get_hw_address (device_wimax);
        break;
      }
    case NM_DEVICE_TYPE_INFINIBAND:
      {
        NMDeviceInfiniband *device_infiniband = NM_DEVICE_INFINIBAND (device);
        mac = nm_device_infiniband_get_hw_address (device_infiniband);
        break;
      }
    default:
      break;
    }
  /* no MAC address found */
  return mac;
}
Пример #26
0
static NMConnection *
create_connection (NMConnectionItem *item)
{
    NMConnection *connection;
    NMDeviceWifi *device;
    NMAccessPoint *ap;
    NMSetting *s_con;
    NMSetting *s_wireless;
    NMSettingWirelessSecurity *s_wireless_sec;
    NMSetting8021x *s_8021x = NULL;
    const GByteArray *ap_ssid;
    char *id;
    char buf[33];
    int buf_len;
    NM80211Mode mode;
    guint32 dev_caps;
    gboolean supported = TRUE;

    device = NM_DEVICE_WIFI (nm_device_item_get_device (NM_DEVICE_ITEM (item)));
    ap = nm_wifi_item_get_ap (NM_WIFI_ITEM (item));

    dev_caps = nm_device_wifi_get_capabilities (device);
    s_wireless_sec = get_security_for_ap (ap, dev_caps, &supported, &s_8021x);
    if (!supported)
        return NULL;

    if (NM_CONNECTION_ITEM_CLASS (nm_wifi_item_parent_class)->create_connection)
        connection = NM_CONNECTION_ITEM_CLASS (nm_wifi_item_parent_class)->create_connection (item);

    if (!connection)
        return NULL;

    s_wireless = nm_setting_wireless_new ();
    ap_ssid = nm_access_point_get_ssid (ap);
    g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, ap_ssid, NULL);

    mode = nm_access_point_get_mode (ap);
    if (mode == NM_802_11_MODE_ADHOC)
        g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, "adhoc", NULL);
    else if (mode == NM_802_11_MODE_INFRA)
        g_object_set (s_wireless, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL);
    else
        g_assert_not_reached ();

    nm_connection_add_setting (connection, s_wireless);

    if (s_wireless_sec) {
        g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL);
        nm_connection_add_setting (connection, NM_SETTING (s_wireless_sec));
    }
    if (s_8021x)
        nm_connection_add_setting (connection, NM_SETTING (s_8021x));

    s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
    g_object_set (s_con,
                  NM_SETTING_CONNECTION_TYPE, nm_setting_get_name (s_wireless),
                  NM_SETTING_CONNECTION_AUTOCONNECT, !is_manufacturer_default_ssid (ap_ssid),
                  NULL);

    memset (buf, 0, sizeof (buf));
    buf_len = MIN (ap_ssid->len, sizeof (buf) - 1);
    memcpy (buf, ap_ssid->data, buf_len);
    id = nm_utils_ssid_to_utf8 (buf, buf_len);
    g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
    g_free (id);

    return connection;
}
Пример #27
0
static void
detail_device (gpointer data, gpointer user_data)
{
	NMDevice *device = NM_DEVICE (data);
	char *tmp;
	NMDeviceState state;
	guint32 caps;
	guint32 speed;
	const GArray *array;
	gboolean is_default = FALSE;
	const char *id = NULL;
	NMActiveConnection *active;

	active = nm_device_get_active_connection (device);
	if (active) {
		NMConnection *connection;
		NMSettingConnection *s_con;

		is_default = nm_active_connection_get_default (active);

		connection = get_connection_for_active (active);
		if (connection) {
			s_con = nm_connection_get_setting_connection (connection);
			if (s_con)
				id = nm_setting_connection_get_id (s_con);
		}
	}

	print_header ("Device", nm_device_get_iface (device), id);

	/* General information */
	if (NM_IS_DEVICE_ETHERNET (device))
		print_string ("Type", "Wired");
	else if (NM_IS_DEVICE_WIFI (device))
		print_string ("Type", "802.11 WiFi");
	else if (NM_IS_DEVICE_MODEM (device)) {
		NMDeviceModemCapabilities modem_caps;

		modem_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
		if (modem_caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
			print_string ("Type", "Mobile Broadband (GSM)");
		else if (modem_caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
			print_string ("Type", "Mobile Broadband (CDMA)");
		else
			print_string ("Type", "Mobile Broadband (unknown)");
	} else if (NM_IS_DEVICE_BT (device))
		print_string ("Type", "Bluetooth");
	else if (NM_IS_DEVICE_WIMAX (device))
		print_string ("Type", "WiMAX");

	print_string ("Driver", nm_device_get_driver (device) ? nm_device_get_driver (device) : "(unknown)");

	state = nm_device_get_state (device);
	print_string ("State", get_dev_state_string (state));

	if (is_default)
		print_string ("Default", "yes");
	else
		print_string ("Default", "no");

	tmp = NULL;
	if (NM_IS_DEVICE_ETHERNET (device))
		tmp = g_strdup (nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (device)));
	else if (NM_IS_DEVICE_WIFI (device))
		tmp = g_strdup (nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (device)));
	else if (NM_IS_DEVICE_WIMAX (device))
		tmp = g_strdup (nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device)));

	if (tmp) {
		print_string ("HW Address", tmp);
		g_free (tmp);
	}

	/* Capabilities */
	caps = nm_device_get_capabilities (device);
	printf ("\n  Capabilities:\n");
	if (caps & NM_DEVICE_CAP_CARRIER_DETECT)
		print_string ("  Carrier Detect", "yes");

	speed = 0;
	if (NM_IS_DEVICE_ETHERNET (device)) {
		/* Speed in Mb/s */
		speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (device));
	} else if (NM_IS_DEVICE_WIFI (device)) {
		/* Speed in b/s */
		speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device));
		speed /= 1000;
	}

	if (speed) {
		char *speed_string;

		speed_string = g_strdup_printf ("%u Mb/s", speed);
		print_string ("  Speed", speed_string);
		g_free (speed_string);
	}

	/* Wireless specific information */
	if ((NM_IS_DEVICE_WIFI (device))) {
		guint32 wcaps;
		NMAccessPoint *active_ap = NULL;
		const char *active_bssid = NULL;
		const GPtrArray *aps;

		printf ("\n  Wireless Properties\n");

		wcaps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device));

		if (wcaps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104))
			print_string ("  WEP Encryption", "yes");
		if (wcaps & NM_WIFI_DEVICE_CAP_WPA)
			print_string ("  WPA Encryption", "yes");
		if (wcaps & NM_WIFI_DEVICE_CAP_RSN)
			print_string ("  WPA2 Encryption", "yes");

		if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
			active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device));
			active_bssid = active_ap ? nm_access_point_get_hw_address (active_ap) : NULL;
		}

		printf ("\n  Wireless Access Points %s\n", active_ap ? "(* = current AP)" : "");

		aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
		if (aps && aps->len)
			g_ptr_array_foreach ((GPtrArray *) aps, detail_access_point, (gpointer) active_bssid);
	} else if (NM_IS_DEVICE_ETHERNET (device)) {
		printf ("\n  Wired Properties\n");

		if (nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device)))
			print_string ("  Carrier", "on");
		else
			print_string ("  Carrier", "off");
	} else if (NM_IS_DEVICE_WIMAX (device)) {
		NMDeviceWimax *wimax = NM_DEVICE_WIMAX (device);
		NMWimaxNsp *active_nsp = NULL;
		const char *active_name = NULL;
		const GPtrArray *nsps;

		if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
			guint tmp_uint;
			gint tmp_int;
			const char *tmp_str;

			active_nsp = nm_device_wimax_get_active_nsp (wimax);
			active_name = active_nsp ? nm_wimax_nsp_get_name (active_nsp) : NULL;

			printf ("\n  Link Status\n");

			tmp_uint = nm_device_wimax_get_center_frequency (wimax);
			if (tmp_uint)
				tmp = g_strdup_printf ("%'.1f MHz", (double) tmp_uint / 1000.0);
			else
				tmp = g_strdup ("(unknown)");
			print_string ("  Center Freq.", tmp);
			g_free (tmp);

			tmp_int = nm_device_wimax_get_rssi (wimax);
			if (tmp_int)
				tmp = g_strdup_printf ("%d dBm", tmp_int);
			else
				tmp = g_strdup ("(unknown)");
			print_string ("  RSSI", tmp);
			g_free (tmp);

			tmp_int = nm_device_wimax_get_cinr (wimax);
			if (tmp_int)
				tmp = g_strdup_printf ("%d dB", tmp_int);
			else
				tmp = g_strdup ("(unknown)");
			print_string ("  CINR", tmp);
			g_free (tmp);

			tmp_int = nm_device_wimax_get_tx_power (wimax);
			if (tmp_int)
				tmp = g_strdup_printf ("%'.2f dBm", (float) tmp_int / 2.0);
			else
				tmp = g_strdup ("(unknown)");
			print_string ("  TX Power", tmp);
			g_free (tmp);

			tmp_str = nm_device_wimax_get_bsid (wimax);
			if (tmp_str)
				print_string ("  BSID", tmp_str);
			else
				print_string ("  BSID", "(unknown)");
		}

		printf ("\n  WiMAX NSPs %s\n", active_nsp ? "(* current NSP)" : "");

		nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device));
		if (nsps && nsps->len)
			g_ptr_array_foreach ((GPtrArray *) nsps, detail_nsp, (gpointer) active_name);
	}

	/* IP Setup info */
	if (state == NM_DEVICE_STATE_ACTIVATED) {
		NMIP4Config *cfg4 = nm_device_get_ip4_config (device);
		NMIP6Config *cfg6 = nm_device_get_ip6_config (device);
		GSList *iter;

		if (cfg4) {
			printf ("\n  IPv4 Settings:\n");

			for (iter = (GSList *) nm_ip4_config_get_addresses (cfg4); iter; iter = g_slist_next (iter)) {
				NMIP4Address *addr = (NMIP4Address *) iter->data;
				guint32 prefix = nm_ip4_address_get_prefix (addr);
				char *tmp2;

				tmp = ip4_address_as_string (nm_ip4_address_get_address (addr));
				print_string ("  Address", tmp);
				g_free (tmp);

				tmp2 = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (prefix));
				tmp = g_strdup_printf ("%d (%s)", prefix, tmp2);
				g_free (tmp2);
				print_string ("  Prefix", tmp);
				g_free (tmp);

				tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr));
				print_string ("  Gateway", tmp);
				g_free (tmp);
				printf ("\n");
			}

			array = nm_ip4_config_get_nameservers (cfg4);
			if (array) {
				int i;

				for (i = 0; i < array->len; i++) {
					tmp = ip4_address_as_string (g_array_index (array, guint32, i));
					print_string ("  DNS", tmp);
					g_free (tmp);
				}
			}
		}

		if (cfg6) {
			printf ("\n  IPv6 Settings:\n");

			for (iter = (GSList *) nm_ip6_config_get_addresses (cfg6); iter; iter = g_slist_next (iter)) {
				NMIP6Address *addr = (NMIP6Address *) iter->data;
				guint32 prefix = nm_ip6_address_get_prefix (addr);

				tmp = ip6_address_as_string (nm_ip6_address_get_address (addr));
				print_string ("  Address", tmp);
				g_free (tmp);

				tmp = g_strdup_printf ("%d", prefix);
				print_string ("  Prefix", tmp);
				g_free (tmp);

				tmp = ip6_address_as_string (nm_ip6_address_get_gateway (addr));
				print_string ("  Gateway", tmp);
				g_free (tmp);
				printf ("\n");
			}

			for (iter = (GSList *) nm_ip6_config_get_nameservers (cfg6); iter; iter = g_slist_next (iter)) {
				tmp = ip6_address_as_string (iter->data);
				print_string ("  DNS", tmp);
				g_free (tmp);
			}
		}
	}

	printf ("\n\n");
}
Пример #28
0
static void
synchronize_device (Network *self,
                    NMDevice *device)
{
  const char *iface_name = nm_device_get_iface (device);
  Netinterface *iface;
  NMIP4Config *ip4config;
  NMIP6Config *ip6config;

  iface = g_hash_table_lookup (self->ifname_to_netinterface,
                               iface_name);
  g_assert (iface);
  cockpit_network_netinterface_set_name (COCKPIT_NETWORK_NETINTERFACE (iface), iface_name);

  ip4config = nm_device_get_ip4_config (device);
  if (ip4config)
    {
      const GSList *addresses = nm_ip4_config_get_addresses (ip4config);
      const GSList *iter;
      GVariantBuilder builder;

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(yyyyu)"));

      for (iter = addresses; iter; iter = iter->next)
        {
          NMIP4Address *ip4addr = iter->data;
          guint32 ipaddr = ntohl (nm_ip4_address_get_address (ip4addr));
          guint32 prefix = nm_ip4_address_get_prefix (ip4addr);

          g_variant_builder_add_value (&builder, ip4_addr_variant_new (ipaddr, prefix));
        }

      cockpit_network_netinterface_set_ip4_addresses (COCKPIT_NETWORK_NETINTERFACE (iface), g_variant_builder_end (&builder));
    }
  ip6config = nm_device_get_ip6_config (device);
  if (ip6config)
    {
      const GSList *addresses = nm_ip6_config_get_addresses (ip6config);
      const GSList *iter;
      GVariantBuilder builder;

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(yyyyyyyyyyyyyyyyu)"));

      for (iter = addresses; iter; iter = iter->next)
        {
          NMIP6Address *ip6addr = iter->data;

          g_variant_builder_add_value (&builder, ip6_addr_variant_new (nm_ip6_address_get_address (ip6addr),
                                                                       nm_ip6_address_get_prefix (ip6addr)));
        }

      cockpit_network_netinterface_set_ip6_addresses (COCKPIT_NETWORK_NETINTERFACE (iface), g_variant_builder_end (&builder));
    }

  synchronize_device_config (self, iface, device);

  switch (nm_device_get_device_type (device))
    {
    case NM_DEVICE_TYPE_ETHERNET:
      synchronize_device_ethernet (self, iface, NM_DEVICE_ETHERNET (device));
      break;
    case NM_DEVICE_TYPE_WIFI:
      synchronize_device_wifi (self, iface, NM_DEVICE_WIFI (device));
      break;
    default:
      break;
    }
}
Пример #29
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;
}
Пример #30
0
void WifiStatusNM::setConnectedAccessPoint(WifiAccessPoint *ap, String psk) {
  ScopedPointer<StringArray> cmd;

  for (const auto& listener : listeners)
    listener->handleWifiBusy();

  // disconnect if no ap provided
  if (ap == nullptr) {
    NMActiveConnection *conn = nm_device_get_active_connection(nmdevice);
    removeNMConnection(nmdevice, conn);

    return;
  }
  // try to connect to ap, dispatch events on success and failure
  else {
    NMConnection *connection = NULL;
    NMSettingWireless *s_wifi = NULL;
    NMSettingWirelessSecurity *s_wsec = NULL;
    const char *nm_ap_path = NULL;
    const GPtrArray *ap_list;
    NMAccessPoint *candidate_ap;

    //FIXME: expand WifiAccessPoint struct to know which NMAccessPoint it is
    ap_list = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(nmdevice));
    if (ap_list == NULL)
      return;

    for (int i = 0; i < ap_list->len; i++) {
      const char *candidate_hash;
      candidate_ap = (NMAccessPoint *) g_ptr_array_index(ap_list, i);
      candidate_hash = utils_hash_ap(nm_access_point_get_ssid(candidate_ap),
                                     nm_access_point_get_mode(candidate_ap),
                                     nm_access_point_get_flags(candidate_ap),
                                     nm_access_point_get_wpa_flags(candidate_ap),
                                     nm_access_point_get_rsn_flags(candidate_ap));

      if (ap->hash == candidate_hash) {
        nm_ap_path = nm_object_get_path(NM_OBJECT(candidate_ap));
        break;
      }
    }

    if (!nm_ap_path)
      return;

    connecting = true;

    connection = nm_connection_new();
    s_wifi = (NMSettingWireless *) nm_setting_wireless_new();
    nm_connection_add_setting(connection, NM_SETTING(s_wifi));
    g_object_set(s_wifi,
                 NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid(candidate_ap),
                 NM_SETTING_WIRELESS_HIDDEN, false,
                 NULL);

    if (!psk.isEmpty()) {
      s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new();
      nm_connection_add_setting(connection, NM_SETTING(s_wsec));

      if (nm_access_point_get_wpa_flags(candidate_ap) == NM_802_11_AP_SEC_NONE &&
          nm_access_point_get_rsn_flags(candidate_ap) == NM_802_11_AP_SEC_NONE) {
        /* WEP */
        nm_setting_wireless_security_set_wep_key(s_wsec, 0, psk.toRawUTF8());
	if (isValidWEPKeyFormat(psk))
          g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE,
                       NM_WEP_KEY_TYPE_KEY, NULL);
	else if (isValidWEPPassphraseFormat(psk))
          g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE,
                       NM_WEP_KEY_TYPE_PASSPHRASE, NULL);
	else
	  DBG("User input invalid WEP Key type, psk.length() = " << psk.length()
              << ", not in [5,10,13,26]");
      } else {
        g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk.toRawUTF8(), NULL);
      }
    }

    nm_client_add_and_activate_connection(nmclient,
                                                connection,
                                                nmdevice,
                                                nm_ap_path,
                                                handle_add_and_activate_finish,
                                                this);
  }
}