1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
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.
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.
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.
19 * Copyright 2007 - 2013 Red Hat, Inc.
20 * Copyright 2007 - 2008 Novell, Inc.
23 #include "nm-default.h"
26 #include <net/ethernet.h>
28 #include "nm-setting-bluetooth.h"
29 #include "nm-setting-cdma.h"
30 #include "nm-setting-gsm.h"
31 #include "nm-setting-private.h"
33 #include "nm-utils-private.h"
36 * SECTION:nm-setting-bluetooth
37 * @short_description: Describes Bluetooth connection properties
39 * The #NMSettingBluetooth object is a #NMSetting subclass that describes
40 * properties necessary for connection to devices that provide network
41 * connections via the Bluetooth Dial-Up Networking (DUN) and Network Access
42 * Point (NAP) profiles.
45 G_DEFINE_TYPE_WITH_CODE (NMSettingBluetooth, nm_setting_bluetooth, NM_TYPE_SETTING,
46 _nm_register_setting (BLUETOOTH, 1))
47 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BLUETOOTH)
49 #define NM_SETTING_BLUETOOTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothPrivate))
54 } NMSettingBluetoothPrivate;
65 * nm_setting_bluetooth_new:
67 * Creates a new #NMSettingBluetooth object with default values.
69 * Returns: (transfer full): the new empty #NMSettingBluetooth object
71 NMSetting *nm_setting_bluetooth_new (void)
73 return (NMSetting *) g_object_new (NM_TYPE_SETTING_BLUETOOTH, NULL);
77 * nm_setting_bluetooth_get_connection_type:
78 * @setting: the #NMSettingBluetooth
80 * Returns the connection method for communicating with the remote device (i.e.
81 * either DUN to a DUN-capable device or PANU to a NAP-capable device).
83 * Returns: the type, either %NM_SETTING_BLUETOOTH_TYPE_PANU or
84 * %NM_SETTING_BLUETOOTH_TYPE_DUN
87 nm_setting_bluetooth_get_connection_type (NMSettingBluetooth *setting)
89 g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (setting), NULL);
91 return NM_SETTING_BLUETOOTH_GET_PRIVATE (setting)->type;
95 * nm_setting_bluetooth_get_bdaddr:
96 * @setting: the #NMSettingBluetooth
98 * Gets the Bluetooth address of the remote device which this setting
99 * describes a connection to.
101 * Returns: the Bluetooth address
104 nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting)
106 g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (setting), NULL);
108 return NM_SETTING_BLUETOOTH_GET_PRIVATE (setting)->bdaddr;
112 verify (NMSetting *setting, NMConnection *connection, GError **error)
114 NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (setting);
117 g_set_error_literal (error,
119 NM_CONNECTION_ERROR_MISSING_PROPERTY,
120 _("property is missing"));
121 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR);
125 if (!nm_utils_hwaddr_valid (priv->bdaddr, ETH_ALEN)) {
126 g_set_error_literal (error,
128 NM_CONNECTION_ERROR_INVALID_PROPERTY,
129 _("property is invalid"));
130 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR);
135 g_set_error_literal (error,
137 NM_CONNECTION_ERROR_MISSING_PROPERTY,
138 _("property is missing"));
139 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
141 } else if (!g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN) &&
142 !g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_PANU)) {
145 NM_CONNECTION_ERROR_INVALID_PROPERTY,
146 _("'%s' is not a valid value for the property"),
148 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
152 /* Make sure the corresponding 'type' setting is present */
154 && !strcmp (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN)) {
155 gboolean gsm = FALSE, cdma = FALSE;
157 gsm = !!nm_connection_get_setting_gsm (connection);
158 cdma = !!nm_connection_get_setting_cdma (connection);
161 /* We can't return MISSING_SETTING here, because we don't know
162 * whether to prefix the message with NM_SETTING_GSM_SETTING_NAME or
163 * NM_SETTING_CDMA_SETTING_NAME.
167 NM_CONNECTION_ERROR_INVALID_SETTING,
168 _("'%s' connection requires '%s' or '%s' setting"),
169 NM_SETTING_BLUETOOTH_TYPE_DUN,
170 NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME);
171 g_prefix_error (error, "%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME);
175 /* PANU doesn't need a 'type' setting since no further configuration
176 * is required at the interface level.
183 nm_setting_bluetooth_init (NMSettingBluetooth *setting)
188 finalize (GObject *object)
190 NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (object);
192 g_free (priv->bdaddr);
195 G_OBJECT_CLASS (nm_setting_bluetooth_parent_class)->finalize (object);
199 set_property (GObject *object, guint prop_id,
200 const GValue *value, GParamSpec *pspec)
202 NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (object);
206 g_free (priv->bdaddr);
207 priv->bdaddr = g_value_dup_string (value);
211 priv->type = g_value_dup_string (value);
214 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220 get_property (GObject *object, guint prop_id,
221 GValue *value, GParamSpec *pspec)
223 NMSettingBluetooth *setting = NM_SETTING_BLUETOOTH (object);
227 g_value_set_string (value, nm_setting_bluetooth_get_bdaddr (setting));
230 g_value_set_string (value, nm_setting_bluetooth_get_connection_type (setting));
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 nm_setting_bluetooth_class_init (NMSettingBluetoothClass *setting_class)
241 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
242 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
244 g_type_class_add_private (setting_class, sizeof (NMSettingBluetoothPrivate));
246 /* virtual methods */
247 object_class->set_property = set_property;
248 object_class->get_property = get_property;
249 object_class->finalize = finalize;
250 parent_class->verify = verify;
255 * NMSettingBluetooth:bdaddr:
257 * The Bluetooth address of the device.
259 g_object_class_install_property
260 (object_class, PROP_BDADDR,
261 g_param_spec_string (NM_SETTING_BLUETOOTH_BDADDR, "", "",
264 NM_SETTING_PARAM_INFERRABLE |
265 G_PARAM_STATIC_STRINGS));
266 _nm_setting_class_transform_property (parent_class, NM_SETTING_BLUETOOTH_BDADDR,
267 G_VARIANT_TYPE_BYTESTRING,
268 _nm_utils_hwaddr_to_dbus,
269 _nm_utils_hwaddr_from_dbus);
272 * NMSettingBluetooth:type:
274 * Either "dun" for Dial-Up Networking connections or "panu" for Personal
275 * Area Networking connections to devices supporting the NAP profile.
277 g_object_class_install_property
278 (object_class, PROP_TYPE,
279 g_param_spec_string (NM_SETTING_BLUETOOTH_TYPE, "", "",
282 NM_SETTING_PARAM_INFERRABLE |
283 G_PARAM_STATIC_STRINGS));