static void
get_property (GObject *object,
              guint prop_id,
              GValue *value,
              GParamSpec *pspec)
{
	NMDeviceBt *device = NM_DEVICE_BT (object);

	_nm_object_ensure_inited (NM_OBJECT (object));

	switch (prop_id) {
	case PROP_HW_ADDRESS:
		g_value_set_string (value, nm_device_bt_get_hw_address (device));
		break;
	case PROP_NAME:
		g_value_set_string (value, nm_device_bt_get_name (device));
		break;
	case PROP_BT_CAPABILITIES:
		g_value_set_uint (value, nm_device_bt_get_capabilities (device));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
Example #2
0
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	NMSettingConnection *s_con;
	NMSettingBluetooth *s_bt;
	const char *ctype;
	const GByteArray *mac;
	const char *hw_str;
	struct ether_addr *hw_mac;
	NMBluetoothCapabilities dev_caps;
	NMBluetoothCapabilities bt_type;

	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	s_con = nm_connection_get_setting_connection (connection);
	g_assert (s_con);

	ctype = nm_setting_connection_get_connection_type (s_con);
	if (strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME) != 0) {
		g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION,
		             "The connection was not a Bluetooth connection.");
		return FALSE;
	}

	s_bt = nm_connection_get_setting_bluetooth (connection);
	if (!s_bt) {
		g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION,
		             "The connection was not a valid Bluetooth connection.");
		return FALSE;
	}

	/* Check BT address */
	hw_str = nm_device_bt_get_hw_address (NM_DEVICE_BT (device));
	if (hw_str) {
		hw_mac = ether_aton (hw_str);
		if (!hw_mac) {
			g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC,
			             "Invalid device MAC address.");
			return FALSE;
		}
		mac = nm_setting_bluetooth_get_bdaddr (s_bt);
		if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) {
			g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MAC_MISMATCH,
			             "The MACs of the device and the connection didn't match.");
			return FALSE;
		}
	}

	dev_caps = nm_device_bt_get_capabilities (NM_DEVICE_BT (device));
	bt_type = get_connection_bt_type (connection);
	if (!(bt_type & dev_caps)) {
		g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS,
		             "The device missed BT capabilities required by the connection.");
		return FALSE;
	}

	return TRUE;
}
static const char *
bt_get_hw_address (NMDeviceItem *item)
{
    NMDeviceBt *device;

    device = NM_DEVICE_BT (nm_device_item_get_device (NM_DEVICE_ITEM (item)));

    return nm_device_bt_get_hw_address (device);
}
Example #4
0
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
	NMSettingBluetooth *s_bt;
	const char *hw_addr, *setting_addr;
	NMBluetoothCapabilities dev_caps;
	NMBluetoothCapabilities bt_type;

	if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->connection_compatible (device, connection, error))
		return FALSE;

	if (!nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
		g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
		             _("The connection was not a Bluetooth connection."));
		return FALSE;
	}

	/* Check BT address */
	hw_addr = nm_device_bt_get_hw_address (NM_DEVICE_BT (device));
	if (hw_addr) {
		if (!nm_utils_hwaddr_valid (hw_addr, ETH_ALEN)) {
			g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
			                     _("Invalid device Bluetooth address."));
			return FALSE;
		}
		s_bt = nm_connection_get_setting_bluetooth (connection);
		setting_addr = nm_setting_bluetooth_get_bdaddr (s_bt);
		if (setting_addr && !nm_utils_hwaddr_matches (setting_addr, -1, hw_addr, -1)) {
			g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
			                     _("The Bluetooth addresses of the device and the connection didn't match."));
			return FALSE;
		}
	}

	dev_caps = nm_device_bt_get_capabilities (NM_DEVICE_BT (device));
	bt_type = get_connection_bt_type (connection);
	if (!(bt_type & dev_caps)) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
		                     _("The device is lacking Bluetooth capabilities required by the connection."));
		return FALSE;
	}

	return TRUE;
}
Example #5
0
static const char *
get_hw_address (NMDevice *device)
{
	return nm_device_bt_get_hw_address (NM_DEVICE_BT (device));
}
static gboolean
check_bt_compatible (NMDeviceBt *device, NMConnection *connection, GError **error)
{
        NMSettingConnection *s_con;
        NMSettingBluetooth *s_bt;
        const GByteArray *array;
        char *str;
        const char *device_hw_str;
        int addr_match = FALSE;
        const char *bt_type_str;
        guint32 bt_type, bt_capab;

        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

        s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
        g_assert (s_con);

        if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_BLUETOOTH_SETTING_NAME)) {
                g_set_error (error, 0, 0,
                             "The connection was not a Bluetooth connection.");
                return FALSE;
        }

        s_bt = NM_SETTING_BLUETOOTH (nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH));
        if (!s_bt) {
                g_set_error (error, 0, 0,
                             "The connection was not a valid Bluetooth connection.");
                return FALSE;
        }

        array = nm_setting_bluetooth_get_bdaddr (s_bt);
        if (!array || (array->len != ETH_ALEN)) {
                g_set_error (error, 0, 0,
                             "The connection did not contain a valid Bluetooth address.");
                return FALSE;
        }

        bt_type_str = nm_setting_bluetooth_get_connection_type (s_bt);
        g_assert (bt_type_str);

        bt_type = NM_BT_CAPABILITY_NONE;
        if (!strcmp (bt_type_str, NM_SETTING_BLUETOOTH_TYPE_DUN))
                bt_type = NM_BT_CAPABILITY_DUN;
        else if (!strcmp (bt_type_str, NM_SETTING_BLUETOOTH_TYPE_PANU))
                bt_type = NM_BT_CAPABILITY_NAP;

        bt_capab = nm_device_bt_get_capabilities (device);
        if (!(bt_type & bt_capab)) {
                g_set_error (error, 0, 0,
                             "The connection was not compatible with the device's capabilities.");
                return FALSE;
        }

        device_hw_str = nm_device_bt_get_hw_address (device);

        str = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
                               array->data[0], array->data[1], array->data[2],
                               array->data[3], array->data[4], array->data[5]);
        addr_match = !strcmp (device_hw_str, str);
        g_free (str);

        return addr_match;
}