CEPage * ce_page_wireless_new (NMConnection *connection, GtkWindow *parent_window, GError **error) { CEPageWireless *self; CEPageWirelessPrivate *priv; CEPage *parent; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); self = CE_PAGE_WIRELESS (g_object_new (CE_TYPE_PAGE_WIRELESS, CE_PAGE_CONNECTION, connection, CE_PAGE_PARENT_WINDOW, parent_window, NULL)); parent = CE_PAGE (self); parent->xml = glade_xml_new (GLADEDIR "/ce-page-wireless.glade", "WirelessPage", NULL); if (!parent->xml) { g_set_error (error, 0, 0, "%s", _("Could not load WiFi user interface.")); g_object_unref (self); return NULL; } parent->page = glade_xml_get_widget (parent->xml, "WirelessPage"); if (!parent->page) { g_set_error (error, 0, 0, "%s", _("Could not load WiFi user interface.")); g_object_unref (self); return NULL; } g_object_ref_sink (parent->page); parent->title = g_strdup (_("Wireless")); wireless_private_init (self); priv = CE_PAGE_WIRELESS_GET_PRIVATE (self); priv->setting = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS); if (!priv->setting) { priv->setting = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); nm_connection_add_setting (connection, NM_SETTING (priv->setting)); } g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL); if (!ce_page_initialize (parent, NULL, error)) { g_object_unref (self); return NULL; } return CE_PAGE (self); }
NMConnection * nma_ethernet_dialog_get_connection (GtkWidget *dialog) { NMConnection *connection, *tmp_connection; WirelessSecurity *security; NMSetting *s_8021x, *s_con; g_return_val_if_fail (dialog != NULL, NULL); connection = g_object_get_data (G_OBJECT (dialog), "connection"); security = g_object_get_data (G_OBJECT (dialog), "security"); /* Here's a nice hack to work around the fact that ws_802_1x_fill_connection() * needs a wireless setting and a connection setting for various things. */ tmp_connection = nm_simple_connection_new (); /* Add the fake connection setting (mainly for the UUID for cert ignore checking) */ s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); g_assert (s_con); nm_connection_add_setting (tmp_connection, NM_SETTING (g_object_ref (s_con))); /* And the fake wireless setting */ nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ()); /* Fill up the 802.1x setting */ ws_802_1x_fill_connection (security, "wpa_eap_auth_combo", tmp_connection); /* Grab it and add it to our original connection */ s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X); nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x))); /* Save new CA cert ignore values to GSettings */ eap_method_ca_cert_ignore_save (tmp_connection); /* Remove the 8021x setting to prevent the clearing of secrets when the * simple-connection is destroyed. */ nm_connection_remove_setting (tmp_connection, NM_TYPE_SETTING_802_1X); g_object_unref (tmp_connection); return connection; }
void wifi_connection_new (GtkWindow *parent, PageNewConnectionResultFunc result_func, PageGetConnectionsFunc get_connections_func, gpointer user_data) { NMConnection *connection; NMSetting *s_wifi; connection = ce_page_new_connection (_("Wireless connection %d"), NM_SETTING_WIRELESS_SETTING_NAME, TRUE, get_connections_func, user_data); s_wifi = nm_setting_wireless_new (); g_object_set (s_wifi, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); nm_connection_add_setting (connection, s_wifi); (*result_func) (connection, FALSE, NULL, user_data); }
CEPage * ce_page_wifi_new (NMConnectionEditor *editor, NMConnection *connection, GtkWindow *parent_window, NMClient *client, const char **out_secrets_setting_name, GError **error) { CEPageWifi *self; CEPageWifiPrivate *priv; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); self = CE_PAGE_WIFI (ce_page_new (CE_TYPE_PAGE_WIFI, editor, connection, parent_window, client, UIDIR "/ce-page-wifi.ui", "WifiPage", _("Wi-Fi"))); if (!self) { g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load Wi-Fi user interface.")); return NULL; } wifi_private_init (self); priv = CE_PAGE_WIFI_GET_PRIVATE (self); priv->setting = nm_connection_get_setting_wireless (connection); if (!priv->setting) { priv->setting = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); nm_connection_add_setting (connection, NM_SETTING (priv->setting)); } g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL); return CE_PAGE (self); }
NMSettingsConnectionInterface * nma_wired_dialog_get_connection (GtkWidget *dialog) { NMSettingsConnectionInterface *connection; WirelessSecurity *security; NMConnection *tmp_connection; NMSetting *s_8021x, *s_con; g_return_val_if_fail (dialog != NULL, NULL); connection = g_object_get_data (G_OBJECT (dialog), "connection"); security = g_object_get_data (G_OBJECT (dialog), "security"); /* Here's a nice hack to work around the fact that ws_802_1x_fill_connection() * needs a wireless setting and a connection setting for various things. */ tmp_connection = nm_connection_new (); /* Add the fake connection setting (mainly for the UUID for cert ignore checking) */ s_con = nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION); g_assert (s_con); nm_connection_add_setting (tmp_connection, NM_SETTING (g_object_ref (s_con))); /* And the fake wireless setting */ nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ()); /* Fill up the 802.1x setting */ ws_802_1x_fill_connection (security, "wpa_eap_auth_combo", tmp_connection); /* Grab it and add it to our original connection */ s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X); nm_connection_add_setting (NM_CONNECTION (connection), NM_SETTING (g_object_ref (s_8021x))); g_object_unref (tmp_connection); return connection; }
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 update_wireless_setting_from_if_block(NMConnection *connection, if_block *block) { gint wpa_l= strlen("wpa-"); gint wireless_l= strlen("wireless-"); if_data *curr = block->info; const gchar* value = ifparser_getkey (block, "inet"); struct _Mapping mapping[] = { {"ssid", "ssid"}, {"essid", "ssid"}, {"mode", "mode"}, { NULL, NULL} }; NMSettingWireless *wireless_setting = NULL; if(value && !strcmp("ppp", value)) { return; } nm_log_info (LOGD_SETTINGS, "update wireless settings (%s).", block->name); wireless_setting = NM_SETTING_WIRELESS(nm_setting_wireless_new()); while(curr) { if(strlen(curr->key) > wireless_l && !strncmp("wireless-", curr->key, wireless_l)) { const gchar* newkey = map_by_mapping(mapping, curr->key+wireless_l); nm_log_info (LOGD_SETTINGS, "wireless setting key: %s='%s'", newkey, curr->data); if(newkey && !strcmp("ssid", newkey)) { GBytes *ssid; gint len = strlen(curr->data); ssid = g_bytes_new (curr->data, len); g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, ssid, NULL); g_bytes_unref (ssid); nm_log_info (LOGD_SETTINGS, "setting wireless ssid = %d", len); } else if(newkey && !strcmp("mode", newkey)) { if (!g_ascii_strcasecmp (curr->data, "Managed") || !g_ascii_strcasecmp (curr->data, "Auto")) g_object_set (wireless_setting, NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, NULL); else if (!g_ascii_strcasecmp (curr->data, "Ad-Hoc")) g_object_set (wireless_setting, NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_ADHOC, NULL); else if (!g_ascii_strcasecmp (curr->data, "Master")) g_object_set (wireless_setting, NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_AP, NULL); else nm_log_warn (LOGD_SETTINGS, "Invalid mode '%s' (not 'Ad-Hoc', 'Ap', 'Managed', or 'Auto')", curr->data); } else { g_object_set(wireless_setting, newkey, curr->data, NULL); } } else if(strlen(curr->key) > wpa_l && !strncmp("wpa-", curr->key, wpa_l)) { const gchar* newkey = map_by_mapping(mapping, curr->key+wpa_l); if(newkey && !strcmp("ssid", newkey)) { GBytes *ssid; gint len = strlen(curr->data); ssid = g_bytes_new (curr->data, len); g_object_set (wireless_setting, NM_SETTING_WIRELESS_SSID, ssid, NULL); g_bytes_unref (ssid); nm_log_info (LOGD_SETTINGS, "setting wpa ssid = %d", len); } else if(newkey) { g_object_set(wireless_setting, newkey, curr->data, NULL); nm_log_info (LOGD_SETTINGS, "setting wpa newkey(%s)=data(%s)", newkey, curr->data); } } curr = curr->next; } nm_connection_add_setting(connection, (NMSetting*) wireless_setting); }
static void test_update_secrets_wifi (void) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; unsigned char tmpssid[] = { 0x31, 0x33, 0x33, 0x37 }; const char *wepkey = "11111111111111111111111111"; GHashTable *secrets; GError *error = NULL; char *uuid; GByteArray *ssid; gboolean success; connection = nm_connection_new (); g_assert (connection); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); g_assert (s_con); uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Wireless", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); /* Wireless setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); g_assert (s_wifi); ssid = g_byte_array_sized_new (sizeof (tmpssid)); g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); g_byte_array_free (ssid, TRUE); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); /* Wifi security */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); g_assert (s_wsec); g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); /* Build up the secrets hash */ secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy); g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey)); g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY)); success = nm_connection_update_secrets (connection, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, secrets, &error); if (!success) { /* Print the warning message before we assert success */ g_assert (error); g_warning ("Error updating connection secrets: %s", error->message); g_clear_error (&error); } g_assert (success); }
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); } }
void cc_network_panel_connect_to_8021x_network (CcNetworkPanel *panel, NMClient *client, NMRemoteSettings *settings, NMDevice *device, const gchar *arg_access_point) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; NM80211ApSecurityFlags wpa_flags, rsn_flags; GtkWidget *dialog; char *uuid; NMAccessPoint *ap; g_debug ("connect to 8021x wifi"); ap = nm_device_wifi_get_access_point_by_path (NM_DEVICE_WIFI (device), arg_access_point); if (ap == NULL) { g_warning ("didn't find access point with path %s", arg_access_point); return; } /* If the AP is WPA[2]-Enterprise then we need to set up a minimal 802.1x * setting and ask the user for more information. */ rsn_flags = nm_access_point_get_rsn_flags (ap); wpa_flags = nm_access_point_get_wpa_flags (ap); if (!(rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X) && !(wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { g_warning ("Network panel loaded with connect-8021x-wifi but the " "access point does not support 802.1x"); return; } connection = nm_connection_new (); /* Need a UUID for the "always ask" stuff in the Dialog of Doom */ s_con = (NMSettingConnection *) nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); 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 (ap), NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); nm_setting_802_1x_add_eap_method (s_8021x, "ttls"); g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL); nm_connection_add_setting (connection, NM_SETTING (s_8021x)); dialog = nma_wireless_dialog_new (client, settings, connection, device, ap, FALSE); show_wireless_dialog (panel, client, settings, dialog); }
static void test_wifi_wpa_psk (const char *detail, OptType key_type, const char *key_data, const unsigned char *expected, size_t expected_size) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIP4Config *s_ip4; NMSupplicantConfig *config; GHashTable *hash; char *uuid; gboolean success; GError *error = NULL; GByteArray *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; GByteArray *bssid; const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; const char *bssid_str = "11:22:33:44:55:66"; connection = nm_connection_new (); ASSERT (connection != NULL, detail, "failed to allocate new connection"); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); ASSERT (s_con != NULL, detail, "failed to allocate new %s setting", NM_SETTING_CONNECTION_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Wifi WEP Key", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); ASSERT (s_wifi != NULL, detail, "failed to allocate new %s setting", NM_SETTING_WIRELESS_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_byte_array_sized_new (sizeof (ssid_data)); g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); bssid = g_byte_array_sized_new (sizeof (bssid_data)); g_byte_array_append (bssid, bssid_data, sizeof (bssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NM_SETTING_WIRELESS_BAND, "bg", NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); g_byte_array_free (ssid, TRUE); g_byte_array_free (bssid, TRUE); /* Wifi Security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); ASSERT (s_wsec != NULL, detail, "failed to allocate new %s setting", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NM_SETTING_WIRELESS_SECURITY_PSK, key_data, NULL); nm_setting_wireless_security_add_proto (s_wsec, "wpa"); nm_setting_wireless_security_add_proto (s_wsec, "rsn"); nm_setting_wireless_security_add_pairwise (s_wsec, "tkip"); nm_setting_wireless_security_add_pairwise (s_wsec, "ccmp"); nm_setting_wireless_security_add_group (s_wsec, "tkip"); nm_setting_wireless_security_add_group (s_wsec, "ccmp"); /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); ASSERT (s_ip4 != NULL, detail, "failed to allocate new %s setting", NM_SETTING_IP4_CONFIG_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, detail, "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); config = nm_supplicant_config_new (); ASSERT (config != NULL, detail, "failed to create new supplicant config"); success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE); ASSERT (success == TRUE, detail, "failed to add wireless setting to supplicant config."); success = nm_supplicant_config_add_setting_wireless_security (config, s_wsec, NULL, "376aced7-b28c-46be-9a62-fcdf072571da"); ASSERT (success == TRUE, detail, "failed to add wireless security to supplicant config."); hash = nm_supplicant_config_get_hash (config); ASSERT (hash != NULL, detail, "failed to hash supplicant config options."); validate_opt (detail, hash, "scan_ssid", TYPE_INT, GINT_TO_POINTER (1), -1); validate_opt (detail, hash, "ssid", TYPE_BYTES, ssid_data, sizeof (ssid_data)); validate_opt (detail, hash, "bssid", TYPE_KEYWORD, bssid_str, -1); validate_opt (detail, hash, "key_mgmt", TYPE_KEYWORD, "WPA-PSK", -1); validate_opt (detail, hash, "proto", TYPE_KEYWORD, "WPA RSN", -1); validate_opt (detail, hash, "pairwise", TYPE_KEYWORD, "TKIP CCMP", -1); validate_opt (detail, hash, "group", TYPE_KEYWORD, "TKIP CCMP", -1); validate_opt (detail, hash, "psk", key_type, expected, expected_size); g_object_unref (connection); }
static void test_wifi_open (void) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingIP4Config *s_ip4; NMSupplicantConfig *config; GHashTable *hash; char *uuid; gboolean success; GError *error = NULL; GByteArray *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; GByteArray *bssid; const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; const char *bssid_str = "11:22:33:44:55:66"; connection = nm_connection_new (); ASSERT (connection != NULL, "wifi-open", "failed to allocate new connection"); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); ASSERT (s_con != NULL, "wifi-open", "failed to allocate new %s setting", NM_SETTING_CONNECTION_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Wifi Open", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); ASSERT (s_wifi != NULL, "wifi-open", "failed to allocate new %s setting", NM_SETTING_WIRELESS_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_byte_array_sized_new (sizeof (ssid_data)); g_byte_array_append (ssid, ssid_data, sizeof (ssid_data)); bssid = g_byte_array_sized_new (sizeof (bssid_data)); g_byte_array_append (bssid, bssid_data, sizeof (bssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_BSSID, bssid, NM_SETTING_WIRELESS_MODE, "infrastructure", NM_SETTING_WIRELESS_BAND, "bg", NULL); g_byte_array_free (ssid, TRUE); g_byte_array_free (bssid, TRUE); /* IP4 setting */ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); ASSERT (s_ip4 != NULL, "wifi-open", "failed to allocate new %s setting", NM_SETTING_IP4_CONFIG_SETTING_NAME); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, "wifi-open", "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); config = nm_supplicant_config_new (); ASSERT (config != NULL, "wifi-open", "failed to create new supplicant config"); success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE); ASSERT (success == TRUE, "wifi-open", "failed to add wireless setting to supplicant config."); success = nm_supplicant_config_add_no_security (config); ASSERT (success == TRUE, "wifi-open", "failed to add wireless security to supplicant config."); hash = nm_supplicant_config_get_hash (config); ASSERT (hash != NULL, "wifi-open", "failed to hash supplicant config options."); validate_opt ("wifi-open", hash, "scan_ssid", TYPE_INT, GINT_TO_POINTER (1), -1); validate_opt ("wifi-open", hash, "ssid", TYPE_BYTES, ssid_data, sizeof (ssid_data)); validate_opt ("wifi-open", hash, "bssid", TYPE_KEYWORD, bssid_str, -1); validate_opt ("wifi-open", hash, "key_mgmt", TYPE_KEYWORD, "NONE", -1); g_object_unref (connection); }
static void test_wifi_wep_key (const char *detail, NMWepKeyType wep_type, const char *key_data, const unsigned char *expected, size_t expected_size) { NMConnection *connection; NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSettingIPConfig *s_ip4; NMSupplicantConfig *config; GHashTable *hash; char *uuid; gboolean success; GError *error = NULL; GBytes *ssid; const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 }; const char *bssid_str = "11:22:33:44:55:66"; connection = nm_simple_connection_new (); /* Connection setting */ s_con = (NMSettingConnection *) nm_setting_connection_new (); nm_connection_add_setting (connection, NM_SETTING (s_con)); uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, "Test Wifi WEP Key", NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NULL); g_free (uuid); /* Wifi setting */ s_wifi = (NMSettingWireless *) nm_setting_wireless_new (); nm_connection_add_setting (connection, NM_SETTING (s_wifi)); ssid = g_bytes_new (ssid_data, sizeof (ssid_data)); g_object_set (s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_BSSID, bssid_str, NM_SETTING_WIRELESS_MODE, "infrastructure", NM_SETTING_WIRELESS_BAND, "bg", NULL); g_bytes_unref (ssid); /* Wifi Security setting */ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, wep_type, NULL); nm_setting_wireless_security_set_wep_key (s_wsec, 0, key_data); /* IP4 setting */ s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); nm_connection_add_setting (connection, NM_SETTING (s_ip4)); g_object_set (s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); ASSERT (nm_connection_verify (connection, &error) == TRUE, detail, "failed to verify connection: %s", (error && error->message) ? error->message : "(unknown)"); config = nm_supplicant_config_new (); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*added 'ssid' value 'Test SSID'*"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*added 'scan_ssid' value '1'*"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*added 'bssid' value '11:22:33:44:55:66'*"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*added 'freq_list' value *"); success = nm_supplicant_config_add_setting_wireless (config, s_wifi, 0); ASSERT (success == TRUE, detail, "failed to add wireless setting to supplicant config."); g_test_assert_expected_messages (); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*added 'key_mgmt' value 'NONE'"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*added 'wep_key0' value *"); g_test_expect_message ("NetworkManager", G_LOG_LEVEL_MESSAGE, "*added 'wep_tx_keyidx' value '0'"); success = nm_supplicant_config_add_setting_wireless_security (config, s_wsec, NULL, "376aced7-b28c-46be-9a62-fcdf072571da"); ASSERT (success == TRUE, detail, "failed to add wireless security to supplicant config."); g_test_assert_expected_messages (); hash = nm_supplicant_config_get_hash (config); ASSERT (hash != NULL, detail, "failed to hash supplicant config options."); validate_opt (detail, hash, "scan_ssid", TYPE_INT, GINT_TO_POINTER (1), -1); validate_opt (detail, hash, "ssid", TYPE_BYTES, ssid_data, sizeof (ssid_data)); validate_opt (detail, hash, "bssid", TYPE_KEYWORD, bssid_str, -1); validate_opt (detail, hash, "key_mgmt", TYPE_KEYWORD, "NONE", -1); validate_opt (detail, hash, "wep_tx_keyidx", TYPE_INT, GINT_TO_POINTER (0), -1); validate_opt (detail, hash, "wep_key0", TYPE_BYTES, expected, expected_size); g_object_unref (connection); }
static void nmt_page_wifi_constructed (GObject *object) { NmtPageWifiPrivate *priv = NMT_PAGE_WIFI_GET_PRIVATE (object); NmtPageWifi *wifi = NMT_PAGE_WIFI (object); NmtDeviceEntry *deventry; NmtEditorSection *section; NmtEditorGrid *grid; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wsec; NmtNewtWidget *widget, *hbox, *subgrid; NmtNewtWidget *mode, *band, *security, *entry; NmtNewtStack *stack; NMConnection *conn; conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (wifi)); s_wireless = nm_connection_get_setting_wireless (conn); if (!s_wireless) { nm_connection_add_setting (conn, nm_setting_wireless_new ()); s_wireless = nm_connection_get_setting_wireless (conn); } s_wsec = nm_connection_get_setting_wireless_security (conn); if (!s_wsec) { /* It makes things simpler if we always have a * NMSettingWirelessSecurity; we'll hold a ref on one, and add * it to and remove it from the connection as needed. */ s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); } priv->s_wsec = g_object_ref_sink (s_wsec); deventry = nmt_editor_page_device_get_device_entry (NMT_EDITOR_PAGE_DEVICE (object)); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, deventry, "mac-address", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); section = nmt_editor_section_new (_("WI-FI"), NULL, TRUE); grid = nmt_editor_section_get_body (section); widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY); g_object_bind_property_full (s_wireless, NM_SETTING_WIRELESS_SSID, widget, "text", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE, ssid_transform_to_entry, ssid_transform_from_entry, s_wireless, NULL); nmt_editor_grid_append (grid, _("SSID"), widget, NULL); widget = nmt_newt_popup_new (wifi_mode); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MODE, widget, "active-id", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("Mode"), widget, NULL); mode = widget; hbox = nmt_newt_grid_new (); widget = nmt_newt_popup_new (wifi_band); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_BAND, widget, "active-id", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (NMT_NEWT_GRID (hbox), widget, 0, 0); band = widget; widget = nmt_newt_entry_numeric_new (10, 0, 255); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_CHANNEL, widget, "text", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_newt_grid_add (NMT_NEWT_GRID (hbox), widget, 1, 0); nmt_newt_widget_set_padding (widget, 1, 0, 0, 0); g_object_bind_property_full (band, "active-id", widget, "visible", G_BINDING_SYNC_CREATE, band_transform_to_channel_visibility, NULL, NULL, NULL); g_object_bind_property_full (mode, "active-id", hbox, "visible", G_BINDING_SYNC_CREATE, mode_transform_to_band_visibility, NULL, NULL, NULL); nmt_editor_grid_append (grid, _("Channel"), hbox, NULL); nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL); widget = nmt_newt_popup_new (wifi_security); nmt_editor_grid_append (grid, _("Security"), widget, NULL); security = widget; widget = nmt_newt_stack_new (); stack = NMT_NEWT_STACK (widget); /* none */ subgrid = nmt_editor_grid_new (); nmt_newt_stack_add (stack, "none", subgrid); /* wpa-personal */ subgrid = nmt_editor_grid_new (); widget = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD); g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK, widget, "password", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL); nmt_newt_stack_add (stack, "wpa-personal", subgrid); /* "wpa-enterprise" */ // FIXME widget = nmt_newt_label_new (_("(No support for wpa-enterprise yet...)")); nmt_newt_stack_add (stack, "wpa-enterprise", widget); /* wep-key */ subgrid = nmt_editor_grid_new (); widget = entry = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Key"), widget, NULL); widget = nmt_newt_popup_new (wep_index); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("WEP index"), widget, NULL); nm_editor_bind_wireless_security_wep_key (s_wsec, entry, "password", widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); widget = nmt_newt_popup_new (wep_auth); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Authentication"), widget, NULL); nmt_newt_stack_add (stack, "wep-key", subgrid); /* wep-passphrase */ subgrid = nmt_editor_grid_new (); widget = entry = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL); widget = nmt_newt_popup_new (wep_index); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("WEP index"), widget, NULL); nm_editor_bind_wireless_security_wep_key (s_wsec, entry, "password", widget, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); widget = nmt_newt_popup_new (wep_auth); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Authentication"), widget, NULL); nmt_newt_stack_add (stack, "wep-passphrase", subgrid); /* "dynamic-wep" */ // FIXME widget = nmt_newt_label_new (_("(No support for dynamic-wep yet...)")); nmt_newt_stack_add (stack, "dynamic-wep", widget); /* leap */ subgrid = nmt_editor_grid_new (); widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Username"), widget, NULL); g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, widget, "text", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); widget = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD); g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, widget, "password", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL); nmt_newt_stack_add (stack, "leap", subgrid); nmt_editor_grid_append (grid, NULL, NMT_NEWT_WIDGET (stack), NULL); g_object_bind_property (security, "active-id", stack, "active-id", G_BINDING_SYNC_CREATE); nm_editor_bind_wireless_security_method (conn, s_wsec, security, "active-id", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL); widget = nmt_mac_entry_new (40, ETH_ALEN); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_BSSID, widget, "mac-address", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("BSSID"), widget, NULL); widget = nmt_mac_entry_new (40, ETH_ALEN); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, widget, "mac-address", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("Cloned MAC address"), widget, NULL); widget = nmt_mtu_entry_new (); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MTU, widget, "mtu", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("MTU"), widget, NULL); nmt_editor_page_add_section (NMT_EDITOR_PAGE (wifi), section); G_OBJECT_CLASS (nmt_page_wifi_parent_class)->constructed (object); }
static void dialog_response (GtkDialog *dialog, gint response, gpointer user_data) { NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data); NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self); NMSetting *setting; GtkTreeModel *model; GtkTreeIter iter; WirelessSecurity *sec = NULL; if (response != GTK_RESPONSE_OK) goto out; if (!priv->connection) { /* Create new connection */ char *id; char *uuid; GByteArray *ssid; priv->connection = nm_connection_new (); /* Wireless setting */ setting = nm_setting_wireless_new (); ssid = validate_dialog_ssid (self); g_object_set (setting, NM_SETTING_WIRELESS_SSID, ssid, NULL); nm_connection_add_setting (priv->connection, setting); if (ssid) { id = nm_utils_ssid_to_utf8 ((char *) ssid->data, ssid->len); g_byte_array_free (ssid, TRUE); } else id = NULL; /* Connection setting */ setting = nm_setting_connection_new (); uuid = nm_utils_uuid_generate (); /* FIXME: don't autoconnect until the connection is successful at least once */ /* Don't autoconnect adhoc networks by default for now */ g_object_set (setting, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_ID, id, NM_SETTING_CONNECTION_AUTOCONNECT, !priv->adhoc_create, NULL); g_free (uuid); g_free (id); nm_connection_add_setting (priv->connection, setting); /* IPv4 setting */ if (priv->adhoc_create) { g_object_set (setting, NM_SETTING_WIRELESS_MODE, "adhoc", NULL); setting = nm_setting_ip4_config_new (); g_object_set (setting, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED, NULL); nm_connection_add_setting (priv->connection, setting); } } model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->sec_combo)); gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->sec_combo), &iter); gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1); if (sec && !priv->nag_ignored) { GtkWidget *nag_dialog; /* Nag the user about certificates or whatever. Only destroy the dialog * if no nagging was done. */ nag_dialog = wireless_security_nag_user (sec); 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; } } /* Fill security */ if (sec) { wireless_security_fill_connection (sec, priv->connection); wireless_security_unref (sec); } else { /* Unencrypted */ setting = nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS); g_object_set (setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); } out: g_signal_emit (self, signals[DONE], 0, response); nm_utils_dialog_done (); /* FIXME: clear security? */ }