device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-core / nm-setting-wimax.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 2011 - 2013 Red Hat, Inc.
20  * Copyright 2009 Novell, Inc.
21  */
22
23 #include "nm-default.h"
24
25 #include <string.h>
26 #include <net/ethernet.h>
27
28 #include "nm-setting-wimax.h"
29 #include "nm-setting-private.h"
30 #include "nm-utils.h"
31 #include "nm-utils-private.h"
32
33 /**
34  * SECTION:nm-setting-wimax
35  * @short_description: Describes 802.16e Mobile WiMAX connection properties
36  *
37  * The #NMSettingWimax object is a #NMSetting subclass that describes properties
38  * necessary for connection to 802.16e Mobile WiMAX networks.
39  *
40  * NetworkManager no longer supports WiMAX; while this API remains available for
41  * backward-compatibility reasons, it serves no real purpose, since WiMAX
42  * connections cannot be activated.
43  **/
44
45 G_DEFINE_TYPE_WITH_CODE (NMSettingWimax, nm_setting_wimax, NM_TYPE_SETTING,
46                          _nm_register_setting (WIMAX, 1))
47 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIMAX)
48
49 #define NM_SETTING_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIMAX, NMSettingWimaxPrivate))
50
51 typedef struct {
52         char *network_name;
53         char *mac_address;
54 } NMSettingWimaxPrivate;
55
56 enum {
57         PROP_0,
58         PROP_NETWORK_NAME,
59         PROP_MAC_ADDRESS,
60
61         LAST_PROP
62 };
63
64 /**
65  * nm_setting_wimax_new:
66  *
67  * Creates a new #NMSettingWimax object with default values.
68  *
69  * Returns: the new empty #NMSettingWimax object
70  *
71  * Deprecated: 1.2: WiMAX is no longer supported.
72  **/
73 NMSetting *
74 nm_setting_wimax_new (void)
75 {
76         return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIMAX, NULL);
77 }
78
79 /**
80  * nm_setting_wimax_get_network_name:
81  * @setting: the #NMSettingWimax
82  *
83  * Returns the WiMAX NSP name (ex "Sprint" or "CLEAR") which identifies the
84  * specific WiMAX network this setting describes a connection to.
85  *
86  * Returns: the WiMAX NSP name
87  *
88  * Deprecated: 1.2: WiMAX is no longer supported.
89  **/
90 const char *
91 nm_setting_wimax_get_network_name (NMSettingWimax *setting)
92 {
93         g_return_val_if_fail (NM_IS_SETTING_WIMAX (setting), NULL);
94
95         return NM_SETTING_WIMAX_GET_PRIVATE (setting)->network_name;
96 }
97
98 /**
99  * nm_setting_wimax_get_mac_address:
100  * @setting: the #NMSettingWimax
101  *
102  * Returns the MAC address of a WiMAX device which this connection is locked
103  * to.
104  *
105  * Returns: the MAC address
106  *
107  * Deprecated: 1.2: WiMAX is no longer supported.
108  **/
109 const char *
110 nm_setting_wimax_get_mac_address (NMSettingWimax *setting)
111 {
112         g_return_val_if_fail (NM_IS_SETTING_WIMAX (setting), NULL);
113
114         return NM_SETTING_WIMAX_GET_PRIVATE (setting)->mac_address;
115 }
116
117 static gboolean
118 verify (NMSetting *setting, NMConnection *connection, GError **error)
119 {
120         NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (setting);
121
122         if (!priv->network_name) {
123                 g_set_error_literal (error,
124                                      NM_CONNECTION_ERROR,
125                                      NM_CONNECTION_ERROR_MISSING_PROPERTY,
126                                      _("property is missing"));
127                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_NETWORK_NAME);
128                 return FALSE;
129         }
130
131         if (!strlen (priv->network_name)) {
132                 g_set_error_literal (error,
133                                      NM_CONNECTION_ERROR,
134                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
135                                      _("property is empty"));
136                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_NETWORK_NAME);
137                 return FALSE;
138         }
139
140         if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, ETH_ALEN)) {
141                 g_set_error_literal (error,
142                                      NM_CONNECTION_ERROR,
143                                      NM_CONNECTION_ERROR_INVALID_PROPERTY,
144                                      _("property is invalid"));
145                 g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_MAC_ADDRESS);
146                 return FALSE;
147         }
148
149         return TRUE;
150 }
151
152 static void
153 nm_setting_wimax_init (NMSettingWimax *setting)
154 {
155 }
156
157 static void
158 finalize (GObject *object)
159 {
160         NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (object);
161
162         g_free (priv->network_name);
163         g_free (priv->mac_address);
164
165         G_OBJECT_CLASS (nm_setting_wimax_parent_class)->finalize (object);
166 }
167
168 static void
169 set_property (GObject *object, guint prop_id,
170               const GValue *value, GParamSpec *pspec)
171 {
172         NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (object);
173
174         switch (prop_id) {
175         case PROP_NETWORK_NAME:
176                 g_free (priv->network_name);
177                 priv->network_name = g_value_dup_string (value);
178                 break;
179         case PROP_MAC_ADDRESS:
180                 g_free (priv->mac_address);
181                 priv->mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
182                                                                            ETH_ALEN);
183                 break;
184         default:
185                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
186                 break;
187         }
188 }
189
190 static void
191 get_property (GObject *object, guint prop_id,
192               GValue *value, GParamSpec *pspec)
193 {
194         NMSettingWimax *setting = NM_SETTING_WIMAX (object);
195
196         switch (prop_id) {
197         case PROP_NETWORK_NAME:
198                 g_value_set_string (value, nm_setting_wimax_get_network_name (setting));
199                 break;
200         case PROP_MAC_ADDRESS:
201                 g_value_set_string (value, nm_setting_wimax_get_mac_address (setting));
202                 break;
203         default:
204                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205                 break;
206         }
207 }
208
209 static void
210 nm_setting_wimax_class_init (NMSettingWimaxClass *setting_class)
211 {
212         GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
213         NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
214
215         g_type_class_add_private (setting_class, sizeof (NMSettingWimaxPrivate));
216
217         /* virtual methods */
218         object_class->set_property = set_property;
219         object_class->get_property = get_property;
220         object_class->finalize     = finalize;
221         parent_class->verify       = verify;
222
223         /* Properties */
224         /**
225          * NMSettingWimax:network-name:
226          *
227          * Network Service Provider (NSP) name of the WiMAX network this connection
228          * should use.
229          *
230          * Deprecated: 1.2: WiMAX is no longer supported.
231          **/
232         g_object_class_install_property
233                 (object_class, PROP_NETWORK_NAME,
234                  g_param_spec_string (NM_SETTING_WIMAX_NETWORK_NAME, "", "",
235                                       NULL,
236                                       G_PARAM_READWRITE |
237                                       G_PARAM_STATIC_STRINGS));
238
239         /**
240          * NMSettingWimax:mac-address:
241          *
242          * If specified, this connection will only apply to the WiMAX device whose
243          * MAC address matches. This property does not change the MAC address of the
244          * device (known as MAC spoofing).
245          *
246          * Deprecated: 1.2: WiMAX is no longer supported.
247          **/
248         g_object_class_install_property
249                 (object_class, PROP_MAC_ADDRESS,
250                  g_param_spec_string (NM_SETTING_WIMAX_MAC_ADDRESS, "", "",
251                                       NULL,
252                                       G_PARAM_READWRITE |
253                                       G_PARAM_STATIC_STRINGS));
254         _nm_setting_class_transform_property (parent_class, NM_SETTING_WIMAX_MAC_ADDRESS,
255                                               G_VARIANT_TYPE_BYTESTRING,
256                                               _nm_utils_hwaddr_to_dbus,
257                                               _nm_utils_hwaddr_from_dbus);
258 }