Exemple #1
0
static DBusMessage *register_agent(DBusConnection *conn,
					DBusMessage *msg, void *user_data)
{
	struct agent *agent;
	const char *sender, *path, *capability;
	uint8_t cap;

	sender = dbus_message_get_sender(msg);

	agent = g_hash_table_lookup(agent_list, sender);
	if (agent)
		return btd_error_already_exists(msg);

	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
						DBUS_TYPE_STRING, &capability,
						DBUS_TYPE_INVALID) == FALSE)
		return btd_error_invalid_args(msg);

	cap = parse_io_capability(capability);
	if (cap == IO_CAPABILITY_INVALID)
		return btd_error_invalid_args(msg);

	agent = agent_create(sender, path, cap);
	if (!agent)
		return btd_error_invalid_args(msg);

	DBG("agent %s", agent->owner);

	g_hash_table_replace(agent_list, agent->owner, agent);

	return dbus_message_new_method_return(msg);
}
Exemple #2
0
static DBusMessage *register_player(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	struct media_adapter *adapter = data;
	struct media_player *mp;
	DBusMessageIter args;
	const char *sender, *path;
	int err;

	sender = dbus_message_get_sender(msg);

	dbus_message_iter_init(msg, &args);

	dbus_message_iter_get_basic(&args, &path);
	dbus_message_iter_next(&args);

	if (media_adapter_find_player(adapter, sender, path) != NULL)
		return btd_error_already_exists(msg);

	mp = media_player_create(adapter, sender, path, &err);
	if (mp == NULL) {
		if (err == -EPROTONOSUPPORT)
			return btd_error_not_supported(msg);
		else
			return btd_error_invalid_args(msg);
	}

	if (parse_player_properties(mp, &args) == FALSE) {
		media_player_destroy(mp);
		return btd_error_invalid_args(msg);
	}

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Exemple #3
0
static DBusMessage *update_xml_record(DBusMessage *msg,
					struct service_adapter *serv_adapter)
{
	struct record_data *user_record;
	sdp_record_t *sdp_record;
	const char *record;
	dbus_uint32_t handle;
	int len;

	if (dbus_message_get_args(msg, NULL,
				DBUS_TYPE_UINT32, &handle,
				DBUS_TYPE_STRING, &record,
				DBUS_TYPE_INVALID) == FALSE)
		return btd_error_invalid_args(msg);

	len = (record ? strlen(record) : 0);
	if (len == 0)
		return btd_error_invalid_args(msg);

	user_record = find_record(serv_adapter, handle,
				dbus_message_get_sender(msg));
	if (!user_record)
		return btd_error_not_available(msg);

	sdp_record = sdp_xml_parse_record(record, len);
	if (!sdp_record) {
		error("Parsing of XML service record failed");
		return btd_error_failed(msg,
					"Parsing of XML service record failed");
	}

	return update_record(msg, serv_adapter, handle, sdp_record);
}
Exemple #4
0
static DBusMessage *input_device_set_report(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	DBusMessageIter iter;
	uint32_t rpt_type;
	const gchar *rpt;

	struct input_device *idev = data;
	tDTUN_DEVICE_METHOD method;

	if (!dbus_message_iter_init(msg, &iter))
		return btd_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
		return btd_error_invalid_args(msg);
	dbus_message_iter_get_basic(&iter, &rpt_type);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return btd_error_invalid_args(msg);
	dbus_message_iter_get_basic(&iter, &rpt);

	method.hh_set_rpt.hdr.id = DTUN_METHOD_HH_SET_RPT;
	method.hh_set_rpt.hdr.len = sizeof(tDTUN_METHOD_HH_SET_RPT) - sizeof(tDTUN_HDR);
	memcpy(&method.hh_set_rpt.bdaddr, &idev->dst, 6);
	method.hh_set_rpt.r_type = (uint8_t) rpt_type;
	strncpy(method.hh_set_rpt.data, rpt, 1023);
	method.hh_set_rpt.data[1023] = '\0';

	dtun_client_call_method(&method);
	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
static DBusMessage *add_remote_data(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct btd_adapter *adapter = data;
	uint8_t *hash, *randomizer;
	int32_t hlen, rlen;
	const char *addr;
	bdaddr_t bdaddr;

	if (!dbus_message_get_args(msg, NULL,
			DBUS_TYPE_STRING, &addr,
			DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &hash, &hlen,
			DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &randomizer, &rlen,
			DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	if (hlen != 16 || rlen != 16 || bachk(addr))
		return btd_error_invalid_args(msg);

	str2ba(addr, &bdaddr);

	if (btd_adapter_add_remote_oob_data(adapter, &bdaddr, hash, randomizer))
		return btd_error_failed(msg, "Request failed");

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Exemple #6
0
static DBusMessage *input_device_send_data(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	DBusMessageIter iter;
	const gchar *send_data;

	struct input_device *idev = data;
	tDTUN_DEVICE_METHOD method;

	if (!dbus_message_iter_init(msg, &iter))
		return btd_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return btd_error_invalid_args(msg);
	dbus_message_iter_get_basic(&iter, &send_data);

	method.hh_send_data.hdr.id = DTUN_METHOD_HH_SEND_DATA;
	method.hh_send_data.hdr.len = sizeof(tDTUN_METHOD_HH_SEND_DATA) - sizeof(tDTUN_HDR);
	memcpy(&method.hh_send_data.bdaddr, &idev->dst, 6);
	strncpy(method.hh_send_data.data, send_data, 1023);
	method.hh_send_data.data[1023] = '\0';

	dtun_client_call_method(&method);
	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
static DBusMessage *unregister_advertisement(DBusConnection *conn,
						DBusMessage *msg,
						void *user_data)
{
	struct btd_advertising *manager = user_data;
	DBusMessageIter args;
	struct advertisement *ad;
	struct dbus_obj_match match;

	DBG("UnregisterAdvertisement");

	if (!dbus_message_iter_init(msg, &args))
		return btd_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
		return btd_error_invalid_args(msg);

	dbus_message_iter_get_basic(&args, &match.path);

	match.owner = dbus_message_get_sender(msg);

	ad = queue_find(manager->ads, match_advertisement, &match);
	if (!ad)
		return btd_error_does_not_exist(msg);

	advertisement_remove(ad);

	return dbus_message_new_method_return(msg);
}
Exemple #8
0
static DBusMessage *media_folder_change_folder(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	struct media_player *mp = data;
	struct media_folder *folder = mp->scope;
	struct player_callback *cb = mp->cb;
	const char *path;
	int err;

	if (!dbus_message_get_args(msg, NULL,
					DBUS_TYPE_OBJECT_PATH, &path,
					DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	if (folder->msg != NULL)
		return btd_error_failed(msg, strerror(EBUSY));

	folder = media_player_find_folder(mp, path);
	if (folder == NULL)
		return btd_error_invalid_args(msg);

	if (mp->scope == folder)
		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);

	if (folder == mp->playlist || folder == mp->folder ||
						folder == mp->search) {
		media_player_change_scope(mp, folder);
		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
	}

	/*
	 * ChangePath can only navigate one level up/down so check if folder
	 * is direct child or parent of the current folder otherwise fail.
	 */
	if (!g_slist_find(mp->folder->subfolders, folder) &&
				!g_slist_find(folder->subfolders, mp->folder))
		return btd_error_invalid_args(msg);

	if (cb->cbs->change_folder == NULL)
		return btd_error_not_supported(msg);

	err = cb->cbs->change_folder(mp, folder->item->name, folder->item->uid,
								cb->user_data);
	if (err < 0)
		return btd_error_failed(msg, strerror(-err));

	mp->scope->msg = dbus_message_ref(msg);

	return NULL;
}
static DBusMessage *register_advertisement(DBusConnection *conn,
						DBusMessage *msg,
						void *user_data)
{
	struct btd_advertising *manager = user_data;
	DBusMessageIter args;
	struct advertisement *ad;
	struct dbus_obj_match match;
	uint8_t instance;

	DBG("RegisterAdvertisement");

	if (!dbus_message_iter_init(msg, &args))
		return btd_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
		return btd_error_invalid_args(msg);

	dbus_message_iter_get_basic(&args, &match.path);

	match.owner = dbus_message_get_sender(msg);

	if (queue_find(manager->ads, match_advertisement, &match))
		return btd_error_already_exists(msg);

	instance = util_get_uid(&manager->instance_bitmap, manager->max_ads);
	if (!instance)
		return btd_error_failed(msg, "Maximum advertisements reached");

	dbus_message_iter_next(&args);

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY)
		return btd_error_invalid_args(msg);

	ad = advertisement_create(conn, msg, match.path);
	if (!ad)
		return btd_error_failed(msg,
					"Failed to register advertisement");

	DBG("Registered advertisement at path %s", match.path);

	ad->instance = instance;
	ad->manager = manager;

	queue_push_tail(manager->ads, ad);

	return NULL;
}
Exemple #10
0
static DBusMessage *media_folder_list_items(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	struct media_player *mp = data;
	struct media_folder *folder = mp->scope;
	struct player_callback *cb = mp->cb;
	DBusMessageIter iter;
	uint32_t start, end;
	int err;

	dbus_message_iter_init(msg, &iter);

	if (parse_filters(mp, &iter, &start, &end) < 0)
		return btd_error_invalid_args(msg);

	if (cb->cbs->list_items == NULL)
		return btd_error_not_supported(msg);

	if (folder->msg != NULL)
		return btd_error_failed(msg, strerror(EBUSY));

	err = cb->cbs->list_items(mp, folder->item->name, start, end,
							cb->user_data);
	if (err < 0)
		return btd_error_failed(msg, strerror(-err));

	folder->msg = dbus_message_ref(msg);

	return NULL;
}
Exemple #11
0
static DBusMessage *media_folder_search(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct media_player *mp = data;
	struct media_folder *folder = mp->scope;
	struct player_callback *cb = mp->cb;
	DBusMessageIter iter;
	const char *string;
	int err;

	dbus_message_iter_init(msg, &iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return btd_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &string);

	if (!mp->searchable || folder != mp->folder || !cb->cbs->search)
		return btd_error_not_supported(msg);

	if (folder->msg != NULL)
		return btd_error_failed(msg, strerror(EINVAL));

	err = cb->cbs->search(mp, string, cb->user_data);
	if (err < 0)
		return btd_error_failed(msg, strerror(-err));

	folder->msg = dbus_message_ref(msg);

	return NULL;
}
Exemple #12
0
static DBusMessage *unregister_agent(DBusConnection *conn,
					DBusMessage *msg, void *user_data)
{
	struct agent *agent;
	const char *sender, *path;

	sender = dbus_message_get_sender(msg);

	agent = g_hash_table_lookup(agent_list, sender);
	if (!agent)
		return btd_error_does_not_exist(msg);

	DBG("agent %s", agent->owner);

	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
						DBUS_TYPE_INVALID) == FALSE)
		return btd_error_invalid_args(msg);

	if (g_str_equal(path, agent->path) == FALSE)
		return btd_error_does_not_exist(msg);

	agent_disconnect(conn, agent);

	return dbus_message_new_method_return(msg);
}
Exemple #13
0
static DBusMessage *unregister_agent(DBusConnection *conn,
				DBusMessage *msg, void *data)
{
	struct audio_device *device = data;
	struct gateway *gw = device->gateway;
	const char *path;

	if (!gw->agent)
		goto done;

	if (strcmp(gw->agent->name, dbus_message_get_sender(msg)) != 0)
		return btd_error_not_authorized(msg);

	if (!dbus_message_get_args(msg, NULL,
				DBUS_TYPE_OBJECT_PATH, &path,
				DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	if (strcmp(gw->agent->path, path) != 0)
		return btd_error_does_not_exist(msg);

	g_dbus_remove_watch(conn, gw->agent->watch);

	agent_free(gw->agent);
	gw->agent = NULL;

done:
	return dbus_message_new_method_return(msg);
}
Exemple #14
0
static DBusMessage *register_agent(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct audio_device *device = data;
	struct gateway *gw = device->gateway;
	struct hf_agent *agent;
	const char *path, *name;

	if (gw->agent)
		return btd_error_already_exists(msg);

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
						DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	name = dbus_message_get_sender(msg);
	agent = g_new0(struct hf_agent, 1);

	agent->name = g_strdup(name);
	agent->path = g_strdup(path);

	agent->watch = g_dbus_add_disconnect_watch(conn, name,
						agent_exited, gw, NULL);

	gw->agent = agent;

	return dbus_message_new_method_return(msg);
}
static void controlpoint_method_reply(struct controlpoint_req *req,
								uint8_t code)
{
	DBusMessage *reply;

	switch (code) {
	case RSP_SUCCESS:
		reply = dbus_message_new_method_return(req->msg);
		break;
	case RSP_NOT_SUPPORTED:
		reply = btd_error_not_supported(req->msg);
		break;
	case RSP_INVALID_PARAM:
		reply = btd_error_invalid_args(req->msg);
		break;
	case RSP_FAILED:
		reply = btd_error_failed(req->msg, "Failed");
		break;
	default:
		reply = btd_error_failed(req->msg, "Unknown error");
		break;
	}

	g_dbus_send_message(btd_get_dbus_connection(), reply);

	dbus_message_unref(req->msg);
}
Exemple #16
0
static DBusMessage *add_service_record(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct service_adapter *serv_adapter = data;
	DBusMessage *reply;
	const char *sender, *record;
	dbus_uint32_t handle;
	int err;

	if (dbus_message_get_args(msg, NULL,
			DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE)
		return btd_error_invalid_args(msg);

	sender = dbus_message_get_sender(msg);
	err = add_xml_record(sender, serv_adapter, record, &handle);
	if (err < 0)
		return btd_error_failed(msg, strerror(-err));

	reply = dbus_message_new_method_return(msg);
	if (!reply)
		return NULL;

	dbus_message_append_args(reply, DBUS_TYPE_UINT32, &handle,
							DBUS_TYPE_INVALID);

	return reply;
}
Exemple #17
0
static DBusMessage *notify_unread_alert(DBusConnection *conn, DBusMessage *msg,
                                        void *data)
{
    uint32_t category_id = 0;
    uint8_t category_id_bit;
    uint8_t unread_count;

    if (!dbus_message_get_args(msg, NULL,
                               DBUS_TYPE_BYTE, &category_id,
                               DBUS_TYPE_BYTE, &unread_count,
                               DBUS_TYPE_INVALID)) {
        error("Invalid arguments");
        return NULL;
    }

    category_id_bit = 1 << category_id;
    if (!(supp_unread_alerts & category_id_bit)) {
        error("Unsupported catergory ID");
        return btd_error_invalid_args(msg);
    }

    unread_alerts[category_id].category_id = category_id;
    unread_alerts[category_id].unread_count = unread_count;

    DBG("Updated category %d", category_id);

    g_slist_foreach(alert_adapters, __notify_new_alert,
                    (gpointer)category_id);

    return dbus_message_new_method_return(msg);
}
Exemple #18
0
static DBusMessage *unregister_watcher(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct heartrate_adapter *hradapter = data;
	struct watcher *watcher;
	const char *sender = dbus_message_get_sender(msg);
	char *path;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
							DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	watcher = find_watcher(hradapter->watchers, sender, path);
	if (watcher == NULL)
		return btd_error_does_not_exist(msg);

	hradapter->watchers = g_slist_remove(hradapter->watchers, watcher);
	g_dbus_remove_watch(conn, watcher->id);

	if (g_slist_length(hradapter->watchers) == 0)
		g_slist_foreach(hradapter->devices, disable_measurement, 0);

	DBG("heartrate watcher [%s] unregistered", path);

	return dbus_message_new_method_return(msg);
}
static DBusMessage *set_cumulative_wheel_rev(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	struct csc *csc = data;
	dbus_uint32_t value;
	struct controlpoint_req *req;
	uint8_t att_val[5]; /* uint8 opcode + uint32 value */

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &value,
							DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	if (csc->pending_req != NULL)
		return btd_error_in_progress(msg);

	req = g_new(struct controlpoint_req, 1);
	req->csc = csc;
	req->opcode = SET_CUMULATIVE_VALUE;
	req->msg = dbus_message_ref(msg);

	csc->pending_req = req;

	att_val[0] = SET_CUMULATIVE_VALUE;
	put_le32(value, att_val + 1);

	gatt_write_char(csc->attrib, csc->controlpoint_val_handle, att_val,
		sizeof(att_val), controlpoint_write_cb, req);

	return NULL;
}
Exemple #20
0
static DBusMessage *unregister_server(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct network_adapter *na = data;
	struct network_server *ns;
	DBusMessage *reply;
	const char *uuid;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &uuid,
							DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	ns = find_server_by_uuid(na->servers, uuid);
	if (!ns)
		return btd_error_failed(msg, "Invalid UUID");

	reply = dbus_message_new_method_return(msg);
	if (!reply)
		return NULL;

	g_dbus_remove_watch(conn, ns->watch_id);

	server_disconnect(conn, ns);

	return reply;
}
Exemple #21
0
static DBusMessage *register_watcher(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct heartrate_adapter *hradapter = data;
	struct watcher *watcher;
	const char *sender = dbus_message_get_sender(msg);
	char *path;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
							DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	watcher = find_watcher(hradapter->watchers, sender, path);
	if (watcher != NULL)
		return btd_error_already_exists(msg);

	watcher = g_new0(struct watcher, 1);
	watcher->hradapter = hradapter;
	watcher->id = g_dbus_add_disconnect_watch(conn, sender, watcher_exit_cb,
						watcher, destroy_watcher);
	watcher->srv = g_strdup(sender);
	watcher->path = g_strdup(path);

	if (g_slist_length(hradapter->watchers) == 0)
		g_slist_foreach(hradapter->devices, enable_measurement, 0);

	hradapter->watchers = g_slist_prepend(hradapter->watchers, watcher);

	DBG("heartrate watcher [%s] registered", path);

	return dbus_message_new_method_return(msg);
}
Exemple #22
0
static DBusMessage *set_link_loss_alert(DBusConnection *conn, DBusMessage *msg,
						const char *level, void *data)
{
	struct monitor *monitor = data;
	struct btd_device *device = monitor->device;
	bdaddr_t sba, dba;

	if (!level_is_valid(level))
		return btd_error_invalid_args(msg);

	if (g_strcmp0(monitor->linklosslevel, level) == 0)
		return dbus_message_new_method_return(msg);

	g_free(monitor->linklosslevel);
	monitor->linklosslevel = g_strdup(level);

	adapter_get_address(device_get_adapter(device), &sba);
	device_get_address(device, &dba);

	write_proximity_config(&sba, &dba, "LinkLossAlertLevel", level);

	if (monitor->attrib)
		write_alert_level(monitor);

	return dbus_message_new_method_return(msg);
}
Exemple #23
0
static DBusMessage *set_value(DBusConnection *conn, DBusMessage *msg,
			DBusMessageIter *iter, struct characteristic *chr)
{
	struct gatt_service *gatt = chr->gatt;
	DBusMessageIter sub;
	uint8_t *value;
	int len;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY ||
			dbus_message_iter_get_element_type(iter) != DBUS_TYPE_BYTE)
		return btd_error_invalid_args(msg);

	dbus_message_iter_recurse(iter, &sub);

	dbus_message_iter_get_fixed_array(&sub, &value, &len);

	characteristic_set_value(chr, value, len);

	if (gatt->attioid == 0)
		gatt->attioid = btd_device_add_attio_callback(gatt->dev,
							attio_connected,
							attio_disconnected,
							gatt);

	if (gatt->attrib)
		gatt_write_cmd(gatt->attrib, chr->handle, value, len,
								NULL, NULL);
	else
		gatt->offline_chars = g_slist_append(gatt->offline_chars, chr);

	return dbus_message_new_method_return(msg);
}
Exemple #24
0
static DBusMessage *unregister_watcher(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	const char *sender = dbus_message_get_sender(msg);
	struct gatt_service *gatt = data;
	struct watcher *watcher, *match;
	GSList *l;
	char *path;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
							DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	match = g_new0(struct watcher, 1);
	match->name = g_strdup(sender);
	match->path = g_strdup(path);
	l = g_slist_find_custom(gatt->watchers, match, watcher_cmp);
	INFO("unregistering watcher %s",match->path);
	watcher_free(match);
	if (!l)
		return btd_error_not_authorized(msg);


	watcher = l->data;
	g_dbus_remove_watch(conn, watcher->id);
	gatt->watchers = g_slist_remove(gatt->watchers, watcher);
	watcher_free(watcher);

	if (gatt->watchers == NULL && gatt->attioid) {
		btd_device_remove_attio_callback(gatt->dev, gatt->attioid);
		gatt->attioid = 0;
	}

	return dbus_message_new_method_return(msg);
}
Exemple #25
0
static DBusMessage *register_watcher(DBusConnection *conn,
						DBusMessage *msg, void *data)
{
	const char *sender = dbus_message_get_sender(msg);
	struct gatt_service *gatt = data;
	struct watcher *watcher;
	char *path;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
							DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	watcher = g_new0(struct watcher, 1);
	watcher->name = g_strdup(sender);
	watcher->gatt = gatt;
	watcher->path = g_strdup(path);
	watcher->id = g_dbus_add_disconnect_watch(conn, sender, watcher_exit,
							watcher, watcher_free);

	INFO("registering watcher on %s",watcher->path);
	if (gatt->attioid == 0) {
		gatt->attioid = btd_device_add_attio_callback(gatt->dev,
							attio_connected,
							attio_disconnected,
							gatt);
	}
	gatt->watchers = g_slist_append(gatt->watchers, watcher);

	return dbus_message_new_method_return(msg);
}
Exemple #26
0
static DBusMessage *unread_alert(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	const char *sender = dbus_message_get_sender(msg);
	struct alert_data *alert;
	const char *category;
	unsigned int i;
	uint16_t count;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &category,
						DBUS_TYPE_UINT16, &count,
						DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	alert = get_alert_data_by_category(category);
	if (!alert) {
		DBG("Category %s not registered", category);
		return btd_error_invalid_args(msg);
	}

	if (!valid_count(category, count)) {
		DBG("Count %d is invalid for %s category", count, category);
		return btd_error_invalid_args(msg);
	}

	if (!g_str_equal(alert->srv, sender)) {
		DBG("Sender %s is not registered in category %s", sender,
								category);
		return btd_error_invalid_args(msg);
	}

	for (i = 0; i < G_N_ELEMENTS(anp_categories); i++) {
		if (g_str_equal(anp_categories[i], category)) {
			uint8_t value[2];

			value[0] = i; /* Category ID */
			value[1] = count; /* Unread count */

			g_slist_foreach(alert_adapters, update_unread_alert,
									value);
		}
	}

	DBG("category %s, count %d", category, count);

	return dbus_message_new_method_return(msg);
}
Exemple #27
0
static DBusMessage *register_alert(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	const char *sender = dbus_message_get_sender(msg);
	char *path;
	const char *category;
	const char *c;
	struct alert_data *alert;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &c,
			DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	category = valid_category(c);
	if (!category) {
		DBG("Invalid category: %s", c);
		return btd_error_invalid_args(msg);
	}

	if (registered_category(category)) {
		DBG("Category %s already registered", category);
		return dbus_message_new_method_return(msg);
	}

	alert = g_new0(struct alert_data, 1);
	alert->srv = g_strdup(sender);
	alert->path = g_strdup(path);
	alert->category = category;
	alert->watcher = g_dbus_add_disconnect_watch(conn, alert->srv,
					watcher_disconnect, alert, NULL);

	if (alert->watcher == 0) {
		alert_data_destroy(alert);
		DBG("Could not register disconnect watcher");
		return btd_error_failed(msg,
				"Could not register disconnect watcher");
	}

	registered_alerts = g_slist_append(registered_alerts, alert);

	g_slist_foreach(alert_adapters, update_supported_categories, NULL);

	DBG("RegisterAlert(\"%s\", \"%s\")", alert->category, alert->path);

	return dbus_message_new_method_return(msg);
}
static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
								void *data)
{
	struct media_transport *transport = data;
	DBusMessageIter iter;
	DBusMessageIter value;
	const char *property, *sender;
	GSList *l;
	int err;

	if (!dbus_message_iter_init(msg, &iter))
		return btd_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return btd_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &property);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return btd_error_invalid_args(msg);
	dbus_message_iter_recurse(&iter, &value);

	sender = dbus_message_get_sender(msg);
	err = -EINVAL;

	/* Check if sender has acquired the transport */
	for (l = transport->owners; l; l = l->next) {
		struct media_owner *owner = l->data;

		if (g_strcmp0(owner->name, sender) == 0) {
			err = transport->set_property(transport, property,
								&value);
			break;
		}
	}

	if (err < 0) {
		if (err == -EINVAL)
			return btd_error_invalid_args(msg);
		return btd_error_failed(msg, strerror(-err));
	}

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Exemple #29
0
static DBusMessage *signal_strength(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	dbus_uint32_t strength;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &strength,
						DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	if (strength > 5)
		return btd_error_invalid_args(msg);

	telephony_update_indicator(dummy_indicators, "signal", strength);

	DBG("telephony-dummy: signal strength set to %u", strength);

	return dbus_message_new_method_return(msg);
}
Exemple #30
0
static DBusMessage *battery_level(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	dbus_uint32_t level;

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &level,
						DBUS_TYPE_INVALID))
		return btd_error_invalid_args(msg);

	if (level > 5)
		return btd_error_invalid_args(msg);

	telephony_update_indicator(dummy_indicators, "battchg", level);

	DBG("telephony-dummy: battery level set to %u", level);

	return dbus_message_new_method_return(msg);
}