linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: anderson.briglia@openbossa.org
To: linux-bluetooth@vger.kernel.org
Cc: Sheldon Demario <sheldon.demario@openbossa.org>
Subject: [RFC 2/7] Add read RSSI on hciops
Date: Wed, 15 Jun 2011 17:02:59 -0400	[thread overview]
Message-ID: <4df91d6b.0b73650a.190f.17a7@mx.google.com> (raw)
In-Reply-To: <1308171784-24442-1-git-send-email-y>

From: Sheldon Demario <sheldon.demario@openbossa.org>

Extend adapter_ops adding a function to read the RSSI of an active
connection asynchronously. This patch extends hciops only, mgmtops
requires kernel changes to become functional.
---
 plugins/hciops.c  |   39 +++++++++++++++++++++++++++++++++++++++
 plugins/mgmtops.c |   11 +++++++++++
 src/adapter.h     |    1 +
 src/event.c       |    8 ++++++++
 src/event.h       |    1 +
 5 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 93cf822..a9cfc25 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -1789,6 +1789,22 @@ static inline void read_txpower_complete(int index, void *ptr)
 	btd_event_txpower_read(&dev->bdaddr, &conn->bdaddr, rp->level);
 }
 
+static inline void read_rssi_complete(int index, void *ptr)
+{
+	struct dev_info *dev = &devs[index];
+	read_rssi_rp *rp = ptr;
+	struct bt_conn *conn;
+
+	if (rp->status)
+		return;
+
+	conn = find_conn_by_handle(dev, rp->handle);
+	if (conn == NULL)
+		return;
+
+	btd_event_rssi_read(&dev->bdaddr, &conn->bdaddr, rp->rssi);
+}
+
 static inline void cmd_complete(int index, void *ptr)
 {
 	struct dev_info *dev = &devs[index];
@@ -1863,6 +1879,9 @@ static inline void cmd_complete(int index, void *ptr)
 	case cmd_opcode_pack(OGF_HOST_CTL, OCF_READ_TRANSMIT_POWER_LEVEL):
 		ptr += sizeof(evt_cmd_complete);
 		read_txpower_complete(index, ptr);
+	case cmd_opcode_pack(OGF_STATUS_PARAM, OCF_READ_RSSI):
+		ptr += sizeof(evt_cmd_complete);
+		read_rssi_complete(index, ptr);
 		break;
 	};
 }
@@ -3178,6 +3197,25 @@ static int hciops_read_clock(int index, bdaddr_t *bdaddr, int which,
 	return 0;
 }
 
+static int hciops_read_rssi(int index, bdaddr_t *bdaddr)
+{
+	struct dev_info *dev = &devs[index];
+	uint16_t handle;
+	int err;
+
+	err = get_handle(index, bdaddr, &handle);
+	if (err < 0)
+		return err;
+
+	err = hci_send_cmd(dev->sk, OGF_STATUS_PARAM, OCF_READ_RSSI,
+						sizeof(handle), &handle);
+
+	if (err < 0 )
+		return -errno;
+
+	return 0;
+}
+
 static int hciops_read_tx_power(int index, bdaddr_t *bdaddr)
 {
 	struct dev_info *dev = &devs[index];
@@ -3706,6 +3744,7 @@ static struct btd_adapter_ops hci_ops = {
 	.set_dev_class = hciops_set_dev_class,
 	.set_fast_connectable = hciops_fast_connectable,
 	.read_clock = hciops_read_clock,
+	.read_rssi = hciops_read_rssi,
 	.read_tx_power = hciops_read_tx_power,
 	.read_bdaddr = hciops_read_bdaddr,
 	.block_device = hciops_block_device,
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 7ee86de..3be2607 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1673,6 +1673,16 @@ static int mgmt_read_clock(int index, bdaddr_t *bdaddr, int which, int timeout,
 	return -ENOSYS;
 }
 
+static int mgmt_read_rssi(int index, bdaddr_t *bdaddr)
+{
+	char addr[18];
+
+	ba2str(bdaddr, addr);
+	DBG("index %d addr %s", index, addr);
+
+	return -ENOSYS;
+}
+
 static int mgmt_read_tx_power(int index, bdaddr_t *bdaddr)
 {
 	char addr[18];
@@ -2026,6 +2036,7 @@ static struct btd_adapter_ops mgmt_ops = {
 	.set_dev_class = mgmt_set_dev_class,
 	.set_fast_connectable = mgmt_fast_connectable,
 	.read_clock = mgmt_read_clock,
+	.read_rssi = mgmt_read_rssi,
 	.read_tx_power = mgmt_read_tx_power,
 	.read_bdaddr = mgmt_read_bdaddr,
 	.block_device = mgmt_block_device,
diff --git a/src/adapter.h b/src/adapter.h
index 1fa7431..342530c 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -182,6 +182,7 @@ struct btd_adapter_ops {
 	int (*set_fast_connectable) (int index, gboolean enable);
 	int (*read_clock) (int index, bdaddr_t *bdaddr, int which, int timeout,
 					uint32_t *clock, uint16_t *accuracy);
+	int (*read_rssi) (int index, bdaddr_t *bdaddr);
 	int (*read_tx_power) (int index, bdaddr_t *bdaddr);
 	int (*read_bdaddr) (int index, bdaddr_t *bdaddr);
 	int (*block_device) (int index, bdaddr_t *bdaddr);
diff --git a/src/event.c b/src/event.c
index e6383e6..4c613a3 100644
--- a/src/event.c
+++ b/src/event.c
@@ -483,3 +483,11 @@ void btd_event_txpower_read(bdaddr_t *local, bdaddr_t *peer, int8_t level)
 	ba2str(peer, peer_addr);
 	DBG("%s TX Power: %d", peer_addr, level);
 }
+
+void btd_event_rssi_read(bdaddr_t *local, bdaddr_t *peer, int8_t rssi)
+{
+	char peer_addr[18];
+
+	ba2str(peer, peer_addr);
+	DBG("%s RSSI: %d", peer_addr, rssi);
+}
diff --git a/src/event.h b/src/event.h
index 011d933..e0148bb 100644
--- a/src/event.h
+++ b/src/event.h
@@ -41,3 +41,4 @@ int btd_event_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey);
 int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t *key,
 					uint8_t key_type, uint8_t pin_length);
 void btd_event_txpower_read(bdaddr_t *local, bdaddr_t *peer, int8_t level);
+void btd_event_rssi_read(bdaddr_t *local, bdaddr_t *peer, int8_t rssi);
-- 
1.7.4.1


  parent reply	other threads:[~2011-06-15 21:02 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 ` anderson.briglia [this message]
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 ` [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=4df91d6b.0b73650a.190f.17a7@mx.google.com \
    --to=anderson.briglia@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=sheldon.demario@openbossa.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).