Exemplo n.º 1
0
static void pan_create_nap(struct bluetooth_pan *pan)
{
	struct connman_device *device;
	const char* role;
	const char *adapter;

	role = proxy_get_role(pan->btdevice_proxy);
	if (!role) {
		pan_remove_nap(pan);
		return;
	}

	adapter = proxy_get_string(pan->btdevice_proxy, "Adapter");

	if (!adapter)
		return;

	device = g_hash_table_lookup(devices, adapter);

	if (!device || !connman_device_get_powered(device))
		return;

	if (!pan->network) {
		const char *address;
		char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
		const char *name, *path;

		address = proxy_get_string(pan->btdevice_proxy, "Address");
		if (!address) {
			connman_warn("Bluetooth device address missing");
			return;
		}

		address2ident(address, ident);

		pan->network = connman_network_create(ident,
				CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);

		name = proxy_get_string(pan->btdevice_proxy, "Alias");
		path = g_dbus_proxy_get_path(pan->btnetwork_proxy);

		DBG("network %p %s %s", pan->network, path, name);

		if (!pan->network) {
			connman_warn("Bluetooth network %s creation failed",
					path);
			return;
		}

		connman_network_set_data(pan->network, pan);
		connman_network_set_name(pan->network, name);
		connman_network_set_group(pan->network, ident);
	}

	pan->pan_role = role;
	connman_device_add_network(device, pan->network);

	if (pan_connect(pan, NULL))
		DBG("network %p already connected", pan->network);
}
Exemplo n.º 2
0
static bool pan_connect(struct bluetooth_pan *pan,
		const char *iface)
{
	int index;

	if (!iface) {
		if (!proxy_get_bool(pan->btnetwork_proxy, "Connected"))
			return false;
		iface = proxy_get_string(pan->btnetwork_proxy, "Interface");
	}

	if (!iface)
		return false;

	index = connman_inet_ifindex(iface);
	if (index < 0) {
		DBG("network %p invalid index %d", pan->network, index);
		return false;
	}

	connman_network_set_index(pan->network, index);
	connman_network_set_connected(pan->network, true);

	return true;
}
Exemplo n.º 3
0
static connman_bool_t pan_connect(struct bluetooth_pan *pan,
		const char *iface)
{
	int index;

	if (iface == NULL) {
		if (proxy_get_bool(pan->btnetwork_proxy, "Connected") == FALSE)
			return FALSE;
		iface = proxy_get_string(pan->btnetwork_proxy, "Interface");
	}

	if (iface == NULL)
		return FALSE;

	index = connman_inet_ifindex(iface);
	if (index < 0) {
		DBG("network %p invalid index %d", pan->network, index);
		return FALSE;
	}

	connman_network_set_index(pan->network, index);
	connman_network_set_connected(pan->network, TRUE);

	return TRUE;
}
Exemplo n.º 4
0
static void enable_device(struct connman_device *device, const char *path)
{
	GHashTableIter iter;
	gpointer key, value;

	DBG("device %p %s", device, path);
	connman_device_set_powered(device, true);

	g_hash_table_iter_init(&iter, networks);
	while (g_hash_table_iter_next(&iter, &key, &value)) {
		struct bluetooth_pan *pan = value;

		if (g_strcmp0(proxy_get_string(pan->btdevice_proxy, "Adapter"),
						path) == 0) {

			DBG("enable network %p", pan->network);
			pan_create_nap(pan);
		}
	}
}
Exemplo n.º 5
0
static void device_create(GDBusProxy *proxy)
{
	struct connman_device *device = NULL;
	const char *path = g_dbus_proxy_get_path(proxy);
	const char *address;
	char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
	bool powered;

	address = proxy_get_string(proxy, "Address");
	if (!address)
		return;

	address2ident(address, ident);

	device = connman_device_create("bluetooth",
			CONNMAN_DEVICE_TYPE_BLUETOOTH);
	if (!device)
		return;

	connman_device_set_data(device, g_dbus_proxy_ref(proxy));
	connman_device_set_ident(device, ident);

	g_hash_table_replace(devices, g_strdup(path), device);

	DBG("device %p %s device powered %d adapter powered %d", device,
			path, connman_device_get_powered(device),
			proxy_get_bool(proxy, "Powered"));

	if (connman_device_register(device) < 0) {
		g_hash_table_remove(devices, device);
		return;
	}

	g_dbus_proxy_set_property_watch(proxy, adapter_property_change, NULL);

	powered = proxy_get_bool(proxy, "Powered");
	connman_device_set_powered(device, powered);

	if (proxy_get_role(proxy) && !bluetooth_tethering)
		tethering_create(path, NULL, NULL, false);
}
Exemplo n.º 6
0
static void device_enable_cb(const DBusError *error, void *user_data)
{
	char *path = user_data;
	struct connman_device *device;
	GHashTableIter iter;
	gpointer key, value;

	device = g_hash_table_lookup(devices, path);
	if (device == NULL) {
		DBG("device already removed");
		goto out;
	}

	if (dbus_error_is_set(error) == TRUE) {
		connman_warn("Bluetooth device %s not enabled %s",
				path, error->message);
		goto out;
	}

	DBG("device %p %s", device, path);

	connman_device_set_powered(device, TRUE);

	g_hash_table_iter_init(&iter, networks);
	while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
		struct bluetooth_pan *pan = value;

		if (g_strcmp0(proxy_get_string(pan->btdevice_proxy, "Adapter"),
						path) == 0) {

			DBG("enable network %p", pan->network);
			pan_create_nap(pan);
		}
	}

out:
	g_free(path);
}