static void cancel_gatt_req(void *data, void *user_data)
{
	unsigned int id = PTR_TO_UINT(data);
	struct bt_scpp *scan = user_data;

	g_attrib_cancel(scan->attrib, id);
}
Example #2
0
static void get_report(struct uhid_event *ev, void *user_data)
{
	struct hog_device *hogdev = user_data;
	struct report *report;
	guint8 err;

	/* uhid never sends reqs in parallel; if there's a req, it timed out */
	if (hogdev->getrep_att) {
		g_attrib_cancel(hogdev->attrib, hogdev->getrep_att);
		hogdev->getrep_att = 0;
	}

	hogdev->getrep_id = ev->u.get_report.id;

	report = find_report(hogdev, ev->u.get_report.rtype,
							ev->u.get_report.rnum);
	if (!report) {
		err = ENOTSUP;
		goto fail;
	}

	hogdev->getrep_att = gatt_read_char(hogdev->attrib,
						report->decl->value_handle,
						get_report_cb, hogdev);
	if (!hogdev->getrep_att) {
		err = ENOMEM;
		goto fail;
	}

	return;

fail:
	/* cancel the request on failure */
	get_report_cb(err, NULL, 0, hogdev);
}
Example #3
0
static void set_report(struct uhid_event *ev, void *user_data)
{
	struct hog_device *hogdev = user_data;
	struct report *report;
	void *data;
	int size;
	int err;

	/* uhid never sends reqs in parallel; if there's a req, it timed out */
	if (hogdev->setrep_att) {
		g_attrib_cancel(hogdev->attrib, hogdev->setrep_att);
		hogdev->setrep_att = 0;
	}

	hogdev->setrep_id = ev->u.set_report.id;

	report = find_report(hogdev, ev->u.set_report.rtype,
							ev->u.set_report.rnum);
	if (!report) {
		err = ENOTSUP;
		goto fail;
	}

	data = ev->u.set_report.data;
	size = ev->u.set_report.size;
	if (hogdev->has_report_id && size > 0) {
		data++;
		--size;
	}

	DBG("Sending report type %d ID %d to handle 0x%X", report->type,
				report->id, report->decl->value_handle);

	if (hogdev->attrib == NULL)
		return;

	hogdev->setrep_att = gatt_write_char(hogdev->attrib,
						report->decl->value_handle,
						data, size, set_report_cb,
						hogdev);
	if (!hogdev->setrep_att) {
		err = ENOMEM;
		goto fail;
	}

	return;
fail:
	/* cancel the request on failure */
	set_report_cb(err, NULL, 0, hogdev);
}
static void discover_desc(struct bt_scpp *scpp, GAttrib *attrib,
				uint16_t start, uint16_t end, bt_uuid_t *uuid,
				gatt_cb_t func, gpointer user_data)
{
	unsigned int id;

	id = gatt_discover_desc(attrib, start, end, uuid, func, user_data);

	if (queue_push_head(scpp->gatt_op, UINT_TO_PTR(id)))
		return;

	error("scpp: Could not discover descriptor");
	g_attrib_cancel(attrib, id);
}
static void write_char(struct bt_scpp *scan, GAttrib *attrib, uint16_t handle,
					const uint8_t *value, size_t vlen,
					GAttribResultFunc func,
					gpointer user_data)
{
	unsigned int id;

	id = gatt_write_char(attrib, handle, value, vlen, func, user_data);

	if (queue_push_head(scan->gatt_op, UINT_TO_PTR(id)))
		return;

	error("scpp: Could not read char");
	g_attrib_cancel(attrib, id);
}
Example #6
0
static void discover_desc(struct bt_scpp *scpp, GAttrib *attrib,
				uint16_t start, uint16_t end, bt_uuid_t *uuid,
				gatt_cb_t func, gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(scpp, user_data);
	if (!req)
		return;

	id = gatt_discover_desc(attrib, start, end, uuid, func, req);
	if (set_and_store_gatt_req(scpp, req, id))
		return;

	error("scpp: Could not discover descriptor");
	g_attrib_cancel(attrib, id);
	free(req);
}
Example #7
0
static void read_char(struct bt_dis *dis, GAttrib *attrib, uint16_t handle,
				GAttribResultFunc func, gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(dis, user_data);
	if (!req)
		return;

	id = gatt_read_char(attrib, handle, func, req);

	if (set_and_store_gatt_req(dis, req, id))
		return;

	error("dis: Could not read characteristic");
	g_attrib_cancel(attrib, id);
	free(req);
}
Example #8
0
static void write_char(struct bt_scpp *scan, GAttrib *attrib, uint16_t handle,
					const uint8_t *value, size_t vlen,
					GAttribResultFunc func,
					gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(scan, user_data);
	if (!req)
		return;

	id = gatt_write_char(attrib, handle, value, vlen, func, req);

	if (set_and_store_gatt_req(scan, req, id))
		return;

	error("scpp: Could not read char");
	g_attrib_cancel(attrib, id);
	free(req);
}
Example #9
0
static void discover_char(struct bt_dis *dis, GAttrib *attrib,
						uint16_t start, uint16_t end,
						bt_uuid_t *uuid, gatt_cb_t func,
						gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(dis, user_data);
	if (!req)
		return;

	id = gatt_discover_char(attrib, start, end, uuid, func, req);

	if (set_and_store_gatt_req(dis, req, id))
		return;

	error("dis: Could not send discover characteristic");
	g_attrib_cancel(attrib, id);
	free(req);
}
Example #10
0
static void cancel_gatt_req(struct gatt_request *req)
{
	if (g_attrib_cancel(req->bas->attrib, req->id))
		destroy_gatt_req(req);
}