summary refs log tree commit diff
path: root/src/nm-device-bt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nm-device-bt.c')
-rw-r--r--src/nm-device-bt.c157
1 files changed, 82 insertions, 75 deletions
diff --git a/src/nm-device-bt.c b/src/nm-device-bt.c
index c36e0c0b..726762b6 100644
--- a/src/nm-device-bt.c
+++ b/src/nm-device-bt.c
@@ -31,7 +31,6 @@
 #include "nm-bluez-common.h"
 #include "nm-dbus-manager.h"
 #include "nm-device-bt.h"
-#include "nm-device-interface.h"
 #include "nm-device-private.h"
 #include "nm-logging.h"
 #include "nm-marshal.h"
@@ -45,6 +44,8 @@
 #include "nm-setting-ppp.h"
 #include "nm-device-bt-glue.h"
 #include "NetworkManagerUtils.h"
+#include "nm-enum-types.h"
+#include "nm-utils.h"
 
 #define BLUETOOTH_DUN_UUID "dun"
 #define BLUETOOTH_NAP_UUID "nap"
@@ -91,14 +92,7 @@ enum {
 static guint signals[LAST_SIGNAL] = { 0 };
 
 
-typedef enum {
-	NM_BT_ERROR_CONNECTION_NOT_BT = 0,
-	NM_BT_ERROR_CONNECTION_INVALID,
-	NM_BT_ERROR_CONNECTION_INCOMPATIBLE,
-} NMBtError;
-
 #define NM_BT_ERROR (nm_bt_error_quark ())
-#define NM_TYPE_BT_ERROR (nm_bt_error_get_type ())
 
 static GQuark
 nm_bt_error_quark (void)
@@ -109,30 +103,6 @@ nm_bt_error_quark (void)
 	return quark;
 }
 
-/* This should really be standard. */
-#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
-
-static GType
-nm_bt_error_get_type (void)
-{
-	static GType etype = 0;
-
-	if (etype == 0) {
-		static const GEnumValue values[] = {
-			/* Connection was not a BT connection. */
-			ENUM_ENTRY (NM_BT_ERROR_CONNECTION_NOT_BT, "ConnectionNotBt"),
-			/* Connection was not a valid BT connection. */
-			ENUM_ENTRY (NM_BT_ERROR_CONNECTION_INVALID, "ConnectionInvalid"),
-			/* Connection does not apply to this device. */
-			ENUM_ENTRY (NM_BT_ERROR_CONNECTION_INCOMPATIBLE, "ConnectionIncompatible"),
-			{ 0, 0, 0 }
-		};
-		etype = g_enum_register_static ("NMBtError", values);
-	}
-	return etype;
-}
-
-
 guint32 nm_device_bt_get_capabilities (NMDeviceBt *self)
 {
 	g_return_val_if_fail (self != NULL, NM_BT_CAPABILITY_NONE);
@@ -155,7 +125,7 @@ get_connection_bt_type (NMConnection *connection)
 	NMSettingBluetooth *s_bt;
 	const char *bt_type;
 
-	s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
+	s_bt = nm_connection_get_setting_bluetooth (connection);
 	if (!s_bt)
 		return NM_BT_CAPABILITY_NONE;
 
@@ -183,7 +153,7 @@ real_get_best_auto_connection (NMDevice *device,
 		NMSettingConnection *s_con;
 		guint32 bt_type;
 
-		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+		s_con = nm_connection_get_setting_connection (connection);
 		g_assert (s_con);
 
 		if (!nm_setting_connection_get_autoconnect (s_con))
@@ -214,7 +184,7 @@ real_check_connection_compatible (NMDevice *device,
 	int addr_match = FALSE;
 	guint32 bt_type;
 
-	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+	s_con = nm_connection_get_setting_connection (connection);
 	g_assert (s_con);
 
 	if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_BLUETOOTH_SETTING_NAME)) {
@@ -224,7 +194,7 @@ real_check_connection_compatible (NMDevice *device,
 		return FALSE;
 	}
 
-	s_bt = NM_SETTING_BLUETOOTH (nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH));
+	s_bt = nm_connection_get_setting_bluetooth (connection);
 	if (!s_bt) {
 		g_set_error (error,
 		             NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID,
@@ -276,12 +246,12 @@ real_complete_connection (NMDevice *device,
 	NMSettingPPP *s_ppp;
 	const char *format = NULL, *preferred = NULL;
 
-	s_gsm = (NMSettingGsm *) nm_connection_get_setting (connection, NM_TYPE_SETTING_GSM);
-	s_cdma = (NMSettingCdma *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CDMA);
-	s_serial = (NMSettingSerial *) nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL);
-	s_ppp = (NMSettingPPP *) nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP);
+	s_gsm = nm_connection_get_setting_gsm (connection);
+	s_cdma = nm_connection_get_setting_cdma (connection);
+	s_serial = nm_connection_get_setting_serial (connection);
+	s_ppp = nm_connection_get_setting_ppp (connection);
 
-	s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
+	s_bt = nm_connection_get_setting_bluetooth (connection);
 	if (!s_bt) {
 		s_bt = (NMSettingBluetooth *) nm_setting_bluetooth_new ();
 		nm_connection_add_setting (connection, NM_SETTING (s_bt));
@@ -404,6 +374,42 @@ real_get_generic_capabilities (NMDevice *dev)
 	return NM_DEVICE_CAP_NM_SUPPORTED;
 }
 
+static gboolean
+hwaddr_matches (NMDevice *device,
+                NMConnection *connection,
+                const guint8 *other_hwaddr,
+                guint other_hwaddr_len,
+                gboolean fail_if_no_hwaddr)
+{
+	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
+	NMSettingBluetooth *s_bt;
+	const GByteArray *mac = NULL;
+	gboolean matches = FALSE;
+	GByteArray *devmac;
+
+	s_bt = nm_connection_get_setting_bluetooth (connection);
+	if (s_bt)
+		mac = nm_setting_bluetooth_get_bdaddr (s_bt);
+
+	if (mac) {
+		devmac = nm_utils_hwaddr_atoba (priv->bdaddr, ARPHRD_ETHER);
+		g_return_val_if_fail (devmac != NULL, FALSE);
+		g_return_val_if_fail (devmac->len == mac->len, FALSE);
+
+		if (other_hwaddr) {
+			g_return_val_if_fail (other_hwaddr_len == devmac->len, FALSE);
+			matches = (memcmp (mac->data, other_hwaddr, mac->len) == 0) ? TRUE : FALSE;
+		} else
+			matches = (memcmp (mac->data, devmac->data, mac->len) == 0) ? TRUE : FALSE;
+
+		g_byte_array_free (devmac, TRUE);
+		return matches;
+	} else if (fail_if_no_hwaddr == FALSE)
+		return TRUE;
+
+	return FALSE;
+}
+
 /*****************************************************************************/
 /* IP method PPP */
 
@@ -421,17 +427,19 @@ ppp_failed (NMModem *modem, NMDeviceStateReason reason, gpointer user_data)
 {
 	NMDevice *device = NM_DEVICE (user_data);
 
-	switch (nm_device_interface_get_state (NM_DEVICE_INTERFACE (device))) {
+	switch (nm_device_get_state (device)) {
 	case NM_DEVICE_STATE_PREPARE:
 	case NM_DEVICE_STATE_CONFIG:
 	case NM_DEVICE_STATE_NEED_AUTH:
-	case NM_DEVICE_STATE_IP_CHECK:
-	case NM_DEVICE_STATE_SECONDARIES:
-	case NM_DEVICE_STATE_ACTIVATED:
 		nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, reason);
 		break;
 	case NM_DEVICE_STATE_IP_CONFIG:
-		if (nm_device_ip_config_should_fail (device, FALSE)) {
+	case NM_DEVICE_STATE_IP_CHECK:
+	case NM_DEVICE_STATE_SECONDARIES:
+	case NM_DEVICE_STATE_ACTIVATED:
+		if (nm_device_activate_ip4_state_in_conf (device))
+			nm_device_activate_schedule_ip4_config_timeout (device);
+		else {
 			nm_device_state_changed (device,
 			                         NM_DEVICE_STATE_FAILED,
 			                         NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
@@ -478,7 +486,7 @@ modem_prepare_result (NMModem *modem,
 	NMDevice *device = NM_DEVICE (user_data);
 	NMDeviceState state;
 
-	state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
+	state = nm_device_get_state (device);
 	g_return_if_fail (state == NM_DEVICE_STATE_CONFIG || state == NM_DEVICE_STATE_NEED_AUTH);
 
 	if (success) {
@@ -526,10 +534,8 @@ modem_ip4_config_result (NMModem *self,
                          gpointer user_data)
 {
 	NMDevice *device = NM_DEVICE (user_data);
-	NMDeviceState state;
 
-	state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (device));
-	g_return_if_fail (state == NM_DEVICE_STATE_IP_CONFIG);
+	g_return_if_fail (nm_device_activate_ip4_state_in_conf (device) == TRUE);
 
 	if (error) {
 		nm_log_warn (LOGD_MB | LOGD_IP4 | LOGD_BT,
@@ -543,7 +549,7 @@ modem_ip4_config_result (NMModem *self,
 		if (iface)
 			nm_device_set_ip_iface (device, iface);
 
-		nm_device_activate_schedule_stage4_ip4_config_get (device);
+		nm_device_activate_schedule_ip4_config_result (device, config);
 	}
 }
 
@@ -613,7 +619,7 @@ nm_device_bt_modem_added (NMDeviceBt *self,
 	/* Can only accept the modem in stage2, but since the interface matched
 	 * what we were expecting, don't let anything else claim the modem either.
 	 */
-	state = nm_device_interface_get_state (NM_DEVICE_INTERFACE (self));
+	state = nm_device_get_state (NM_DEVICE (self));
 	if (state != NM_DEVICE_STATE_CONFIG) {
 		nm_log_warn (LOGD_BT | LOGD_MB,
 		             "(%s): modem found but device not in correct state (%d)",
@@ -847,15 +853,14 @@ static NMActStageReturn
 real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
 {
 	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
-	NMActRequest *req;
 	NMDBusManager *dbus_mgr;
 	DBusGConnection *g_connection;
 	gboolean dun = FALSE;
+	NMConnection *connection;
 
-	req = nm_device_get_act_request (device);
-	g_assert (req);
-
-	priv->bt_type = get_connection_bt_type (nm_act_request_get_connection (req));
+	connection = nm_device_get_connection (device);
+	g_assert (connection);
+	priv->bt_type = get_connection_bt_type (connection);
 	if (priv->bt_type == NM_BT_CAPABILITY_NONE) {
 		// FIXME: set a reason code
 		return NM_ACT_STAGE_RETURN_FAILURE;
@@ -920,7 +925,9 @@ real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
 }
 
 static NMActStageReturn
-real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
+real_act_stage3_ip4_config_start (NMDevice *device,
+                                  NMIP4Config **out_config,
+                                  NMDeviceStateReason *reason)
 {
 	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
 	NMActStageReturn ret;
@@ -931,27 +938,26 @@ real_act_stage3_ip4_config_start (NMDevice *device, NMDeviceStateReason *reason)
 		                                        NM_DEVICE_CLASS (nm_device_bt_parent_class),
 		                                        reason);
 	} else
-		ret = NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip4_config_start (device, reason);
+		ret = NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip4_config_start (device, out_config, reason);
 
 	return ret;
 }
 
 static NMActStageReturn
-real_act_stage4_get_ip4_config (NMDevice *device,
-                                NMIP4Config **config,
-                                NMDeviceStateReason *reason)
+real_act_stage3_ip6_config_start (NMDevice *device,
+                                  NMIP6Config **out_config,
+                                  NMDeviceStateReason *reason)
 {
 	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
 	NMActStageReturn ret;
 
 	if (priv->bt_type == NM_BT_CAPABILITY_DUN) {
-		ret = nm_modem_stage4_get_ip4_config (NM_DEVICE_BT_GET_PRIVATE (device)->modem,
-		                                      device,
-		                                      NM_DEVICE_CLASS (nm_device_bt_parent_class),
-		                                      config,
-		                                      reason);
+		ret = nm_modem_stage3_ip6_config_start (NM_DEVICE_BT_GET_PRIVATE (device)->modem,
+		                                        device,
+		                                        NM_DEVICE_CLASS (nm_device_bt_parent_class),
+		                                        reason);
 	} else
-		ret = NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage4_get_ip4_config (device, config, reason);
+		ret = NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip6_config_start (device, out_config, reason);
 
 	return ret;
 }
@@ -1037,15 +1043,15 @@ nm_device_bt_new (const char *udi,
 	g_return_val_if_fail (capabilities != NM_BT_CAPABILITY_NONE, NULL);
 
 	device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_BT,
-	                                    NM_DEVICE_INTERFACE_UDI, udi,
-	                                    NM_DEVICE_INTERFACE_IFACE, bdaddr,
-	                                    NM_DEVICE_INTERFACE_DRIVER, "bluez",
+	                                    NM_DEVICE_UDI, udi,
+	                                    NM_DEVICE_IFACE, bdaddr,
+	                                    NM_DEVICE_DRIVER, "bluez",
 	                                    NM_DEVICE_BT_HW_ADDRESS, bdaddr,
 	                                    NM_DEVICE_BT_NAME, name,
 	                                    NM_DEVICE_BT_CAPABILITIES, capabilities,
-	                                    NM_DEVICE_INTERFACE_MANAGED, managed,
-	                                    NM_DEVICE_INTERFACE_TYPE_DESC, "Bluetooth",
-	                                    NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_BT,
+	                                    NM_DEVICE_MANAGED, managed,
+	                                    NM_DEVICE_TYPE_DESC, "Bluetooth",
+	                                    NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BT,
 	                                    NULL);
 	if (device)
 		g_signal_connect (device, "state-changed", G_CALLBACK (device_state_changed), device);
@@ -1148,9 +1154,10 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
 	device_class->deactivate = real_deactivate;
 	device_class->act_stage2_config = real_act_stage2_config;
 	device_class->act_stage3_ip4_config_start = real_act_stage3_ip4_config_start;
-	device_class->act_stage4_get_ip4_config = real_act_stage4_get_ip4_config;
+	device_class->act_stage3_ip6_config_start = real_act_stage3_ip6_config_start;
 	device_class->check_connection_compatible = real_check_connection_compatible;
 	device_class->complete_connection = real_complete_connection;
+	device_class->hwaddr_matches = hwaddr_matches;
 
 	/* Properties */
 	g_object_class_install_property