From: anderson.briglia@openbossa.org
To: linux-bluetooth@vger.kernel.org
Cc: Bruna Moreira <bruna.moreira@openbossa.org>
Subject: [RFC 6/7] Implement mgmt_read_tx_power command
Date: Wed, 15 Jun 2011 17:03:03 -0400 [thread overview]
Message-ID: <4df91d72.0b73650a.190f.17ab@mx.google.com> (raw)
In-Reply-To: <1308171784-24442-1-git-send-email-y>
From: Bruna Moreira <bruna.moreira@openbossa.org>
This patch implements a new command to read the TX power of an active
connection asynchronously in the 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 038b18d..57f22d8 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -215,6 +215,16 @@ struct mgmt_rp_read_rssi {
int8_t rssi;
} __packed;
+#define MGMT_OP_READ_TX_POWER_LEVEL 0x001E
+struct mgmt_cp_read_tx_power_level {
+ bdaddr_t bdaddr;
+} __packed;
+struct mgmt_rp_read_tx_power_level {
+ uint8_t status;
+ bdaddr_t bdaddr;
+ int8_t level;
+} __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 074435c..bf702ea 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1065,6 +1065,36 @@ static void set_local_name_complete(int sk, uint16_t index, void *buf,
adapter_update_local_name(adapter, (char *) rp->name);
}
+static void read_tx_power_complete(int sk, uint16_t index, void *buf, size_t len)
+{
+ struct mgmt_rp_read_tx_power_level *rp = buf;
+ struct controller_info *info;
+ char addr[18];
+
+ if (len < sizeof(*rp)) {
+ error("Too small tx power complete event");
+ return;
+ }
+
+ if (index > max_index) {
+ error("Unexpected index %u in read tx power complete", index);
+ return;
+ }
+
+ if (rp->status) {
+ DBG("TX power read error %01x", rp->status);
+ return;
+ }
+
+ ba2str(&rp->bdaddr, addr);
+
+ DBG("hci%d addr=%s level=%d", index, addr, rp->level);
+
+ info = &controllers[index];
+
+ btd_event_txpower_read(&info->bdaddr, &rp->bdaddr, rp->level);
+}
+
static void read_local_oob_data_complete(int sk, uint16_t index, void *buf,
size_t len)
{
@@ -1222,6 +1252,9 @@ static void mgmt_cmd_complete(int sk, uint16_t index, void *buf, size_t len)
case MGMT_OP_SET_LOCAL_NAME:
set_local_name_complete(sk, index, ev->data, len);
break;
+ case MGMT_OP_READ_TX_POWER_LEVEL:
+ read_tx_power_complete(sk, index, ev->data, len);
+ break;
case MGMT_OP_READ_LOCAL_OOB_DATA:
read_local_oob_data_complete(sk, index, ev->data, len);
break;
@@ -1727,12 +1760,21 @@ static int mgmt_read_rssi(int index, bdaddr_t *bdaddr)
static int mgmt_read_tx_power(int index, bdaddr_t *bdaddr)
{
- char addr[18];
+ char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_read_tx_power_level)];
+ struct mgmt_hdr *hdr = (void *) buf;
+ struct mgmt_cp_read_tx_power_level *cp = (void *) &buf[sizeof(*hdr)];
- ba2str(bdaddr, addr);
- DBG("index %d addr %s read transmit power level", index, addr);
+ memset(buf, 0, sizeof(buf));
+ hdr->opcode = htobs(MGMT_OP_READ_TX_POWER_LEVEL);
+ 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_bdaddr(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 ` [RFC 5/7] Implement mgmt_read_rssi command anderson.briglia
2011-06-15 21:03 ` anderson.briglia [this message]
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=4df91d72.0b73650a.190f.17ab@mx.google.com \
--to=anderson.briglia@openbossa.org \
--cc=bruna.moreira@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).