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>
27 #include <netinet/ether.h>
28 #include <dbus/dbus-glib.h>
30 #include "NetworkManager.h"
31 #include "nm-setting-wireless.h"
32 #include "nm-param-spec-specialized.h"
34 #include "nm-dbus-glib-types.h"
35 #include "nm-utils-private.h"
36 #include "nm-setting-private.h"
39 * SECTION:nm-setting-wireless
40 * @short_description: Describes connection properties for 802.11 Wi-Fi networks
41 * @include: nm-setting-wireless.h
43 * The #NMSettingWireless object is a #NMSetting subclass that describes properties
44 * necessary for connection to 802.11 Wi-Fi networks.
48 * nm_setting_wireless_error_quark:
50 * Registers an error quark for #NMSettingWireless if necessary.
52 * Returns: the error quark used for #NMSettingWireless errors.
55 nm_setting_wireless_error_quark (void)
59 if (G_UNLIKELY (!quark))
60 quark = g_quark_from_static_string ("nm-setting-wireless-error-quark");
65 G_DEFINE_TYPE_WITH_CODE (NMSettingWireless, nm_setting_wireless, NM_TYPE_SETTING,
66 _nm_register_setting (NM_SETTING_WIRELESS_SETTING_NAME,
69 NM_SETTING_WIRELESS_ERROR))
70 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS)
72 #define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate))
82 GByteArray *device_mac_address;
83 GByteArray *cloned_mac_address;
84 GSList *mac_address_blacklist;
90 } NMSettingWirelessPrivate;
102 PROP_CLONED_MAC_ADDRESS,
103 PROP_MAC_ADDRESS_BLACKLIST,
114 match_cipher (const char *cipher,
115 const char *expected,
120 if (strcmp (cipher, expected) != 0)
123 if (!(wpa_flags & flag) && !(rsn_flags & flag))
130 * nm_setting_wireless_ap_security_compatible:
131 * @s_wireless: a #NMSettingWireless
132 * @s_wireless_sec: a #NMSettingWirelessSecurity or %NULL
133 * @ap_flags: the %NM80211ApFlags of the given access point
134 * @ap_wpa: the %NM80211ApSecurityFlags of the given access point's WPA
136 * @ap_rsn: the %NM80211ApSecurityFlags of the given access point's WPA2/RSN
138 * @ap_mode: the 802.11 mode of the AP, either Ad-Hoc or Infrastructure
140 * Given a #NMSettingWireless and an optional #NMSettingWirelessSecurity,
141 * determine if the configuration given by the settings is compatible with
142 * the security of an access point using that access point's capability flags
143 * and mode. Useful for clients that wish to filter a set of connections
144 * against a set of access points and determine which connections are
145 * compatible with which access points.
147 * Returns: %TRUE if the given settings are compatible with the access point's
148 * security flags and mode, %FALSE if they are not.
151 nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
152 NMSettingWirelessSecurity *s_wireless_sec,
153 NM80211ApFlags ap_flags,
154 NM80211ApSecurityFlags ap_wpa,
155 NM80211ApSecurityFlags ap_rsn,
158 const char *key_mgmt = NULL, *cipher;
160 gboolean found = FALSE;
162 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE);
164 if (!s_wireless_sec) {
165 if ( (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
166 || (ap_wpa != NM_802_11_AP_SEC_NONE)
167 || (ap_rsn != NM_802_11_AP_SEC_NONE))
172 key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec);
177 if (!strcmp (key_mgmt, "none")) {
178 if ( !(ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
179 || (ap_wpa != NM_802_11_AP_SEC_NONE)
180 || (ap_rsn != NM_802_11_AP_SEC_NONE))
186 if (!strcmp (key_mgmt, "wpa-none")) {
187 if (ap_mode != NM_802_11_MODE_ADHOC)
189 /* FIXME: validate ciphers if they're in the beacon */
193 /* Adhoc WPA2 (ie, RSN IBSS) */
194 if (ap_mode == NM_802_11_MODE_ADHOC) {
195 if (strcmp (key_mgmt, "wpa-psk"))
198 /* Ensure the AP has RSN PSK capability */
199 if (!(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
202 /* Fall through and check ciphers in generic WPA-PSK code */
205 /* Dynamic WEP or LEAP */
206 if (!strcmp (key_mgmt, "ieee8021x")) {
207 if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY))
210 /* If the AP is advertising a WPA IE, make sure it supports WEP ciphers */
211 if (ap_wpa != NM_802_11_AP_SEC_NONE) {
212 if (!(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
215 /* quick check; can't use AP if it doesn't support at least one
216 * WEP cipher in both pairwise and group suites.
218 if ( !(ap_wpa & (NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104))
219 || !(ap_wpa & (NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104)))
222 /* Match at least one pairwise cipher with AP's capability if the
223 * wireless-security setting explicitly lists pairwise ciphers
225 num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
226 for (i = 0, found = FALSE; i < num; i++) {
227 cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
228 if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP40)))
230 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP104)))
236 /* Match at least one group cipher with AP's capability if the
237 * wireless-security setting explicitly lists group ciphers
239 num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
240 for (i = 0, found = FALSE; i < num; i++) {
241 cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
242 if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP40)))
244 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP104)))
253 /* WPA[2]-PSK and WPA[2] Enterprise */
254 if ( !strcmp (key_mgmt, "wpa-psk")
255 || !strcmp (key_mgmt, "wpa-eap")) {
257 if (!strcmp (key_mgmt, "wpa-psk")) {
258 if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_PSK)
259 && !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
261 } else if (!strcmp (key_mgmt, "wpa-eap")) {
262 if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
263 && !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
267 // FIXME: should handle WPA and RSN separately here to ensure that
268 // if the Connection only uses WPA we don't match a cipher against
269 // the AP's RSN IE instead
271 /* Match at least one pairwise cipher with AP's capability if the
272 * wireless-security setting explicitly lists pairwise ciphers
274 num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
275 for (i = 0, found = FALSE; i < num; i++) {
276 cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
277 if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_TKIP)))
279 if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_CCMP)))
285 /* Match at least one group cipher with AP's capability if the
286 * wireless-security setting explicitly lists group ciphers
288 num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
289 for (i = 0, found = FALSE; i < num; i++) {
290 cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
292 if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP40)))
294 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP104)))
296 if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_TKIP)))
298 if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_CCMP)))
311 * nm_setting_wireless_new:
313 * Creates a new #NMSettingWireless object with default values.
315 * Returns: (transfer full): the new empty #NMSettingWireless object
318 nm_setting_wireless_new (void)
320 return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRELESS, NULL);
324 * nm_setting_wireless_get_ssid:
325 * @setting: the #NMSettingWireless
327 * Returns: the #NMSettingWireless:ssid property of the setting
330 nm_setting_wireless_get_ssid (NMSettingWireless *setting)
332 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
334 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->ssid;
338 * nm_setting_wireless_get_mode:
339 * @setting: the #NMSettingWireless
341 * Returns: the #NMSettingWireless:mode property of the setting
344 nm_setting_wireless_get_mode (NMSettingWireless *setting)
346 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
348 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mode;
352 * nm_setting_wireless_get_band:
353 * @setting: the #NMSettingWireless
355 * Returns: the #NMSettingWireless:band property of the setting
358 nm_setting_wireless_get_band (NMSettingWireless *setting)
360 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
362 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->band;
366 * nm_setting_wireless_get_channel:
367 * @setting: the #NMSettingWireless
369 * Returns: the #NMSettingWireless:channel property of the setting
372 nm_setting_wireless_get_channel (NMSettingWireless *setting)
374 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
376 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->channel;
380 * nm_setting_wireless_get_bssid:
381 * @setting: the #NMSettingWireless
383 * Returns: the #NMSettingWireless:bssid property of the setting
386 nm_setting_wireless_get_bssid (NMSettingWireless *setting)
388 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
390 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->bssid;
394 * nm_setting_wireless_get_rate:
395 * @setting: the #NMSettingWireless
397 * Returns: the #NMSettingWireless:rate property of the setting
400 nm_setting_wireless_get_rate (NMSettingWireless *setting)
402 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
404 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->rate;
408 * nm_setting_wireless_get_tx_power:
409 * @setting: the #NMSettingWireless
411 * Returns: the #NMSettingWireless:tx-power property of the setting
414 nm_setting_wireless_get_tx_power (NMSettingWireless *setting)
416 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
418 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->tx_power;
422 * nm_setting_wireless_get_mac_address:
423 * @setting: the #NMSettingWireless
425 * Returns: the #NMSettingWireless:mac-address property of the setting
428 nm_setting_wireless_get_mac_address (NMSettingWireless *setting)
430 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
432 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->device_mac_address;
436 * nm_setting_wireless_get_cloned_mac_address:
437 * @setting: the #NMSettingWireless
439 * Returns: the #NMSettingWireless:cloned-mac-address property of the setting
442 nm_setting_wireless_get_cloned_mac_address (NMSettingWireless *setting)
444 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
446 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->cloned_mac_address;
450 * nm_setting_wireless_get_mac_address_blacklist:
451 * @setting: the #NMSettingWireless
453 * Returns: (element-type GLib.ByteArray): the
454 * #NMSettingWireless:mac-address-blacklist property of the setting
457 nm_setting_wireless_get_mac_address_blacklist (NMSettingWireless *setting)
459 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
461 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist;
465 * nm_setting_wireless_get_num_mac_blacklist_items:
466 * @setting: the #NMSettingWireless
468 * Returns: the number of blacklisted MAC addresses
473 nm_setting_wireless_get_num_mac_blacklist_items (NMSettingWireless *setting)
475 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
477 return g_slist_length (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist);
481 * nm_setting_wireless_get_mac_blacklist_item:
482 * @setting: the #NMSettingWireless
483 * @idx: the zero-based index of the MAC address entry
485 * Returns: the blacklisted MAC address string (hex-digits-and-colons notation)
491 nm_setting_wireless_get_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
493 NMSettingWirelessPrivate *priv;
495 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
497 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
498 g_return_val_if_fail (idx <= g_slist_length (priv->mac_address_blacklist), NULL);
500 return (const char *) g_slist_nth_data (priv->mac_address_blacklist, idx);
504 * nm_setting_wireless_add_mac_blacklist_item:
505 * @setting: the #NMSettingWireless
506 * @mac: the MAC address string (hex-digits-and-colons notation) to blacklist
508 * Adds a new MAC address to the #NMSettingWireless:mac-address-blacklist property.
510 * Returns: %TRUE if the MAC address was added; %FALSE if the MAC address
511 * is invalid or was already present
516 nm_setting_wireless_add_mac_blacklist_item (NMSettingWireless *setting, const char *mac)
518 NMSettingWirelessPrivate *priv;
522 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
523 g_return_val_if_fail (mac != NULL, FALSE);
525 if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
528 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
529 for (iter = priv->mac_address_blacklist; iter; iter = g_slist_next (iter)) {
530 if (!strcasecmp (mac, (char *) iter->data))
534 priv->mac_address_blacklist = g_slist_append (priv->mac_address_blacklist,
535 g_ascii_strup (mac, -1));
536 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
541 * nm_setting_wireless_remove_mac_blacklist_item:
542 * @setting: the #NMSettingWireless
543 * @idx: index number of the MAC address
545 * Removes the MAC address at index @idx from the blacklist.
550 nm_setting_wireless_remove_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
552 NMSettingWirelessPrivate *priv;
555 g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
557 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
558 elt = g_slist_nth (priv->mac_address_blacklist, idx);
559 g_return_if_fail (elt != NULL);
562 priv->mac_address_blacklist = g_slist_delete_link (priv->mac_address_blacklist, elt);
563 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
567 * nm_setting_wireless_remove_mac_blacklist_item_by_value:
568 * @setting: the #NMSettingWireless
569 * @mac: the MAC address string (hex-digits-and-colons notation) to remove from
572 * Removes the MAC address @mac from the blacklist.
574 * Returns: %TRUE if the MAC address was found and removed; %FALSE if it was not.
579 nm_setting_wireless_remove_mac_blacklist_item_by_value (NMSettingWireless *setting, const char *mac)
581 NMSettingWirelessPrivate *priv;
585 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
586 g_return_val_if_fail (mac != NULL, FALSE);
588 if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
591 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
592 for (iter = priv->mac_address_blacklist; iter; iter = g_slist_next (iter)) {
593 if (!strcasecmp (mac, (char *) iter->data)) {
594 priv->mac_address_blacklist = g_slist_delete_link (priv->mac_address_blacklist, iter);
595 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
603 * nm_setting_wireless_clear_mac_blacklist_items:
604 * @setting: the #NMSettingWireless
606 * Removes all blacklisted MAC addresses.
611 nm_setting_wireless_clear_mac_blacklist_items (NMSettingWireless *setting)
613 g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
615 g_slist_free_full (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist, g_free);
616 NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist = NULL;
617 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
621 * nm_setting_wireless_get_mtu:
622 * @setting: the #NMSettingWireless
624 * Returns: the #NMSettingWireless:mtu property of the setting
627 nm_setting_wireless_get_mtu (NMSettingWireless *setting)
629 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
631 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mtu;
635 * nm_setting_wireless_get_security:
636 * @setting: the #NMSettingWireless
638 * Returns: the #NMSettingWireless:security property of the setting
640 * Deprecated: 0.9.10: No longer used. Security rescrictions are recognized by
641 * the presence of NM_SETTING_WIRELESS_SECURITY_SETTING_NAME in the connection.
644 nm_setting_wireless_get_security (NMSettingWireless *setting)
646 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
648 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->security;
652 * nm_setting_wireless_get_hidden:
653 * @setting: the #NMSettingWireless
655 * Returns: the #NMSettingWireless:hidden property of the setting
658 nm_setting_wireless_get_hidden (NMSettingWireless *setting)
660 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
662 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->hidden;
666 * nm_setting_wireless_get_powersave:
667 * @setting: the #NMSettingWireless
669 * Returns: the #NMSettingWireless:powersave property of the setting
674 nm_setting_wireless_get_powersave (NMSettingWireless *setting)
676 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
678 return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->powersave;
682 * nm_setting_wireless_add_seen_bssid:
683 * @setting: the #NMSettingWireless
684 * @bssid: the new BSSID to add to the list
686 * Adds a new Wi-Fi AP's BSSID to the previously seen BSSID list of the setting.
687 * NetworkManager now tracks previously seen BSSIDs internally so this function
688 * no longer has much use. Actually, changes you make using this function will
691 * Returns: %TRUE if @bssid was already known, %FALSE if not
694 nm_setting_wireless_add_seen_bssid (NMSettingWireless *setting,
697 NMSettingWirelessPrivate *priv;
700 gboolean found = FALSE;
702 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
703 g_return_val_if_fail (bssid != NULL, FALSE);
705 lower_bssid = g_ascii_strdown (bssid, -1);
709 priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
711 for (iter = priv->seen_bssids; iter; iter = iter->next) {
712 if (!strcmp ((char *) iter->data, lower_bssid)) {
719 priv->seen_bssids = g_slist_prepend (priv->seen_bssids, lower_bssid);
720 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SEEN_BSSIDS);
722 g_free (lower_bssid);
728 * nm_setting_wireless_get_num_seen_bssids:
729 * @setting: the #NMSettingWireless
731 * Returns: the number of BSSIDs in the previously seen BSSID list
734 nm_setting_wireless_get_num_seen_bssids (NMSettingWireless *setting)
736 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
738 return g_slist_length (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids);
742 * nm_setting_wireless_get_seen_bssid:
743 * @setting: the #NMSettingWireless
744 * @i: index of a BSSID in the previously seen BSSID list
746 * Returns: the BSSID at index @i
749 nm_setting_wireless_get_seen_bssid (NMSettingWireless *setting,
752 g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
754 return (const char *) g_slist_nth_data (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids, i);
758 verify (NMSetting *setting, GSList *all_settings, GError **error)
760 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
761 const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NULL };
762 const char *valid_bands[] = { "a", "bg", NULL };
766 g_set_error_literal (error,
767 NM_SETTING_WIRELESS_ERROR,
768 NM_SETTING_WIRELESS_ERROR_MISSING_PROPERTY,
769 _("property is missing"));
770 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID);
774 if (!priv->ssid->len || priv->ssid->len > 32) {
775 g_set_error_literal (error,
776 NM_SETTING_WIRELESS_ERROR,
777 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
778 _("SSID length is out of range <1-32> bytes"));
779 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID);
783 if (priv->mode && !_nm_utils_string_in_list (priv->mode, valid_modes)) {
785 NM_SETTING_WIRELESS_ERROR,
786 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
787 _("'%s' is not a valid Wi-Fi mode"),
789 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MODE);
793 if (priv->band && !_nm_utils_string_in_list (priv->band, valid_bands)) {
795 NM_SETTING_WIRELESS_ERROR,
796 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
797 _("'%s' is not a valid band"),
799 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BAND);
803 if (priv->channel && !priv->band) {
805 NM_SETTING_WIRELESS_ERROR,
806 NM_SETTING_WIRELESS_ERROR_CHANNEL_REQUIRES_BAND,
807 _("requires setting '%s' property"),
808 NM_SETTING_WIRELESS_BAND);
809 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CHANNEL);
814 if (!nm_utils_wifi_is_channel_valid (priv->channel, priv->band)) {
816 NM_SETTING_WIRELESS_ERROR,
817 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
818 _("'%d' is not a valid channel"),
820 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CHANNEL);
825 if (priv->bssid && priv->bssid->len != ETH_ALEN) {
826 g_set_error_literal (error,
827 NM_SETTING_WIRELESS_ERROR,
828 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
829 _("property is invalid"));
830 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BSSID);
834 if (priv->device_mac_address && priv->device_mac_address->len != ETH_ALEN) {
835 g_set_error_literal (error,
836 NM_SETTING_WIRELESS_ERROR,
837 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
838 _("property is invalid"));
839 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS);
843 if (priv->cloned_mac_address && priv->cloned_mac_address->len != ETH_ALEN) {
844 g_set_error_literal (error,
845 NM_SETTING_WIRELESS_ERROR,
846 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
847 _("property is invalid"));
848 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS);
852 for (iter = priv->mac_address_blacklist; iter; iter = iter->next) {
853 struct ether_addr addr;
855 if (!ether_aton_r (iter->data, &addr)) {
857 NM_SETTING_WIRELESS_ERROR,
858 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
859 _("'%s' is not a valid MAC address"),
860 (const char *) iter->data);
861 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
866 for (iter = priv->seen_bssids; iter; iter = iter->next) {
867 struct ether_addr addr;
869 if (!ether_aton_r (iter->data, &addr)) {
871 NM_SETTING_WIRELESS_ERROR,
872 NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
873 _("'%s' is not a valid MAC address"),
874 (const char *) iter->data);
875 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SEEN_BSSIDS);
884 nm_setting_wireless_init (NMSettingWireless *setting)
889 finalize (GObject *object)
891 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
895 g_free (priv->security);
898 g_byte_array_free (priv->ssid, TRUE);
900 g_byte_array_free (priv->bssid, TRUE);
901 if (priv->device_mac_address)
902 g_byte_array_free (priv->device_mac_address, TRUE);
903 if (priv->cloned_mac_address)
904 g_byte_array_free (priv->cloned_mac_address, TRUE);
905 g_slist_free_full (priv->mac_address_blacklist, g_free);
906 g_slist_free_full (priv->seen_bssids, g_free);
908 G_OBJECT_CLASS (nm_setting_wireless_parent_class)->finalize (object);
912 set_property (GObject *object, guint prop_id,
913 const GValue *value, GParamSpec *pspec)
915 NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
920 g_byte_array_free (priv->ssid, TRUE);
921 priv->ssid = g_value_dup_boxed (value);
925 priv->mode = g_value_dup_string (value);
929 priv->band = g_value_dup_string (value);
932 priv->channel = g_value_get_uint (value);
936 g_byte_array_free (priv->bssid, TRUE);
937 priv->bssid = g_value_dup_boxed (value);
940 priv->rate = g_value_get_uint (value);
943 priv->tx_power = g_value_get_uint (value);
945 case PROP_MAC_ADDRESS:
946 if (priv->device_mac_address)
947 g_byte_array_free (priv->device_mac_address, TRUE);
948 priv->device_mac_address = g_value_dup_boxed (value);
950 case PROP_CLONED_MAC_ADDRESS:
951 if (priv->cloned_mac_address)
952 g_byte_array_free (priv->cloned_mac_address, TRUE);
953 priv->cloned_mac_address = g_value_dup_boxed (value);
955 case PROP_MAC_ADDRESS_BLACKLIST:
956 g_slist_free_full (priv->mac_address_blacklist, g_free);
957 priv->mac_address_blacklist = g_value_dup_boxed (value);
960 priv->mtu = g_value_get_uint (value);
962 case PROP_SEEN_BSSIDS:
963 g_slist_free_full (priv->seen_bssids, g_free);
964 priv->seen_bssids = g_value_dup_boxed (value);
967 g_free (priv->security);
968 priv->security = g_value_dup_string (value);
971 priv->hidden = g_value_get_boolean (value);
974 priv->powersave = g_value_get_uint (value);
977 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
983 get_property (GObject *object, guint prop_id,
984 GValue *value, GParamSpec *pspec)
986 NMSettingWireless *setting = NM_SETTING_WIRELESS (object);
990 g_value_set_boxed (value, nm_setting_wireless_get_ssid (setting));
993 g_value_set_string (value, nm_setting_wireless_get_mode (setting));
996 g_value_set_string (value, nm_setting_wireless_get_band (setting));
999 g_value_set_uint (value, nm_setting_wireless_get_channel (setting));
1002 g_value_set_boxed (value, nm_setting_wireless_get_bssid (setting));
1005 g_value_set_uint (value, nm_setting_wireless_get_rate (setting));
1008 g_value_set_uint (value, nm_setting_wireless_get_tx_power (setting));
1010 case PROP_MAC_ADDRESS:
1011 g_value_set_boxed (value, nm_setting_wireless_get_mac_address (setting));
1013 case PROP_CLONED_MAC_ADDRESS:
1014 g_value_set_boxed (value, nm_setting_wireless_get_cloned_mac_address (setting));
1016 case PROP_MAC_ADDRESS_BLACKLIST:
1017 g_value_set_boxed (value, nm_setting_wireless_get_mac_address_blacklist (setting));
1020 g_value_set_uint (value, nm_setting_wireless_get_mtu (setting));
1022 case PROP_SEEN_BSSIDS:
1023 g_value_set_boxed (value, NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids);
1026 g_value_set_string (value, NM_SETTING_WIRELESS_GET_PRIVATE (setting)->security);
1029 g_value_set_boolean (value, nm_setting_wireless_get_hidden (setting));
1031 case PROP_POWERSAVE:
1032 g_value_set_uint (value, nm_setting_wireless_get_powersave (setting));
1035 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1041 nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class)
1043 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1044 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1046 g_type_class_add_private (setting_class, sizeof (NMSettingWirelessPrivate));
1048 /* virtual methods */
1049 object_class->set_property = set_property;
1050 object_class->get_property = get_property;
1051 object_class->finalize = finalize;
1052 parent_class->verify = verify;
1056 * NMSettingWireless:ssid:
1058 * SSID of the Wi-Fi network. Must be specified.
1060 g_object_class_install_property
1061 (object_class, PROP_SSID,
1062 _nm_param_spec_specialized (NM_SETTING_WIRELESS_SSID, "", "",
1063 DBUS_TYPE_G_UCHAR_ARRAY,
1065 G_PARAM_STATIC_STRINGS));
1068 * NMSettingWireless:mode:
1070 * Wi-Fi network mode; one of "infrastructure", "adhoc" or "ap". If blank,
1071 * infrastructure is assumed.
1073 g_object_class_install_property
1074 (object_class, PROP_MODE,
1075 g_param_spec_string (NM_SETTING_WIRELESS_MODE, "", "",
1078 G_PARAM_STATIC_STRINGS));
1081 * NMSettingWireless:band:
1083 * 802.11 frequency band of the network. One of "a" for 5GHz 802.11a or
1084 * "bg" for 2.4GHz 802.11. This will lock associations to the Wi-Fi network
1085 * to the specific band, i.e. if "a" is specified, the device will not
1086 * associate with the same network in the 2.4GHz band even if the network's
1087 * settings are compatible. This setting depends on specific driver
1088 * capability and may not work with all drivers.
1090 g_object_class_install_property
1091 (object_class, PROP_BAND,
1092 g_param_spec_string (NM_SETTING_WIRELESS_BAND, "", "",
1095 G_PARAM_STATIC_STRINGS));
1098 * NMSettingWireless:channel:
1100 * Wireless channel to use for the Wi-Fi connection. The device will only
1101 * join (or create for Ad-Hoc networks) a Wi-Fi network on the specified
1102 * channel. Because channel numbers overlap between bands, this property
1103 * also requires the "band" property to be set.
1105 g_object_class_install_property
1106 (object_class, PROP_CHANNEL,
1107 g_param_spec_uint (NM_SETTING_WIRELESS_CHANNEL, "", "",
1111 G_PARAM_STATIC_STRINGS));
1114 * NMSettingWireless:bssid:
1116 * If specified, directs the device to only associate with the given access
1117 * point. This capability is highly driver dependent and not supported by
1118 * all devices. Note: this property does not control the BSSID used when
1119 * creating an Ad-Hoc network and is unlikely to in the future.
1121 g_object_class_install_property
1122 (object_class, PROP_BSSID,
1123 _nm_param_spec_specialized (NM_SETTING_WIRELESS_BSSID, "", "",
1124 DBUS_TYPE_G_UCHAR_ARRAY,
1126 G_PARAM_STATIC_STRINGS));
1129 * NMSettingWireless:rate:
1131 * If non-zero, directs the device to only use the specified bitrate for
1132 * communication with the access point. Units are in Kb/s, ie 5500 = 5.5
1133 * Mbit/s. This property is highly driver dependent and not all devices
1134 * support setting a static bitrate.
1136 g_object_class_install_property
1137 (object_class, PROP_RATE,
1138 g_param_spec_uint (NM_SETTING_WIRELESS_RATE, "", "",
1142 NM_SETTING_PARAM_FUZZY_IGNORE |
1143 G_PARAM_STATIC_STRINGS));
1146 * NMSettingWireless:tx-power:
1148 * If non-zero, directs the device to use the specified transmit power.
1149 * Units are dBm. This property is highly driver dependent and not all
1150 * devices support setting a static transmit power.
1152 g_object_class_install_property
1153 (object_class, PROP_TX_POWER,
1154 g_param_spec_uint (NM_SETTING_WIRELESS_TX_POWER, "", "",
1158 NM_SETTING_PARAM_FUZZY_IGNORE |
1159 G_PARAM_STATIC_STRINGS));
1162 * NMSettingWireless:mac-address:
1164 * If specified, this connection will only apply to the Wi-Fi device whose
1165 * permanent MAC address matches. This property does not change the MAC
1166 * address of the device (i.e. MAC spoofing).
1168 g_object_class_install_property
1169 (object_class, PROP_MAC_ADDRESS,
1170 _nm_param_spec_specialized (NM_SETTING_WIRELESS_MAC_ADDRESS, "", "",
1171 DBUS_TYPE_G_UCHAR_ARRAY,
1173 G_PARAM_STATIC_STRINGS));
1176 * NMSettingWireless:cloned-mac-address:
1178 * If specified, request that the Wi-Fi device use this MAC address instead
1179 * of its permanent MAC address. This is known as MAC cloning or spoofing.
1181 g_object_class_install_property
1182 (object_class, PROP_CLONED_MAC_ADDRESS,
1183 _nm_param_spec_specialized (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, "", "",
1184 DBUS_TYPE_G_UCHAR_ARRAY,
1186 G_PARAM_STATIC_STRINGS));
1189 * NMSettingWireless:mac-address-blacklist:
1191 * A list of permanent MAC addresses of Wi-Fi devices to which this
1192 * connection should never apply. Each MAC address should be given in the
1193 * standard hex-digits-and-colons notation (eg "00:11:22:33:44:55").
1195 g_object_class_install_property
1196 (object_class, PROP_MAC_ADDRESS_BLACKLIST,
1197 _nm_param_spec_specialized (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, "", "",
1198 DBUS_TYPE_G_LIST_OF_STRING,
1200 NM_SETTING_PARAM_FUZZY_IGNORE |
1201 G_PARAM_STATIC_STRINGS));
1204 * NMSettingWireless:seen-bssids:
1206 * A list of BSSIDs (each BSSID formatted as a MAC address like
1207 * "00:11:22:33:44:55") that have been detected as part of the Wi-Fi
1208 * network. NetworkManager internally tracks previously seen BSSIDs. The
1209 * property is only meant for reading and reflects the BSSID list of
1210 * NetworkManager. The changes you make to this property will not be
1213 g_object_class_install_property
1214 (object_class, PROP_SEEN_BSSIDS,
1215 _nm_param_spec_specialized (NM_SETTING_WIRELESS_SEEN_BSSIDS, "", "",
1216 DBUS_TYPE_G_LIST_OF_STRING,
1218 NM_SETTING_PARAM_FUZZY_IGNORE |
1219 G_PARAM_STATIC_STRINGS));
1222 * NMSettingWireless:mtu:
1224 * If non-zero, only transmit packets of the specified size or smaller,
1225 * breaking larger packets up into multiple Ethernet frames.
1227 g_object_class_install_property
1228 (object_class, PROP_MTU,
1229 g_param_spec_uint (NM_SETTING_WIRELESS_MTU, "", "",
1233 NM_SETTING_PARAM_FUZZY_IGNORE |
1234 G_PARAM_STATIC_STRINGS));
1237 * NMSettingWireless:security:
1239 * If the wireless connection has any security restrictions, like 802.1x,
1240 * WEP, or WPA, set this property to
1241 * %NM_SETTING_WIRELESS_SECURITY_SETTING_NAME and ensure the connection
1242 * contains a valid #NMSettingWirelessSecurity setting.
1244 * Deprecated: 0.9.10: No longer used. Security restrictions are recognized
1245 * by the presence of a #NMSettingWirelessSecurity setting in the
1248 g_object_class_install_property
1249 (object_class, PROP_SEC,
1250 g_param_spec_string (NM_SETTING_WIRELESS_SEC, "", "",
1253 G_PARAM_STATIC_STRINGS));
1256 * NMSettingWireless:hidden:
1258 * If %TRUE, indicates this network is a non-broadcasting network that hides
1259 * its SSID. In this case various workarounds may take place, such as
1260 * probe-scanning the SSID for more reliable network discovery. However,
1261 * these workarounds expose inherent insecurities with hidden SSID networks,
1262 * and thus hidden SSID networks should be used with caution.
1264 g_object_class_install_property
1265 (object_class, PROP_HIDDEN,
1266 g_param_spec_boolean (NM_SETTING_WIRELESS_HIDDEN, "", "",
1269 G_PARAM_STATIC_STRINGS));
1272 * NMSettingWireless:powersave:
1274 * If set to %FALSE, Wi-Fi power saving behavior is disabled. If set to
1275 * %TRUE, Wi-Fi power saving behavior is enabled. All other values are
1276 * reserved. Note that even though only boolean values are allowed, the
1277 * property type is an unsigned integer to allow for future expansion.
1281 g_object_class_install_property
1282 (object_class, PROP_POWERSAVE,
1283 g_param_spec_uint (NM_SETTING_WIRELESS_POWERSAVE, "", "",
1286 G_PARAM_STATIC_STRINGS));