コード例 #1
0
static gboolean
real_check_connection_compatible (NMDevice *device,
                                  NMConnection *connection,
                                  GError **error)
{
	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
	NMSettingConnection *s_con;
	NMSettingBluetooth *s_bt;
	const GByteArray *array;
	char *str;
	int addr_match = FALSE;
	guint32 bt_type;

	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,
		             NM_BT_ERROR, NM_BT_ERROR_CONNECTION_NOT_BT,
		             "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,
		             NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID,
		             "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,
		             NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID,
		             "The connection did not contain a valid Bluetooth address.");
		return FALSE;
	}

	bt_type = get_connection_bt_type (connection);
	if (!(bt_type & priv->capabilities)) {
		g_set_error (error,
		             NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INCOMPATIBLE,
		             "The connection was not compatible with the device's capabilities.");
		return FALSE;
	}

	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 (priv->bdaddr, str);
	g_free (str);

	return addr_match;
}
コード例 #2
0
static void
get_property (GObject *object, guint prop_id,
              GValue *value, GParamSpec *pspec)
{
	NMSettingBluetooth *setting = NM_SETTING_BLUETOOTH (object);

	switch (prop_id) {
	case PROP_BDADDR:
		g_value_set_string (value, nm_setting_bluetooth_get_bdaddr (setting));
		break;
	case PROP_TYPE:
		g_value_set_string (value, nm_setting_bluetooth_get_connection_type (setting));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
コード例 #3
0
CEPage *
ce_page_bluetooth_new (NMConnectionEditor *editor,
                       NMConnection *connection,
                       GtkWindow *parent_window,
                       NMClient *client,
                       const char **out_secrets_setting_name,
                       GError **error)
{
	CEPageBluetooth *self;
	CEPageBluetoothPrivate *priv;

	self = CE_PAGE_BLUETOOTH (ce_page_new (CE_TYPE_PAGE_BLUETOOTH,
	                          editor,
	                          connection,
	                          parent_window,
	                          client,
	                          UIDIR "/ce-page-bluetooth.ui",
	                          "BluetoothPage",
	                          _("Bluetooth")));
	if (!self) {
		g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load Bluetooth user interface."));
		return NULL;
	}

	bluetooth_private_init (self);
	priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self);

	priv->setting = nm_connection_get_setting_bluetooth (connection);
	if (!priv->setting) {
		priv->setting = NM_SETTING_BLUETOOTH (nm_setting_bluetooth_new ());
		nm_connection_add_setting (connection, NM_SETTING (priv->setting));
	}

	g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);

	*out_secrets_setting_name = NM_SETTING_BLUETOOTH_SETTING_NAME;

	return CE_PAGE (self);
}
コード例 #4
0
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;
}