diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2010-12-11 23:57:55 +0200 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2010-12-12 00:04:17 +0200 |
commit | 24a34a8b1f8615ad79199efdb6fea479509464b4 (patch) | |
tree | 1bdb1fdfdd0c2bc466d559cbd398a9468d865d98 | |
parent | 9ee252fe7dec24d8906724b9189e28c24331005e (diff) | |
download | bluez-24a34a8b1f8615ad79199efdb6fea479509464b4.tar.gz |
Merge read_mode management command into read_info
The read_mode and read_info commands are issued only once in the
beginning for each adapter so it doesn't make sense to have the
information fetching split across two different commands. Instead all
necessary info can be fetched through the read_info command.
-rw-r--r-- | lib/mgmt.h | 19 | ||||
-rw-r--r-- | plugins/mgmtops.c | 80 |
2 files changed, 22 insertions, 77 deletions
diff --git a/lib/mgmt.h b/lib/mgmt.h index 80b4de58d..70cf4b6a1 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -53,10 +53,14 @@ struct mgmt_cp_read_info { uint16_t index; } __packed; struct mgmt_rp_read_info { - uint8_t status; uint16_t index; uint8_t type; + uint8_t powered; + uint8_t discoverable; + uint8_t pairable; + uint8_t sec_mode; bdaddr_t bdaddr; + uint8_t dev_class[3]; uint8_t features[8]; uint16_t manufacturer; uint8_t hci_ver; @@ -65,19 +69,6 @@ struct mgmt_rp_read_info { #define MGMT_OP_READ_STATISTICS 0x0005 -#define MGMT_OP_READ_MODE 0x0006 -struct mgmt_cp_read_mode { - uint16_t index; -} __packed; -struct mgmt_rp_read_mode { - uint8_t status; - uint16_t index; - uint8_t enabled; - uint8_t mode; -} __packed; - -#define MGMT_OP_WRITE_MODE 0x0007 - #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { uint16_t opcode; diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c index 6a7013fc9..69297db1e 100644 --- a/plugins/mgmtops.c +++ b/plugins/mgmtops.c @@ -55,11 +55,14 @@ static struct controller_info { uint8_t type; bdaddr_t bdaddr; uint8_t features[8]; + uint8_t dev_class[3]; uint16_t manufacturer; uint8_t hci_ver; uint16_t hci_rev; gboolean enabled; - uint8_t mode; + gboolean discoverable; + gboolean pairable; + uint8_t sec_mode; } *controllers = NULL; static int mgmt_sock = -1; @@ -168,23 +171,6 @@ static void mgmt_index_removed(int sk, void *buf, size_t len) remove_controller(index); } -static void read_mode(int sk, uint16_t index) -{ - char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_read_mode)]; - struct mgmt_hdr *hdr = (void *) buf; - struct mgmt_cp_read_mode *cp = (void *) &buf[sizeof(*hdr)]; - - memset(buf, 0, sizeof(buf)); - hdr->opcode = MGMT_OP_READ_MODE; - hdr->len = htobs(sizeof(*cp)); - - cp->index = htobs(index); - - if (write(sk, buf, sizeof(buf)) < 0) - error("Unable to send read_mode command: %s (%d)", - strerror(errno), errno); -} - static void read_index_list_complete(int sk, void *buf, size_t len) { struct mgmt_rp_read_index_list *rp = buf; @@ -225,12 +211,6 @@ static void read_info_complete(int sk, void *buf, size_t len) return; } - if (rp->status != 0) { - error("Reading controller info failed: %s (%u)", - strerror(rp->status), rp->status); - return; - } - index = btohs(bt_get_unaligned(&rp->index)); if (index > max_index) { error("Unexpected index %u in read info complete", index); @@ -239,49 +219,26 @@ static void read_info_complete(int sk, void *buf, size_t len) info = &controllers[index]; info->type = rp->type; + info->enabled = rp->powered; + info->discoverable = rp->discoverable; + info->pairable = rp->pairable; + info->sec_mode = rp->sec_mode; bacpy(&info->bdaddr, &rp->bdaddr); + memcpy(info->dev_class, rp->dev_class, 3); memcpy(info->features, rp->features, 8); info->manufacturer = btohs(bt_get_unaligned(&rp->manufacturer)); info->hci_ver = rp->hci_ver; info->hci_rev = btohs(bt_get_unaligned(&rp->hci_rev)); ba2str(&info->bdaddr, addr); - DBG("hci%u addr %s type %u manufacturer %d hci ver %d:%d", - index, addr, info->type, info->manufacturer, - info->hci_ver, info->hci_rev); - - read_mode(sk, index); -} - -static void read_mode_complete(int sk, void *buf, size_t len) -{ - struct mgmt_rp_read_mode *rp = buf; - struct controller_info *info; - uint16_t index; - - if (len < sizeof(*rp)) { - error("Too small read mode complete event (%zu != %zu)", - len, sizeof(*rp)); - return; - } - - if (rp->status != 0) { - error("Reading controller mode failed: %s (%u)", - strerror(rp->status), rp->status); - return; - } - - index = btohs(bt_get_unaligned(&rp->index)); - if (index > max_index) { - error("Unexpected index %u in read mode complete", index); - return; - } - - info = &controllers[index]; - info->enabled = rp->enabled ? TRUE : FALSE; - info->mode = rp->mode; - - DBG("hci%u enabled %u mode %u", index, info->enabled, info->mode); + DBG("hci%u type %u addr %s", index, info->type, addr); + DBG("hci%u class 0x%02x%02x%02x", index, + info->dev_class[2], info->dev_class[1], info->dev_class[0]); + DBG("hci%u manufacturer %d HCI ver %d:%d", index, info->manufacturer, + info->hci_ver, info->hci_rev); + DBG("hci%u enabled %u discoverable %u pairable %u sec_mode %u", index, + info->enabled, info->discoverable, + info->pairable, info->sec_mode); manager_register_adapter(index, info->enabled); @@ -313,9 +270,6 @@ static void mgmt_cmd_complete(int sk, void *buf, size_t len) case MGMT_OP_READ_INFO: read_info_complete(sk, ev->data, len - sizeof(*ev)); break; - case MGMT_OP_READ_MODE: - read_mode_complete(sk, ev->data, len - sizeof(*ev)); - break; default: error("Unknown command complete for opcode %u", opcode); break; |