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; } }
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 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; }
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"); }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; const char *ctype; const char *hwaddr, *setting_hwaddr; NMDeviceWifiCapabilities wifi_caps; const char *key_mgmt; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_WIRELESS_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_NOT_WIFI_CONNECTION, "The connection was not a Wi-Fi connection."); return FALSE; } s_wifi = nm_connection_get_setting_wireless (connection); if (!s_wifi) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_INVALID_WIFI_CONNECTION, "The connection was not a valid Wi-Fi connection."); return FALSE; } /* Check MAC address */ hwaddr = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (device)); if (hwaddr) { if (!nm_utils_hwaddr_valid (hwaddr, ETH_ALEN)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_INVALID_DEVICE_MAC, "Invalid device MAC address."); return FALSE; } setting_hwaddr = nm_setting_wireless_get_mac_address (s_wifi); if (setting_hwaddr && !nm_utils_hwaddr_matches (setting_hwaddr, -1, hwaddr, -1)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MAC_MISMATCH, "The MACs of the device and the connection didn't match."); return FALSE; } } /* Check device capabilities; we assume all devices can do WEP at least */ wifi_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device)); s_wsec = nm_connection_get_setting_wireless_security (connection); if (s_wsec) { /* Connection has security, verify it against the device's capabilities */ key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); if ( !g_strcmp0 (key_mgmt, "wpa-none") || !g_strcmp0 (key_mgmt, "wpa-psk") || !g_strcmp0 (key_mgmt, "wpa-eap")) { /* Is device only WEP capable? */ if (!(wifi_caps & WPA_CAPS)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MISSING_DEVICE_WPA_CAPS, "The device missed WPA capabilities required by the connection."); return FALSE; } /* Make sure WPA2/RSN-only connections don't get chosen for WPA-only cards */ if (has_proto (s_wsec, "rsn") && !has_proto (s_wsec, "wpa") && !(wifi_caps & RSN_CAPS)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MISSING_DEVICE_RSN_CAPS, "The device missed WPA2/RSN capabilities required by the connection."); return FALSE; } } } return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->connection_compatible (device, connection, error); }
static gboolean security_combo_init (NMAWirelessDialog *self) { NMAWirelessDialogPrivate *priv; GtkListStore *sec_model; GtkTreeIter iter; guint32 ap_flags = 0; guint32 ap_wpa = 0; guint32 ap_rsn = 0; guint32 dev_caps; NMSettingWirelessSecurity *wsec = NULL; NMUtilsSecurityType default_type = NMU_SEC_NONE; NMWepKeyType wep_type = NM_WEP_KEY_TYPE_KEY; int active = -1; int item = 0; NMSettingWireless *s_wireless = NULL; gboolean is_adhoc; g_return_val_if_fail (self != NULL, FALSE); priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self); g_return_val_if_fail (priv->device != NULL, FALSE); g_return_val_if_fail (priv->sec_combo != NULL, FALSE); is_adhoc = priv->adhoc_create; /* The security options displayed are filtered based on device * capabilities, and if provided, additionally by access point capabilities. * If a connection is given, that connection's options should be selected * by default. */ dev_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (priv->device)); if (priv->ap != NULL) { ap_flags = nm_access_point_get_flags (priv->ap); ap_wpa = nm_access_point_get_wpa_flags (priv->ap); ap_rsn = nm_access_point_get_rsn_flags (priv->ap); } if (priv->connection) { const char *mode; const char *security; s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS)); mode = nm_setting_wireless_get_mode (s_wireless); if (mode && !strcmp (mode, "adhoc")) is_adhoc = TRUE; wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS_SECURITY)); security = nm_setting_wireless_get_security (s_wireless); if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) wsec = NULL; if (wsec) { default_type = get_default_type_for_security (wsec, !!priv->ap, ap_flags, dev_caps); if (default_type == NMU_SEC_STATIC_WEP) wep_type = nm_setting_wireless_security_get_wep_key_type (wsec); if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN) wep_type = NM_WEP_KEY_TYPE_KEY; } } else if (is_adhoc) { default_type = NMU_SEC_STATIC_WEP; wep_type = NM_WEP_KEY_TYPE_PASSPHRASE; } sec_model = gtk_list_store_new (2, G_TYPE_STRING, wireless_security_get_g_type ()); if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) { gtk_list_store_append (sec_model, &iter); gtk_list_store_set (sec_model, &iter, S_NAME_COLUMN, _("None"), -1); if (default_type == NMU_SEC_NONE) active = item; item++; } /* Don't show Static WEP if both the AP and the device are capable of WPA, * even though technically it's possible to have this configuration. */ if ( nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn) && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN)))) { WirelessSecurityWEPKey *ws_wep; ws_wep = ws_wep_key_new (priv->connection, NM_WEP_KEY_TYPE_KEY, priv->adhoc_create); if (ws_wep) { add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model, &iter, _("WEP 40/128-bit Key")); if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_KEY)) active = item; item++; } ws_wep = ws_wep_key_new (priv->connection, NM_WEP_KEY_TYPE_PASSPHRASE, priv->adhoc_create); if (ws_wep) { add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model, &iter, _("WEP 128-bit Passphrase")); if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE)) active = item; item++; } } /* Don't show LEAP if both the AP and the device are capable of WPA, * even though technically it's possible to have this configuration. */ if ( nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn) && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN)))) { WirelessSecurityLEAP *ws_leap; ws_leap = ws_leap_new (priv->connection); if (ws_leap) { add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model, &iter, _("LEAP")); if ((active < 0) && (default_type == NMU_SEC_LEAP)) active = item; item++; } } if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) { WirelessSecurityDynamicWEP *ws_dynamic_wep; ws_dynamic_wep = ws_dynamic_wep_new (priv->connection); if (ws_dynamic_wep) { add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model, &iter, _("Dynamic WEP (802.1x)")); if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP)) active = item; item++; } } if ( nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn) || nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) { WirelessSecurityWPAPSK *ws_wpa_psk; ws_wpa_psk = ws_wpa_psk_new (priv->connection); if (ws_wpa_psk) { add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model, &iter, _("WPA & WPA2 Personal")); if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK))) active = item; item++; } } if ( nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn) || nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) { WirelessSecurityWPAEAP *ws_wpa_eap; ws_wpa_eap = ws_wpa_eap_new (priv->connection); if (ws_wpa_eap) { add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model, &iter, _("WPA & WPA2 Enterprise")); if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE))) active = item; item++; } } gtk_combo_box_set_model (GTK_COMBO_BOX (priv->sec_combo), GTK_TREE_MODEL (sec_model)); gtk_combo_box_set_active (GTK_COMBO_BOX (priv->sec_combo), active < 0 ? 0 : (guint32) active); g_object_unref (G_OBJECT (sec_model)); return TRUE; }
static void detail_device (gpointer data, gpointer user_data) { NMDevice *device = NM_DEVICE (data); struct cb_info *info = user_data; char *tmp; NMDeviceState state; guint32 caps; guint32 speed; const GArray *array; int j; gboolean is_default = FALSE; const char *id = NULL; state = nm_device_get_state (device); for (j = 0; info->active && (j < info->active->len); j++) { NMActiveConnection *candidate = g_ptr_array_index (info->active, j); const GPtrArray *devices = nm_active_connection_get_devices (candidate); NMDevice *candidate_dev; NMConnection *connection; NMSettingConnection *s_con; if (!devices || !devices->len) continue; candidate_dev = g_ptr_array_index (devices, 0); if (candidate_dev == device) { if (nm_active_connection_get_default (candidate)) is_default = TRUE; connection = get_connection_for_active (candidate); if (!connection) break; s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); if (s_con) id = nm_setting_connection_get_id (s_con); break; } } 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_GSM_DEVICE (device)) print_string ("Type", "Mobile Broadband (GSM)"); else if (NM_IS_CDMA_DEVICE (device)) print_string ("Type", "Mobile Broadband (CDMA)"); else if (NM_IS_DEVICE_BT (device)) print_string ("Type", "Bluetooth"); print_string ("Driver", nm_device_get_driver (device) ? nm_device_get_driver (device) : "(unknown)"); 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))); 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"); } /* IP Setup info */ if (state == NM_DEVICE_STATE_ACTIVATED) { NMIP4Config *cfg = nm_device_get_ip4_config (device); GSList *iter; printf ("\n IPv4 Settings:\n"); for (iter = (GSList *) nm_ip4_config_get_addresses (cfg); 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 (cfg); 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); } } } printf ("\n\n"); }