From: anderson.briglia@openbossa.org
To: linux-bluetooth@vger.kernel.org
Cc: Anderson Briglia <anderson.briglia@openbossa.org>
Subject: [RFC 5/7] Implement mgmt_read_rssi command
Date: Wed, 15 Jun 2011 17:03:02 -0400 [thread overview]
Message-ID: <4df91d70.0b73650a.190f.17aa@mx.google.com> (raw)
In-Reply-To: <1308171784-24442-1-git-send-email-y>
From: Anderson Briglia <anderson.briglia@openbossa.org>
This patch implements Read RSSI command in management interface.
---
lib/mgmt.h | 10 ++++++++++
plugins/mgmtops.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/lib/mgmt.h b/lib/mgmt.h
index 57e7603..038b18d 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -205,6 +205,16 @@ struct mgmt_cp_remove_remote_oob_data {
#define MGMT_OP_STOP_DISCOVERY 0x001C
+#define MGMT_OP_READ_RSSI 0x001D
+struct mgmt_cp_read_rssi {
+ bdaddr_t bdaddr;
+} __packed;
+struct mgmt_rp_read_rssi {
+ uint8_t status;
+ bdaddr_t bdaddr;
+ int8_t rssi;
+} __packed;
+
#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 3be2607..074435c 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1108,6 +1108,36 @@ static void read_local_oob_data_failed(int sk, uint16_t index)
oob_read_local_data_complete(adapter, NULL, NULL);
}
+static void read_rssi_complete(int sk, uint16_t index, void *buf, size_t len)
+{
+ struct mgmt_rp_read_rssi *rp = buf;
+ struct controller_info *info;
+ char addr[18];
+
+ if (len != sizeof(*rp)) {
+ error("Wrong read_rssi_complete event size");
+ return;
+ }
+
+ if (rp->status) {
+ DBG("Read rssi cmd error %01x", rp->status);
+ return;
+ }
+
+ ba2str(&rp->bdaddr, addr);
+
+ DBG("hci%d %s rssi %d", index, addr, rp->rssi);
+
+ if (index > max_index) {
+ error("Unexpected index %u in read_rssi complete", index);
+ return;
+ }
+
+ info = &controllers[index];
+
+ btd_event_rssi_read(&info->bdaddr, &rp->bdaddr, rp->rssi);
+}
+
static void mgmt_cmd_complete(int sk, uint16_t index, void *buf, size_t len)
{
struct mgmt_ev_cmd_complete *ev = buf;
@@ -1201,6 +1231,9 @@ static void mgmt_cmd_complete(int sk, uint16_t index, void *buf, size_t len)
case MGMT_OP_REMOVE_REMOTE_OOB_DATA:
DBG("remove_remote_oob_data complete");
break;
+ case MGMT_OP_READ_RSSI:
+ read_rssi_complete(sk, index, ev->data, len);
+ break;
default:
error("Unknown command complete for opcode %u", opcode);
break;
@@ -1675,12 +1708,21 @@ static int mgmt_read_clock(int index, bdaddr_t *bdaddr, int which, int timeout,
static int mgmt_read_rssi(int index, bdaddr_t *bdaddr)
{
- char addr[18];
+ char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_read_rssi)];
+ struct mgmt_hdr *hdr = (void *) buf;
+ struct mgmt_cp_read_rssi *cp = (void *) &buf[sizeof(*hdr)];
- ba2str(bdaddr, addr);
- DBG("index %d addr %s", index, addr);
+ memset(buf, 0, sizeof(buf));
+ hdr->opcode = htobs(MGMT_OP_READ_RSSI);
+ hdr->len = htobs(sizeof(*cp));
+ hdr->index = htobs(index);
- return -ENOSYS;
+ bacpy(&cp->bdaddr, bdaddr);
+
+ if (write(mgmt_sock, buf, sizeof(buf)) < 0)
+ return -errno;
+
+ return 0;
}
static int mgmt_read_tx_power(int index, bdaddr_t *bdaddr)
--
1.7.4.1
next prev parent reply other threads:[~2011-06-15 21:03 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1308171784-24442-1-git-send-email-y>
2011-06-15 21:02 ` [RFC 1/7] Add current tx power read on hciops anderson.briglia
2011-06-15 21:02 ` [RFC 2/7] Add read RSSI " anderson.briglia
2011-06-15 21:03 ` [RFC 3/7] Add RSSI read callbacks anderson.briglia
2011-06-15 21:03 ` [RFC 4/7] Add transmission power callbacks anderson.briglia
2011-06-15 21:03 ` anderson.briglia [this message]
2011-06-15 21:03 ` [RFC 6/7] Implement mgmt_read_tx_power command anderson.briglia
2011-06-15 21:03 ` [RFC 7/7] Update Management API documentation anderson.briglia
2011-06-15 22:10 ` Marcel Holtmann
2011-06-15 23:47 ` Anderson Lizardo
2011-06-16 2:29 ` Marcel Holtmann
2011-06-16 6:07 ` Ganir, Chen
2011-06-16 7:54 ` Luiz Augusto von Dentz
2011-06-16 12:35 ` Claudio Takahasi
2011-06-16 14:47 ` Marcel Holtmann
2011-06-16 15:12 ` Claudio Takahasi
2011-06-16 16:08 ` Marcel Holtmann
2011-06-16 20:45 ` Gustavo F. Padovan
2011-06-20 15:47 ` Anderson Briglia
2011-06-20 16:47 ` Marcel Holtmann
2011-06-16 13:49 ` Anderson Lizardo
2011-06-16 14:08 ` Johan Hedberg
2011-06-16 14:17 ` Anderson Lizardo
2011-06-16 7:15 ` GATT and GATT based Profiles architecture - Query Ajay Pillai
2011-06-16 14:04 ` Anderson Lizardo
2011-06-17 9:30 ` Ajay Pillai
2011-06-17 12:10 ` Anderson Lizardo
2011-06-17 12:22 ` Santiago Carot
2011-06-17 12:39 ` Anderson Lizardo
2011-06-17 12:53 ` Santiago Carot
2011-06-20 8:42 ` Ajay Pillai
2011-06-16 6:03 ` [RFC 7/7] Update Management API documentation Ganir, Chen
2011-06-16 13:44 ` Anderson Lizardo
2011-06-16 14:19 ` Ganir, Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4df91d70.0b73650a.190f.17aa@mx.google.com \
--to=anderson.briglia@openbossa.org \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).