static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { NMObject *object; DBusGConnection *connection; NMDHCP6ConfigPrivate *priv; object = (NMObject *) G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); connection = nm_object_get_connection (object); priv->proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, nm_object_get_path (object), NM_DBUS_INTERFACE_DHCP6_CONFIG); register_for_property_changed (NM_DHCP6_CONFIG (object)); return G_OBJECT (object); }
/** * nm_device_wifi_get_access_point_by_path: * @device: a #NMDeviceWifi * @path: the object path of the access point * * Gets a #NMAccessPoint by path. * * Returns: (transfer none): the access point or %NULL if none is found. **/ NMAccessPoint * nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device, const char *path) { const GPtrArray *aps; int i; NMAccessPoint *ap = NULL; g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); g_return_val_if_fail (path != NULL, NULL); aps = nm_device_wifi_get_access_points (device); if (!aps) return NULL; for (i = 0; i < aps->len; i++) { NMAccessPoint *candidate = g_ptr_array_index (aps, i); if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), path)) { ap = candidate; break; } } return ap; }
static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { NMObject *object; NMActiveConnectionPrivate *priv; object = (NMObject *) G_OBJECT_CLASS (nm_active_connection_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object), NM_DBUS_SERVICE, nm_object_get_path (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION); register_for_property_changed (NM_ACTIVE_CONNECTION (object)); return G_OBJECT (object); }
static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { NMObject *object; DBusGConnection *connection; NMIP4ConfigPrivate *priv; object = (NMObject *) G_OBJECT_CLASS (nm_ip4_config_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_IP4_CONFIG_GET_PRIVATE (object); connection = nm_object_get_connection (object); priv->proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, nm_object_get_path (object), NM_DBUS_INTERFACE_IP4_CONFIG); register_for_property_changed (NM_IP4_CONFIG (object)); return G_OBJECT (object); }
/** * nm_device_wimax_get_nsp_by_path: * @wimax: a #NMDeviceWimax * @path: the object path of the NSP * * Gets a #NMWimaxNsp by path. * * Returns: (transfer none): the access point or %NULL if none is found. * * Deprecated: 1.2: WiMAX is no longer supported. **/ NMWimaxNsp * nm_device_wimax_get_nsp_by_path (NMDeviceWimax *wimax, const char *path) { const GPtrArray *nsps; int i; NMWimaxNsp *nsp = NULL; g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); g_return_val_if_fail (path != NULL, NULL); nsps = nm_device_wimax_get_nsps (wimax); if (!nsps) return NULL; for (i = 0; i < nsps->len; i++) { NMWimaxNsp *candidate = g_ptr_array_index (nsps, i); if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), path)) { nsp = candidate; break; } } return nsp; }
static char * wifi_get_specific_object (NMDeviceItem *item) { NMAccessPoint *ap; ap = GET_PRIVATE (item)->current_ap; return g_strdup (nm_object_get_path (NM_OBJECT (ap))); }
void _nm_object_cache_add (NMObject *object) { char *path; _init_cache (); path = g_strdup (nm_object_get_path (object)); g_hash_table_insert (cache, path, object); g_object_set_data_full (G_OBJECT (object), "nm-object-cache-tag", g_strdup (path), (GDestroyNotify) _nm_object_cache_remove_by_path); }
void nm_network_menu_item_add_dupe (NMNetworkMenuItem *item, NMAccessPoint *ap) { const char *path; g_return_if_fail (item != NULL); g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item)); g_return_if_fail (NM_IS_ACCESS_POINT (ap)); path = nm_object_get_path (NM_OBJECT (ap)); item->dupes = g_slist_prepend (item->dupes, g_strdup (path)); }
static GtkWidget * info_dialog_update (NMApplet *applet) { GtkNotebook *notebook; const GPtrArray *connections; int i; int pages = 0; notebook = GTK_NOTEBOOK (glade_xml_get_widget (applet->info_dialog_xml, "info_notebook")); /* Remove old pages */ for (i = gtk_notebook_get_n_pages (notebook); i > 0; i--) gtk_notebook_remove_page (notebook, -1); /* Add new pages */ connections = nm_client_get_active_connections (applet->nm_client); for (i = 0; connections && (i < connections->len); i++) { NMActiveConnection *active_connection = g_ptr_array_index (connections, i); NMConnection *connection; const GPtrArray *devices; if (nm_active_connection_get_state (active_connection) != NM_ACTIVE_CONNECTION_STATE_ACTIVATED) continue; devices = nm_active_connection_get_devices (active_connection); if (!devices || !devices->len) { g_warning ("Active connection %s had no devices!", nm_object_get_path (NM_OBJECT (active_connection))); continue; } connection = get_connection_for_active (applet, active_connection); if (!connection) { g_warning ("%s: couldn't find the default active connection's NMConnection!", __func__); continue; } info_dialog_add_page (notebook, connection, nm_active_connection_get_default (active_connection), g_ptr_array_index (devices, 0)); pages++; } if (pages == 0) { /* Shouldn't really happen but ... */ info_dialog_show_error (_("No valid active connections found!")); return NULL; } return glade_xml_get_widget (applet->info_dialog_xml, "info_dialog"); }
static void wimax_menu_item_activate (GtkMenuItem *item, gpointer user_data) { WimaxMenuItemInfo *info = (WimaxMenuItemInfo *) user_data; const char *specific_object = NULL; if (info->nsp) specific_object = nm_object_get_path (NM_OBJECT (info->nsp)); applet_menu_item_activate_helper (info->device, info->connection, specific_object, info->applet, user_data); }
static void constructed (GObject *object) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object); G_OBJECT_CLASS (nm_device_bt_parent_class)->constructed (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_BLUETOOTH); register_properties (NM_DEVICE_BT (object)); }
static void test_get_active_connections (NMClient *client) { const GPtrArray *connections; int i; g_print ("Active connections:\n"); connections = nm_client_get_active_connections (client); for (i = 0; connections && (i < connections->len); i++) { const GPtrArray *devices; g_print (" %s\n", nm_object_get_path (g_ptr_array_index (connections, i))); devices = nm_active_connection_get_devices (g_ptr_array_index (connections, i)); if (devices) g_ptr_array_foreach ((GPtrArray *) devices, show_active_connection_device, NULL); } }
gboolean nm_network_menu_item_find_dupe (NMNetworkMenuItem *item, NMAccessPoint *ap) { const char *path; GSList *iter; g_return_val_if_fail (item != NULL, FALSE); g_return_val_if_fail (NM_IS_NETWORK_MENU_ITEM (item), FALSE); g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), FALSE); path = nm_object_get_path (NM_OBJECT (ap)); for (iter = item->dupes; iter; iter = g_slist_next (iter)) { if (!strcmp (path, iter->data)) return TRUE; } return FALSE; }
static void constructed (GObject *object) { DBusGConnection *connection; NMIP4ConfigPrivate *priv; G_OBJECT_CLASS (nm_ip4_config_parent_class)->constructed (object); priv = NM_IP4_CONFIG_GET_PRIVATE (object); connection = nm_object_get_connection (NM_OBJECT (object)); priv->proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, nm_object_get_path (NM_OBJECT (object)), NM_DBUS_INTERFACE_IP4_CONFIG); register_properties (NM_IP4_CONFIG (object)); }
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; }
static void deactivate_cb (DBusGProxy *proxy, GError *error, gpointer user_data) { DeactivateInfo *info = user_data; if (info->fn) info->fn (info->device, error, info->user_data); else if (error) { g_warning ("%s: device %s deactivation failed: (%d) %s", __func__, nm_object_get_path (NM_OBJECT (info->device)), error ? error->code : -1, error && error->message ? error->message : "(unknown)"); } g_object_unref (info->device); g_slice_free (DeactivateInfo, info); }
static void constructed (GObject *object) { DBusGConnection *connection; NMDHCP6ConfigPrivate *priv; G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->constructed (object); priv = NM_DHCP6_CONFIG_GET_PRIVATE (object); priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); connection = nm_object_get_connection (NM_OBJECT (object)); priv->proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, nm_object_get_path (NM_OBJECT (object)), NM_DBUS_INTERFACE_DHCP6_CONFIG); register_properties (NM_DHCP6_CONFIG (object)); }
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); }
static void active_connections_changed (NMClient *client, GParamSpec *pspec, gpointer user_data) { const GPtrArray *connections; int i, j; g_print ("Active connections changed:\n"); connections = nm_client_get_active_connections (client); for (i = 0; connections && (i < connections->len); i++) { NMActiveConnection *connection; const GPtrArray *devices; connection = g_ptr_array_index (connections, i); g_print (" %s\n", nm_object_get_path (NM_OBJECT (connection))); devices = nm_active_connection_get_devices (connection); for (j = 0; devices && j < devices->len; j++) g_print (" %s\n", nm_device_get_udi (g_ptr_array_index (devices, j))); if (NM_IS_VPN_CONNECTION (connection)) g_print (" VPN base connection: %s\n", nm_active_connection_get_specific_object (connection)); } }
static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { NMObject *object; NMDevicePrivate *priv; object = (NMObject *) G_OBJECT_CLASS (nm_device_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_DEVICE_GET_PRIVATE (object); priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object), NM_DBUS_SERVICE, nm_object_get_path (object), NM_DBUS_INTERFACE_DEVICE); register_for_property_changed (NM_DEVICE (object)); dbus_g_object_register_marshaller (_nm_marshal_VOID__UINT_UINT_UINT, G_TYPE_NONE, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->proxy, "StateChanged", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "StateChanged", G_CALLBACK (device_state_changed), NM_DEVICE (object), NULL); return G_OBJECT (object); }
/** * nm_client_get_active_connection_by_path: * @client: a #NMClient * @object_path: the object path to search for * * Gets a #NMActiveConnection from a #NMClient. * * Returns: the #NMActiveConnection for the given @object_path or %NULL if none is found. **/ static NMActiveConnection * nm_client_get_active_connection_by_path (NMClient *client, const char *object_path) { const GPtrArray *actives; int i; NMActiveConnection *active = NULL; g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (object_path, NULL); actives = nm_client_get_active_connections (client); if (!actives) return NULL; for (i = 0; i < actives->len; i++) { NMActiveConnection *candidate = g_ptr_array_index (actives, i); if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), object_path)) { active = candidate; break; } } return active; }
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 add_access_point (GisNetworkPage *page, NMAccessPoint *ap, NMAccessPoint *active) { GisNetworkPagePrivate *priv = page->priv; const GByteArray *ssid; const gchar *ssid_text; const gchar *object_path; GtkTreeIter iter; gboolean activated, activating; ssid = nm_access_point_get_ssid (ap); object_path = nm_object_get_path (NM_OBJECT (ap)); if (ssid == NULL) return; ssid_text = nm_utils_escape_ssid (ssid->data, ssid->len); if (active && nm_utils_same_ssid (ssid, nm_access_point_get_ssid (active), TRUE)) { switch (nm_device_get_state (priv->nm_device)) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_SECONDARIES: activated = FALSE; activating = TRUE; break; case NM_DEVICE_STATE_ACTIVATED: activated = TRUE; activating = FALSE; break; default: activated = FALSE; activating = FALSE; break; } } else { activated = FALSE; activating = FALSE; } gtk_list_store_append (priv->ap_list, &iter); gtk_list_store_set (priv->ap_list, &iter, PANEL_WIRELESS_COLUMN_ID, object_path, PANEL_WIRELESS_COLUMN_TITLE, ssid_text, PANEL_WIRELESS_COLUMN_STRENGTH, nm_access_point_get_strength (ap), PANEL_WIRELESS_COLUMN_MODE, nm_access_point_get_mode (ap), PANEL_WIRELESS_COLUMN_SECURITY, get_access_point_security (ap), PANEL_WIRELESS_COLUMN_ACTIVATING, activating, PANEL_WIRELESS_COLUMN_ACTIVE, activated, PANEL_WIRELESS_COLUMN_PULSE, priv->pulse, -1); if (activating) { GtkTreePath *path; GtkTreeModel *model; model = (GtkTreeModel*)priv->ap_list; path = gtk_tree_model_get_path (model, &iter); priv->row = gtk_tree_row_reference_new (model, path); gtk_tree_path_free (path); g_timeout_add (160, bump_pulse, page); } }
static void activate_connection (NMConnection *connection, NMDevice *device, NMObject *specific_object) { NmtNewtForm *form; gs_unref_object NMSecretAgentOld *agent = NULL; NmtNewtWidget *label; NmtSyncOp op; const char *specific_object_path; NMActiveConnection *ac; GError *error = NULL; form = g_object_new (NMT_TYPE_NEWT_FORM, "escape-exits", TRUE, NULL); label = nmt_newt_label_new (_("Connecting...")); nmt_newt_form_set_content (form, label); agent = nm_secret_agent_simple_new ("nmtui"); if (agent) { if (connection) { nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent), nm_object_get_path (NM_OBJECT (connection))); } g_signal_connect (agent, "request-secrets", G_CALLBACK (secrets_requested), NULL); } specific_object_path = specific_object ? nm_object_get_path (specific_object) : NULL; /* There's no way to cancel an nm_client_activate_connection() / * nm_client_add_and_activate_connection() call, so we always let them * complete, even if the user hits Esc; they shouldn't normally take long * to complete anyway. */ nmt_sync_op_init (&op); if (connection) { nm_client_activate_connection_async (nm_client, connection, device, specific_object_path, NULL, activate_callback, &op); } else { nm_client_add_and_activate_connection_async (nm_client, NULL, device, specific_object_path, NULL, add_and_activate_callback, &op); } nmt_newt_form_show (form); ac = nmt_sync_op_wait_pointer (&op, &error); if (!ac) { nmt_newt_message_dialog (_("Could not activate connection: %s"), error->message); g_clear_error (&error); goto done; } else if (nm_active_connection_get_state (ac) == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { /* Already active */ goto done; } else if (!nmt_newt_widget_get_realized (NMT_NEWT_WIDGET (form))) { /* User already hit Esc */ goto done; } if (agent && !connection) { connection = NM_CONNECTION (nm_active_connection_get_connection (ac)); if (connection) { nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent), nm_object_get_path (NM_OBJECT (connection))); } } /* Now wait for the connection to actually reach the ACTIVATED state, * allowing the user to cancel if it takes too long. */ nmt_sync_op_init (&op); g_signal_connect (form, "quit", G_CALLBACK (connect_cancelled), &op); g_signal_connect (ac, "notify::" NM_ACTIVE_CONNECTION_STATE, G_CALLBACK (activate_ac_state_changed), &op); if (!nmt_sync_op_wait_boolean (&op, &error)) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) nmt_newt_message_dialog (_("Could not activate connection: %s"), error->message); g_clear_error (&error); } g_signal_handlers_disconnect_by_func (form, G_CALLBACK (connect_cancelled), &op); g_signal_handlers_disconnect_by_func (ac, G_CALLBACK (activate_ac_state_changed), &op); done: if (nmt_newt_widget_get_realized (NMT_NEWT_WIDGET (form))) nmt_newt_form_quit (form); g_object_unref (form); if (agent) nm_secret_agent_old_unregister (agent, NULL, NULL); }
static void show_access_point_info (NMAccessPoint *ap) { guint32 flags, wpa_flags, rsn_flags, freq, bitrate; guint8 strength; const GByteArray *ssid; const char *hwaddr; NM80211Mode mode; char *freq_str, *ssid_str, *bitrate_str, *strength_str, *wpa_flags_str, *rsn_flags_str; GString *security_str; /* Get AP properties */ 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); ssid = nm_access_point_get_ssid (ap); hwaddr = nm_access_point_get_hw_address (ap); freq = nm_access_point_get_frequency (ap); mode = nm_access_point_get_mode (ap); bitrate = nm_access_point_get_max_bitrate (ap); strength = nm_access_point_get_strength (ap); /* Convert to strings */ ssid_str = nm_utils_ssid_to_utf8 (ssid); freq_str = g_strdup_printf ("%u MHz", freq); bitrate_str = g_strdup_printf ("%u MB/s", bitrate/1000); strength_str = g_strdup_printf ("%u", strength); wpa_flags_str = ap_wpa_rsn_flags_to_string (wpa_flags); rsn_flags_str = ap_wpa_rsn_flags_to_string (rsn_flags); security_str = g_string_new (NULL); 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 (security_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 (security_str, "WEP "); if (wpa_flags != NM_802_11_AP_SEC_NONE) g_string_append (security_str, "WPA "); if (rsn_flags != NM_802_11_AP_SEC_NONE) g_string_append (security_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 (security_str, "Enterprise "); if (security_str->len > 0) g_string_truncate (security_str, security_str->len-1); /* Chop off last space */ printf ("SSID: %s\n", ssid_str); printf ("BSSID: %s\n", hwaddr); printf ("Mode: %s\n", mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc" : mode == NM_802_11_MODE_INFRA ? "Infrastructure" : "Unknown"); printf ("Freq: %s\n", freq_str); printf ("Bitrate: %s\n", bitrate_str); printf ("Strength: %s\n", strength_str); printf ("Security: %s\n", security_str->str); printf ("WPA flags: %s\n", wpa_flags_str); printf ("RSN flags: %s\n", rsn_flags_str); printf ("D-Bus path: %s\n\n", nm_object_get_path (NM_OBJECT (ap))); g_free (ssid_str); g_free (freq_str); g_free (bitrate_str); g_free (strength_str); g_free (wpa_flags_str); g_free (rsn_flags_str); g_string_free (security_str, TRUE); }
static void add_access_point (GisNetworkPage *page, NMAccessPoint *ap, NMAccessPoint *active) { GisNetworkPagePrivate *priv = gis_network_page_get_instance_private (page); const GByteArray *ssid; gchar *ssid_text; const gchar *object_path; gboolean activated, activating; guint security; guint strength; const gchar *icon_name; GtkWidget *row; GtkWidget *widget; GtkWidget *box; ssid = nm_access_point_get_ssid (ap); object_path = nm_object_get_path (NM_OBJECT (ap)); if (ssid == NULL) return; ssid_text = nm_utils_ssid_to_utf8 (ssid); if (active && nm_utils_same_ssid (ssid, nm_access_point_get_ssid (active), TRUE)) { switch (nm_device_get_state (priv->nm_device)) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_SECONDARIES: activated = FALSE; activating = TRUE; break; case NM_DEVICE_STATE_ACTIVATED: activated = TRUE; activating = FALSE; break; default: activated = FALSE; activating = FALSE; break; } } else { activated = FALSE; activating = FALSE; } security = get_access_point_security (ap); strength = nm_access_point_get_strength (ap); row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); gtk_widget_set_margin_start (row, 12); gtk_widget_set_margin_end (row, 12); widget = gtk_label_new (ssid_text); gtk_widget_set_margin_top (widget, 12); gtk_widget_set_margin_bottom (widget, 12); gtk_box_pack_start (GTK_BOX (row), widget, FALSE, FALSE, 0); if (activated) { widget = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU); gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); gtk_widget_set_valign (widget, GTK_ALIGN_CENTER); gtk_box_pack_start (GTK_BOX (row), widget, FALSE, FALSE, 0); } widget = gtk_spinner_new (); gtk_widget_set_no_show_all (widget, TRUE); if (activating) { gtk_widget_show (widget); gtk_spinner_start (GTK_SPINNER (widget)); } gtk_widget_set_halign (widget, GTK_ALIGN_CENTER); gtk_widget_set_valign (widget, GTK_ALIGN_CENTER); gtk_box_pack_start (GTK_BOX (row), widget, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (row), gtk_label_new (""), TRUE, FALSE, 0); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_set_homogeneous (GTK_BOX (box), TRUE); gtk_size_group_add_widget (priv->icons, box); gtk_box_pack_start (GTK_BOX (row), box, FALSE, FALSE, 0); if (security != NM_AP_SEC_UNKNOWN && security != NM_AP_SEC_NONE) { widget = gtk_image_new_from_icon_name ("network-wireless-encrypted-symbolic", GTK_ICON_SIZE_MENU); } else { widget = gtk_label_new (""); } gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0); if (strength < 20) icon_name = "network-wireless-signal-none-symbolic"; else if (strength < 40) icon_name = "network-wireless-signal-weak-symbolic"; else if (strength < 50) icon_name = "network-wireless-signal-ok-symbolic"; else if (strength < 80) icon_name = "network-wireless-signal-good-symbolic"; else icon_name = "network-wireless-signal-excellent-symbolic"; widget = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0); gtk_widget_show_all (row); g_object_set_data (G_OBJECT (row), "object-path", (gpointer) object_path); g_object_set_data (G_OBJECT (row), "ssid", (gpointer) ssid); g_object_set_data (G_OBJECT (row), "strength", GUINT_TO_POINTER (strength)); gtk_container_add (GTK_CONTAINER (priv->network_list), row); }
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)); }