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-param-spec-specialized.h"
29 #include "nm-dbus-glib-types.h"
30 #include "nm-setting-bluetooth.h"
31 #include "nm-setting-cdma.h"
32 #include "nm-setting-gsm.h"
33 #include "nm-setting-private.h"
36 * SECTION:nm-setting-bluetooth
37 * @short_description: Describes Bluetooth connection properties
38 * @include: nm-setting-bluetooth.h
40 * The #NMSettingBluetooth object is a #NMSetting subclass that describes
41 * properties necessary for connection to devices that provide network
42 * connections via the Bluetooth Dial-Up Networking (DUN) and Network Access
43 * Point (NAP) profiles.
47 * nm_setting_bluetooth_error_quark:
49 * Registers an error quark for #NMSettingBluetooth if necessary.
51 * Returns: the error quark used for #NMSettingBluetooth errors.
54 nm_setting_bluetooth_error_quark (void)
58 if (G_UNLIKELY (!quark))
59 quark = g_quark_from_static_string ("nm-setting-bluetooth-error-quark");
64 G_DEFINE_TYPE_WITH_CODE (NMSettingBluetooth, nm_setting_bluetooth, NM_TYPE_SETTING,
65 _nm_register_setting (NM_SETTING_BLUETOOTH_SETTING_NAME,
68 NM_SETTING_BLUETOOTH_ERROR))
69 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BLUETOOTH)
71 #define NM_SETTING_BLUETOOTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothPrivate))
76 } NMSettingBluetoothPrivate;
87 * nm_setting_bluetooth_new:
89 * Creates a new #NMSettingBluetooth object with default values.
91 * Returns: (transfer full): the new empty #NMSettingBluetooth object
93 NMSetting *nm_setting_bluetooth_new (void)
95 return (NMSetting *) g_object_new (NM_TYPE_SETTING_BLUETOOTH, NULL);
99 * nm_setting_bluetooth_get_connection_type:
100 * @setting: the #NMSettingBluetooth
102 * Returns the connection method for communicating with the remote device (i.e.
103 * either DUN to a DUN-capable device or PANU to a NAP-capable device).
105 * Returns: the type, either %NM_SETTING_BLUETOOTH_TYPE_PANU or
106 * %NM_SETTING_BLUETOOTH_TYPE_DUN
109 nm_setting_bluetooth_get_connection_type (NMSettingBluetooth *setting)
111 g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (setting), NULL);
113 return NM_SETTING_BLUETOOTH_GET_PRIVATE (setting)->type;
117 * nm_setting_bluetooth_get_bdaddr:
118 * @setting: the #NMSettingBluetooth
120 * Gets the Bluetooth address of the remote device which this setting
121 * describes a connection to.
123 * Returns: the Bluetooth address
126 nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting)
128 g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (setting), NULL);
130 return NM_SETTING_BLUETOOTH_GET_PRIVATE (setting)->bdaddr;
134 verify (NMSetting *setting, GSList *all_settings, GError **error)
136 NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (setting);
139 g_set_error_literal (error,
140 NM_SETTING_BLUETOOTH_ERROR,
141 NM_SETTING_BLUETOOTH_ERROR_MISSING_PROPERTY,
142 _("property is missing"));
143 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR);
147 if (priv->bdaddr && priv->bdaddr->len != ETH_ALEN) {
148 g_set_error_literal (error,
149 NM_SETTING_BLUETOOTH_ERROR,
150 NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
151 _("property is invalid"));
152 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR);
157 g_set_error_literal (error,
158 NM_SETTING_BLUETOOTH_ERROR,
159 NM_SETTING_BLUETOOTH_ERROR_MISSING_PROPERTY,
160 _("property is missing"));
161 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
163 } else if (!g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN) &&
164 !g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_PANU)) {
166 NM_SETTING_BLUETOOTH_ERROR,
167 NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
168 _("'%s' is not a valid value for the property"),
170 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
174 /* Make sure the corresponding 'type' setting is present */
176 && !strcmp (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN)) {
177 gboolean gsm = FALSE, cdma = FALSE;
179 gsm = !!nm_setting_find_in_list (all_settings, NM_SETTING_GSM_SETTING_NAME);
180 cdma = !!nm_setting_find_in_list (all_settings, NM_SETTING_CDMA_SETTING_NAME);
184 NM_SETTING_BLUETOOTH_ERROR,
185 NM_SETTING_BLUETOOTH_ERROR_TYPE_SETTING_NOT_FOUND,
186 _("requires '%s' or '%s' setting"),
187 NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME);
188 g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
192 /* PANU doesn't need a 'type' setting since no further configuration
193 * is required at the interface level.
200 nm_setting_bluetooth_init (NMSettingBluetooth *setting)
205 finalize (GObject *object)
207 NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (object);
210 g_byte_array_free (priv->bdaddr, TRUE);
213 G_OBJECT_CLASS (nm_setting_bluetooth_parent_class)->finalize (object);
217 set_property (GObject *object, guint prop_id,
218 const GValue *value, GParamSpec *pspec)
220 NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (object);
225 g_byte_array_free (priv->bdaddr, TRUE);
226 priv->bdaddr = g_value_dup_boxed (value);
230 priv->type = g_value_dup_string (value);
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 get_property (GObject *object, guint prop_id,
240 GValue *value, GParamSpec *pspec)
242 NMSettingBluetooth *setting = NM_SETTING_BLUETOOTH (object);
246 g_value_set_boxed (value, nm_setting_bluetooth_get_bdaddr (setting));
249 g_value_set_string (value, nm_setting_bluetooth_get_connection_type (setting));
252 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
258 nm_setting_bluetooth_class_init (NMSettingBluetoothClass *setting_class)
260 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
261 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
263 g_type_class_add_private (setting_class, sizeof (NMSettingBluetoothPrivate));
265 /* virtual methods */
266 object_class->set_property = set_property;
267 object_class->get_property = get_property;
268 object_class->finalize = finalize;
269 parent_class->verify = verify;
274 * NMSettingBluetooth:bdaddr:
276 * The Bluetooth address of the device.
278 g_object_class_install_property
279 (object_class, PROP_BDADDR,
280 _nm_param_spec_specialized (NM_SETTING_BLUETOOTH_BDADDR, "", "",
281 DBUS_TYPE_G_UCHAR_ARRAY,
283 NM_SETTING_PARAM_INFERRABLE |
284 G_PARAM_STATIC_STRINGS));
287 * NMSettingBluetooth:type:
289 * Either "dun" for Dial-Up Networking connections or "panu" for Personal
290 * Area Networking connections to devices supporting the NAP profile.
292 g_object_class_install_property
293 (object_class, PROP_TYPE,
294 g_param_spec_string (NM_SETTING_BLUETOOTH_TYPE, "", "",
297 NM_SETTING_PARAM_INFERRABLE |
298 G_PARAM_STATIC_STRINGS));