1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Copyright 2007 - 2014 Red Hat, Inc.
20 * Copyright 2007 - 2008 Novell, Inc.
23 #include "nm-default.h"
26 #include <net/ethernet.h>
28 #include "nm-setting-wireless.h"
30 #include "nm-utils-private.h"
31 #include "nm-setting-private.h"
34 * SECTION:nm-setting-wireless
35 * @short_description: Describes connection properties for 802.11 Wi-Fi networks
37 * The #NMSettingWireless object is a #NMSetting subclass that describes properties
38 * necessary for connection to 802.11 Wi-Fi networks.
41 G_DEFINE_TYPE_WITH_CODE (NMSettingWireless, nm_setting_wireless, NM_TYPE_SETTING,
42 _nm_register_setting (WIRELESS, 1))
43 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS)
45 #define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate))
55 char *device_mac_address;
56 char *cloned_mac_address;
57 GArray *mac_address_blacklist;
62 NMSettingMacRandomization mac_address_randomization;
63 } NMSettingWirelessPrivate;
75 PROP_CLONED_MAC_ADDRESS,
76 PROP_MAC_ADDRESS_BLACKLIST,
81 PROP_MAC_ADDRESS_RANDOMIZATION,
87 match_cipher (const char *cipher,
93 if (strcmp (cipher, expected) != 0)
96 if (!(wpa_flags & flag) && !(rsn_flags & flag))
103 * nm_setting_wireless_ap_security_compatible:
104 * @s_wireless: a #NMSettingWireless
105 * @s_wireless_sec: a #NMSettingWirelessSecurity or %NULL
106 * @ap_flags: the %NM80211ApFlags of the given access point
107 * @ap_wpa: the %NM80211ApSecurityFlags of the given access point's WPA
109 * @ap_rsn: the %NM80211ApSecurityFlags of the given access point's WPA2/RSN
111 * @ap_mode: the 802.11 mode of the AP, either Ad-Hoc or Infrastructure
113 * Given a #NMSettingWireless and an optional #NMSettingWirelessSecurity,
114 * determine if the configuration given by the settings is compatible with
115 * the security of an access point using that access point's capability flags
116 * and mode. Useful for clients that wish to filter a set of connections
117 * against a set of access points and determine which connections are
118 * compatible with which access points.
120 * Returns: %TRUE if the given settings are compatible with the access point's
121 * security flags and mode, %FALSE if they are not.
124 nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
125 NMSettingWirelessSecurity *s_wireless_sec,
126 NM80211ApFlags ap_flags,
127 NM80211ApSecurityFlags ap_wpa,
128 NM80211ApSecurityFlags ap_rsn,
131 const char *key_mgmt = NULL, *cipher;
133 gboolean found = FALSE;
135 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE);
137 if (!s_wireless_sec) {
138 if ( (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
139 || (ap_wpa != NM_802_11_AP_SEC_NONE)
140 || (ap_rsn != NM_802_11_AP_SEC_NONE))
145 key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec);
150 if (!strcmp (key_mgmt, "none")) {
151 if ( !(ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
152 || (ap_wpa != NM_802_11_AP_SEC_NONE)
153 || (ap_rsn != NM_802_11_AP_SEC_NONE))
159 if (!strcmp (key_mgmt, "wpa-none")) {
160 if (ap_mode != NM_802_11_MODE_ADHOC)
162 /* FIXME: validate ciphers if they're in the beacon */
166 /* Adhoc WPA2 (ie, RSN IBSS) */
167 if (ap_mode == NM_802_11_MODE_ADHOC) {
168 if (strcmp (key_mgmt, "wpa-psk"))
171 /* Ensure the AP has RSN PSK capability */
172 if (!(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
175 /* Fall through and check ciphers in generic WPA-PSK code */
178 /* Dynamic WEP or LEAP */
179 if (!strcmp (key_mgmt, "ieee8021x")) {
180 if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY))
183 /* If the AP is advertising a WPA IE, make sure it supports WEP ciphers */
184 if (ap_wpa != NM_802_11_AP_SEC_NONE) {
185 if (!(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
188 /* quick check; can't use AP if it doesn't support at least one
189 * WEP cipher in both pairwise and group suites.
191 if ( !(ap_wpa & (NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104))
192 || !(ap_wpa & (NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104)))
195 /* Match at least one pairwise cipher with AP's capability if the
196 * wireless-security setting explicitly lists pairwise ciphers
198 num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
199 for (i = 0, found = FALSE; i < num; i++) {
200 cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
201 if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP40)))
203 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP104)))
209 /* Match at least one group cipher with AP's capability if the
210 * wireless-security setting explicitly lists group ciphers
212 num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
213 for (i = 0, found = FALSE; i < num; i++) {
214 cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
215 if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP40)))
217 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP104)))
226 /* WPA[2]-PSK and WPA[2] Enterprise */
227 if ( !strcmp (key_mgmt, "wpa-psk")
228 || !strcmp (key_mgmt, "wpa-eap")) {
230 if (!strcmp (key_mgmt, "wpa-psk")) {
231 if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_PSK)
232 && !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
234 } else if (!strcmp (key_mgmt, "wpa-eap")) {
235 if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
236 && !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
240 // FIXME: should handle WPA and RSN separately here to ensure that
241 // if the Connection only uses WPA we don't match a cipher against
242 // the AP's RSN IE instead
244 /* Match at least one pairwise cipher with AP's capability if the
245 * wireless-security setting explicitly lists pairwise ciphers
247 num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
248 for (i = 0, found = FALSE; i < num; i++) {
249 cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
250 if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_TKIP)))
252 if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_CCMP)))
258 /* Match at least one group cipher with AP's capability if the
259 * wireless-security setting explicitly lists group ciphers
261 num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
262 for (i = 0, found = FALSE; i < num; i++) {
263 cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
265 if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP40)))
267 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP104)))
269 if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_TKIP)))
271 if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_CCMP)))
284 * nm_setting_wireless_new:
286 * Creates a new #NMSettingWireless object with default values.
288 * Returns: (transfer full): the new empty #NMSettingWireless object
291 nm_setting_wireless_new (void)
293 return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRELESS, NULL);
297 * nm_setting_wireless_get_ssid:
298 * @setting: the #NMSettingWireless
300 * Returns: (transfer none): the #NMSettingWireless:ssid property of the setting
303 nm_setting_wireless_get_ssid (NMSettingWireless *setting)
305 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
307 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->ssid;
311 * nm_setting_wireless_get_mode:
312 * @setting: the #NMSettingWireless
314 * Returns: the #NMSettingWireless:mode property of the setting
317 nm_setting_wireless_get_mode (NMSettingWireless *setting)
319 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
321 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mode;
325 * nm_setting_wireless_get_band:
326 * @setting: the #NMSettingWireless
328 * Returns: the #NMSettingWireless:band property of the setting
331 nm_setting_wireless_get_band (NMSettingWireless *setting)
333 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
335 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->band;
339 * nm_setting_wireless_get_channel:
340 * @setting: the #NMSettingWireless
342 * Returns: the #NMSettingWireless:channel property of the setting
345 nm_setting_wireless_get_channel (NMSettingWireless *setting)
347 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
349 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->channel;
353 * nm_setting_wireless_get_bssid:
354 * @setting: the #NMSettingWireless
356 * Returns: the #NMSettingWireless:bssid property of the setting
359 nm_setting_wireless_get_bssid (NMSettingWireless *setting)
361 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
363 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->bssid;
367 * nm_setting_wireless_get_rate:
368 * @setting: the #NMSettingWireless
370 * Returns: the #NMSettingWireless:rate property of the setting
373 nm_setting_wireless_get_rate (NMSettingWireless *setting)
375 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
377 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->rate;
381 * nm_setting_wireless_get_tx_power:
382 * @setting: the #NMSettingWireless
384 * Returns: the #NMSettingWireless:tx-power property of the setting
387 nm_setting_wireless_get_tx_power (NMSettingWireless *setting)
389 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
391 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->tx_power;
395 * nm_setting_wireless_get_mac_address:
396 * @setting: the #NMSettingWireless
398 * Returns: the #NMSettingWireless:mac-address property of the setting
401 nm_setting_wireless_get_mac_address (NMSettingWireless *setting)
403 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
405 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->device_mac_address;
409 * nm_setting_wireless_get_cloned_mac_address:
410 * @setting: the #NMSettingWireless
412 * Returns: the #NMSettingWireless:cloned-mac-address property of the setting
415 nm_setting_wireless_get_cloned_mac_address (NMSettingWireless *setting)
417 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
419 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->cloned_mac_address;
423 * nm_setting_wireless_get_mac_address_blacklist:
424 * @setting: the #NMSettingWireless
426 * Returns: the #NMSettingWireless:mac-address-blacklist property of the setting
429 nm_setting_wireless_get_mac_address_blacklist (NMSettingWireless *setting)
431 NMSettingWirelessPrivate *priv;
433 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
435 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
436 return (const char * const *) priv->mac_address_blacklist->data;
440 * nm_setting_wireless_get_num_mac_blacklist_items:
441 * @setting: the #NMSettingWireless
443 * Returns: the number of blacklisted MAC addresses
446 nm_setting_wireless_get_num_mac_blacklist_items (NMSettingWireless *setting)
448 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
450 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist->len;
454 * nm_setting_wireless_get_mac_blacklist_item:
455 * @setting: the #NMSettingWireless
456 * @idx: the zero-based index of the MAC address entry
458 * Returns: the blacklisted MAC address string (hex-digits-and-colons notation)
462 nm_setting_wireless_get_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
464 NMSettingWirelessPrivate *priv;
466 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
468 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
469 g_return_val_if_fail (idx <= priv->mac_address_blacklist->len, NULL);
471 return g_array_index (priv->mac_address_blacklist, const char *, idx);
475 * nm_setting_wireless_add_mac_blacklist_item:
476 * @setting: the #NMSettingWireless
477 * @mac: the MAC address string (hex-digits-and-colons notation) to blacklist
479 * Adds a new MAC address to the #NMSettingWireless:mac-address-blacklist property.
481 * Returns: %TRUE if the MAC address was added; %FALSE if the MAC address
482 * is invalid or was already present
485 nm_setting_wireless_add_mac_blacklist_item (NMSettingWireless *setting, const char *mac)
487 NMSettingWirelessPrivate *priv;
488 const char *candidate;
491 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
492 g_return_val_if_fail (mac != NULL, FALSE);
494 if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
497 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
498 for (i = 0; i < priv->mac_address_blacklist->len; i++) {
499 candidate = g_array_index (priv->mac_address_blacklist, char *, i);
500 if (nm_utils_hwaddr_matches (mac, -1, candidate, -1))
504 mac = nm_utils_hwaddr_canonical (mac, ETH_ALEN);
505 g_array_append_val (priv->mac_address_blacklist, mac);
506 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
511 * nm_setting_wireless_remove_mac_blacklist_item:
512 * @setting: the #NMSettingWireless
513 * @idx: index number of the MAC address
515 * Removes the MAC address at index @idx from the blacklist.
518 nm_setting_wireless_remove_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
520 NMSettingWirelessPrivate *priv;
522 g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
524 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
525 g_return_if_fail (idx < priv->mac_address_blacklist->len);
527 g_array_remove_index (priv->mac_address_blacklist, idx);
528 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
532 * nm_setting_wireless_remove_mac_blacklist_item_by_value:
533 * @setting: the #NMSettingWireless
534 * @mac: the MAC address string (hex-digits-and-colons notation) to remove from
537 * Removes the MAC address @mac from the blacklist.
539 * Returns: %TRUE if the MAC address was found and removed; %FALSE if it was not.
542 nm_setting_wireless_remove_mac_blacklist_item_by_value (NMSettingWireless *setting, const char *mac)
544 NMSettingWirelessPrivate *priv;
545 const char *candidate;
548 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
549 g_return_val_if_fail (mac != NULL, FALSE);
551 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
552 for (i = 0; i < priv->mac_address_blacklist->len; i++) {
553 candidate = g_array_index (priv->mac_address_blacklist, char *, i);
554 if (!nm_utils_hwaddr_matches (mac, -1, candidate, -1)) {
555 g_array_remove_index (priv->mac_address_blacklist, i);
556 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
564 * nm_setting_wireless_clear_mac_blacklist_items:
565 * @setting: the #NMSettingWireless
567 * Removes all blacklisted MAC addresses.
570 nm_setting_wireless_clear_mac_blacklist_items (NMSettingWireless *setting)
572 g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
574 g_array_set_size (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist, 0);
575 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
579 * nm_setting_wireless_get_mtu:
580 * @setting: the #NMSettingWireless
582 * Returns: the #NMSettingWireless:mtu property of the setting
585 nm_setting_wireless_get_mtu (NMSettingWireless *setting)
587 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
589 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mtu;
593 * nm_setting_wireless_get_hidden:
594 * @setting: the #NMSettingWireless
596 * Returns: the #NMSettingWireless:hidden property of the setting
599 nm_setting_wireless_get_hidden (NMSettingWireless *setting)
601 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
603 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->hidden;
607 * nm_setting_wireless_get_powersave:
608 * @setting: the #NMSettingWireless
610 * Returns: the #NMSettingWireless:powersave property of the setting
615 nm_setting_wireless_get_powersave (NMSettingWireless *setting)
617 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
619 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->powersave;
623 * nm_setting_wireless_get_mac_address_randomization:
624 * @setting: the #NMSettingWireless
626 * Returns: the #NMSettingWireless:mac-address-randomization property of the
631 NMSettingMacRandomization
632 nm_setting_wireless_get_mac_address_randomization (NMSettingWireless *setting)
634 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
636 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_randomization;
640 * nm_setting_wireless_add_seen_bssid:
641 * @setting: the #NMSettingWireless
642 * @bssid: the new BSSID to add to the list
644 * Adds a new Wi-Fi AP's BSSID to the previously seen BSSID list of the setting.
645 * NetworkManager now tracks previously seen BSSIDs internally so this function
646 * no longer has much use. Actually, changes you make using this function will
649 * Returns: %TRUE if @bssid was already known, %FALSE if not
652 nm_setting_wireless_add_seen_bssid (NMSettingWireless *setting,
655 NMSettingWirelessPrivate *priv;
658 gboolean found = FALSE;
660 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
661 g_return_val_if_fail (bssid != NULL, FALSE);
663 lower_bssid = g_ascii_strdown (bssid, -1);
667 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
669 for (iter = priv->seen_bssids; iter; iter = iter->next) {
670 if (!strcmp ((char *) iter->data, lower_bssid)) {
677 priv->seen_bssids = g_slist_prepend (priv->seen_bssids, lower_bssid);
678 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SEEN_BSSIDS);
680 g_free (lower_bssid);
686 * nm_setting_wireless_get_num_seen_bssids:
687 * @setting: the #NMSettingWireless
689 * Returns: the number of BSSIDs in the previously seen BSSID list
692 nm_setting_wireless_get_num_seen_bssids (NMSettingWireless *setting)
694 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
696 return g_slist_length (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids);
700 * nm_setting_wireless_get_seen_bssid:
701 * @setting: the #NMSettingWireless
702 * @i: index of a BSSID in the previously seen BSSID list
704 * Returns: the BSSID at index @i
707 nm_setting_wireless_get_seen_bssid (NMSettingWireless *setting,
710 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
712 return (const char *) g_slist_nth_data (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids, i);
716 verify (NMSetting *setting, NMConnection *connection, GError **error)
718 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
719 const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NULL };
720 const char *valid_bands[] = { "a", "bg", NULL };
726 g_set_error_literal (error,
728 NM_CONNECTION_ERROR_MISSING_PROPERTY,
729 _("property is missing"));
730 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID);
734 length = g_bytes_get_size (priv->ssid);
735 if (length == 0 || length > 32) {
736 g_set_error_literal (error,
738 NM_CONNECTION_ERROR_INVALID_PROPERTY,
739 _("SSID length is out of range <1-32> bytes"));
740 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID);
744 if (priv->mode && !_nm_utils_string_in_list (priv->mode, valid_modes)) {
747 NM_CONNECTION_ERROR_INVALID_PROPERTY,
748 _("'%s' is not a valid Wi-Fi mode"),
750 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MODE);
754 if (priv->band && !_nm_utils_string_in_list (priv->band, valid_bands)) {
757 NM_CONNECTION_ERROR_INVALID_PROPERTY,
758 _("'%s' is not a valid band"),
760 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BAND);
764 if (priv->channel && !priv->band) {
767 NM_CONNECTION_ERROR_MISSING_PROPERTY,
768 _("'%s' requires setting '%s' property"),
769 NM_SETTING_WIRELESS_CHANNEL, NM_SETTING_WIRELESS_BAND);
770 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BAND);
775 if (!nm_utils_wifi_is_channel_valid (priv->channel, priv->band)) {
778 NM_CONNECTION_ERROR_INVALID_PROPERTY,
779 _("'%d' is not a valid channel"),
781 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CHANNEL);
786 if (priv->bssid && !nm_utils_hwaddr_valid (priv->bssid, ETH_ALEN)) {
787 g_set_error_literal (error,
789 NM_CONNECTION_ERROR_INVALID_PROPERTY,
790 _("property is invalid"));
791 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BSSID);
795 if (priv->device_mac_address && !nm_utils_hwaddr_valid (priv->device_mac_address, ETH_ALEN)) {
796 g_set_error_literal (error,
798 NM_CONNECTION_ERROR_INVALID_PROPERTY,
799 _("property is invalid"));
800 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS);
804 if (priv->cloned_mac_address && !nm_utils_hwaddr_valid (priv->cloned_mac_address, ETH_ALEN)) {
805 g_set_error_literal (error,
807 NM_CONNECTION_ERROR_INVALID_PROPERTY,
808 _("property is invalid"));
809 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS);
813 for (i = 0; i < priv->mac_address_blacklist->len; i++) {
814 const char *mac = g_array_index (priv->mac_address_blacklist, const char *, i);
816 if (!nm_utils_hwaddr_valid (mac, ETH_ALEN)) {
819 NM_CONNECTION_ERROR_INVALID_PROPERTY,
820 _("'%s' is not a valid MAC address"),
822 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
827 for (iter = priv->seen_bssids; iter; iter = iter->next) {
828 if (!nm_utils_hwaddr_valid (iter->data, ETH_ALEN)) {
831 NM_CONNECTION_ERROR_INVALID_PROPERTY,
832 _("'%s' is not a valid MAC address"),
833 (const char *) iter->data);
834 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SEEN_BSSIDS);
843 nm_setting_wireless_get_security (NMSetting *setting,
844 NMConnection *connection,
845 const char *property_name)
847 if (nm_connection_get_setting_wireless_security (connection))
848 return g_variant_new_string (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
854 clear_blacklist_item (char **item_p)
860 nm_setting_wireless_init (NMSettingWireless *setting)
862 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
864 /* We use GArray rather than GPtrArray so it will automatically be NULL-terminated */
865 priv->mac_address_blacklist = g_array_new (TRUE, FALSE, sizeof (char *));
866 g_array_set_clear_func (priv->mac_address_blacklist, (GDestroyNotify) clear_blacklist_item);
870 finalize (GObject *object)
872 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
878 g_bytes_unref (priv->ssid);
879 g_free (priv->bssid);
880 g_free (priv->device_mac_address);
881 g_free (priv->cloned_mac_address);
882 g_array_unref (priv->mac_address_blacklist);
883 g_slist_free_full (priv->seen_bssids, g_free);
885 G_OBJECT_CLASS (nm_setting_wireless_parent_class)->finalize (object);
889 set_property (GObject *object, guint prop_id,
890 const GValue *value, GParamSpec *pspec)
892 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
893 const char * const *blacklist;
900 g_bytes_unref (priv->ssid);
901 priv->ssid = g_value_dup_boxed (value);
905 priv->mode = g_value_dup_string (value);
909 priv->band = g_value_dup_string (value);
912 priv->channel = g_value_get_uint (value);
915 g_free (priv->bssid);
916 priv->bssid = g_value_dup_string (value);
919 priv->rate = g_value_get_uint (value);
922 priv->tx_power = g_value_get_uint (value);
924 case PROP_MAC_ADDRESS:
925 g_free (priv->device_mac_address);
926 priv->device_mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
929 case PROP_CLONED_MAC_ADDRESS:
930 g_free (priv->cloned_mac_address);
931 priv->cloned_mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
934 case PROP_MAC_ADDRESS_BLACKLIST:
935 blacklist = g_value_get_boxed (value);
936 g_array_set_size (priv->mac_address_blacklist, 0);
937 if (blacklist && *blacklist) {
938 for (i = 0; blacklist[i]; i++) {
939 mac = _nm_utils_hwaddr_canonical_or_invalid (blacklist[i], ETH_ALEN);
940 g_array_append_val (priv->mac_address_blacklist, mac);
945 priv->mtu = g_value_get_uint (value);
947 case PROP_SEEN_BSSIDS:
948 g_slist_free_full (priv->seen_bssids, g_free);
949 priv->seen_bssids = _nm_utils_strv_to_slist (g_value_get_boxed (value), TRUE);
952 priv->hidden = g_value_get_boolean (value);
955 priv->powersave = g_value_get_uint (value);
957 case PROP_MAC_ADDRESS_RANDOMIZATION:
958 priv->mac_address_randomization = g_value_get_uint (value);
961 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
967 get_property (GObject *object, guint prop_id,
968 GValue *value, GParamSpec *pspec)
970 NMSettingWireless *setting = NM_SETTING_WIRELESS (object);
971 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
975 g_value_set_boxed (value, nm_setting_wireless_get_ssid (setting));
978 g_value_set_string (value, nm_setting_wireless_get_mode (setting));
981 g_value_set_string (value, nm_setting_wireless_get_band (setting));
984 g_value_set_uint (value, nm_setting_wireless_get_channel (setting));
987 g_value_set_string (value, nm_setting_wireless_get_bssid (setting));
990 g_value_set_uint (value, nm_setting_wireless_get_rate (setting));
993 g_value_set_uint (value, nm_setting_wireless_get_tx_power (setting));
995 case PROP_MAC_ADDRESS:
996 g_value_set_string (value, nm_setting_wireless_get_mac_address (setting));
998 case PROP_CLONED_MAC_ADDRESS:
999 g_value_set_string (value, nm_setting_wireless_get_cloned_mac_address (setting));
1001 case PROP_MAC_ADDRESS_BLACKLIST:
1002 g_value_set_boxed (value, (char **) priv->mac_address_blacklist->data);
1005 g_value_set_uint (value, nm_setting_wireless_get_mtu (setting));
1007 case PROP_SEEN_BSSIDS:
1008 g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->seen_bssids, TRUE));
1011 g_value_set_boolean (value, nm_setting_wireless_get_hidden (setting));
1013 case PROP_POWERSAVE:
1014 g_value_set_uint (value, nm_setting_wireless_get_powersave (setting));
1016 case PROP_MAC_ADDRESS_RANDOMIZATION:
1017 g_value_set_uint (value, nm_setting_wireless_get_mac_address_randomization (setting));
1020 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1026 nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class)
1028 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1029 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1031 g_type_class_add_private (setting_class, sizeof (NMSettingWirelessPrivate));
1033 /* virtual methods */
1034 object_class->set_property = set_property;
1035 object_class->get_property = get_property;
1036 object_class->finalize = finalize;
1037 parent_class->verify = verify;
1041 * NMSettingWireless:ssid:
1043 * SSID of the Wi-Fi network. Must be specified.
1047 * format: string (or decimal-byte list - obsolete)
1048 * description: SSID of Wi-Fi network.
1049 * example: ssid=Quick Net
1054 * description: SSID of Wi-Fi network.
1055 * example: ESSID="Quick Net"
1058 g_object_class_install_property
1059 (object_class, PROP_SSID,
1060 g_param_spec_boxed (NM_SETTING_WIRELESS_SSID, "", "",
1063 G_PARAM_STATIC_STRINGS));
1066 * NMSettingWireless:mode:
1068 * Wi-Fi network mode; one of "infrastructure", "adhoc" or "ap". If blank,
1069 * infrastructure is assumed.
1074 * values: Ad-Hoc, Managed (Auto) [case insensitive]
1075 * description: Wi-Fi network mode.
1078 g_object_class_install_property
1079 (object_class, PROP_MODE,
1080 g_param_spec_string (NM_SETTING_WIRELESS_MODE, "", "",
1083 G_PARAM_STATIC_STRINGS));
1086 * NMSettingWireless:band:
1088 * 802.11 frequency band of the network. One of "a" for 5GHz 802.11a or
1089 * "bg" for 2.4GHz 802.11. This will lock associations to the Wi-Fi network
1090 * to the specific band, i.e. if "a" is specified, the device will not
1091 * associate with the same network in the 2.4GHz band even if the network's
1092 * settings are compatible. This setting depends on specific driver
1093 * capability and may not work with all drivers.
1099 * description: BAND alone is honored, but CHANNEL overrides BAND since it
1104 g_object_class_install_property
1105 (object_class, PROP_BAND,
1106 g_param_spec_string (NM_SETTING_WIRELESS_BAND, "", "",
1109 G_PARAM_STATIC_STRINGS));
1112 * NMSettingWireless:channel:
1114 * Wireless channel to use for the Wi-Fi connection. The device will only
1115 * join (or create for Ad-Hoc networks) a Wi-Fi network on the specified
1116 * channel. Because channel numbers overlap between bands, this property
1117 * also requires the "band" property to be set.
1122 * description: Channel used for the Wi-Fi communication.
1123 * Channels greater than 14 mean "a" band, otherwise the
1125 * example: CHANNEL=6
1128 g_object_class_install_property
1129 (object_class, PROP_CHANNEL,
1130 g_param_spec_uint (NM_SETTING_WIRELESS_CHANNEL, "", "",
1134 G_PARAM_STATIC_STRINGS));
1137 * NMSettingWireless:bssid:
1139 * If specified, directs the device to only associate with the given access
1140 * point. This capability is highly driver dependent and not supported by
1141 * all devices. Note: this property does not control the BSSID used when
1142 * creating an Ad-Hoc network and is unlikely to in the future.
1146 * variable: BSSID(+)
1147 * description: Restricts association only to a single AP.
1148 * example: BSSID=00:1E:BD:64:83:21
1151 g_object_class_install_property
1152 (object_class, PROP_BSSID,
1153 g_param_spec_string (NM_SETTING_WIRELESS_BSSID, "", "",
1156 G_PARAM_STATIC_STRINGS));
1157 _nm_setting_class_transform_property (parent_class, NM_SETTING_WIRELESS_BSSID,
1158 G_VARIANT_TYPE_BYTESTRING,
1159 _nm_utils_hwaddr_to_dbus,
1160 _nm_utils_hwaddr_from_dbus);
1163 * NMSettingWireless:rate:
1165 * If non-zero, directs the device to only use the specified bitrate for
1166 * communication with the access point. Units are in Kb/s, ie 5500 = 5.5
1167 * Mbit/s. This property is highly driver dependent and not all devices
1168 * support setting a static bitrate.
1173 * description: This property is not handled by ifcfg-rh plugin.
1176 g_object_class_install_property
1177 (object_class, PROP_RATE,
1178 g_param_spec_uint (NM_SETTING_WIRELESS_RATE, "", "",
1182 NM_SETTING_PARAM_FUZZY_IGNORE |
1183 G_PARAM_STATIC_STRINGS));
1186 * NMSettingWireless:tx-power:
1188 * If non-zero, directs the device to use the specified transmit power.
1189 * Units are dBm. This property is highly driver dependent and not all
1190 * devices support setting a static transmit power.
1193 * property: tx-power
1195 * description: This property is not handled by ifcfg-rh plugin.
1198 g_object_class_install_property
1199 (object_class, PROP_TX_POWER,
1200 g_param_spec_uint (NM_SETTING_WIRELESS_TX_POWER, "", "",
1204 NM_SETTING_PARAM_FUZZY_IGNORE |
1205 G_PARAM_STATIC_STRINGS));
1208 * NMSettingWireless:mac-address:
1210 * If specified, this connection will only apply to the Wi-Fi device whose
1211 * permanent MAC address matches. This property does not change the MAC
1212 * address of the device (i.e. MAC spoofing).
1215 * property: mac-address
1216 * format: ususal hex-digits-and-colons notation
1217 * description: MAC address in traditional hex-digits-and-colons notation
1218 * (e.g. 00:22:68:12:79:A2), or semicolon separated list of 6 bytes (obsolete)
1219 * (e.g. 0;34;104;18;121;162).
1222 * property: mac-address
1224 * description: Hardware address of the device in traditional hex-digits-and-colons
1225 * notation (e.g. 00:22:68:14:5A:05).
1228 g_object_class_install_property
1229 (object_class, PROP_MAC_ADDRESS,
1230 g_param_spec_string (NM_SETTING_WIRELESS_MAC_ADDRESS, "", "",
1233 G_PARAM_STATIC_STRINGS));
1234 _nm_setting_class_transform_property (parent_class, NM_SETTING_WIRELESS_MAC_ADDRESS,
1235 G_VARIANT_TYPE_BYTESTRING,
1236 _nm_utils_hwaddr_to_dbus,
1237 _nm_utils_hwaddr_from_dbus);
1240 * NMSettingWireless:cloned-mac-address:
1242 * If specified, request that the Wi-Fi device use this MAC address instead
1243 * of its permanent MAC address. This is known as MAC cloning or spoofing.
1246 * property: cloned-mac-address
1247 * format: ususal hex-digits-and-colons notation
1248 * description: Cloned MAC address in traditional hex-digits-and-colons notation
1249 * (e.g. 00:22:68:12:79:B2), or semicolon separated list of 6 bytes (obsolete)
1250 * (e.g. 0;34;104;18;121;178).
1253 * property: cloned-mac-address
1255 * description: Cloned (spoofed) MAC address in traditional hex-digits-and-colons
1256 * notation (e.g. 00:22:68:14:5A:99).
1259 g_object_class_install_property
1260 (object_class, PROP_CLONED_MAC_ADDRESS,
1261 g_param_spec_string (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, "", "",
1264 G_PARAM_STATIC_STRINGS));
1265 _nm_setting_class_transform_property (parent_class, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS,
1266 G_VARIANT_TYPE_BYTESTRING,
1267 _nm_utils_hwaddr_to_dbus,
1268 _nm_utils_hwaddr_from_dbus);
1271 * NMSettingWireless:mac-address-blacklist:
1273 * A list of permanent MAC addresses of Wi-Fi devices to which this
1274 * connection should never apply. Each MAC address should be given in the
1275 * standard hex-digits-and-colons notation (eg "00:11:22:33:44:55").
1278 * property: mac-address-blacklist
1279 * format: list of MACs (separated with semicolons)
1280 * description: MAC address blacklist.
1281 * example: mac-address-blacklist= 00:22:68:12:79:A6;00:22:68:12:79:78
1284 * property: mac-address-blacklist
1285 * variable: HWADDR_BLACKLIST(+)
1286 * description: It denies usage of the connection for any device whose address
1290 g_object_class_install_property
1291 (object_class, PROP_MAC_ADDRESS_BLACKLIST,
1292 g_param_spec_boxed (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, "", "",
1295 NM_SETTING_PARAM_FUZZY_IGNORE |
1296 G_PARAM_STATIC_STRINGS));
1299 * NMSettingWireless:seen-bssids:
1301 * A list of BSSIDs (each BSSID formatted as a MAC address like
1302 * "00:11:22:33:44:55") that have been detected as part of the Wi-Fi
1303 * network. NetworkManager internally tracks previously seen BSSIDs. The
1304 * property is only meant for reading and reflects the BSSID list of
1305 * NetworkManager. The changes you make to this property will not be
1309 * property: seen-bssids
1311 * description: This property is not handled by ifcfg-rh plugin.
1314 g_object_class_install_property
1315 (object_class, PROP_SEEN_BSSIDS,
1316 g_param_spec_boxed (NM_SETTING_WIRELESS_SEEN_BSSIDS, "", "",
1319 NM_SETTING_PARAM_FUZZY_IGNORE |
1320 G_PARAM_STATIC_STRINGS));
1323 * NMSettingWireless:mtu:
1325 * If non-zero, only transmit packets of the specified size or smaller,
1326 * breaking larger packets up into multiple Ethernet frames.
1331 * description: MTU of the wireless interface.
1334 g_object_class_install_property
1335 (object_class, PROP_MTU,
1336 g_param_spec_uint (NM_SETTING_WIRELESS_MTU, "", "",
1340 NM_SETTING_PARAM_FUZZY_IGNORE |
1341 G_PARAM_STATIC_STRINGS));
1344 * NMSettingWireless:hidden:
1346 * If %TRUE, indicates this network is a non-broadcasting network that hides
1347 * its SSID. In this case various workarounds may take place, such as
1348 * probe-scanning the SSID for more reliable network discovery. However,
1349 * these workarounds expose inherent insecurities with hidden SSID networks,
1350 * and thus hidden SSID networks should be used with caution.
1354 * variable: SSID_HIDDEN(+)
1355 * description: Whether the network hides the SSID.
1358 g_object_class_install_property
1359 (object_class, PROP_HIDDEN,
1360 g_param_spec_boolean (NM_SETTING_WIRELESS_HIDDEN, "", "",
1363 G_PARAM_STATIC_STRINGS));
1366 * NMSettingWireless:powersave:
1368 * One of %NM_SETTING_WIRELESS_POWERSAVE_DISABLE (disable Wi-Fi power
1369 * saving), %NM_SETTING_WIRELESS_POWERSAVE_ENABLE (enable Wi-Fi power
1370 * saving), %NM_SETTING_WIRELESS_POWERSAVE_IGNORE (don't touch currently
1371 * configure setting) or %NM_SETTING_WIRELESS_POWERSAVE_DEFAULT (use the
1372 * globally configured value). All other values are reserved.
1377 * property: powersave
1378 * variable: POWERSAVE(+)
1379 * values: default, ignore, enable, disable
1380 * description: Enables or disables Wi-Fi power saving.
1381 * example: POWERSAVE=enable
1384 g_object_class_install_property
1385 (object_class, PROP_POWERSAVE,
1386 g_param_spec_uint (NM_SETTING_WIRELESS_POWERSAVE, "", "",
1387 0, G_MAXUINT32, NM_SETTING_WIRELESS_POWERSAVE_DEFAULT,
1389 G_PARAM_STATIC_STRINGS));
1392 * NMSettingWireless:mac-address-randomization:
1394 * One of %NM_SETTING_MAC_RANDOMIZATION_DEFAULT (never randomize unless
1395 * the user has set a global default to randomize and the supplicant
1396 * supports randomization), %NM_SETTING_MAC_RANDOMIZATION_NEVER (never
1397 * randomize the MAC address), or %NM_SETTING_MAC_RANDOMIZATION_ALWAYS
1398 * (always randomize the MAC address).
1403 * property: mac-address-randomization
1404 * variable: MAC_ADDRESS_RANDOMIZATION(+)
1405 * values: default, never, always
1406 * description: Enables or disables Wi-Fi MAC address randomization.
1407 * example: MAC_ADDRESS_RANDOMIZATION=always
1410 g_object_class_install_property
1411 (object_class, PROP_MAC_ADDRESS_RANDOMIZATION,
1412 g_param_spec_uint (NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, "", "",
1413 0, G_MAXUINT32, NM_SETTING_MAC_RANDOMIZATION_DEFAULT,
1415 G_PARAM_STATIC_STRINGS));
1417 /* Compatibility for deprecated property */
1419 * property: security
1421 * description: This property is deprecated and not handled by ifcfg-rh-plugin.
1424 * property: security
1425 * description: This property is deprecated, but can be set to the value
1426 * '802-11-wireless-security' when a wireless security setting is also
1427 * present in the connection dictionary, for compatibility with very old
1428 * NetworkManager daemons.
1431 _nm_setting_class_add_dbus_only_property (parent_class, "security",
1432 G_VARIANT_TYPE_STRING,
1433 nm_setting_wireless_get_security, NULL);