diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index daf39a7..f8ec19c 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
}
}
+static uint8_t chan_get_transaction(struct avctp_channel *chan)
+{
+ GSList *l, *tmp;
+ uint8_t transaction;
+
+ if (!chan->processed)
+ goto done;
+
+ tmp = g_slist_copy(chan->processed);
+
+ /* Find first unused transaction id */
+ for (l = tmp; l; l = g_slist_next(l)) {
+ struct avctp_pending_req *req = l->data;
+
+ if (req->transaction == chan->transaction) {
+ chan->transaction++;
+ chan->transaction %= 16;
+ tmp = g_slist_delete_link(tmp, l);
+ l = tmp;
+ }
+ }
+
+ g_slist_free(tmp);
+
+done:
+ transaction = chan->transaction;
+
+ chan->transaction++;
+ chan->transaction %= 16;
+
+ return transaction;
+}
+
static int avctp_send(struct avctp_channel *control, uint8_t transaction,
uint8_t cr, uint8_t code,
uint8_t subunit, uint8_t opcode,
avctp = (void *) control->buffer;
avc = (void *) avctp + sizeof(*avctp);
+ if (transaction > 16)
+ transaction = chan_get_transaction(control);
+
avctp->transaction = transaction;
avctp->packet_type = AVCTP_PACKET_SINGLE;
avctp->cr = cr;
GDestroyNotify destroy)
{
struct avctp_pending_req *p;
- GSList *l, *tmp;
-
- if (!chan->processed)
- goto done;
-
- tmp = g_slist_copy(chan->processed);
-
- /* Find first unused transaction id */
- for (l = tmp; l; l = g_slist_next(l)) {
- struct avctp_pending_req *req = l->data;
-
- if (req->transaction == chan->transaction) {
- chan->transaction++;
- chan->transaction %= 16;
- tmp = g_slist_delete_link(tmp, l);
- l = tmp;
- }
- }
- g_slist_free(tmp);
-
-done:
p = g_new0(struct avctp_pending_req, 1);
p->chan = chan;
- p->transaction = chan->transaction;
+ p->transaction = chan_get_transaction(chan);
p->process = process;
p->data = data;
p->destroy = destroy;
- chan->transaction++;
- chan->transaction %= 16;
-
return p;
}
if (control == NULL)
return -ENOTCONN;
+ /* If the request set a callback send it directly */
+ if (!func)
+ return avctp_send(session->control, -1, AVCTP_COMMAND,
+ code, subunit, opcode, operands, operand_count);
+
req = g_new0(struct avctp_control_req, 1);
req->code = code;
req->subunit = subunit;