nm-device.c 64.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
18 19
 * Copyright 2007 - 2008 Novell, Inc.
 * Copyright 2007 - 2012 Red Hat, Inc.
20 21
 */

22
#include "nm-default.h"
23

24
#include <string.h>
25
#include <libudev.h>
26

27
#include "NetworkManager.h"
28 29

#include "nm-utils/nm-udev-utils.h"
30
#include "nm-device-ethernet.h"
31
#include "nm-device-adsl.h"
32
#include "nm-device-wifi.h"
33
#include "nm-device-modem.h"
34
#include "nm-device-bt.h"
35
#include "nm-device-olpc-mesh.h"
Dan Williams's avatar
Dan Williams committed
36
#include "nm-device-wimax.h"
37
#include "nm-device-infiniband.h"
Dan Winship's avatar
Dan Winship committed
38
#include "nm-device-bond.h"
39
#include "nm-device-team.h"
Thomas Graf's avatar
Thomas Graf committed
40
#include "nm-device-bridge.h"
Dan Williams's avatar
Dan Williams committed
41
#include "nm-device-vlan.h"
42
#include "nm-device-generic.h"
43 44
#include "nm-device.h"
#include "nm-device-private.h"
45 46
#include "nm-object-private.h"
#include "nm-object-cache.h"
47 48
#include "nm-remote-connection.h"
#include "nm-types.h"
49
#include "nm-dbus-glib-types.h"
50
#include "nm-utils.h"
51
#include "nm-dbus-helpers-private.h"
52

53 54 55 56 57 58
static GType _nm_device_gtype_for_path (DBusGConnection *connection,
                                        const char *path);
static void _nm_device_gtype_for_path_async (DBusGConnection *connection,
                                             const char *path,
                                             NMObjectTypeCallbackFunc callback,
                                             gpointer user_data);
59
gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error);
60 61

G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT,
62 63
                         _nm_object_register_type_func (g_define_type_id, _nm_device_gtype_for_path,
                                                        _nm_device_gtype_for_path_async);
64
                         )
65

66 67
#define DBUS_G_TYPE_UINT_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID))

68 69 70
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))

typedef struct {
71
	DBusGProxy *proxy;
72

73
	char *iface;
74
	char *ip_iface;
75
	NMDeviceType device_type;
76 77
	char *udi;
	char *driver;
78 79
	char *driver_version;
	char *firmware_version;
80
	char *type_description;
81
	NMDeviceCapabilities capabilities;
82
	gboolean real;
83
	gboolean managed;
84
	gboolean firmware_missing;
85
	gboolean autoconnect;
86
	NMIP4Config *ip4_config;
87
	NMDHCP4Config *dhcp4_config;
88
	NMIP6Config *ip6_config;
89
	NMDHCP6Config *dhcp6_config;
90
	NMDeviceState state;
91
	NMDeviceState last_seen_state;
92
	NMDeviceStateReason reason;
93

94
	NMActiveConnection *active_connection;
95
	GPtrArray *available_connections;
96

97
	NMUdevClient *udev_client;
98 99 100
	char *product, *short_product;
	char *vendor, *short_vendor;
	char *description, *bus_name;
101 102

	char *physical_port_id;
103
	guint32 mtu;
104 105
} NMDevicePrivate;

106 107
enum {
	PROP_0,
108 109 110
	PROP_INTERFACE,
	PROP_UDI,
	PROP_DRIVER,
111 112
	PROP_DRIVER_VERSION,
	PROP_FIRMWARE_VERSION,
113
	PROP_CAPABILITIES,
114
	PROP_REAL,
115
	PROP_MANAGED,
116
	PROP_AUTOCONNECT,
117
	PROP_FIRMWARE_MISSING,
118
	PROP_IP4_CONFIG,
119
	PROP_DHCP4_CONFIG,
120
	PROP_IP6_CONFIG,
121
	PROP_STATE,
122
	PROP_STATE_REASON,
123 124
	PROP_PRODUCT,
	PROP_VENDOR,
125
	PROP_DHCP6_CONFIG,
126
	PROP_IP_INTERFACE,
127
	PROP_DEVICE_TYPE,
128
	PROP_ACTIVE_CONNECTION,
129
	PROP_AVAILABLE_CONNECTIONS,
130
	PROP_PHYSICAL_PORT_ID,
131
	PROP_MTU,
132 133 134 135

	LAST_PROP
};

136 137 138 139 140 141 142 143
enum {
	STATE_CHANGED,

	LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

144 145 146 147 148 149
/**
 * nm_device_error_quark:
 *
 * Registers an error quark for #NMDevice if necessary.
 *
 * Returns: the error quark used for #NMDevice errors.
150 151
 *
 * Since: 0.9.10
152 153 154 155 156 157 158 159 160 161
 **/
GQuark
nm_device_error_quark (void)
{
	static GQuark quark = 0;

	if (G_UNLIKELY (quark == 0))
		quark = g_quark_from_static_string ("nm-device-error-quark");
	return quark;
}
162

163 164 165
static void
nm_device_init (NMDevice *device)
{
166 167 168
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);

	priv->state = NM_DEVICE_STATE_UNKNOWN;
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
	priv->reason = NM_DEVICE_STATE_REASON_NONE;
}

static gboolean
demarshal_state_reason (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);

	if (!G_VALUE_HOLDS (value, DBUS_G_TYPE_UINT_STRUCT))
		return FALSE;

	dbus_g_type_struct_get (value,
	                        0, &priv->state,
	                        1, &priv->reason,
	                        G_MAXUINT);

	_nm_object_queue_notify (object, NM_DEVICE_STATE_REASON);
	return TRUE;
187 188 189
}

static void
190
register_properties (NMDevice *device)
191 192
{
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
193 194 195 196 197
	const NMPropertiesInfo property_info[] = {
		{ NM_DEVICE_UDI,               &priv->udi },
		{ NM_DEVICE_INTERFACE,         &priv->iface },
		{ NM_DEVICE_IP_INTERFACE,      &priv->ip_iface },
		{ NM_DEVICE_DRIVER,            &priv->driver },
198 199
		{ NM_DEVICE_DRIVER_VERSION,    &priv->driver_version },
		{ NM_DEVICE_FIRMWARE_VERSION,  &priv->firmware_version },
200
		{ NM_DEVICE_CAPABILITIES,      &priv->capabilities },
201
		{ NM_DEVICE_REAL,              &priv->real },
202
		{ NM_DEVICE_MANAGED,           &priv->managed },
203
		{ NM_DEVICE_AUTOCONNECT,       &priv->autoconnect },
204
		{ NM_DEVICE_FIRMWARE_MISSING,  &priv->firmware_missing },
205 206 207 208
		{ NM_DEVICE_IP4_CONFIG,        &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG },
		{ NM_DEVICE_DHCP4_CONFIG,      &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
		{ NM_DEVICE_IP6_CONFIG,        &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG },
		{ NM_DEVICE_DHCP6_CONFIG,      &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG },
209
		{ NM_DEVICE_STATE,             &priv->state },
210
		{ NM_DEVICE_STATE_REASON,      &priv->state, demarshal_state_reason },
211
		{ NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
212
		{ NM_DEVICE_AVAILABLE_CONNECTIONS, &priv->available_connections, NULL, NM_TYPE_REMOTE_CONNECTION },
213
		{ NM_DEVICE_PHYSICAL_PORT_ID,  &priv->physical_port_id },
214
		{ NM_DEVICE_MTU,               &priv->mtu },
215

216
		/* Properties that exist in D-Bus but that we don't track */
217
		{ "ip4-address", NULL },
218
		{ "device-type", NULL },
219

220 221 222
		{ NULL },
	};

223 224 225
	_nm_object_register_properties (NM_OBJECT (device),
	                                priv->proxy,
	                                property_info);
226 227
}

228 229 230 231 232 233 234 235 236 237 238 239
typedef struct {
	NMDeviceState old_state;
	NMDeviceState new_state;
	NMDeviceStateReason reason;
} StateChangeData;

static void
device_state_change_reloaded (GObject *object,
                              GAsyncResult *result,
                              gpointer user_data)
{
	NMDevice *self = NM_DEVICE (object);
240
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
241
	StateChangeData *data = user_data;
Dan Winship's avatar
Dan Winship committed
242 243 244 245 246
	NMDeviceState old_state = data->old_state;
	NMDeviceState new_state = data->new_state;
	NMDeviceStateReason reason = data->reason;

	g_slice_free (StateChangeData, data);
247 248 249

	_nm_object_reload_properties_finish (NM_OBJECT (object), result, NULL);

250 251 252 253 254
	/* If the device changes state several times in rapid succession, then we'll
	 * queue several reload_properties() calls, and there's no guarantee that
	 * they'll finish in the right order. In that case, only emit the signal
	 * for the last one.
	 */
Dan Winship's avatar
Dan Winship committed
255
	if (priv->last_seen_state != new_state)
256 257 258 259 260
		return;

	/* Ensure that nm_device_get_state() will return the right value even if
	 * we haven't processed the corresponding PropertiesChanged yet.
	 */
Dan Winship's avatar
Dan Winship committed
261
	priv->state = new_state;
262

263
	g_signal_emit (self, signals[STATE_CHANGED], 0,
Dan Winship's avatar
Dan Winship committed
264
	               new_state, old_state, reason);
265 266
}

267 268 269 270 271 272 273
static void
device_state_changed (DBusGProxy *proxy,
                      NMDeviceState new_state,
                      NMDeviceState old_state,
                      NMDeviceStateReason reason,
                      gpointer user_data)
{
274 275 276
	NMDevice *self = NM_DEVICE (user_data);
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);

277
	if (old_state != new_state) {
278 279 280 281 282 283
		StateChangeData *data;

		/* Our object-valued properties (eg, ip4_config) will still
		 * have their old values at this point, because NMObject is
		 * in the process of asynchronously reading the new values.
		 * Wait for that to finish before emitting the signal.
284
		 */
285 286
		priv->last_seen_state = new_state;

287 288 289 290 291 292 293
		data = g_slice_new (StateChangeData);
		data->old_state = old_state;
		data->new_state = new_state;
		data->reason = reason;
		_nm_object_reload_properties_async (NM_OBJECT (user_data),
		                                    device_state_change_reloaded,
		                                    data);
294
	}
295 296
}

297 298 299 300
static GType
_nm_device_gtype_from_dtype (NMDeviceType dtype)
{
	switch (dtype) {
301
	case NM_DEVICE_TYPE_VETH:
302 303 304 305 306 307 308 309
	case NM_DEVICE_TYPE_ETHERNET:
		return NM_TYPE_DEVICE_ETHERNET;
	case NM_DEVICE_TYPE_WIFI:
		return NM_TYPE_DEVICE_WIFI;
	case NM_DEVICE_TYPE_MODEM:
		return NM_TYPE_DEVICE_MODEM;
	case NM_DEVICE_TYPE_BT:
		return NM_TYPE_DEVICE_BT;
310 311
	case NM_DEVICE_TYPE_ADSL:
		return NM_TYPE_DEVICE_ADSL;
312 313 314 315 316 317 318 319
	case NM_DEVICE_TYPE_OLPC_MESH:
		return NM_TYPE_DEVICE_OLPC_MESH;
	case NM_DEVICE_TYPE_WIMAX:
		return NM_TYPE_DEVICE_WIMAX;
	case NM_DEVICE_TYPE_INFINIBAND:
		return NM_TYPE_DEVICE_INFINIBAND;
	case NM_DEVICE_TYPE_BOND:
		return NM_TYPE_DEVICE_BOND;
320 321
	case NM_DEVICE_TYPE_TEAM:
		return NM_TYPE_DEVICE_TEAM;
Thomas Graf's avatar
Thomas Graf committed
322 323
	case NM_DEVICE_TYPE_BRIDGE:
		return NM_TYPE_DEVICE_BRIDGE;
324 325
	case NM_DEVICE_TYPE_VLAN:
		return NM_TYPE_DEVICE_VLAN;
326
	case NM_DEVICE_TYPE_GENERIC:
327
	case NM_DEVICE_TYPE_TUN:
328
	case NM_DEVICE_TYPE_IP_TUNNEL:
329
		return NM_TYPE_DEVICE_GENERIC;
330
	default:
331 332
		/* Fall back to NMDeviceGeneric for unknown devices */
		return NM_TYPE_DEVICE_GENERIC;
333 334 335
	}
}

336
static void
337
constructed (GObject *object)
338
{
339
	NMDevicePrivate *priv;
340

341
	G_OBJECT_CLASS (nm_device_parent_class)->constructed (object);
342

343
	priv = NM_DEVICE_GET_PRIVATE (object);
344
	/* Catch failure of subclasses to call _nm_device_set_device_type() */
345 346 347
	g_warn_if_fail (priv->device_type != NM_DEVICE_TYPE_UNKNOWN);
	/* Catch a subclass setting the wrong type */
	g_warn_if_fail (G_OBJECT_TYPE (object) == _nm_device_gtype_from_dtype (priv->device_type));
348

349
	priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE);
350

351
	register_properties (NM_DEVICE (object));
352

353
	dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
354 355 356
	                                   G_TYPE_NONE,
	                                   G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
	                                   G_TYPE_INVALID);
357 358 359 360 361 362 363

	dbus_g_proxy_add_signal (priv->proxy,
	                         "StateChanged",
	                         G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,
	                         G_TYPE_INVALID);

	dbus_g_proxy_connect_signal (priv->proxy, "StateChanged",
364 365 366
	                             G_CALLBACK (device_state_changed),
	                             NM_DEVICE (object),
	                             NULL);
367 368
}

369 370 371 372 373
static void
dispose (GObject *object)
{
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);

374 375 376 377 378 379
	g_clear_object (&priv->proxy);
	g_clear_object (&priv->ip4_config);
	g_clear_object (&priv->dhcp4_config);
	g_clear_object (&priv->ip6_config);
	g_clear_object (&priv->dhcp6_config);
	g_clear_object (&priv->active_connection);
380

381 382
	priv->udev_client = nm_udev_client_unref (priv->udev_client);

383 384 385 386 387 388 389 390 391
	if (priv->available_connections) {
		int i;

		for (i = 0; i < priv->available_connections->len; i++)
			g_object_unref (priv->available_connections->pdata[i]);
		g_ptr_array_free (priv->available_connections, TRUE);
		priv->available_connections = NULL;
	}

392 393 394
	G_OBJECT_CLASS (nm_device_parent_class)->dispose (object);
}

395 396 397 398 399
static void
finalize (GObject *object)
{
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);

400
	g_free (priv->iface);
401
	g_free (priv->ip_iface);
402 403
	g_free (priv->udi);
	g_free (priv->driver);
404 405
	g_free (priv->driver_version);
	g_free (priv->firmware_version);
406
	g_free (priv->product);
407
	g_free (priv->short_product);
408
	g_free (priv->vendor);
409 410 411
	g_free (priv->short_vendor);
	g_free (priv->description);
	g_free (priv->bus_name);
Dan Winship's avatar
Dan Winship committed
412
	g_free (priv->type_description);
413
	g_free (priv->physical_port_id);
414 415 416 417

	G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
}

418 419 420 421 422 423 424
static void
get_property (GObject *object,
              guint prop_id,
              GValue *value,
              GParamSpec *pspec)
{
	NMDevice *device = NM_DEVICE (object);
425
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
426

427 428
	_nm_object_ensure_inited (NM_OBJECT (object));

429
	switch (prop_id) {
430 431 432
	case PROP_DEVICE_TYPE:
		g_value_set_uint (value, nm_device_get_device_type (device));
		break;
433 434 435 436 437 438
	case PROP_UDI:
		g_value_set_string (value, nm_device_get_udi (device));
		break;
	case PROP_INTERFACE:
		g_value_set_string (value, nm_device_get_iface (device));
		break;
439 440 441
	case PROP_IP_INTERFACE:
		g_value_set_string (value, nm_device_get_ip_iface (device));
		break;
442 443 444
	case PROP_DRIVER:
		g_value_set_string (value, nm_device_get_driver (device));
		break;
445 446 447 448 449 450
	case PROP_DRIVER_VERSION:
		g_value_set_string (value, nm_device_get_driver_version (device));
		break;
	case PROP_FIRMWARE_VERSION:
		g_value_set_string (value, nm_device_get_firmware_version (device));
		break;
451 452 453
	case PROP_CAPABILITIES:
		g_value_set_uint (value, nm_device_get_capabilities (device));
		break;
454 455 456
	case PROP_REAL:
		g_value_set_boolean (value, nm_device_is_real (device));
		break;
457 458 459
	case PROP_MANAGED:
		g_value_set_boolean (value, nm_device_get_managed (device));
		break;
460 461 462
	case PROP_AUTOCONNECT:
		g_value_set_boolean (value, nm_device_get_autoconnect (device));
		break;
463 464 465
	case PROP_FIRMWARE_MISSING:
		g_value_set_boolean (value, nm_device_get_firmware_missing (device));
		break;
466 467 468
	case PROP_IP4_CONFIG:
		g_value_set_object (value, nm_device_get_ip4_config (device));
		break;
469 470 471
	case PROP_DHCP4_CONFIG:
		g_value_set_object (value, nm_device_get_dhcp4_config (device));
		break;
472 473 474
	case PROP_IP6_CONFIG:
		g_value_set_object (value, nm_device_get_ip6_config (device));
		break;
475 476 477
	case PROP_DHCP6_CONFIG:
		g_value_set_object (value, nm_device_get_dhcp6_config (device));
		break;
478 479 480
	case PROP_STATE:
		g_value_set_uint (value, nm_device_get_state (device));
		break;
481 482 483 484 485 486 487 488
	case PROP_STATE_REASON:
		g_value_set_boxed (value,
		                   dbus_g_type_specialized_construct (DBUS_G_TYPE_UINT_STRUCT));
		dbus_g_type_struct_set (value,
		                        0, priv->state,
		                        1, priv->reason,
		                        G_MAXUINT);
		break;
489 490 491
	case PROP_ACTIVE_CONNECTION:
		g_value_set_object (value, nm_device_get_active_connection (device));
		break;
492 493 494
	case PROP_AVAILABLE_CONNECTIONS:
		g_value_set_boxed (value, nm_device_get_available_connections (device));
		break;
495 496 497 498 499 500
	case PROP_PRODUCT:
		g_value_set_string (value, nm_device_get_product (device));
		break;
	case PROP_VENDOR:
		g_value_set_string (value, nm_device_get_vendor (device));
		break;
501 502 503
	case PROP_PHYSICAL_PORT_ID:
		g_value_set_string (value, nm_device_get_physical_port_id (device));
		break;
504 505 506
	case PROP_MTU:
		g_value_set_uint (value, nm_device_get_mtu (device));
		break;
507 508 509 510 511 512
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

513 514 515 516 517 518 519 520
static void
set_property (GObject *object,
              guint prop_id,
              const GValue *value,
              GParamSpec *pspec)
{
	NMDevice *self = NM_DEVICE (object);
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
521
	gboolean b;
522 523 524

	switch (prop_id) {
	case PROP_DEVICE_TYPE:
525
		/* construct-only */
526 527
		priv->device_type = g_value_get_uint (value);
		break;
528 529 530 531 532
	case PROP_MANAGED:
		b = g_value_get_boolean (value);
		if (priv->managed != b)
			nm_device_set_managed (NM_DEVICE (object), b);
		break;
533 534 535 536 537
	case PROP_AUTOCONNECT:
		b = g_value_get_boolean (value);
		if (priv->autoconnect != b)
			nm_device_set_autoconnect (NM_DEVICE (object), b);
		break;
538 539 540 541 542 543
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

544 545 546 547 548
static void
nm_device_class_init (NMDeviceClass *device_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (device_class);

549 550
	g_type_class_add_private (device_class, sizeof (NMDevicePrivate));

551
	/* virtual methods */
552
	object_class->constructed = constructed;
553
	object_class->get_property = get_property;
554
	object_class->set_property = set_property;
555
	object_class->dispose = dispose;
556
	object_class->finalize = finalize;
557

558 559
	device_class->connection_compatible = connection_compatible;

560
	/* properties */
561 562 563 564 565 566

	/**
	 * NMDevice:interface:
	 *
	 * The interface of the device.
	 **/
567 568
	g_object_class_install_property
		(object_class, PROP_INTERFACE,
569 570 571 572
		 g_param_spec_string (NM_DEVICE_INTERFACE, "", "",
		                      NULL,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
573

574 575 576 577 578 579 580 581
	/**
	 * NMDevice:ip-interface:
	 *
	 * The IP interface of the device which should be used for all IP-related
	 * operations like addressing and routing.
	 **/
	g_object_class_install_property
		(object_class, PROP_IP_INTERFACE,
582 583 584 585
		 g_param_spec_string (NM_DEVICE_IP_INTERFACE, "", "",
		                      NULL,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
586

587 588 589 590 591 592 593
	/**
	 * NMDevice:device-type:
	 *
	 * The numeric type of the device.
	 **/
	g_object_class_install_property
		(object_class, PROP_DEVICE_TYPE,
594 595 596 597
		 g_param_spec_uint (NM_DEVICE_DEVICE_TYPE, "", "",
		                    NM_DEVICE_TYPE_UNKNOWN, G_MAXUINT32, NM_DEVICE_TYPE_UNKNOWN,
		                    G_PARAM_READABLE |
		                    G_PARAM_STATIC_STRINGS));
598 599 600
	/**
	 * NMDevice:udi:
	 *
601 602 603 604 605 606
	 * An operating-system specific device hardware identifier; this is not
	 * unique to a specific hardware device across reboots or hotplugs.  It
	 * is an opaque string which for some device types (Bluetooth, Modem)
	 * contains an identifier provided by the underlying hardware service daemon
	 * such as Bluez or ModemManager, and clients can use this property to
	 * request more information about the device from those services.
607
	 **/
608 609
	g_object_class_install_property
		(object_class, PROP_UDI,
610 611 612 613
		 g_param_spec_string (NM_DEVICE_UDI, "", "",
		                      NULL,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
614

615 616 617 618 619
	/**
	 * NMDevice:driver:
	 *
	 * The driver of the device.
	 **/
620 621
	g_object_class_install_property
		(object_class, PROP_DRIVER,
622 623 624 625
		 g_param_spec_string (NM_DEVICE_DRIVER, "", "",
		                      NULL,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
626

627 628 629 630 631 632 633
	/**
	 * NMDevice:driver-version:
	 *
	 * The version of the device driver.
	 **/
	g_object_class_install_property
		(object_class, PROP_DRIVER_VERSION,
634
		 g_param_spec_string (NM_DEVICE_DRIVER_VERSION, "", "",
635
		                      NULL,
636 637
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
638 639 640 641 642 643 644 645

	/**
	 * NMDevice:firmware-version:
	 *
	 * The firmware version of the device.
	 **/
	g_object_class_install_property
		(object_class, PROP_FIRMWARE_VERSION,
646
		 g_param_spec_string (NM_DEVICE_FIRMWARE_VERSION, "", "",
647
		                      NULL,
648 649
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
650

651 652 653 654 655
	/**
	 * NMDevice:capabilities:
	 *
	 * The capabilities of the device.
	 **/
656 657
	g_object_class_install_property
		(object_class, PROP_CAPABILITIES,
658 659 660 661
		 g_param_spec_uint (NM_DEVICE_CAPABILITIES, "", "",
		                    0, G_MAXUINT32, 0,
		                    G_PARAM_READABLE |
		                    G_PARAM_STATIC_STRINGS));
662

663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
	/**
	 * NMDevice:real:
	 *
	 * Whether the device is real or is a placeholder device that could
	 * be created automatically by NetworkManager if one of its
	 * #NMDevice:available-connections was activated.
	 *
	 * Since: 1.2
	 **/
	g_object_class_install_property
		(object_class, PROP_REAL,
		 g_param_spec_boolean (NM_DEVICE_REAL, "", "",
		                       FALSE,
		                       G_PARAM_READABLE |
		                       G_PARAM_STATIC_STRINGS));

679 680 681 682 683
	/**
	 * NMDevice:managed:
	 *
	 * Whether the device is managed by NetworkManager.
	 **/
684 685
	g_object_class_install_property
		(object_class, PROP_MANAGED,
686 687 688 689
		 g_param_spec_boolean (NM_DEVICE_MANAGED, "", "",
		                       FALSE,
		                       G_PARAM_READABLE |
		                       G_PARAM_STATIC_STRINGS));
690

691 692 693 694 695 696 697
	/**
	 * NMDevice:autoconnect:
	 *
	 * Whether the device can auto-activate a connection.
	 **/
	g_object_class_install_property
		(object_class, PROP_AUTOCONNECT,
698
		 g_param_spec_boolean (NM_DEVICE_AUTOCONNECT, "", "",
699
		                       TRUE,
700 701
		                       G_PARAM_READWRITE |
		                       G_PARAM_STATIC_STRINGS));
702

703 704 705 706 707 708 709 710
	/**
	 * NMDevice:firmware-missing:
	 *
	 * When %TRUE indicates the device is likely missing firmware required
	 * for its operation.
	 **/
	g_object_class_install_property
		(object_class, PROP_FIRMWARE_MISSING,
711 712 713 714
		 g_param_spec_boolean (NM_DEVICE_FIRMWARE_MISSING, "", "",
		                       FALSE,
		                       G_PARAM_READABLE |
		                       G_PARAM_STATIC_STRINGS));
715

716 717 718 719 720
	/**
	 * NMDevice:ip4-config:
	 *
	 * The #NMIP4Config of the device.
	 **/
721 722
	g_object_class_install_property
		(object_class, PROP_IP4_CONFIG,
723 724 725 726
		 g_param_spec_object (NM_DEVICE_IP4_CONFIG, "", "",
		                      NM_TYPE_IP4_CONFIG,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
727

728 729 730 731 732
	/**
	 * NMDevice:dhcp4-config:
	 *
	 * The #NMDHCP4Config of the device.
	 **/
733 734
	g_object_class_install_property
		(object_class, PROP_DHCP4_CONFIG,
735 736 737 738
		 g_param_spec_object (NM_DEVICE_DHCP4_CONFIG, "", "",
		                      NM_TYPE_DHCP4_CONFIG,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
739

740 741 742 743 744 745 746
	/**
	 * NMDevice:ip6-config:
	 *
	 * The #NMIP6Config of the device.
	 **/
	g_object_class_install_property
		(object_class, PROP_IP6_CONFIG,
747
		 g_param_spec_object (NM_DEVICE_IP6_CONFIG, "", "",
748
		                      NM_TYPE_IP6_CONFIG,
749 750
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
751

752 753 754 755 756 757 758
	/**
	 * NMDevice:dhcp6-config:
	 *
	 * The #NMDHCP6Config of the device.
	 **/
	g_object_class_install_property
		(object_class, PROP_DHCP6_CONFIG,
759 760 761 762
		 g_param_spec_object (NM_DEVICE_DHCP6_CONFIG, "", "",
		                      NM_TYPE_DHCP6_CONFIG,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
763

764 765 766 767 768
	/**
	 * NMDevice:state:
	 *
	 * The state of the device.
	 **/
769 770
	g_object_class_install_property
		(object_class, PROP_STATE,
771 772 773 774
		 g_param_spec_uint (NM_DEVICE_STATE, "", "",
		                    0, G_MAXUINT32, 0,
		                    G_PARAM_READABLE |
		                    G_PARAM_STATIC_STRINGS));
775

776 777 778 779 780 781 782
	/**
	 * NMDevice:state-reason:
	 *
	 * The state and reason of the device.
	 **/
	g_object_class_install_property
		(object_class, PROP_STATE_REASON,
783
		 g_param_spec_boxed (NM_DEVICE_STATE_REASON, "", "",
784
		                     DBUS_G_TYPE_UINT_STRUCT,
785 786
		                     G_PARAM_READABLE |
		                     G_PARAM_STATIC_STRINGS));
787

788 789 790 791 792 793 794
	/**
	 * NMDevice:active-connection:
	 *
	 * The #NMActiveConnection object that "owns" this device during activation.
	 **/
	g_object_class_install_property
		(object_class, PROP_ACTIVE_CONNECTION,
795
		 g_param_spec_object (NM_DEVICE_ACTIVE_CONNECTION, "", "",
796
		                      NM_TYPE_ACTIVE_CONNECTION,
797 798
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
799

800 801 802 803
	/**
	 * NMDevice:available-connections:
	 *
	 * The available connections (#NMRemoteConnection) of the device
804 805
	 *
	 * Since: 0.9.8
806 807 808
	 **/
	g_object_class_install_property
		(object_class, PROP_AVAILABLE_CONNECTIONS,
809 810 811 812
		 g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "",
		                     NM_TYPE_OBJECT_ARRAY,
		                     G_PARAM_READABLE |
		                     G_PARAM_STATIC_STRINGS));
813

814 815 816 817 818
	/**
	 * NMDevice:vendor:
	 *
	 * The vendor string of the device.
	 **/
819 820
	g_object_class_install_property
		(object_class, PROP_VENDOR,
821 822 823 824
		 g_param_spec_string (NM_DEVICE_VENDOR, "", "",
		                      NULL,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
825

826 827 828 829 830
	/**
	 * NMDevice:product:
	 *
	 * The product string of the device.
	 **/
831 832
	g_object_class_install_property
		(object_class, PROP_PRODUCT,
833 834 835 836
		 g_param_spec_string (NM_DEVICE_PRODUCT, "", "",
		                      NULL,
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
837

838 839 840 841 842 843 844 845 846 847
	/**
	 * NMDevice:physical-port-id:
	 *
	 * The physical port ID of the device. (See
	 * nm_device_get_physical_port_id().)
	 *
	 * Since: 0.9.10
	 **/
	g_object_class_install_property
		(object_class, PROP_PHYSICAL_PORT_ID,
848
		 g_param_spec_string (NM_DEVICE_PHYSICAL_PORT_ID, "", "",
849
		                      NULL,
850 851
		                      G_PARAM_READABLE |
		                      G_PARAM_STATIC_STRINGS));
852

853 854 855 856 857 858 859 860 861
	/**
	 * NMDevice:mtu:
	 *
	 * The MTU of the device.
	 *
	 * Since: 0.9.10
	 **/
	g_object_class_install_property
		(object_class, PROP_MTU,
862
		 g_param_spec_uint (NM_DEVICE_MTU, "", "",
863
		                    0, G_MAXUINT32, 1500,
864 865
		                    G_PARAM_READABLE |
		                    G_PARAM_STATIC_STRINGS));
866

867
	/* signals */
868 869 870

	/**
	 * NMDevice::state-changed:
871 872 873 874
	 * @device: the device object that received the signal
	 * @new_state: the new state of the device
	 * @old_state: the previous state of the device
	 * @reason: the reason describing the state change
875 876 877
	 *
	 * Notifies the state change of a #NMDevice.
	 **/
878 879
	signals[STATE_CHANGED] =
		g_signal_new ("state-changed",
880 881 882 883 884 885
		              G_OBJECT_CLASS_TYPE (object_class),
		              G_SIGNAL_RUN_FIRST,
		              G_STRUCT_OFFSET (NMDeviceClass, state_changed),
		              NULL, NULL, NULL,
		              G_TYPE_NONE, 3,
		              G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
886 887
}

888
/**
889
 * _nm_device_set_device_type:
890 891 892 893 894 895 896
 * @device: the device
 * @dtype: the NM device type
 *
 * Sets the NM device type if it wasn't set during construction.  INTERNAL
 * ONLY METHOD.
 **/
void
897
_nm_device_set_device_type (NMDevice *device, NMDeviceType dtype)
898
{
899 900 901 902 903 904 905 906 907 908
	NMDevicePrivate *priv;

	g_return_if_fail (device != NULL);
	g_return_if_fail (dtype != NM_DEVICE_TYPE_UNKNOWN);

	priv = NM_DEVICE_GET_PRIVATE (device);
	if (priv->device_type == NM_DEVICE_TYPE_UNKNOWN)
		priv->device_type = dtype;
	else
		g_warn_if_fail (dtype == priv->device_type);
909 910
}

911 912
NMDeviceType
_nm_device_type_for_path (DBusGConnection *connection, const char *path)
913
{
914 915
	DBusGProxy *proxy;
	GError *err = NULL;
916
	GValue value = G_VALUE_INIT;
917

Dan Winship's avatar
Dan Winship committed
918
	proxy = _nm_dbus_new_proxy_for_connection (connection, path, DBUS_INTERFACE_PROPERTIES);
919 920
	if (!proxy) {
		g_warning ("%s: couldn't create D-Bus object proxy.", __func__);
921
		return G_TYPE_INVALID;
922
	}
923

924
	if (!dbus_g_proxy_call (proxy,
925 926 927 928 929
	                        "Get", &err,
	                        G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE,
	                        G_TYPE_STRING, "DeviceType",
	                        G_TYPE_INVALID,
	                        G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
930 931
		g_warning ("Error in get_property: %s\n", err->message);
		g_error_free (err);
932 933
		g_object_unref (proxy);
		return G_TYPE_INVALID;
934
	}
935
	g_object_unref (proxy);
936

937 938 939 940 941 942 943 944
	return g_value_get_uint (&value);
}

static GType
_nm_device_gtype_for_path (DBusGConnection *connection,
                           const char *path)
{
	return _nm_device_gtype_from_dtype (_nm_device_type_for_path (connection, path));
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
}

/**
 * nm_device_new:
 * @connection: the #DBusGConnection
 * @path: the DBus object path of the device
 *
 * Creates a new #NMDevice.
 *
 * Returns: (transfer full): a new device
 **/
GObject *
nm_device_new (DBusGConnection *connection, const char *path)
{
	GType dtype;
960
	NMDevice *device = NULL;
961

962 963 964
	g_return_val_if_fail (connection != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);

965
	dtype = _nm_device_gtype_for_path (connection, path);
966 967 968
	if (dtype == G_TYPE_INVALID)
		return NULL;

969 970 971 972 973 974
	device = (NMDevice *) g_object_new (dtype,
	                                    NM_OBJECT_DBUS_CONNECTION, connection,
	                                    NM_OBJECT_DBUS_PATH, path,
	                                    NULL);
	_nm_object_ensure_inited (NM_OBJECT (device));
	return G_OBJECT (device);
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
}

typedef struct {
	DBusGConnection *connection;
	NMObjectTypeCallbackFunc callback;
	gpointer user_data;
} NMDeviceAsyncData;

static void
async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
{
	NMDeviceAsyncData *async_data = user_data;
	GValue value = G_VALUE_INIT;
	const char *path = dbus_g_proxy_get_path (proxy);
	GError *error = NULL;
	GType type;

	if (dbus_g_proxy_end_call (proxy, call, &error,
	                           G_TYPE_VALUE, &value,
	                           G_TYPE_INVALID)) {
		NMDeviceType dtype;

		dtype = g_value_get_uint (&value);
998
		type = _nm_device_gtype_from_dtype (dtype);
999 1000 1001 1002
	} else {
		g_warning ("%s: could not read properties for %s: %s", __func__, path, error->message);
		g_error_free (error);
		type = G_TYPE_INVALID;
1003 1004
	}

1005
	async_data->callback (type, async_data->user_data);
1006
	g_object_unref (proxy);
1007 1008 1009 1010
	g_slice_free (NMDeviceAsyncData, async_data);
}

static void
1011
_nm_device_gtype_for_path_async (DBusGConnection *connection,
1012 1013 1014
                                const char *path,
                                NMObjectTypeCallbackFunc callback,
                                gpointer user_data)
1015 1016 1017 1018 1019 1020 1021 1022 1023
{
	NMDeviceAsyncData *async_data;
	DBusGProxy *proxy;

	async_data = g_slice_new (NMDeviceAsyncData);
	async_data->connection = connection;
	async_data->callback = callback;
	async_data->user_data = user_data;

Dan Winship's avatar
Dan Winship committed
1024
	proxy = _nm_dbus_new_proxy_for_connection (connection, path, DBUS_INTERFACE_PROPERTIES);
1025 1026 1027 1028 1029
	dbus_g_proxy_begin_call (proxy, "Get",
	                         async_got_type, async_data, NULL,
	                         G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE,
	                         G_TYPE_STRING, "DeviceType",
	                         G_TYPE_INVALID);
1030 1031
}

1032 1033 1034 1035 1036 1037 1038 1039 1040
/**
 * nm_device_get_iface:
 * @device: a #NMDevice
 *
 * Gets the interface name of the #NMDevice.
 *
 * Returns: the interface of the device. This is the internal string used by the
 * device, and must not be modified.
 **/
1041
const char *
1042 1043 1044 1045
nm_device_get_iface (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

1046 1047
	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->iface;
1048 1049
}

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
/**
 * nm_device_get_ip_iface:
 * @device: a #NMDevice
 *
 * Gets the IP interface name of the #NMDevice over which IP traffic flows
 * when the device is in the ACTIVATED state.
 *
 * Returns: the IP traffic interface of the device. This is the internal string
 * used by the device, and must not be modified.
 **/
const char *
nm_device_get_ip_iface (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

1065 1066
	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->ip_iface;
1067 1068
}

1069 1070 1071 1072
/**
 * nm_device_get_device_type:
 * @device: a #NMDevice
 *
1073
 * Returns the numeric type of the #NMDevice, ie Ethernet, Wi-Fi, etc.
1074 1075 1076 1077 1078 1079 1080 1081
 *
 * Returns: the device type
 **/
NMDeviceType
nm_device_get_device_type (NMDevice *self)
{
	g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_TYPE_UNKNOWN);

1082
	return NM_DEVICE_GET_PRIVATE (self)->device_type;
1083 1084
}

1085 1086 1087 1088
/**
 * nm_device_get_udi:
 * @device: a #NMDevice
 *
1089
 * Gets the Unique Device Identifier of the #NMDevice.
1090
 *
1091 1092 1093
 * Returns: the Unique Device Identifier of the device.  This identifier may be
 * used to gather more information about the device from various operating
 * system services like udev or sysfs.
1094
 **/
1095
const char *
1096 1097 1098 1099
nm_device_get_udi (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

1100 1101
	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->udi;
1102 1103
}

1104 1105 1106 1107 1108 1109 1110 1111 1112
/**
 * nm_device_get_driver:
 * @device: a #NMDevice
 *
 * Gets the driver of the #NMDevice.
 *
 * Returns: the driver of the device. This is the internal string used by the
 * device, and must not be modified.
 **/
1113
const char *
1114 1115 1116 1117
nm_device_get_driver (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

1118 1119
	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->driver;
1120 1121
}

1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
/**
 * nm_device_get_driver_version:
 * @device: a #NMDevice
 *
 * Gets the driver version of the #NMDevice.
 *
 * Returns: the version of the device driver. This is the internal string used by the
 * device, and must not be modified.
 **/
const char *
nm_device_get_driver_version (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->driver_version;
}

/**
 * nm_device_get_firmware_version:
 * @device: a #NMDevice
 *
 * Gets the firmware version of the #NMDevice.
 *
 * Returns: the firmware version of the device. This is the internal string used by the
 * device, and must not be modified.
 **/
const char *
nm_device_get_firmware_version (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->firmware_version;
}

1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
/**
 * nm_device_get_type_description:
 * @device: a #NMDevice
 *
 * Gets a (non-localized) description of the type of device that
 * @device is.
 *
 * Returns: the type description of the device. This is the internal
 * string used by the device, and must not be modified.
 *
 * Since: 0.9.10
 **/
const char *
nm_device_get_type_description (NMDevice *device)
{
	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
	const char *desc, *typename;

	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

	if (priv->type_description)
		return priv->type_description;

	if (NM_DEVICE_GET_CLASS (device)->get_type_description) {
		desc = NM_DEVICE_GET_CLASS (device)->get_type_description (device);
		if (desc)
			return desc;
	}

	typename = G_OBJECT_TYPE_NAME (device);
	if (g_str_has_prefix (typename, "NMDevice"))
		typename += 8;
	priv->type_description = g_ascii_strdown (typename, -1);

	return priv->type_description;
}

1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216
/**
 * nm_device_get_hw_address:
 * @device: a #NMDevice
 *
 * Gets the current a hardware address (MAC) for the @device.
 *
 * Returns: the current MAC of the device, or %NULL.
 * This is the internal string used by the device, and must not be modified.
 *
 * Since: 0.9.10
 **/
const char *
nm_device_get_hw_address (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), NULL);

	if (NM_DEVICE_GET_CLASS (device)->get_hw_address)
		return NM_DEVICE_GET_CLASS (device)->get_hw_address (device);

	return NULL;
}

1217 1218 1219 1220 1221 1222 1223 1224
/**
 * nm_device_get_capabilities:
 * @device: a #NMDevice
 *
 * Gets the device' capabilities.
 *
 * Returns: the capabilities
 **/
1225
NMDeviceCapabilities
1226 1227
nm_device_get_capabilities (NMDevice *device)
{
1228 1229
	g_return_val_if_fail (NM_IS_DEVICE (device), 0);

1230 1231
	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->capabilities;
1232 1233
}

1234 1235 1236 1237 1238 1239 1240 1241
/**
 * nm_device_get_managed:
 * @device: a #NMDevice
 *
 * Whether the #NMDevice is managed by NetworkManager.
 *
 * Returns: %TRUE if the device is managed by NetworkManager
 **/
1242 1243 1244 1245 1246
gboolean
nm_device_get_managed (NMDevice *device)
{
	g_return_val_if_fail (NM_IS_DEVICE (device), 0);

1247 1248
	_nm_object_ensure_inited (NM_OBJECT (device));
	return NM_DEVICE_GET_PRIVATE (device)->managed;
1249 1250
}

1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
/**
 * nm_device_set_managed:
 * @device: a #NMDevice
 * @managed: %TRUE to make the device managed by NetworkManager.
 *
 * Enables or disables management of  #NMDevice by NetworkManager.
 *
 * Since: 1.2
 **/
void
nm_device_set_managed (NMDevice *device, gboolean managed)
{
	GValue value = G_VALUE_INIT;

	g_return_if_fail (NM_IS_DEVICE (device));

	managed = !!managed;

	g_value_init (&value, G_TYPE_BOOLEAN);
	g_value_set_boolean (&value, managed);

	NM_DEVICE_GET_PRIVATE (device)->managed = managed;

	_nm_object_set_property (NM_OBJECT (device),
	                         NM_DBUS_INTERFACE_DEVICE,
	                         "Managed",
	                         &value);
}

1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
/**
 * nm_device_get_autoconnect:
 * @device: a #NMDevice
 *
 * Whether the #NMDevice can be autoconnected.
 *
 * Returns: %TRUE if the device is allowed to be autoconnected
 **/