static void
wizard_done (NMConnection *connection,
             gboolean auto_created,
             gboolean canceled,
             gpointer user_data)
{
	ConnectNetworkInfo *info = user_data;

	if (canceled == FALSE) {
		g_return_if_fail (connection != NULL);

		/* Ask NM to add the new connection and activate it; NM will fill in the
		 * missing details based on the specific object and the device.
		 */
		nm_client_add_and_activate_connection (info->applet->nm_client,
		                                       connection,
		                                       info->device,
		                                       "/",
		                                       add_and_activate_connection_done,
		                                       info->applet);
	}

	g_object_unref (info->device);
	g_free (info);
}
static void
dbus_connect_3g_cb (NMConnection *connection,
                    gboolean auto_created,
                    gboolean canceled,
                    gpointer user_data)
{
	Dbus3gInfo *info = user_data;

	if (canceled == FALSE) {
		g_return_if_fail (connection != NULL);

		/* Ask NM to add the new connection and activate it; NM will fill in the
		 * missing details based on the specific object and the device.
		 */
		nm_client_add_and_activate_connection (info->applet->nm_client,
		                                       connection,
		                                       info->device,
		                                       "/",
		                                       dbus_3g_add_and_activate_cb,
		                                       info->applet);
	}

	g_object_unref (info->device);
	memset (info, 0, sizeof (*info));
	g_free (info);
}
static void
connect_3g (NMConnection *connection,
            gboolean canceled,
            gpointer user_data)
{
    MobileDialogClosure *closure = user_data;

    if (canceled == FALSE) {
        g_return_if_fail (connection != NULL);

        /* Ask NM to add the new connection and activate it; NM will fill in the
         * missing details based on the specific object and the device.
         */
        nm_client_add_and_activate_connection (closure->client,
                                               connection,
                                               closure->device,
                                               "/",
                                               activate_new_cb,
                                               NULL);
    }

    mobile_dialog_closure_free (closure);
}
예제 #4
0
static void
row_activated (GtkListBox *box,
               GtkListBoxRow *row,
               GisNetworkPage *page)
{
  GisNetworkPagePrivate *priv = gis_network_page_get_instance_private (page);
  gchar *object_path;
  GSList *list, *filtered, *l;
  NMConnection *connection;
  NMConnection *connection_to_activate;
  NMSettingWireless *setting;
  const GByteArray *ssid_target;
  const GByteArray *ssid;
  GtkWidget *child;

  if (priv->refreshing)
    return;

  child = gtk_bin_get_child (GTK_BIN (row));
  object_path = g_object_get_data (G_OBJECT (child), "object-path");
  ssid_target = g_object_get_data (G_OBJECT (child), "ssid");

  if (g_strcmp0 (object_path, "ap-other...") == 0) {
    connect_to_hidden_network (page);
    goto out;
  }

  list = nm_remote_settings_list_connections (priv->nm_settings);
  filtered = nm_device_filter_connections (priv->nm_device, list);

  connection_to_activate = NULL;

  for (l = filtered; l; l = l->next) {
    connection = NM_CONNECTION (l->data);
    setting = nm_connection_get_setting_wireless (connection);
    if (!NM_IS_SETTING_WIRELESS (setting))
      continue;

    ssid = nm_setting_wireless_get_ssid (setting);
    if (ssid == NULL)
      continue;

    if (nm_utils_same_ssid (ssid, ssid_target, TRUE)) {
      connection_to_activate = connection;
      break;
    }
  }
  g_slist_free (list);
  g_slist_free (filtered);

  if (connection_to_activate != NULL) {
    nm_client_activate_connection (priv->nm_client,
                                   connection_to_activate,
                                   priv->nm_device, NULL,
                                   connection_activate_cb, page);
    goto out;
  }

  nm_client_add_and_activate_connection (priv->nm_client,
                                         NULL,
                                         priv->nm_device, object_path,
                                         connection_add_activate_cb, page);

 out:
  refresh_wireless_list (page);
}
예제 #5
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);
  }
}
static void
wireless_dialog_response_cb (GtkDialog *foo,
                             gint response,
                             gpointer user_data)
{
    NMAWirelessDialog *dialog = NMA_WIRELESS_DIALOG (foo);
    WirelessDialogClosure *closure = user_data;
    NMConnection *connection, *fuzzy_match = NULL;
    NMDevice *device;
    NMAccessPoint *ap;
    GSList *all, *iter;

    if (response != GTK_RESPONSE_OK)
        goto done;

    if (!nma_wireless_dialog_get_nag_ignored (dialog)) {
        GtkWidget *nag_dialog;

        /* Nag the user about certificates or whatever.  Only destroy the dialog
         * if no nagging was done.
         */
        nag_dialog = nma_wireless_dialog_nag_user (dialog);
        if (nag_dialog) {
            gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
            g_signal_connect (nag_dialog, "response",
                              G_CALLBACK (nag_dialog_response_cb),
                              dialog);
            return;
        }
    }

    /* nma_wireless_dialog_get_connection() returns a connection with the
     * refcount incremented, so the caller must remember to unref it.
     */
    connection = nma_wireless_dialog_get_connection (dialog, &device, &ap);
    g_assert (connection);
    g_assert (device);

    /* Find a similar connection and use that instead */
    all = nm_remote_settings_list_connections (closure->settings);
    for (iter = all; iter; iter = g_slist_next (iter)) {
        if (nm_connection_compare (connection,
                                   NM_CONNECTION (iter->data),
                                   (NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) {
            fuzzy_match = NM_CONNECTION (iter->data);
            break;
        }
    }
    g_slist_free (all);

    if (fuzzy_match) {
        nm_client_activate_connection (closure->client,
                                       fuzzy_match,
                                       device,
                                       ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
                                       activate_existing_cb,
                                       NULL);
    } else {
        NMSetting *s_con;
        NMSettingWireless *s_wifi;
        const char *mode = NULL;

        /* Entirely new connection */

        /* Don't autoconnect adhoc networks by default for now */
        s_wifi = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
        if (s_wifi)
            mode = nm_setting_wireless_get_mode (s_wifi);
        if (g_strcmp0 (mode, "adhoc") == 0) {
            s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
            if (!s_con) {
                s_con = nm_setting_connection_new ();
                nm_connection_add_setting (connection, s_con);
            }
            g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL);
        }

        nm_client_add_and_activate_connection (closure->client,
                                               connection,
                                               device,
                                               ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL,
                                               activate_new_cb,
                                               NULL);
    }

    /* Balance nma_wireless_dialog_get_connection() */
    g_object_unref (connection);

done:
    gtk_widget_hide (GTK_WIDGET (dialog));
    gtk_widget_destroy (GTK_WIDGET (dialog));
}