device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-util / nm-setting-wireless.c
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3 /*
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.
8  *
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.
13  *
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.
18  *
19  * Copyright 2007 - 2014 Red Hat, Inc.
20  * Copyright 2007 - 2008 Novell, Inc.
21  */
22
23 #include "nm-default.h"
24
25 #include <string.h>
26 #include <net/ethernet.h>
27 #include <netinet/ether.h>
28 #include <dbus/dbus-glib.h>
29
30 #include "NetworkManager.h"
31 #include "nm-setting-wireless.h"
32 #include "nm-param-spec-specialized.h"
33 #include "nm-utils.h"
34 #include "nm-dbus-glib-types.h"
35 #include "nm-utils-private.h"
36 #include "nm-setting-private.h"
37
38 /**
39  * SECTION:nm-setting-wireless
40  * @short_description: Describes connection properties for 802.11 Wi-Fi networks
41  * @include: nm-setting-wireless.h
42  *
43  * The #NMSettingWireless object is a #NMSetting subclass that describes properties
44  * necessary for connection to 802.11 Wi-Fi networks.
45  **/
46
47 /**
48  * nm_setting_wireless_error_quark:
49  *
50  * Registers an error quark for #NMSettingWireless if necessary.
51  *
52  * Returns: the error quark used for #NMSettingWireless errors.
53  **/
54 GQuark
55 nm_setting_wireless_error_quark (void)
56 {
57         static GQuark quark;
58
59         if (G_UNLIKELY (!quark))
60                 quark = g_quark_from_static_string ("nm-setting-wireless-error-quark");
61         return quark;
62 }
63
64
65 G_DEFINE_TYPE_WITH_CODE (NMSettingWireless, nm_setting_wireless, NM_TYPE_SETTING,
66                          _nm_register_setting (NM_SETTING_WIRELESS_SETTING_NAME,
67                                                g_define_type_id,
68                                                1,
69                                                NM_SETTING_WIRELESS_ERROR))
70 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIRELESS)
71
72 #define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate))
73
74 typedef struct {
75         GByteArray *ssid;
76         char *mode;
77         char *band;
78         guint32 channel;
79         GByteArray *bssid;
80         guint32 rate;
81         guint32 tx_power;
82         GByteArray *device_mac_address;
83         GByteArray *cloned_mac_address;
84         GSList *mac_address_blacklist;
85         guint32 mtu;
86         GSList *seen_bssids;
87         char *security;
88         gboolean hidden;
89         guint32 powersave;
90 } NMSettingWirelessPrivate;
91
92 enum {
93         PROP_0,
94         PROP_SSID,
95         PROP_MODE,
96         PROP_BAND,
97         PROP_CHANNEL,
98         PROP_BSSID,
99         PROP_RATE,
100         PROP_TX_POWER,
101         PROP_MAC_ADDRESS,
102         PROP_CLONED_MAC_ADDRESS,
103         PROP_MAC_ADDRESS_BLACKLIST,
104         PROP_MTU,
105         PROP_SEEN_BSSIDS,
106         PROP_SEC,
107         PROP_HIDDEN,
108         PROP_POWERSAVE,
109
110         LAST_PROP
111 };
112
113 static gboolean
114 match_cipher (const char *cipher,
115               const char *expected,
116               guint32 wpa_flags,
117               guint32 rsn_flags,
118               guint32 flag)
119 {
120         if (strcmp (cipher, expected) != 0)
121                 return FALSE;
122
123         if (!(wpa_flags & flag) && !(rsn_flags & flag))
124                 return FALSE;
125
126         return TRUE;
127 }
128
129 /**
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
135  * capabilities
136  * @ap_rsn: the %NM80211ApSecurityFlags of the given access point's WPA2/RSN
137  * capabilities
138  * @ap_mode: the 802.11 mode of the AP, either Ad-Hoc or Infrastructure
139  *
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.
146  *
147  * Returns: %TRUE if the given settings are compatible with the access point's
148  * security flags and mode, %FALSE if they are not.
149  */
150 gboolean
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,
156                                             NM80211Mode ap_mode)
157 {
158         const char *key_mgmt = NULL, *cipher;
159         guint32 num, i;
160         gboolean found = FALSE;
161
162         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE);
163
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))
168                         return FALSE;
169                 return TRUE;
170         }
171
172         key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec);
173         if (!key_mgmt)
174                 return FALSE;
175
176         /* Static WEP */
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))
181                         return FALSE;
182                 return TRUE;
183         }
184
185         /* Adhoc WPA */
186         if (!strcmp (key_mgmt, "wpa-none")) {
187                 if (ap_mode != NM_802_11_MODE_ADHOC)
188                         return FALSE;
189                 /* FIXME: validate ciphers if they're in the beacon */
190                 return TRUE;
191         }
192
193         /* Adhoc WPA2 (ie, RSN IBSS) */
194         if (ap_mode == NM_802_11_MODE_ADHOC) {
195                 if (strcmp (key_mgmt, "wpa-psk"))
196                         return FALSE;
197
198                 /* Ensure the AP has RSN PSK capability */
199                 if (!(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
200                         return FALSE;
201
202                 /* Fall through and check ciphers in generic WPA-PSK code */
203         }
204
205         /* Dynamic WEP or LEAP */
206         if (!strcmp (key_mgmt, "ieee8021x")) {
207                 if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY))
208                         return FALSE;
209
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))
213                                 return FALSE;
214
215                         /* quick check; can't use AP if it doesn't support at least one
216                          * WEP cipher in both pairwise and group suites.
217                          */
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)))
220                                 return FALSE;
221
222                         /* Match at least one pairwise cipher with AP's capability if the
223                          * wireless-security setting explicitly lists pairwise ciphers
224                          */
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)))
229                                         break;
230                                 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP104)))
231                                         break;
232                         }
233                         if (!found && num)
234                                 return FALSE;
235
236                         /* Match at least one group cipher with AP's capability if the
237                          * wireless-security setting explicitly lists group ciphers
238                          */
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)))
243                                         break;
244                                 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP104)))
245                                         break;
246                         }
247                         if (!found && num)
248                                 return FALSE;
249                 }
250                 return TRUE;
251         }
252
253         /* WPA[2]-PSK and WPA[2] Enterprise */
254         if (   !strcmp (key_mgmt, "wpa-psk")
255             || !strcmp (key_mgmt, "wpa-eap")) {
256
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))
260                                 return FALSE;
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))
264                                 return FALSE;
265                 }
266
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
270
271                 /* Match at least one pairwise cipher with AP's capability if the
272                  * wireless-security setting explicitly lists pairwise ciphers
273                  */
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)))
278                                 break;
279                         if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_CCMP)))
280                                 break;
281                 }
282                 if (!found && num)
283                         return FALSE;
284
285                 /* Match at least one group cipher with AP's capability if the
286                  * wireless-security setting explicitly lists group ciphers
287                  */
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);
291
292                         if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP40)))
293                                 break;
294                         if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP104)))
295                                 break;
296                         if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_TKIP)))
297                                 break;
298                         if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_CCMP)))
299                                 break;
300                 }
301                 if (!found && num)
302                         return FALSE;
303
304                 return TRUE;
305         }
306
307         return FALSE;
308 }
309
310 /**
311  * nm_setting_wireless_new:
312  *
313  * Creates a new #NMSettingWireless object with default values.
314  *
315  * Returns: (transfer full): the new empty #NMSettingWireless object
316  **/
317 NMSetting *
318 nm_setting_wireless_new (void)
319 {
320         return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRELESS, NULL);
321 }
322
323 /**
324  * nm_setting_wireless_get_ssid:
325  * @setting: the #NMSettingWireless
326  *
327  * Returns: the #NMSettingWireless:ssid property of the setting
328  **/
329 const GByteArray *
330 nm_setting_wireless_get_ssid (NMSettingWireless *setting)
331 {
332         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
333
334         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->ssid;
335 }
336
337 /**
338  * nm_setting_wireless_get_mode:
339  * @setting: the #NMSettingWireless
340  *
341  * Returns: the #NMSettingWireless:mode property of the setting
342  **/
343 const char *
344 nm_setting_wireless_get_mode (NMSettingWireless *setting)
345 {
346         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
347
348         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mode;
349 }
350
351 /**
352  * nm_setting_wireless_get_band:
353  * @setting: the #NMSettingWireless
354  *
355  * Returns: the #NMSettingWireless:band property of the setting
356  **/
357 const char *
358 nm_setting_wireless_get_band (NMSettingWireless *setting)
359 {
360         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
361
362         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->band;
363 }
364
365 /**
366  * nm_setting_wireless_get_channel:
367  * @setting: the #NMSettingWireless
368  *
369  * Returns: the #NMSettingWireless:channel property of the setting
370  **/
371 guint32
372 nm_setting_wireless_get_channel (NMSettingWireless *setting)
373 {
374         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
375
376         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->channel;
377 }
378
379 /**
380  * nm_setting_wireless_get_bssid:
381  * @setting: the #NMSettingWireless
382  *
383  * Returns: the #NMSettingWireless:bssid property of the setting
384  **/
385 const GByteArray *
386 nm_setting_wireless_get_bssid (NMSettingWireless *setting)
387 {
388         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
389
390         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->bssid;
391 }
392
393 /**
394  * nm_setting_wireless_get_rate:
395  * @setting: the #NMSettingWireless
396  *
397  * Returns: the #NMSettingWireless:rate property of the setting
398  **/
399 guint32
400 nm_setting_wireless_get_rate (NMSettingWireless *setting)
401 {
402         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
403
404         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->rate;
405 }
406
407 /**
408  * nm_setting_wireless_get_tx_power:
409  * @setting: the #NMSettingWireless
410  *
411  * Returns: the #NMSettingWireless:tx-power property of the setting
412  **/
413 guint32
414 nm_setting_wireless_get_tx_power (NMSettingWireless *setting)
415 {
416         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
417
418         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->tx_power;
419 }
420
421 /**
422  * nm_setting_wireless_get_mac_address:
423  * @setting: the #NMSettingWireless
424  *
425  * Returns: the #NMSettingWireless:mac-address property of the setting
426  **/
427 const GByteArray *
428 nm_setting_wireless_get_mac_address (NMSettingWireless *setting)
429 {
430         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
431
432         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->device_mac_address;
433 }
434
435 /**
436  * nm_setting_wireless_get_cloned_mac_address:
437  * @setting: the #NMSettingWireless
438  *
439  * Returns: the #NMSettingWireless:cloned-mac-address property of the setting
440  **/
441 const GByteArray *
442 nm_setting_wireless_get_cloned_mac_address (NMSettingWireless *setting)
443 {
444         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
445
446         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->cloned_mac_address;
447 }
448
449 /**
450  * nm_setting_wireless_get_mac_address_blacklist:
451  * @setting: the #NMSettingWireless
452  *
453  * Returns: (element-type GLib.ByteArray): the
454  * #NMSettingWireless:mac-address-blacklist property of the setting
455  **/
456 const GSList *
457 nm_setting_wireless_get_mac_address_blacklist (NMSettingWireless *setting)
458 {
459         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
460
461         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist;
462 }
463
464 /**
465  * nm_setting_wireless_get_num_mac_blacklist_items:
466  * @setting: the #NMSettingWireless
467  *
468  * Returns: the number of blacklisted MAC addresses
469  *
470  * Since: 0.9.10
471  **/
472 guint32
473 nm_setting_wireless_get_num_mac_blacklist_items (NMSettingWireless *setting)
474 {
475         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
476
477         return g_slist_length (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist);
478 }
479
480 /**
481  * nm_setting_wireless_get_mac_blacklist_item:
482  * @setting: the #NMSettingWireless
483  * @idx: the zero-based index of the MAC address entry
484  *
485  * Returns: the blacklisted MAC address string (hex-digits-and-colons notation)
486  * at index @idx
487  *
488  * Since: 0.9.10
489  **/
490 const char *
491 nm_setting_wireless_get_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
492 {
493         NMSettingWirelessPrivate *priv;
494
495         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
496
497         priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
498         g_return_val_if_fail (idx <= g_slist_length (priv->mac_address_blacklist), NULL);
499
500         return (const char *) g_slist_nth_data (priv->mac_address_blacklist, idx);
501 }
502
503 /**
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
507  *
508  * Adds a new MAC address to the #NMSettingWireless:mac-address-blacklist property.
509  *
510  * Returns: %TRUE if the MAC address was added; %FALSE if the MAC address
511  * is invalid or was already present
512  *
513  * Since: 0.9.10
514  **/
515 gboolean
516 nm_setting_wireless_add_mac_blacklist_item (NMSettingWireless *setting, const char *mac)
517 {
518         NMSettingWirelessPrivate *priv;
519         GSList *iter;
520         guint8 buf[32];
521
522         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
523         g_return_val_if_fail (mac != NULL, FALSE);
524
525         if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
526                 return FALSE;
527
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))
531                         return FALSE;
532         }
533
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);
537         return TRUE;
538 }
539
540 /**
541  * nm_setting_wireless_remove_mac_blacklist_item:
542  * @setting: the #NMSettingWireless
543  * @idx: index number of the MAC address
544  *
545  * Removes the MAC address at index @idx from the blacklist.
546  *
547  * Since: 0.9.10
548  **/
549 void
550 nm_setting_wireless_remove_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
551 {
552         NMSettingWirelessPrivate *priv;
553         GSList *elt;
554
555         g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
556
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);
560
561         g_free (elt->data);
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);
564 }
565
566 /**
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
570  * the blacklist
571  *
572  * Removes the MAC address @mac from the blacklist.
573  *
574  * Returns: %TRUE if the MAC address was found and removed; %FALSE if it was not.
575  *
576  * Since: 0.9.10
577  **/
578 gboolean
579 nm_setting_wireless_remove_mac_blacklist_item_by_value (NMSettingWireless *setting, const char *mac)
580 {
581         NMSettingWirelessPrivate *priv;
582         GSList *iter;
583         guint8 buf[32];
584
585         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
586         g_return_val_if_fail (mac != NULL, FALSE);
587
588         if (!nm_utils_hwaddr_aton (mac, ARPHRD_ETHER, buf))
589                 return FALSE;
590
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);
596                         return TRUE;
597                 }
598         }
599         return FALSE;
600 }
601
602 /**
603  * nm_setting_wireless_clear_mac_blacklist_items:
604  * @setting: the #NMSettingWireless
605  *
606  * Removes all blacklisted MAC addresses.
607  *
608  * Since: 0.9.10
609  **/
610 void
611 nm_setting_wireless_clear_mac_blacklist_items (NMSettingWireless *setting)
612 {
613         g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
614
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);
618 }
619
620 /**
621  * nm_setting_wireless_get_mtu:
622  * @setting: the #NMSettingWireless
623  *
624  * Returns: the #NMSettingWireless:mtu property of the setting
625  **/
626 guint32
627 nm_setting_wireless_get_mtu (NMSettingWireless *setting)
628 {
629         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
630
631         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mtu;
632 }
633
634 /**
635  * nm_setting_wireless_get_security:
636  * @setting: the #NMSettingWireless
637  *
638  * Returns: the #NMSettingWireless:security property of the setting
639  *
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.
642  **/
643 const char *
644 nm_setting_wireless_get_security (NMSettingWireless *setting)
645 {
646         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
647
648         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->security;
649 }
650
651 /**
652  * nm_setting_wireless_get_hidden:
653  * @setting: the #NMSettingWireless
654  *
655  * Returns: the #NMSettingWireless:hidden property of the setting
656  **/
657 gboolean
658 nm_setting_wireless_get_hidden (NMSettingWireless *setting)
659 {
660         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
661
662         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->hidden;
663 }
664
665 /**
666  * nm_setting_wireless_get_powersave:
667  * @setting: the #NMSettingWireless
668  *
669  * Returns: the #NMSettingWireless:powersave property of the setting
670  *
671  * Since: 1.2
672  **/
673 guint32
674 nm_setting_wireless_get_powersave (NMSettingWireless *setting)
675 {
676         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
677
678         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->powersave;
679 }
680
681 /**
682  * nm_setting_wireless_add_seen_bssid:
683  * @setting: the #NMSettingWireless
684  * @bssid: the new BSSID to add to the list
685  *
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
689  * not be preserved.
690  *
691  * Returns: %TRUE if @bssid was already known, %FALSE if not
692  **/
693 gboolean
694 nm_setting_wireless_add_seen_bssid (NMSettingWireless *setting,
695                                     const char *bssid)
696 {
697         NMSettingWirelessPrivate *priv;
698         char *lower_bssid;
699         GSList *iter;
700         gboolean found = FALSE;
701
702         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
703         g_return_val_if_fail (bssid != NULL, FALSE);
704
705         lower_bssid = g_ascii_strdown (bssid, -1);
706         if (!lower_bssid)
707                 return FALSE;
708
709         priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
710
711         for (iter = priv->seen_bssids; iter; iter = iter->next) {
712                 if (!strcmp ((char *) iter->data, lower_bssid)) {
713                         found = TRUE;
714                         break;
715                 }
716         }
717
718         if (!found) {
719                 priv->seen_bssids = g_slist_prepend (priv->seen_bssids, lower_bssid);
720                 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SEEN_BSSIDS);
721         } else
722                 g_free (lower_bssid);
723
724         return !found;
725 }
726
727 /**
728  * nm_setting_wireless_get_num_seen_bssids:
729  * @setting: the #NMSettingWireless
730  *
731  * Returns: the number of BSSIDs in the previously seen BSSID list
732  **/
733 guint32
734 nm_setting_wireless_get_num_seen_bssids (NMSettingWireless *setting)
735 {
736         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
737
738         return g_slist_length (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids);
739 }
740
741 /**
742  * nm_setting_wireless_get_seen_bssid:
743  * @setting: the #NMSettingWireless
744  * @i: index of a BSSID in the previously seen BSSID list
745  *
746  * Returns: the BSSID at index @i
747  **/
748 const char *
749 nm_setting_wireless_get_seen_bssid (NMSettingWireless *setting,
750                                     guint32 i)
751 {
752         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
753
754         return (const char *) g_slist_nth_data (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids, i);
755 }
756
757 static gboolean
758 verify (NMSetting *setting, GSList *all_settings, GError **error)
759 {
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 };
763         GSList *iter;
764
765         if (!priv->ssid) {
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);
771                 return FALSE;
772         }
773
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);
780                 return FALSE;
781         }
782
783         if (priv->mode && !_nm_utils_string_in_list (priv->mode, valid_modes)) {
784                 g_set_error (error,
785                              NM_SETTING_WIRELESS_ERROR,
786                              NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
787                              _("'%s' is not a valid Wi-Fi mode"),
788                              priv->mode);
789                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MODE);
790                 return FALSE;
791         }
792
793         if (priv->band && !_nm_utils_string_in_list (priv->band, valid_bands)) {
794                 g_set_error (error,
795                              NM_SETTING_WIRELESS_ERROR,
796                              NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
797                              _("'%s' is not a valid band"),
798                              priv->band);
799                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BAND);
800                 return FALSE;
801         }
802
803         if (priv->channel && !priv->band) {
804                 g_set_error (error,
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);
810                 return FALSE;
811         }
812
813         if (priv->channel) {
814                 if (!nm_utils_wifi_is_channel_valid (priv->channel, priv->band)) {
815                         g_set_error (error,
816                                      NM_SETTING_WIRELESS_ERROR,
817                                      NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
818                                      _("'%d' is not a valid channel"),
819                                      priv->channel);
820                         g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CHANNEL);
821                         return FALSE;
822                 }
823         }
824
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);
831                 return FALSE;
832         }
833
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);
840                 return FALSE;
841         }
842
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);
849                 return FALSE;
850         }
851
852         for (iter = priv->mac_address_blacklist; iter; iter = iter->next) {
853                 struct ether_addr addr;
854
855                 if (!ether_aton_r (iter->data, &addr)) {
856                         g_set_error (error,
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);
862                         return FALSE;
863                 }
864         }
865
866         for (iter = priv->seen_bssids; iter; iter = iter->next) {
867                 struct ether_addr addr;
868
869                 if (!ether_aton_r (iter->data, &addr)) {
870                         g_set_error (error,
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);
876                         return FALSE;
877                 }
878         }
879
880         return TRUE;
881 }
882
883 static void
884 nm_setting_wireless_init (NMSettingWireless *setting)
885 {
886 }
887
888 static void
889 finalize (GObject *object)
890 {
891         NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
892
893         g_free (priv->mode);
894         g_free (priv->band);
895         g_free (priv->security);
896
897         if (priv->ssid)
898                 g_byte_array_free (priv->ssid, TRUE);
899         if (priv->bssid)
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);
907
908         G_OBJECT_CLASS (nm_setting_wireless_parent_class)->finalize (object);
909 }
910
911 static void
912 set_property (GObject *object, guint prop_id,
913               const GValue *value, GParamSpec *pspec)
914 {
915         NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
916
917         switch (prop_id) {
918         case PROP_SSID:
919                 if (priv->ssid)
920                         g_byte_array_free (priv->ssid, TRUE);
921                 priv->ssid = g_value_dup_boxed (value);
922                 break;
923         case PROP_MODE:
924                 g_free (priv->mode);
925                 priv->mode = g_value_dup_string (value);
926                 break;
927         case PROP_BAND:
928                 g_free (priv->band);
929                 priv->band = g_value_dup_string (value);
930                 break;
931         case PROP_CHANNEL:
932                 priv->channel = g_value_get_uint (value);
933                 break;
934         case PROP_BSSID:
935                 if (priv->bssid)
936                         g_byte_array_free (priv->bssid, TRUE);
937                 priv->bssid = g_value_dup_boxed (value);
938                 break;
939         case PROP_RATE:
940                 priv->rate = g_value_get_uint (value);
941                 break;
942         case PROP_TX_POWER:
943                 priv->tx_power = g_value_get_uint (value);
944                 break;
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);
949                 break;
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);
954                 break;
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);
958                 break;
959         case PROP_MTU:
960                 priv->mtu = g_value_get_uint (value);
961                 break;
962         case PROP_SEEN_BSSIDS:
963                 g_slist_free_full (priv->seen_bssids, g_free);
964                 priv->seen_bssids = g_value_dup_boxed (value);
965                 break;
966         case PROP_SEC:
967                 g_free (priv->security);
968                 priv->security = g_value_dup_string (value);
969                 break;
970         case PROP_HIDDEN:
971                 priv->hidden = g_value_get_boolean (value);
972                 break;
973         case PROP_POWERSAVE:
974                 priv->powersave = g_value_get_uint (value);
975                 break;
976         default:
977                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
978                 break;
979         }
980 }
981
982 static void
983 get_property (GObject *object, guint prop_id,
984               GValue *value, GParamSpec *pspec)
985 {
986         NMSettingWireless *setting = NM_SETTING_WIRELESS (object);
987
988         switch (prop_id) {
989         case PROP_SSID:
990                 g_value_set_boxed (value, nm_setting_wireless_get_ssid (setting));
991                 break;
992         case PROP_MODE:
993                 g_value_set_string (value, nm_setting_wireless_get_mode (setting));
994                 break;
995         case PROP_BAND:
996                 g_value_set_string (value, nm_setting_wireless_get_band (setting));
997                 break;
998         case PROP_CHANNEL:
999                 g_value_set_uint (value, nm_setting_wireless_get_channel (setting));
1000                 break;
1001         case PROP_BSSID:
1002                 g_value_set_boxed (value, nm_setting_wireless_get_bssid (setting));
1003                 break;
1004         case PROP_RATE:
1005                 g_value_set_uint (value, nm_setting_wireless_get_rate (setting));
1006                 break;
1007         case PROP_TX_POWER:
1008                 g_value_set_uint (value, nm_setting_wireless_get_tx_power (setting));
1009                 break;
1010         case PROP_MAC_ADDRESS:
1011                 g_value_set_boxed (value, nm_setting_wireless_get_mac_address (setting));
1012                 break;
1013         case PROP_CLONED_MAC_ADDRESS:
1014                 g_value_set_boxed (value, nm_setting_wireless_get_cloned_mac_address (setting));
1015                 break;
1016         case PROP_MAC_ADDRESS_BLACKLIST:
1017                 g_value_set_boxed (value, nm_setting_wireless_get_mac_address_blacklist (setting));
1018                 break;
1019         case PROP_MTU:
1020                 g_value_set_uint (value, nm_setting_wireless_get_mtu (setting));
1021                 break;
1022         case PROP_SEEN_BSSIDS:
1023                 g_value_set_boxed (value, NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids);
1024                 break;
1025         case PROP_SEC:
1026                 g_value_set_string (value, NM_SETTING_WIRELESS_GET_PRIVATE (setting)->security);
1027                 break;
1028         case PROP_HIDDEN:
1029                 g_value_set_boolean (value, nm_setting_wireless_get_hidden (setting));
1030                 break;
1031         case PROP_POWERSAVE:
1032                 g_value_set_uint (value, nm_setting_wireless_get_powersave (setting));
1033                 break;
1034         default:
1035                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1036                 break;
1037         }
1038 }
1039
1040 static void
1041 nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class)
1042 {
1043         GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1044         NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1045
1046         g_type_class_add_private (setting_class, sizeof (NMSettingWirelessPrivate));
1047
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;
1053
1054         /* Properties */
1055         /**
1056          * NMSettingWireless:ssid:
1057          *
1058          * SSID of the Wi-Fi network. Must be specified.
1059          **/
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,
1064                                              G_PARAM_READWRITE |
1065                                              G_PARAM_STATIC_STRINGS));
1066
1067         /**
1068          * NMSettingWireless:mode:
1069          *
1070          * Wi-Fi network mode; one of "infrastructure", "adhoc" or "ap".  If blank,
1071          * infrastructure is assumed.
1072          **/
1073         g_object_class_install_property
1074                 (object_class, PROP_MODE,
1075                  g_param_spec_string (NM_SETTING_WIRELESS_MODE, "", "",
1076                                       NULL,
1077                                       G_PARAM_READWRITE |
1078                                       G_PARAM_STATIC_STRINGS));
1079
1080         /**
1081          * NMSettingWireless:band:
1082          *
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.
1089          **/
1090         g_object_class_install_property
1091                 (object_class, PROP_BAND,
1092                  g_param_spec_string (NM_SETTING_WIRELESS_BAND, "", "",
1093                                       NULL,
1094                                       G_PARAM_READWRITE |
1095                                       G_PARAM_STATIC_STRINGS));
1096
1097         /**
1098          * NMSettingWireless:channel:
1099          *
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.
1104          **/
1105         g_object_class_install_property
1106                 (object_class, PROP_CHANNEL,
1107                  g_param_spec_uint (NM_SETTING_WIRELESS_CHANNEL, "", "",
1108                                     0, G_MAXUINT32, 0,
1109                                     G_PARAM_READWRITE |
1110                                     G_PARAM_CONSTRUCT |
1111                                     G_PARAM_STATIC_STRINGS));
1112
1113         /**
1114          * NMSettingWireless:bssid:
1115          *
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.
1120          **/
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,
1125                                              G_PARAM_READWRITE |
1126                                              G_PARAM_STATIC_STRINGS));
1127
1128         /**
1129          * NMSettingWireless:rate:
1130          *
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.
1135          **/
1136         g_object_class_install_property
1137                 (object_class, PROP_RATE,
1138                  g_param_spec_uint (NM_SETTING_WIRELESS_RATE, "", "",
1139                                     0, G_MAXUINT32, 0,
1140                                     G_PARAM_READWRITE |
1141                                     G_PARAM_CONSTRUCT |
1142                                     NM_SETTING_PARAM_FUZZY_IGNORE |
1143                                     G_PARAM_STATIC_STRINGS));
1144
1145         /**
1146          * NMSettingWireless:tx-power:
1147          *
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.
1151          **/
1152         g_object_class_install_property
1153                 (object_class, PROP_TX_POWER,
1154                  g_param_spec_uint (NM_SETTING_WIRELESS_TX_POWER, "", "",
1155                                     0, G_MAXUINT32, 0,
1156                                     G_PARAM_READWRITE |
1157                                     G_PARAM_CONSTRUCT |
1158                                     NM_SETTING_PARAM_FUZZY_IGNORE |
1159                                     G_PARAM_STATIC_STRINGS));
1160
1161         /**
1162          * NMSettingWireless:mac-address:
1163          *
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).
1167          **/
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,
1172                                              G_PARAM_READWRITE |
1173                                              G_PARAM_STATIC_STRINGS));
1174
1175         /**
1176          * NMSettingWireless:cloned-mac-address:
1177          *
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.
1180          **/
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,
1185                                              G_PARAM_READWRITE |
1186                                              G_PARAM_STATIC_STRINGS));
1187
1188         /**
1189          * NMSettingWireless:mac-address-blacklist:
1190          *
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").
1194          **/
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,
1199                                              G_PARAM_READWRITE |
1200                                              NM_SETTING_PARAM_FUZZY_IGNORE |
1201                                              G_PARAM_STATIC_STRINGS));
1202
1203         /**
1204          * NMSettingWireless:seen-bssids:
1205          *
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
1211          * preserved.
1212          **/
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,
1217                                              G_PARAM_READWRITE |
1218                                              NM_SETTING_PARAM_FUZZY_IGNORE |
1219                                              G_PARAM_STATIC_STRINGS));
1220
1221         /**
1222          * NMSettingWireless:mtu:
1223          *
1224          * If non-zero, only transmit packets of the specified size or smaller,
1225          * breaking larger packets up into multiple Ethernet frames.
1226          **/
1227         g_object_class_install_property
1228                 (object_class, PROP_MTU,
1229                  g_param_spec_uint (NM_SETTING_WIRELESS_MTU, "", "",
1230                                     0, G_MAXUINT32, 0,
1231                                     G_PARAM_READWRITE |
1232                                     G_PARAM_CONSTRUCT |
1233                                     NM_SETTING_PARAM_FUZZY_IGNORE |
1234                                     G_PARAM_STATIC_STRINGS));
1235
1236         /**
1237          * NMSettingWireless:security:
1238          *
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.
1243          *
1244          * Deprecated: 0.9.10: No longer used. Security restrictions are recognized
1245          * by the presence of a #NMSettingWirelessSecurity setting in the
1246          * connection.
1247          **/
1248         g_object_class_install_property
1249                 (object_class, PROP_SEC,
1250                  g_param_spec_string (NM_SETTING_WIRELESS_SEC, "", "",
1251                                       NULL,
1252                                       G_PARAM_READWRITE |
1253                                       G_PARAM_STATIC_STRINGS));
1254
1255         /**
1256          * NMSettingWireless:hidden:
1257          *
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.
1263          **/
1264         g_object_class_install_property
1265                 (object_class, PROP_HIDDEN,
1266                  g_param_spec_boolean (NM_SETTING_WIRELESS_HIDDEN, "", "",
1267                                        FALSE,
1268                                        G_PARAM_READWRITE |
1269                                        G_PARAM_STATIC_STRINGS));
1270
1271         /**
1272          * NMSettingWireless:powersave:
1273          *
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.
1278          *
1279          * Since: 1.2
1280          **/
1281         g_object_class_install_property
1282                 (object_class, PROP_POWERSAVE,
1283                  g_param_spec_uint (NM_SETTING_WIRELESS_POWERSAVE, "", "",
1284                                     0, G_MAXUINT32, 0,
1285                                     G_PARAM_READWRITE |
1286                                     G_PARAM_STATIC_STRINGS));
1287 }