Beispiel #1
0
static void cmd_play(int argc, char *argv[])
{
	GDBusProxy *proxy;

	if (argc > 1) {
		proxy = g_dbus_proxy_lookup(items, NULL, argv[1],
						BLUEZ_MEDIA_ITEM_INTERFACE);
		if (proxy == NULL) {
			bt_shell_printf("Item %s not available\n", argv[1]);
			return bt_shell_noninteractive_quit(EXIT_FAILURE);
		}
	} else {
		if (!check_default_player())
			return bt_shell_noninteractive_quit(EXIT_FAILURE);
		proxy = default_player;
	}

	if (g_dbus_proxy_method_call(proxy, "Play", NULL, play_reply,
							NULL, NULL) == FALSE) {
		bt_shell_printf("Failed to play\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Attempting to play %s\n", argv[1] ? : "");
}
Beispiel #2
0
/**
* @brief Connect the modem associated to its connman network
*/
static int network_connect(struct connman_network *network)
{
	struct qmi_data *qmi = NULL;


	DBG("Network %p", network);

	qmi = connman_network_get_data(network);
	if(!qmi) {

		connman_error("Could not get device data.");
		return -ENODEV;
	}

	DBG("Network %p %p", network, qmi);
	/* Request connecting qmi network */
	g_dbus_proxy_method_call(	qmi->qmi_proxy_device,
								CONNECT_DEVICE,
								network_connect_append,
								network_connect_callback,
								qmi,
								NULL);

	return -EINPROGRESS;
}
Beispiel #3
0
/**
* @brief Disconnect the associated modem
*/
static int network_disconnect(struct connman_network *network)
{
	struct qmi_data *qmi = connman_network_get_data(network);

	DBG("Network %p %p", network, qmi);

	qmi = connman_network_get_data(network);
	if(!qmi) {

		connman_error("Could not get device data.");
		return -ENODEV;
	}

	DBG("Network %p %p", network, qmi);

	qmi->modem_connected = FALSE;
	if(qmi->network)
		connman_network_set_connected(qmi->network, FALSE);

	//FIXME Hack NAT enable by default
	__connman_nat_disable("qmi");

	g_assert(qmi->qmi_proxy_device);

	/* Request disconnect */
	g_dbus_proxy_method_call(	qmi->qmi_proxy_device,
								DISCONNECT_DEVICE,
								NULL,
								network_disconnect_callback,
								qmi,
								NULL);

	return 0;
}
Beispiel #4
0
void agent_register(DBusConnection *conn, GDBusProxy *manager,
						const char *capability)

{
	if (agent_registered == TRUE) {
		bt_shell_printf("Agent is already registered\n");
		return;
	}

	agent_capability = capability;

	if (g_dbus_register_interface(conn, AGENT_PATH,
					AGENT_INTERFACE, methods,
					NULL, NULL, NULL, NULL) == FALSE) {
		bt_shell_printf("Failed to register agent object\n");
		return;
	}

	if (g_dbus_proxy_method_call(manager, "RegisterAgent",
						register_agent_setup,
						register_agent_reply,
						conn, NULL) == FALSE) {
		bt_shell_printf("Failed to call register agent method\n");
		return;
	}

	agent_capability = NULL;
}
Beispiel #5
0
static void cmd_change_folder(int argc, char *argv[])
{
	GDBusProxy *proxy;

	if (dbus_validate_path(argv[1], NULL) == FALSE) {
		bt_shell_printf("Not a valid path\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	if (check_default_player() == FALSE)
		return bt_shell_noninteractive_quit(EXIT_FAILURE);

	proxy = g_dbus_proxy_lookup(folders, NULL,
					g_dbus_proxy_get_path(default_player),
					BLUEZ_MEDIA_FOLDER_INTERFACE);
	if (proxy == NULL) {
		bt_shell_printf("Operation not supported\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	if (g_dbus_proxy_method_call(proxy, "ChangeFolder", change_folder_setup,
				change_folder_reply, argv[1], NULL) == FALSE) {
		bt_shell_printf("Failed to change current folder\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Attempting to change folder\n");
}
Beispiel #6
0
static void cmd_search(int argc, char *argv[])
{
	GDBusProxy *proxy;
	char *string;

	if (check_default_player() == FALSE)
		return bt_shell_noninteractive_quit(EXIT_FAILURE);

	proxy = g_dbus_proxy_lookup(folders, NULL,
					g_dbus_proxy_get_path(default_player),
					BLUEZ_MEDIA_FOLDER_INTERFACE);
	if (proxy == NULL) {
		bt_shell_printf("Operation not supported\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	string = g_strdup(argv[1]);

	if (g_dbus_proxy_method_call(proxy, "Search", search_setup,
				search_reply, string, g_free) == FALSE) {
		bt_shell_printf("Failed to search\n");
		g_free(string);
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Attempting to search\n");
}
static connman_bool_t tethering_create(const char *path,
		struct connman_technology *technology, const char *bridge,
		connman_bool_t enabled)
{
	struct tethering_info *tethering = g_new0(struct tethering_info, 1);
	GDBusProxy *proxy;
	const char *method;
	connman_bool_t result;

	DBG("path %s bridge %s", path, bridge);

	if (bridge == NULL)
		return -EINVAL;

	proxy = g_dbus_proxy_new(client, path, "org.bluez.NetworkServer1");
	if (proxy == NULL)
		return FALSE;

	tethering->technology = technology;
	tethering->bridge = g_strdup(bridge);
	tethering->enable = enabled;

	if (tethering->enable)
		method = "Register";
	else
		method = "Unregister";

	result = g_dbus_proxy_method_call(proxy, method, tethering_append,
			tethering_create_cb, tethering, tethering_free);

	g_dbus_proxy_unref(proxy);

	return result;
}
Beispiel #8
0
void gatt_register_profile(DBusConnection *conn, GDBusProxy *proxy,
								wordexp_t *w)
{
	GList *l;

	l = g_list_find_custom(managers, proxy, match_proxy);
	if (!l) {
		rl_printf("Unable to find GattManager proxy\n");
		return;
	}

	if (g_dbus_register_interface(conn, PROFILE_PATH,
					PROFILE_INTERFACE, methods,
					NULL, NULL, NULL, NULL) == FALSE) {
		rl_printf("Failed to register profile object\n");
		return;
	}

	if (g_dbus_proxy_method_call(l->data, "RegisterProfile",
						register_profile_setup,
						register_profile_reply, w,
						NULL) == FALSE) {
		rl_printf("Failed register profile\n");
		return;
	}
}
static void register_app(GDBusProxy *proxy)
{
	if (!g_dbus_proxy_method_call(proxy, "RegisterApplication",
					register_app_setup, register_app_reply,
					NULL, NULL)) {
		printf("Unable to call RegisterApplication\n");
		return;
	}
}
Beispiel #10
0
static void read_attribute(GDBusProxy *proxy)
{
	if (g_dbus_proxy_method_call(proxy, "ReadValue", NULL, read_reply,
							NULL, NULL) == FALSE) {
		rl_printf("Failed to read\n");
		return;
	}

	rl_printf("Attempting to read %s\n", g_dbus_proxy_get_path(proxy));
}
Beispiel #11
0
static void cmd_list_items(int argc, char *argv[])
{
	GDBusProxy *proxy;
	struct list_items_args *args;

	if (check_default_player() == FALSE)
		return bt_shell_noninteractive_quit(EXIT_FAILURE);

	proxy = g_dbus_proxy_lookup(folders, NULL,
					g_dbus_proxy_get_path(default_player),
					BLUEZ_MEDIA_FOLDER_INTERFACE);
	if (proxy == NULL) {
		bt_shell_printf("Operation not supported\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	args = g_new0(struct list_items_args, 1);
	args->start = -1;
	args->end = -1;

	if (argc < 2)
		goto done;

	errno = 0;
	args->start = strtol(argv[1], NULL, 10);
	if (errno != 0) {
		bt_shell_printf("%s(%d)\n", strerror(errno), errno);
		g_free(args);
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	if (argc < 3)
		goto done;

	errno = 0;
	args->end = strtol(argv[2], NULL, 10);
	if (errno != 0) {
		bt_shell_printf("%s(%d)\n", strerror(errno), errno);
		g_free(args);
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

done:
	if (g_dbus_proxy_method_call(proxy, "ListItems", list_items_setup,
				list_items_reply, args, g_free) == FALSE) {
		bt_shell_printf("Failed to change current folder\n");
		g_free(args);
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Attempting to list items\n");
}
Beispiel #12
0
static void cmd_next(int argc, char *argv[])
{
	if (!check_default_player())
		return bt_shell_noninteractive_quit(EXIT_FAILURE);

	if (g_dbus_proxy_method_call(default_player, "Next", NULL, next_reply,
							NULL, NULL) == FALSE) {
		bt_shell_printf("Failed to jump to next\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Attempting to jump to next\n");
}
Beispiel #13
0
static void cmd_rewind(int argc, char *argv[])
{
	if (!check_default_player())
		return bt_shell_noninteractive_quit(EXIT_FAILURE);

	if (g_dbus_proxy_method_call(default_player, "Rewind", NULL,
					rewind_reply, NULL, NULL) == FALSE) {
		bt_shell_printf("Failed to rewind\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Rewind playback\n");
}
Beispiel #14
0
void ad_unregister(DBusConnection *conn, GDBusProxy *manager)
{
	if (!manager)
		ad_release(conn);

	if (!registered)
		return;

	if (g_dbus_proxy_method_call(manager, "UnregisterAdvertisement",
					unregister_setup, unregister_reply,
					conn, NULL) == FALSE) {
		rl_printf("Failed to unregister advertisement method\n");
		return;
	}
}
Beispiel #15
0
static void notify_attribute(GDBusProxy *proxy, bool enable)
{
	const char *method;

	if (enable == TRUE)
		method = "StartNotify";
	else
		method = "StopNotify";

	if (g_dbus_proxy_method_call(proxy, method, NULL, notify_reply,
				GUINT_TO_POINTER(enable), NULL) == FALSE) {
		rl_printf("Failed to %s notify\n", enable ? "start" : "stop");
		return;
	}
}
Beispiel #16
0
static void cmd_fast_forward(int argc, char *argv[])
{
	if (!check_default_player())
		return bt_shell_noninteractive_quit(EXIT_FAILURE);

	if (g_dbus_proxy_method_call(default_player, "FastForward", NULL,
				fast_forward_reply, NULL, NULL) == FALSE) {
		bt_shell_printf("Failed to jump to previous\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Fast forward playback\n");

	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
}
Beispiel #17
0
void agent_default(DBusConnection *conn, GDBusProxy *manager)
{
	if (agent_registered == FALSE) {
		bt_shell_printf("No agent is registered\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	if (g_dbus_proxy_method_call(manager, "RequestDefaultAgent",
						request_default_setup,
						request_default_reply,
						NULL, NULL) == FALSE) {
		bt_shell_printf("Failed to call RequestDefaultAgent method\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}
}
Beispiel #18
0
/**
* @brief Thread to init qmi devices
*
* Will be called to init a new connected qmi devices.
* Open Modem via qmi-dbus manager interface, get all currently available properties,
* set connman properties and finally add a new connman device.
*/
static void*
init_modems_thread(gpointer unused) {

	GHashTableIter iter;
	gpointer key, value;


	DBG("qmi hash %p", qmi_hash);

	if(qmi_hash == NULL) {

		return NULL;
	}

	/* Run as long as the qmi-dbus runs */
	while(qmi_service_connected) {

		g_hash_table_iter_init(&iter, qmi_hash);
		while(g_hash_table_iter_next(&iter, &key, &value) == TRUE) {

			/* Only connected devices should be in the hash table, hopefully */
			struct qmi_data *qmi = (struct qmi_data *)value;

			if( (qmi->modem_opened == TRUE) || 		/* Device already opened */
				(qmi->modem_opening == TRUE) ) {	/* Device trying to connect */

				continue;
			}

			DBG("Trying to open device %s", qmi->devpath);
			qmi->modem_opening = TRUE;
			g_dbus_proxy_method_call(	qmi_proxy_manager,
										OPEN_DEVICE,
										open_modem_append,
										open_modem_callback,
										value,
										NULL);

		}

		sem_wait(&new_device_sem);
	}
	DBG("Thread aborted");

	return NULL;

}
Beispiel #19
0
static int bluetooth_pan_disconnect(struct connman_network *network)
{
	struct bluetooth_pan *pan = connman_network_get_data(network);
	const char *path;

	DBG("network %p", network);

	if (!pan)
		return -EINVAL;

	path = g_dbus_proxy_get_path(pan->btnetwork_proxy);

	if (!g_dbus_proxy_method_call(pan->btnetwork_proxy, "Disconnect",
			NULL, pan_disconnect_cb, g_strdup(path), g_free))
		return -EIO;

       return -EINPROGRESS;
}
Beispiel #20
0
void gatt_unregister_profile(DBusConnection *conn, GDBusProxy *proxy)
{
	GList *l;

	l = g_list_find_custom(managers, proxy, match_proxy);
	if (!l) {
		rl_printf("Unable to find GattManager proxy\n");
		return;
	}

	if (g_dbus_proxy_method_call(l->data, "UnregisterProfile",
						unregister_profile_setup,
						unregister_profile_reply, conn,
						NULL) == FALSE) {
		rl_printf("Failed unregister profile\n");
		return;
	}
}
Beispiel #21
0
/**
* @brief Callback connecting network
*/
static void
network_connect_callback(DBusMessage *message, void *user_data) {

	struct qmi_data *qmi = (struct qmi_data *)user_data;

	DBG("qmi data %p DBusmessage %p", qmi, message);

	g_return_if_fail(qmi);

	if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
		const char *dbus_error = dbus_message_get_error_name(message);

		/*Failure during connecting */
		qmi->modem_connected = FALSE;
		if(qmi->network)
			connman_network_set_connected(qmi->network, FALSE);

		connman_error("%s", dbus_error);

		return;
	}

	/* Connected successfully */
	qmi->modem_connected = TRUE;
	connman_network_set_connected(qmi->network, TRUE);

	DBG("Device %s connected %d", qmi->devpath, qmi->modem_connected);

	g_assert(qmi->qmi_proxy_device);
	/* Request all available properties */
	g_dbus_proxy_method_call(	qmi->qmi_proxy_device,
								GET_PROPERTIES,
								NULL,
								get_properties_callback,
								qmi,
								NULL);

    //FIXME Hack NAT enable by default
    __connman_nat_enable("qmi", NULL, 0);


}
Beispiel #22
0
static void cmd_queue(int argc, char *argv[])
{
	GDBusProxy *proxy;

	proxy = g_dbus_proxy_lookup(items, NULL, argv[1],
						BLUEZ_MEDIA_ITEM_INTERFACE);
	if (proxy == NULL) {
		bt_shell_printf("Item %s not available\n", argv[1]);
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	if (g_dbus_proxy_method_call(proxy, "AddtoNowPlaying", NULL,
					add_to_nowplaying_reply, NULL,
					NULL) == FALSE) {
		bt_shell_printf("Failed to play\n");
		return bt_shell_noninteractive_quit(EXIT_FAILURE);
	}

	bt_shell_printf("Attempting to queue %s\n", argv[1]);
}
Beispiel #23
0
static int bluetooth_pan_connect(struct connman_network *network)
{
	struct bluetooth_pan *pan = connman_network_get_data(network);
	const char *path;

	DBG("network %p", network);

	if (!pan)
		return -EINVAL;

	path = g_dbus_proxy_get_path(pan->btnetwork_proxy);

	if (!g_dbus_proxy_method_call(pan->btnetwork_proxy, "Connect",
			pan_connect_append, pan_connect_cb,
			g_strdup(path), g_free))
		return -EIO;

	connman_network_set_associating(pan->network, true);

	return -EINPROGRESS;
}
Beispiel #24
0
void agent_unregister(DBusConnection *conn, GDBusProxy *manager)
{
	if (agent_registered == FALSE) {
		bt_shell_printf("No agent is registered\n");
		return;
	}

	if (!manager) {
		bt_shell_printf("Agent unregistered\n");
		agent_release(conn);
		return;
	}

	if (g_dbus_proxy_method_call(manager, "UnregisterAgent",
						unregister_agent_setup,
						unregister_agent_reply,
						conn, NULL) == FALSE) {
		bt_shell_printf("Failed to call unregister agent method\n");
		return;
	}
}
Beispiel #25
0
/**
* @brief Close a opened modem
*/
static void close_modem(gpointer key, gpointer value, gpointer user_data) {

	struct qmi_data *qmi = (struct qmi_data *)value;

	DBG("QMI data %p", qmi);

	g_return_if_fail(qmi);

	/* Only request closing modem if qmi-dbus runs */
	if(qmi_service_connected == FALSE)
		return;

	g_dbus_proxy_method_call(	qmi_proxy_manager,
								CLOSE_DEVICE,
								close_modem_append,
								close_modem_callback,
								qmi,
								NULL);


}
Beispiel #26
0
void ad_register(DBusConnection *conn, GDBusProxy *manager, const char *type)
{
	if (registered == TRUE) {
		rl_printf("Advertisement is already registered\n");
		return;
	}

	ad_type = g_strdup(type);

	if (g_dbus_register_interface(conn, AD_PATH, AD_IFACE, ad_methods,
					NULL, ad_props, NULL, NULL) == FALSE) {
		rl_printf("Failed to register advertising object\n");
		return;
	}

	if (g_dbus_proxy_method_call(manager, "RegisterAdvertisement",
					register_setup, register_reply,
					conn, NULL) == FALSE) {
		rl_printf("Failed to register advertising\n");
		return;
	}
}
Beispiel #27
0
static void write_attribute(GDBusProxy *proxy, char *arg)
{
	struct iovec iov;
	uint8_t value[512];
	char *entry;
	int i;

	for (i = 0; (entry = strsep(&arg, " \t")) != NULL; i++) {
		long int val;
		char *endptr = NULL;

		if (*entry == '\0')
			continue;

		if (i > 512) {
			rl_printf("Too much data\n");
			return;
		}

		val = strtol(entry, &endptr, 0);
		if (!endptr || *endptr != '\0' || val > UINT8_MAX) {
			rl_printf("Invalid value at index %d\n", i);
			return;
		}

		value[i] = val;
	}

	iov.iov_base = value;
	iov.iov_len = i;

	if (g_dbus_proxy_method_call(proxy, "WriteValue", write_setup,
					write_reply, &iov, NULL) == FALSE) {
		rl_printf("Failed to write\n");
		return;
	}

	rl_printf("Attempting to write %s\n", g_dbus_proxy_get_path(proxy));
}
Beispiel #28
0
static void connect_handler(DBusConnection *connection, void *user_data)
{
	GDBusClient *client = user_data;
	GDBusProxy *proxy;

	g_print("Bluetooth connected\n");

	proxy = g_dbus_proxy_new(client, "/org/bluez",
					"org.bluez.ProfileManager1");
	if (!proxy)
		return;

	g_dbus_register_interface(connection, IAP_PATH,
					"org.bluez.Profile1",
					methods, NULL, NULL, NULL, NULL);

	g_dbus_proxy_method_call(proxy, "RegisterProfile", 
					register_profile_setup,
					register_profile_reply, NULL, NULL);

	g_dbus_proxy_unref(proxy);
}
Beispiel #29
0
/**
* @brief Callback qmi device open modem
*/
static void
open_modem_callback(DBusMessage *message, void *user_data) {

	DBusMessageIter iter;
	struct qmi_data *qmi = (struct qmi_data *)user_data;
	gchar *help;

	DBG("qmi data %p DBusmessage %p", qmi, message);

	if(qmi == NULL) {

		connman_error("No QMI device");
		qmi->modem_opening = FALSE;
		return;
	}

	if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
		const char *dbus_error = dbus_message_get_error_name(message);

		connman_error("%s", dbus_error);
		qmi->modem_opening = FALSE;
		return;

	}

	if((dbus_message_iter_init(message, &iter) == TRUE) &&
			(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_OBJECT_PATH)) {

		dbus_message_iter_get_basic(&iter, &help);
		qmi->object_path = g_strdup(help);
	}
	else {

		connman_error("Return type invalid");
		qmi->modem_opening = FALSE;
		return;
	}

	DBG("Modem opened object path %s", qmi->object_path);

	if(!qmi->qmi_proxy_device) {

		qmi->qmi_proxy_device = g_dbus_proxy_new(	qmi_client,
												qmi->object_path,
												QMI_DEVICE_INTERFACE);
	}

	if(qmi->qmi_proxy_device == NULL) {

		connman_error("QMI proxy device not created");
		/* Just return, if failure we have a memory issue, then. */
		return;
	}

	g_dbus_proxy_method_call(	qmi->qmi_proxy_device,
								GET_PROPERTIES,
								NULL,
								open_modem_get_properties_callback,
								qmi,
								NULL);

}