man,libnm-core: fix typos
[NetworkManager.git] / libnm-core / 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
28 #include "nm-setting-wireless.h"
29 #include "nm-utils.h"
30 #include "nm-utils-private.h"
31 #include "nm-setting-private.h"
32
33 /**
34  * SECTION:nm-setting-wireless
35  * @short_description: Describes connection properties for 802.11 Wi-Fi networks
36  *
37  * The #NMSettingWireless object is a #NMSetting subclass that describes properties
38  * necessary for connection to 802.11 Wi-Fi networks.
39  **/
40
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)
44
45 #define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate))
46
47 typedef struct {
48         GBytes *ssid;
49         char *mode;
50         char *band;
51         guint32 channel;
52         char *bssid;
53         guint32 rate;
54         guint32 tx_power;
55         char *device_mac_address;
56         char *cloned_mac_address;
57         GArray *mac_address_blacklist;
58         guint32 mtu;
59         GSList *seen_bssids;
60         gboolean hidden;
61         guint32 powersave;
62         NMSettingMacRandomization mac_address_randomization;
63 } NMSettingWirelessPrivate;
64
65 enum {
66         PROP_0,
67         PROP_SSID,
68         PROP_MODE,
69         PROP_BAND,
70         PROP_CHANNEL,
71         PROP_BSSID,
72         PROP_RATE,
73         PROP_TX_POWER,
74         PROP_MAC_ADDRESS,
75         PROP_CLONED_MAC_ADDRESS,
76         PROP_MAC_ADDRESS_BLACKLIST,
77         PROP_MTU,
78         PROP_SEEN_BSSIDS,
79         PROP_HIDDEN,
80         PROP_POWERSAVE,
81         PROP_MAC_ADDRESS_RANDOMIZATION,
82
83         LAST_PROP
84 };
85
86 static gboolean
87 match_cipher (const char *cipher,
88               const char *expected,
89               guint32 wpa_flags,
90               guint32 rsn_flags,
91               guint32 flag)
92 {
93         if (strcmp (cipher, expected) != 0)
94                 return FALSE;
95
96         if (!(wpa_flags & flag) && !(rsn_flags & flag))
97                 return FALSE;
98
99         return TRUE;
100 }
101
102 /**
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
108  * capabilities
109  * @ap_rsn: the %NM80211ApSecurityFlags of the given access point's WPA2/RSN
110  * capabilities
111  * @ap_mode: the 802.11 mode of the AP, either Ad-Hoc or Infrastructure
112  *
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.
119  *
120  * Returns: %TRUE if the given settings are compatible with the access point's
121  * security flags and mode, %FALSE if they are not.
122  */
123 gboolean
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,
129                                             NM80211Mode ap_mode)
130 {
131         const char *key_mgmt = NULL, *cipher;
132         guint32 num, i;
133         gboolean found = FALSE;
134
135         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE);
136
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))
141                         return FALSE;
142                 return TRUE;
143         }
144
145         key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec);
146         if (!key_mgmt)
147                 return FALSE;
148
149         /* Static WEP */
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))
154                         return FALSE;
155                 return TRUE;
156         }
157
158         /* Adhoc WPA */
159         if (!strcmp (key_mgmt, "wpa-none")) {
160                 if (ap_mode != NM_802_11_MODE_ADHOC)
161                         return FALSE;
162                 /* FIXME: validate ciphers if they're in the beacon */
163                 return TRUE;
164         }
165
166         /* Adhoc WPA2 (ie, RSN IBSS) */
167         if (ap_mode == NM_802_11_MODE_ADHOC) {
168                 if (strcmp (key_mgmt, "wpa-psk"))
169                         return FALSE;
170
171                 /* Ensure the AP has RSN PSK capability */
172                 if (!(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
173                         return FALSE;
174
175                 /* Fall through and check ciphers in generic WPA-PSK code */
176         }
177
178         /* Dynamic WEP or LEAP */
179         if (!strcmp (key_mgmt, "ieee8021x")) {
180                 if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY))
181                         return FALSE;
182
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))
186                                 return FALSE;
187
188                         /* quick check; can't use AP if it doesn't support at least one
189                          * WEP cipher in both pairwise and group suites.
190                          */
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)))
193                                 return FALSE;
194
195                         /* Match at least one pairwise cipher with AP's capability if the
196                          * wireless-security setting explicitly lists pairwise ciphers
197                          */
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)))
202                                         break;
203                                 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP104)))
204                                         break;
205                         }
206                         if (!found && num)
207                                 return FALSE;
208
209                         /* Match at least one group cipher with AP's capability if the
210                          * wireless-security setting explicitly lists group ciphers
211                          */
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)))
216                                         break;
217                                 if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP104)))
218                                         break;
219                         }
220                         if (!found && num)
221                                 return FALSE;
222                 }
223                 return TRUE;
224         }
225
226         /* WPA[2]-PSK and WPA[2] Enterprise */
227         if (   !strcmp (key_mgmt, "wpa-psk")
228             || !strcmp (key_mgmt, "wpa-eap")) {
229
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))
233                                 return FALSE;
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))
237                                 return FALSE;
238                 }
239
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
243
244                 /* Match at least one pairwise cipher with AP's capability if the
245                  * wireless-security setting explicitly lists pairwise ciphers
246                  */
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)))
251                                 break;
252                         if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_CCMP)))
253                                 break;
254                 }
255                 if (!found && num)
256                         return FALSE;
257
258                 /* Match at least one group cipher with AP's capability if the
259                  * wireless-security setting explicitly lists group ciphers
260                  */
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);
264
265                         if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP40)))
266                                 break;
267                         if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP104)))
268                                 break;
269                         if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_TKIP)))
270                                 break;
271                         if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_CCMP)))
272                                 break;
273                 }
274                 if (!found && num)
275                         return FALSE;
276
277                 return TRUE;
278         }
279
280         return FALSE;
281 }
282
283 /**
284  * nm_setting_wireless_new:
285  *
286  * Creates a new #NMSettingWireless object with default values.
287  *
288  * Returns: (transfer full): the new empty #NMSettingWireless object
289  **/
290 NMSetting *
291 nm_setting_wireless_new (void)
292 {
293         return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRELESS, NULL);
294 }
295
296 /**
297  * nm_setting_wireless_get_ssid:
298  * @setting: the #NMSettingWireless
299  *
300  * Returns: (transfer none): the #NMSettingWireless:ssid property of the setting
301  **/
302 GBytes *
303 nm_setting_wireless_get_ssid (NMSettingWireless *setting)
304 {
305         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
306
307         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->ssid;
308 }
309
310 /**
311  * nm_setting_wireless_get_mode:
312  * @setting: the #NMSettingWireless
313  *
314  * Returns: the #NMSettingWireless:mode property of the setting
315  **/
316 const char *
317 nm_setting_wireless_get_mode (NMSettingWireless *setting)
318 {
319         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
320
321         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mode;
322 }
323
324 /**
325  * nm_setting_wireless_get_band:
326  * @setting: the #NMSettingWireless
327  *
328  * Returns: the #NMSettingWireless:band property of the setting
329  **/
330 const char *
331 nm_setting_wireless_get_band (NMSettingWireless *setting)
332 {
333         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
334
335         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->band;
336 }
337
338 /**
339  * nm_setting_wireless_get_channel:
340  * @setting: the #NMSettingWireless
341  *
342  * Returns: the #NMSettingWireless:channel property of the setting
343  **/
344 guint32
345 nm_setting_wireless_get_channel (NMSettingWireless *setting)
346 {
347         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
348
349         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->channel;
350 }
351
352 /**
353  * nm_setting_wireless_get_bssid:
354  * @setting: the #NMSettingWireless
355  *
356  * Returns: the #NMSettingWireless:bssid property of the setting
357  **/
358 const char *
359 nm_setting_wireless_get_bssid (NMSettingWireless *setting)
360 {
361         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
362
363         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->bssid;
364 }
365
366 /**
367  * nm_setting_wireless_get_rate:
368  * @setting: the #NMSettingWireless
369  *
370  * Returns: the #NMSettingWireless:rate property of the setting
371  **/
372 guint32
373 nm_setting_wireless_get_rate (NMSettingWireless *setting)
374 {
375         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
376
377         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->rate;
378 }
379
380 /**
381  * nm_setting_wireless_get_tx_power:
382  * @setting: the #NMSettingWireless
383  *
384  * Returns: the #NMSettingWireless:tx-power property of the setting
385  **/
386 guint32
387 nm_setting_wireless_get_tx_power (NMSettingWireless *setting)
388 {
389         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
390
391         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->tx_power;
392 }
393
394 /**
395  * nm_setting_wireless_get_mac_address:
396  * @setting: the #NMSettingWireless
397  *
398  * Returns: the #NMSettingWireless:mac-address property of the setting
399  **/
400 const char *
401 nm_setting_wireless_get_mac_address (NMSettingWireless *setting)
402 {
403         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
404
405         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->device_mac_address;
406 }
407
408 /**
409  * nm_setting_wireless_get_cloned_mac_address:
410  * @setting: the #NMSettingWireless
411  *
412  * Returns: the #NMSettingWireless:cloned-mac-address property of the setting
413  **/
414 const char *
415 nm_setting_wireless_get_cloned_mac_address (NMSettingWireless *setting)
416 {
417         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
418
419         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->cloned_mac_address;
420 }
421
422 /**
423  * nm_setting_wireless_get_mac_address_blacklist:
424  * @setting: the #NMSettingWireless
425  *
426  * Returns: the #NMSettingWireless:mac-address-blacklist property of the setting
427  **/
428 const char * const *
429 nm_setting_wireless_get_mac_address_blacklist (NMSettingWireless *setting)
430 {
431         NMSettingWirelessPrivate *priv;
432
433         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
434
435         priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
436         return (const char * const *) priv->mac_address_blacklist->data;
437 }
438
439 /**
440  * nm_setting_wireless_get_num_mac_blacklist_items:
441  * @setting: the #NMSettingWireless
442  *
443  * Returns: the number of blacklisted MAC addresses
444  **/
445 guint32
446 nm_setting_wireless_get_num_mac_blacklist_items (NMSettingWireless *setting)
447 {
448         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
449
450         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist->len;
451 }
452
453 /**
454  * nm_setting_wireless_get_mac_blacklist_item:
455  * @setting: the #NMSettingWireless
456  * @idx: the zero-based index of the MAC address entry
457  *
458  * Returns: the blacklisted MAC address string (hex-digits-and-colons notation)
459  * at index @idx
460  **/
461 const char *
462 nm_setting_wireless_get_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
463 {
464         NMSettingWirelessPrivate *priv;
465
466         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
467
468         priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
469         g_return_val_if_fail (idx <= priv->mac_address_blacklist->len, NULL);
470
471         return g_array_index (priv->mac_address_blacklist, const char *, idx);
472 }
473
474 /**
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
478  *
479  * Adds a new MAC address to the #NMSettingWireless:mac-address-blacklist property.
480  *
481  * Returns: %TRUE if the MAC address was added; %FALSE if the MAC address
482  * is invalid or was already present
483  **/
484 gboolean
485 nm_setting_wireless_add_mac_blacklist_item (NMSettingWireless *setting, const char *mac)
486 {
487         NMSettingWirelessPrivate *priv;
488         const char *candidate;
489         int i;
490
491         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
492         g_return_val_if_fail (mac != NULL, FALSE);
493
494         if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
495                 return FALSE;
496
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))
501                         return FALSE;
502         }
503
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);
507         return TRUE;
508 }
509
510 /**
511  * nm_setting_wireless_remove_mac_blacklist_item:
512  * @setting: the #NMSettingWireless
513  * @idx: index number of the MAC address
514  *
515  * Removes the MAC address at index @idx from the blacklist.
516  **/
517 void
518 nm_setting_wireless_remove_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
519 {
520         NMSettingWirelessPrivate *priv;
521
522         g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
523
524         priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
525         g_return_if_fail (idx < priv->mac_address_blacklist->len);
526
527         g_array_remove_index (priv->mac_address_blacklist, idx);
528         g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
529 }
530
531 /**
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
535  * the blacklist
536  *
537  * Removes the MAC address @mac from the blacklist.
538  *
539  * Returns: %TRUE if the MAC address was found and removed; %FALSE if it was not.
540  **/
541 gboolean
542 nm_setting_wireless_remove_mac_blacklist_item_by_value (NMSettingWireless *setting, const char *mac)
543 {
544         NMSettingWirelessPrivate *priv;
545         const char *candidate;
546         int i;
547
548         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
549         g_return_val_if_fail (mac != NULL, FALSE);
550
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);
557                         return TRUE;
558                 }
559         }
560         return FALSE;
561 }
562
563 /**
564  * nm_setting_wireless_clear_mac_blacklist_items:
565  * @setting: the #NMSettingWireless
566  *
567  * Removes all blacklisted MAC addresses.
568  **/
569 void
570 nm_setting_wireless_clear_mac_blacklist_items (NMSettingWireless *setting)
571 {
572         g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
573
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);
576 }
577
578 /**
579  * nm_setting_wireless_get_mtu:
580  * @setting: the #NMSettingWireless
581  *
582  * Returns: the #NMSettingWireless:mtu property of the setting
583  **/
584 guint32
585 nm_setting_wireless_get_mtu (NMSettingWireless *setting)
586 {
587         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
588
589         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mtu;
590 }
591
592 /**
593  * nm_setting_wireless_get_hidden:
594  * @setting: the #NMSettingWireless
595  *
596  * Returns: the #NMSettingWireless:hidden property of the setting
597  **/
598 gboolean
599 nm_setting_wireless_get_hidden (NMSettingWireless *setting)
600 {
601         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
602
603         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->hidden;
604 }
605
606 /**
607  * nm_setting_wireless_get_powersave:
608  * @setting: the #NMSettingWireless
609  *
610  * Returns: the #NMSettingWireless:powersave property of the setting
611  *
612  * Since: 1.2
613  **/
614 guint32
615 nm_setting_wireless_get_powersave (NMSettingWireless *setting)
616 {
617         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
618
619         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->powersave;
620 }
621
622 /**
623  * nm_setting_wireless_get_mac_address_randomization:
624  * @setting: the #NMSettingWireless
625  *
626  * Returns: the #NMSettingWireless:mac-address-randomization property of the
627  * setting
628  *
629  * Since: 1.2
630  **/
631 NMSettingMacRandomization
632 nm_setting_wireless_get_mac_address_randomization (NMSettingWireless *setting)
633 {
634         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
635
636         return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_randomization;
637 }
638
639 /**
640  * nm_setting_wireless_add_seen_bssid:
641  * @setting: the #NMSettingWireless
642  * @bssid: the new BSSID to add to the list
643  *
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
647  * not be preserved.
648  *
649  * Returns: %TRUE if @bssid was already known, %FALSE if not
650  **/
651 gboolean
652 nm_setting_wireless_add_seen_bssid (NMSettingWireless *setting,
653                                     const char *bssid)
654 {
655         NMSettingWirelessPrivate *priv;
656         char *lower_bssid;
657         GSList *iter;
658         gboolean found = FALSE;
659
660         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
661         g_return_val_if_fail (bssid != NULL, FALSE);
662
663         lower_bssid = g_ascii_strdown (bssid, -1);
664         if (!lower_bssid)
665                 return FALSE;
666
667         priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
668
669         for (iter = priv->seen_bssids; iter; iter = iter->next) {
670                 if (!strcmp ((char *) iter->data, lower_bssid)) {
671                         found = TRUE;
672                         break;
673                 }
674         }
675
676         if (!found) {
677                 priv->seen_bssids = g_slist_prepend (priv->seen_bssids, lower_bssid);
678                 g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SEEN_BSSIDS);
679         } else
680                 g_free (lower_bssid);
681
682         return !found;
683 }
684
685 /**
686  * nm_setting_wireless_get_num_seen_bssids:
687  * @setting: the #NMSettingWireless
688  *
689  * Returns: the number of BSSIDs in the previously seen BSSID list
690  **/
691 guint32
692 nm_setting_wireless_get_num_seen_bssids (NMSettingWireless *setting)
693 {
694         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
695
696         return g_slist_length (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids);
697 }
698
699 /**
700  * nm_setting_wireless_get_seen_bssid:
701  * @setting: the #NMSettingWireless
702  * @i: index of a BSSID in the previously seen BSSID list
703  *
704  * Returns: the BSSID at index @i
705  **/
706 const char *
707 nm_setting_wireless_get_seen_bssid (NMSettingWireless *setting,
708                                     guint32 i)
709 {
710         g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
711
712         return (const char *) g_slist_nth_data (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids, i);
713 }
714
715 static gboolean
716 verify (NMSetting *setting, NMConnection *connection, GError **error)
717 {
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 };
721         GSList *iter;
722         int i;
723         gsize length;
724
725         if (!priv->ssid) {
726                 g_set_error_literal (error,
727                                      NM_CONNECTION_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);
731                 return FALSE;
732         }
733
734         length = g_bytes_get_size (priv->ssid);
735         if (length == 0 || length > 32) {
736                 g_set_error_literal (error,
737                                      NM_CONNECTION_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);
741                 return FALSE;
742         }
743
744         if (priv->mode && !_nm_utils_string_in_list (priv->mode, valid_modes)) {
745                 g_set_error (error,
746                              NM_CONNECTION_ERROR,
747                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
748                              _("'%s' is not a valid Wi-Fi mode"),
749                              priv->mode);
750                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MODE);
751                 return FALSE;
752         }
753
754         if (priv->band && !_nm_utils_string_in_list (priv->band, valid_bands)) {
755                 g_set_error (error,
756                              NM_CONNECTION_ERROR,
757                              NM_CONNECTION_ERROR_INVALID_PROPERTY,
758                              _("'%s' is not a valid band"),
759                              priv->band);
760                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BAND);
761                 return FALSE;
762         }
763
764         if (priv->channel && !priv->band) {
765                 g_set_error (error,
766                              NM_CONNECTION_ERROR,
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);
771                 return FALSE;
772         }
773
774         if (priv->channel) {
775                 if (!nm_utils_wifi_is_channel_valid (priv->channel, priv->band)) {
776                         g_set_error (error,
777                                      NM_CONNECTION_ERROR,
778                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
779                                      _("'%d' is not a valid channel"),
780                                      priv->channel);
781                         g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CHANNEL);
782                         return FALSE;
783                 }
784         }
785
786         if (priv->bssid && !nm_utils_hwaddr_valid (priv->bssid, ETH_ALEN)) {
787                 g_set_error_literal (error,
788                                      NM_CONNECTION_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);
792                 return FALSE;
793         }
794
795         if (priv->device_mac_address && !nm_utils_hwaddr_valid (priv->device_mac_address, ETH_ALEN)) {
796                 g_set_error_literal (error,
797                                      NM_CONNECTION_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);
801                 return FALSE;
802         }
803
804         if (priv->cloned_mac_address && !nm_utils_hwaddr_valid (priv->cloned_mac_address, ETH_ALEN)) {
805                 g_set_error_literal (error,
806                                      NM_CONNECTION_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);
810                 return FALSE;
811         }
812
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);
815
816                 if (!nm_utils_hwaddr_valid (mac, ETH_ALEN)) {
817                         g_set_error (error,
818                                      NM_CONNECTION_ERROR,
819                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
820                                      _("'%s' is not a valid MAC address"),
821                                      mac);
822                         g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
823                         return FALSE;
824                 }
825         }
826
827         for (iter = priv->seen_bssids; iter; iter = iter->next) {
828                 if (!nm_utils_hwaddr_valid (iter->data, ETH_ALEN)) {
829                         g_set_error (error,
830                                      NM_CONNECTION_ERROR,
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);
835                         return FALSE;
836                 }
837         }
838
839         return TRUE;
840 }
841
842 static GVariant *
843 nm_setting_wireless_get_security (NMSetting    *setting,
844                                   NMConnection *connection,
845                                   const char   *property_name)
846 {
847         if (nm_connection_get_setting_wireless_security (connection))
848                 return g_variant_new_string (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
849         else
850                 return NULL;
851 }
852
853 static void
854 clear_blacklist_item (char **item_p)
855 {
856         g_free (*item_p);
857 }
858
859 static void
860 nm_setting_wireless_init (NMSettingWireless *setting)
861 {
862         NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
863
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);
867 }
868
869 static void
870 finalize (GObject *object)
871 {
872         NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
873
874         g_free (priv->mode);
875         g_free (priv->band);
876
877         if (priv->ssid)
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);
884
885         G_OBJECT_CLASS (nm_setting_wireless_parent_class)->finalize (object);
886 }
887
888 static void
889 set_property (GObject *object, guint prop_id,
890               const GValue *value, GParamSpec *pspec)
891 {
892         NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
893         const char * const *blacklist;
894         const char *mac;
895         int i;
896
897         switch (prop_id) {
898         case PROP_SSID:
899                 if (priv->ssid)
900                         g_bytes_unref (priv->ssid);
901                 priv->ssid = g_value_dup_boxed (value);
902                 break;
903         case PROP_MODE:
904                 g_free (priv->mode);
905                 priv->mode = g_value_dup_string (value);
906                 break;
907         case PROP_BAND:
908                 g_free (priv->band);
909                 priv->band = g_value_dup_string (value);
910                 break;
911         case PROP_CHANNEL:
912                 priv->channel = g_value_get_uint (value);
913                 break;
914         case PROP_BSSID:
915                 g_free (priv->bssid);
916                 priv->bssid = g_value_dup_string (value);
917                 break;
918         case PROP_RATE:
919                 priv->rate = g_value_get_uint (value);
920                 break;
921         case PROP_TX_POWER:
922                 priv->tx_power = g_value_get_uint (value);
923                 break;
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),
927                                                                                   ETH_ALEN);
928                 break;
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),
932                                                                                   ETH_ALEN);
933                 break;
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);
941                         }
942                 }
943                 break;
944         case PROP_MTU:
945                 priv->mtu = g_value_get_uint (value);
946                 break;
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);
950                 break;
951         case PROP_HIDDEN:
952                 priv->hidden = g_value_get_boolean (value);
953                 break;
954         case PROP_POWERSAVE:
955                 priv->powersave = g_value_get_uint (value);
956                 break;
957         case PROP_MAC_ADDRESS_RANDOMIZATION:
958                 priv->mac_address_randomization = g_value_get_uint (value);
959                 break;
960         default:
961                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
962                 break;
963         }
964 }
965
966 static void
967 get_property (GObject *object, guint prop_id,
968               GValue *value, GParamSpec *pspec)
969 {
970         NMSettingWireless *setting = NM_SETTING_WIRELESS (object);
971         NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
972
973         switch (prop_id) {
974         case PROP_SSID:
975                 g_value_set_boxed (value, nm_setting_wireless_get_ssid (setting));
976                 break;
977         case PROP_MODE:
978                 g_value_set_string (value, nm_setting_wireless_get_mode (setting));
979                 break;
980         case PROP_BAND:
981                 g_value_set_string (value, nm_setting_wireless_get_band (setting));
982                 break;
983         case PROP_CHANNEL:
984                 g_value_set_uint (value, nm_setting_wireless_get_channel (setting));
985                 break;
986         case PROP_BSSID:
987                 g_value_set_string (value, nm_setting_wireless_get_bssid (setting));
988                 break;
989         case PROP_RATE:
990                 g_value_set_uint (value, nm_setting_wireless_get_rate (setting));
991                 break;
992         case PROP_TX_POWER:
993                 g_value_set_uint (value, nm_setting_wireless_get_tx_power (setting));
994                 break;
995         case PROP_MAC_ADDRESS:
996                 g_value_set_string (value, nm_setting_wireless_get_mac_address (setting));
997                 break;
998         case PROP_CLONED_MAC_ADDRESS:
999                 g_value_set_string (value, nm_setting_wireless_get_cloned_mac_address (setting));
1000                 break;
1001         case PROP_MAC_ADDRESS_BLACKLIST:
1002                 g_value_set_boxed (value, (char **) priv->mac_address_blacklist->data);
1003                 break;
1004         case PROP_MTU:
1005                 g_value_set_uint (value, nm_setting_wireless_get_mtu (setting));
1006                 break;
1007         case PROP_SEEN_BSSIDS:
1008                 g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->seen_bssids, TRUE));
1009                 break;
1010         case PROP_HIDDEN:
1011                 g_value_set_boolean (value, nm_setting_wireless_get_hidden (setting));
1012                 break;
1013         case PROP_POWERSAVE:
1014                 g_value_set_uint (value, nm_setting_wireless_get_powersave (setting));
1015                 break;
1016         case PROP_MAC_ADDRESS_RANDOMIZATION:
1017                 g_value_set_uint (value, nm_setting_wireless_get_mac_address_randomization (setting));
1018                 break;
1019         default:
1020                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1021                 break;
1022         }
1023 }
1024
1025 static void
1026 nm_setting_wireless_class_init (NMSettingWirelessClass *setting_class)
1027 {
1028         GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
1029         NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
1030
1031         g_type_class_add_private (setting_class, sizeof (NMSettingWirelessPrivate));
1032
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;
1038
1039         /* Properties */
1040         /**
1041          * NMSettingWireless:ssid:
1042          *
1043          * SSID of the Wi-Fi network. Must be specified.
1044          **/
1045         /* ---keyfile---
1046          * property: ssid
1047          * format: string (or decimal-byte list - obsolete)
1048          * description: SSID of Wi-Fi network.
1049          * example: ssid=Quick Net
1050          * ---end---
1051          * ---ifcfg-rh---
1052          * property: ssid
1053          * variable: ESSID
1054          * description: SSID of Wi-Fi network.
1055          * example: ESSID="Quick Net"
1056          * ---end---
1057          */
1058         g_object_class_install_property
1059                 (object_class, PROP_SSID,
1060                  g_param_spec_boxed (NM_SETTING_WIRELESS_SSID, "", "",
1061                                      G_TYPE_BYTES,
1062                                      G_PARAM_READWRITE |
1063                                      G_PARAM_STATIC_STRINGS));
1064
1065         /**
1066          * NMSettingWireless:mode:
1067          *
1068          * Wi-Fi network mode; one of "infrastructure", "adhoc" or "ap".  If blank,
1069          * infrastructure is assumed.
1070          **/
1071         /* ---ifcfg-rh---
1072          * property: mode
1073          * variable: MODE
1074          * values: Ad-Hoc, Managed (Auto)  [case insensitive]
1075          * description: Wi-Fi network mode.
1076          * ---end---
1077          */
1078         g_object_class_install_property
1079                 (object_class, PROP_MODE,
1080                  g_param_spec_string (NM_SETTING_WIRELESS_MODE, "", "",
1081                                       NULL,
1082                                       G_PARAM_READWRITE |
1083                                       G_PARAM_STATIC_STRINGS));
1084
1085         /**
1086          * NMSettingWireless:band:
1087          *
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.
1094          **/
1095         /* ---ifcfg-rh---
1096          * property: band
1097          * variable: BAND(+)
1098          * values: a, bg
1099          * description: BAND alone is honored, but CHANNEL overrides BAND since it
1100          *   implies a band.
1101          * example: BAND=bg
1102          * ---end---
1103          */
1104         g_object_class_install_property
1105                 (object_class, PROP_BAND,
1106                  g_param_spec_string (NM_SETTING_WIRELESS_BAND, "", "",
1107                                       NULL,
1108                                       G_PARAM_READWRITE |
1109                                       G_PARAM_STATIC_STRINGS));
1110
1111         /**
1112          * NMSettingWireless:channel:
1113          *
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.
1118          **/
1119         /* ---ifcfg-rh---
1120          * property: channel
1121          * variable: CHANNEL
1122          * description: Channel used for the Wi-Fi communication.
1123          *   Channels greater than 14 mean "a" band, otherwise the
1124          *   band is "bg".
1125          * example: CHANNEL=6
1126          * ---end---
1127          */
1128         g_object_class_install_property
1129                 (object_class, PROP_CHANNEL,
1130                  g_param_spec_uint (NM_SETTING_WIRELESS_CHANNEL, "", "",
1131                                     0, G_MAXUINT32, 0,
1132                                     G_PARAM_READWRITE |
1133                                     G_PARAM_CONSTRUCT |
1134                                     G_PARAM_STATIC_STRINGS));
1135
1136         /**
1137          * NMSettingWireless:bssid:
1138          *
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.
1143          **/
1144         /* ---ifcfg-rh---
1145          * property: bssid
1146          * variable: BSSID(+)
1147          * description: Restricts association only to a single AP.
1148          * example: BSSID=00:1E:BD:64:83:21
1149          * ---end---
1150          */
1151         g_object_class_install_property
1152                 (object_class, PROP_BSSID,
1153                  g_param_spec_string (NM_SETTING_WIRELESS_BSSID, "", "",
1154                                       NULL,
1155                                       G_PARAM_READWRITE |
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);
1161
1162         /**
1163          * NMSettingWireless:rate:
1164          *
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.
1169          **/
1170         /* ---ifcfg-rh---
1171          * property: rate
1172          * variable: (none)
1173          * description: This property is not handled by ifcfg-rh plugin.
1174          * ---end---
1175          */
1176         g_object_class_install_property
1177                 (object_class, PROP_RATE,
1178                  g_param_spec_uint (NM_SETTING_WIRELESS_RATE, "", "",
1179                                     0, G_MAXUINT32, 0,
1180                                     G_PARAM_READWRITE |
1181                                     G_PARAM_CONSTRUCT |
1182                                     NM_SETTING_PARAM_FUZZY_IGNORE |
1183                                     G_PARAM_STATIC_STRINGS));
1184
1185         /**
1186          * NMSettingWireless:tx-power:
1187          *
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.
1191          **/
1192         /* ---ifcfg-rh---
1193          * property: tx-power
1194          * variable: (none)
1195          * description: This property is not handled by ifcfg-rh plugin.
1196          * ---end---
1197          */
1198         g_object_class_install_property
1199                 (object_class, PROP_TX_POWER,
1200                  g_param_spec_uint (NM_SETTING_WIRELESS_TX_POWER, "", "",
1201                                     0, G_MAXUINT32, 0,
1202                                     G_PARAM_READWRITE |
1203                                     G_PARAM_CONSTRUCT |
1204                                     NM_SETTING_PARAM_FUZZY_IGNORE |
1205                                     G_PARAM_STATIC_STRINGS));
1206
1207         /**
1208          * NMSettingWireless:mac-address:
1209          *
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).
1213          **/
1214         /* ---keyfile---
1215          * property: mac-address
1216          * format: usual 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).
1220          * ---end---
1221          * ---ifcfg-rh---
1222          * property: mac-address
1223          * variable: HWADDR
1224          * description: Hardware address of the device in traditional hex-digits-and-colons
1225          *    notation (e.g. 00:22:68:14:5A:05).
1226          * ---end---
1227          */
1228         g_object_class_install_property
1229                 (object_class, PROP_MAC_ADDRESS,
1230                  g_param_spec_string (NM_SETTING_WIRELESS_MAC_ADDRESS, "", "",
1231                                       NULL,
1232                                       G_PARAM_READWRITE |
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);
1238
1239         /**
1240          * NMSettingWireless:cloned-mac-address:
1241          *
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.
1244          **/
1245         /* ---keyfile---
1246          * property: cloned-mac-address
1247          * format: usual 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).
1251          * ---end---
1252          * ---ifcfg-rh---
1253          * property: cloned-mac-address
1254          * variable: MACADDR
1255          * description: Cloned (spoofed) MAC address in traditional hex-digits-and-colons
1256          *    notation (e.g. 00:22:68:14:5A:99).
1257          * ---end---
1258          */
1259         g_object_class_install_property
1260                 (object_class, PROP_CLONED_MAC_ADDRESS,
1261                  g_param_spec_string (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, "", "",
1262                                       NULL,
1263                                       G_PARAM_READWRITE |
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);
1269
1270         /**
1271          * NMSettingWireless:mac-address-blacklist:
1272          *
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").
1276          **/
1277         /* ---keyfile---
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
1282          * ---end---
1283          * ---ifcfg-rh---
1284          * property: mac-address-blacklist
1285          * variable: HWADDR_BLACKLIST(+)
1286          * description: It denies usage of the connection for any device whose address
1287          *   is listed.
1288          * ---end---
1289          */
1290         g_object_class_install_property
1291                 (object_class, PROP_MAC_ADDRESS_BLACKLIST,
1292                  g_param_spec_boxed (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, "", "",
1293                                      G_TYPE_STRV,
1294                                      G_PARAM_READWRITE |
1295                                      NM_SETTING_PARAM_FUZZY_IGNORE |
1296                                      G_PARAM_STATIC_STRINGS));
1297
1298         /**
1299          * NMSettingWireless:seen-bssids:
1300          *
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
1306          * preserved.
1307          **/
1308         /* ---ifcfg-rh---
1309          * property: seen-bssids
1310          * variable: (none)
1311          * description: This property is not handled by ifcfg-rh plugin.
1312          * ---end---
1313          */
1314         g_object_class_install_property
1315                 (object_class, PROP_SEEN_BSSIDS,
1316                  g_param_spec_boxed (NM_SETTING_WIRELESS_SEEN_BSSIDS, "", "",
1317                                      G_TYPE_STRV,
1318                                      G_PARAM_READWRITE |
1319                                      NM_SETTING_PARAM_FUZZY_IGNORE |
1320                                      G_PARAM_STATIC_STRINGS));
1321
1322         /**
1323          * NMSettingWireless:mtu:
1324          *
1325          * If non-zero, only transmit packets of the specified size or smaller,
1326          * breaking larger packets up into multiple Ethernet frames.
1327          **/
1328         /* ---ifcfg-rh---
1329          * property: mtu
1330          * variable: MTU
1331          * description: MTU of the wireless interface.
1332          * ---end---
1333          */
1334         g_object_class_install_property
1335                 (object_class, PROP_MTU,
1336                  g_param_spec_uint (NM_SETTING_WIRELESS_MTU, "", "",
1337                                     0, G_MAXUINT32, 0,
1338                                     G_PARAM_READWRITE |
1339                                     G_PARAM_CONSTRUCT |
1340                                     NM_SETTING_PARAM_FUZZY_IGNORE |
1341                                     G_PARAM_STATIC_STRINGS));
1342
1343         /**
1344          * NMSettingWireless:hidden:
1345          *
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.
1351          **/
1352         /* ---ifcfg-rh---
1353          * property: hidden
1354          * variable: SSID_HIDDEN(+)
1355          * description: Whether the network hides the SSID.
1356          * ---end---
1357          */
1358         g_object_class_install_property
1359                 (object_class, PROP_HIDDEN,
1360                  g_param_spec_boolean (NM_SETTING_WIRELESS_HIDDEN, "", "",
1361                                        FALSE,
1362                                        G_PARAM_READWRITE |
1363                                        G_PARAM_STATIC_STRINGS));
1364
1365         /**
1366          * NMSettingWireless:powersave:
1367          *
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.
1373          *
1374          * Since: 1.2
1375          **/
1376         /* ---ifcfg-rh---
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
1382          * ---end---
1383          */
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,
1388                                     G_PARAM_READWRITE |
1389                                     G_PARAM_STATIC_STRINGS));
1390
1391         /**
1392          * NMSettingWireless:mac-address-randomization:
1393          *
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).
1399          *
1400          * Since: 1.2
1401          **/
1402         /* ---ifcfg-rh---
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
1408          * ---end---
1409          */
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,
1414                                     G_PARAM_READWRITE |
1415                                     G_PARAM_STATIC_STRINGS));
1416
1417         /* Compatibility for deprecated property */
1418         /* ---ifcfg-rh---
1419          * property: security
1420          * variable: (none)
1421          * description: This property is deprecated and not handled by ifcfg-rh-plugin.
1422          * ---end---
1423          * ---dbus---
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.
1429          * ---end---
1430          */
1431         _nm_setting_class_add_dbus_only_property (parent_class, "security",
1432                                                   G_VARIANT_TYPE_STRING,
1433                                                   nm_setting_wireless_get_security, NULL);
1434 }