1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2007 - 2013 Red Hat, Inc.
19 * Copyright 2007 - 2008 Novell, Inc.
20 * Copyright 2009 One Laptop per Child
23 #include "nm-default.h"
26 #include <netinet/ether.h>
27 #include <dbus/dbus-glib.h>
29 #include "NetworkManager.h"
30 #include "nm-setting-olpc-mesh.h"
31 #include "nm-param-spec-specialized.h"
33 #include "nm-dbus-glib-types.h"
34 #include "nm-utils-private.h"
35 #include "nm-setting-private.h"
38 nm_setting_olpc_mesh_error_quark (void)
42 if (G_UNLIKELY (!quark))
43 quark = g_quark_from_static_string ("nm-setting-olpc-mesh-error-quark");
47 static void nm_setting_olpc_mesh_init (NMSettingOlpcMesh *setting);
49 G_DEFINE_TYPE_WITH_CODE (NMSettingOlpcMesh, nm_setting_olpc_mesh, NM_TYPE_SETTING,
50 _nm_register_setting (NM_SETTING_OLPC_MESH_SETTING_NAME,
53 NM_SETTING_OLPC_MESH_ERROR))
54 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_OLPC_MESH)
56 #define NM_SETTING_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMeshPrivate))
61 GByteArray *dhcp_anycast_addr;
62 } NMSettingOlpcMeshPrivate;
68 PROP_DHCP_ANYCAST_ADDRESS,
74 * nm_setting_olpc_mesh_new:
76 * Creates a new #NMSettingOlpcMesh object with default values.
78 * Returns: the new empty #NMSettingOlpcMesh object
80 NMSetting *nm_setting_olpc_mesh_new (void)
82 return (NMSetting *) g_object_new (NM_TYPE_SETTING_OLPC_MESH, NULL);
86 nm_setting_olpc_mesh_init (NMSettingOlpcMesh *setting)
91 nm_setting_olpc_mesh_get_ssid (NMSettingOlpcMesh *setting)
93 g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), NULL);
95 return NM_SETTING_OLPC_MESH_GET_PRIVATE (setting)->ssid;
99 nm_setting_olpc_mesh_get_channel (NMSettingOlpcMesh *setting)
101 g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), 0);
103 return NM_SETTING_OLPC_MESH_GET_PRIVATE (setting)->channel;
107 nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting)
109 g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), NULL);
111 return NM_SETTING_OLPC_MESH_GET_PRIVATE (setting)->dhcp_anycast_addr;
115 verify (NMSetting *setting, GSList *all_settings, GError **error)
117 NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (setting);
120 g_set_error_literal (error,
121 NM_SETTING_OLPC_MESH_ERROR,
122 NM_SETTING_OLPC_MESH_ERROR_MISSING_PROPERTY,
123 _("property is missing"));
124 g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_SSID);
128 if (!priv->ssid->len || priv->ssid->len > 32) {
129 g_set_error_literal (error,
130 NM_SETTING_OLPC_MESH_ERROR,
131 NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
132 _("SSID length is out of range <1-32> bytes"));
133 g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_SSID);
137 if (priv->channel == 0 || priv->channel > 13) {
139 NM_SETTING_OLPC_MESH_ERROR,
140 NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
141 _("'%d' is not a valid channel"),
143 g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_CHANNEL);
147 if (priv->dhcp_anycast_addr && priv->dhcp_anycast_addr->len != ETH_ALEN) {
148 g_set_error_literal (error,
149 NM_SETTING_OLPC_MESH_ERROR,
150 NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
151 _("property is invalid"));
152 g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS);
160 finalize (GObject *object)
162 NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (object);
165 g_byte_array_free (priv->ssid, TRUE);
166 if (priv->dhcp_anycast_addr)
167 g_byte_array_free (priv->dhcp_anycast_addr, TRUE);
169 G_OBJECT_CLASS (nm_setting_olpc_mesh_parent_class)->finalize (object);
173 set_property (GObject *object, guint prop_id,
174 const GValue *value, GParamSpec *pspec)
176 NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (object);
181 g_byte_array_free (priv->ssid, TRUE);
182 priv->ssid = g_value_dup_boxed (value);
185 priv->channel = g_value_get_uint (value);
187 case PROP_DHCP_ANYCAST_ADDRESS:
188 if (priv->dhcp_anycast_addr)
189 g_byte_array_free (priv->dhcp_anycast_addr, TRUE);
190 priv->dhcp_anycast_addr = g_value_dup_boxed (value);
193 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
199 get_property (GObject *object, guint prop_id,
200 GValue *value, GParamSpec *pspec)
202 NMSettingOlpcMesh *setting = NM_SETTING_OLPC_MESH (object);
206 g_value_set_boxed (value, nm_setting_olpc_mesh_get_ssid (setting));
209 g_value_set_uint (value, nm_setting_olpc_mesh_get_channel (setting));
211 case PROP_DHCP_ANYCAST_ADDRESS:
212 g_value_set_boxed (value, nm_setting_olpc_mesh_get_dhcp_anycast_address (setting));
215 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
221 nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *setting_class)
223 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
224 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
226 g_type_class_add_private (setting_class, sizeof (NMSettingOlpcMeshPrivate));
228 /* virtual methods */
229 object_class->set_property = set_property;
230 object_class->get_property = get_property;
231 object_class->finalize = finalize;
232 parent_class->verify = verify;
236 * NMSettingOlpcMesh:ssid:
238 * SSID of the mesh network to join.
240 g_object_class_install_property
241 (object_class, PROP_SSID,
242 _nm_param_spec_specialized (NM_SETTING_OLPC_MESH_SSID, "", "",
243 DBUS_TYPE_G_UCHAR_ARRAY,
245 NM_SETTING_PARAM_INFERRABLE |
246 G_PARAM_STATIC_STRINGS));
249 * NMSettingOlpcMesh:channel:
251 * Channel on which the mesh network to join is located.
253 g_object_class_install_property
254 (object_class, PROP_CHANNEL,
255 g_param_spec_uint (NM_SETTING_OLPC_MESH_CHANNEL, "", "",
259 NM_SETTING_PARAM_INFERRABLE |
260 G_PARAM_STATIC_STRINGS));
263 * NMSettingOlpcMesh:dhcp-anycast-address:
265 * Anycast DHCP MAC address used when requesting an IP address via DHCP.
266 * The specific anycast address used determines which DHCP server class
267 * answers the request.
269 g_object_class_install_property
270 (object_class, PROP_DHCP_ANYCAST_ADDRESS,
271 _nm_param_spec_specialized (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, "", "",
272 DBUS_TYPE_G_UCHAR_ARRAY,
274 G_PARAM_STATIC_STRINGS));