From c989eff9b9a03c7e38e23a2be03ba5867aaeb021 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 24 Feb 2012 01:14:30 +0200 Subject: [PATCH] mgmtops: Cache dev_class update until UUID changes finish --- plugins/mgmtops.c | 64 ++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c index f049c644e..b985eab62 100644 --- a/plugins/mgmtops.c +++ b/plugins/mgmtops.c @@ -72,6 +72,10 @@ static struct controller_info { gboolean pending_uuid; GSList *pending_uuids; + + gboolean pending_class; + uint8_t major; + uint8_t minor; } *controllers = NULL; static int mgmt_sock = -1; @@ -1171,6 +1175,36 @@ static void read_local_oob_data_failed(int sk, uint16_t index) oob_read_local_data_complete(adapter, NULL, NULL); } +static int mgmt_set_dev_class(int index, uint8_t major, uint8_t minor) +{ + char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_set_dev_class)]; + struct mgmt_hdr *hdr = (void *) buf; + struct mgmt_cp_set_dev_class *cp = (void *) &buf[sizeof(*hdr)]; + struct controller_info *info = &controllers[index]; + + DBG("index %d major %u minor %u", index, major, minor); + + if (info->pending_uuid) { + info->major = major; + info->minor = minor; + info->pending_class = TRUE; + return 0; + } + + memset(buf, 0, sizeof(buf)); + hdr->opcode = htobs(MGMT_OP_SET_DEV_CLASS); + hdr->len = htobs(sizeof(*cp)); + hdr->index = htobs(index); + + cp->major = major; + cp->minor = minor; + + if (write(mgmt_sock, buf, sizeof(buf)) < 0) + return -errno; + + return 0; +} + static void mgmt_add_uuid_complete(int sk, uint16_t index, void *buf, size_t len) { @@ -1188,8 +1222,14 @@ static void mgmt_add_uuid_complete(int sk, uint16_t index, void *buf, info->pending_uuid = FALSE; - if (g_slist_length(info->pending_uuids) == 0) + if (g_slist_length(info->pending_uuids) == 0) { + if (info->pending_class) { + info->pending_class = FALSE; + mgmt_set_dev_class(index, info->major, info->minor); + } + return; + } pending = info->pending_uuids->data; @@ -1764,28 +1804,6 @@ static void mgmt_cleanup(void) } } -static int mgmt_set_dev_class(int index, uint8_t major, uint8_t minor) -{ - char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_set_dev_class)]; - struct mgmt_hdr *hdr = (void *) buf; - struct mgmt_cp_set_dev_class *cp = (void *) &buf[sizeof(*hdr)]; - - DBG("index %d major %u minor %u", index, major, minor); - - memset(buf, 0, sizeof(buf)); - hdr->opcode = htobs(MGMT_OP_SET_DEV_CLASS); - hdr->len = htobs(sizeof(*cp)); - hdr->index = htobs(index); - - cp->major = major; - cp->minor = minor; - - if (write(mgmt_sock, buf, sizeof(buf)) < 0) - return -errno; - - return 0; -} - static int mgmt_set_limited_discoverable(int index, gboolean limited) { DBG("index %d limited %d", index, limited); -- 2.47.3