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