From: Szymon Janc <szymon.janc@gmail.com>
To: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 3/4] android/gatt: Add support to read connection RSSI
Date: Fri, 16 May 2014 19:42:01 +0200 [thread overview]
Message-ID: <1769707.WSk76j6M5p@athlon> (raw)
In-Reply-To: <1400253554-31574-3-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
Prefix should be android/bluetooth:
On Friday 16 May 2014 17:19:13 Andrzej Kaczmarek wrote:
> ---
> android/bluetooth.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> android/bluetooth.h | 5 +++++
> 2 files changed, 55 insertions(+)
>
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 1e760d4..ee33676 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -3033,6 +3033,56 @@ bool bt_le_discovery_start(bt_le_device_found cb)
> return false;
> }
>
> +struct read_rssi_user_data {
> + bt_read_device_rssi_done cb;
> + void *user_data;
> +};
> +
> +static void read_device_rssi_cb(uint8_t status, uint16_t length,
> + const void *param, void *user_data)
> +{
> + const struct mgmt_rp_get_conn_info *rp = param;
> + struct read_rssi_user_data *data = user_data;
> +
> + DBG("");
> +
> + if (status)
> + error("Failed to get conn info: %s (0x%02x))",
> + mgmt_errstr(status), status);
> +
> + data->cb(status, &rp->addr.bdaddr, rp->rssi, data->user_data);
This will crash if kernel doesn't support this command.
Since we will add dependency on required mgmt version eventually, I think it
should be enough to bail out if size doesn't match.
if (length < sizeof(*rp)) {
error("Wrong size of get connection info response");
return;
}
> +}
> +
> +bool bt_read_device_rssi(const bdaddr_t *addr, bt_read_device_rssi_done cb,
> + void *user_data)
> +{
> + struct device *dev;
> + struct read_rssi_user_data *data;
> + struct mgmt_cp_get_conn_info cp;
> +
> + /* type is used only as fallback when device is not in cache */
> + dev = get_device(addr, BDADDR_BREDR);
I think we can use find_dev() and fail if none is found, it should be
connected after in first place.
> +
> + memcpy(&cp.addr.bdaddr, addr, sizeof(cp.addr.bdaddr));
> + cp.addr.type = dev->bredr ? BDADDR_BREDR : dev->bdaddr_type;
> +
> + data = new0(struct read_rssi_user_data, 1);
> + if (!data)
> + return false;
> +
> + data->cb = cb;
> + data->user_data = user_data;
> +
> + if (!mgmt_send(mgmt_if, MGMT_OP_GET_CONN_INFO, adapter.index,
> + sizeof(cp), &cp, read_device_rssi_cb, data, free)) {
> + free(data);
> + error("Failed to get conn info");
> + return false;
> + }
> +
> + return true;
> +}
> +
> static uint8_t set_adapter_scan_mode(const void *buf, uint16_t len)
> {
> const uint8_t *mode = buf;
> diff --git a/android/bluetooth.h b/android/bluetooth.h
> index 3eef7a4..6a3e766 100644
> --- a/android/bluetooth.h
> +++ b/android/bluetooth.h
> @@ -50,3 +50,8 @@ bool bt_le_set_advertising(bool advertising,
> bt_le_set_advertising_done cb, uint8_t bt_get_device_android_type(const
> bdaddr_t *addr);
> const char *bt_get_adapter_name(void);
> bool bt_device_is_bonded(const bdaddr_t *bdaddr);
> +
> +typedef void (*bt_read_device_rssi_done)(uint8_t status, const bdaddr_t
> *addr, + int8_t rssi, void *user_data);
> +bool bt_read_device_rssi(const bdaddr_t *addr, bt_read_device_rssi_done cb,
> + void *user_data);
--
Szymon K. Janc
szymon.janc@gmail.com
next prev parent reply other threads:[~2014-05-16 17:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 15:19 [PATCH 1/4] lib: Add definitions for Get Connection Information command Andrzej Kaczmarek
2014-05-16 15:19 ` [PATCH 2/4] tools: Add conn-info to btmgmt Andrzej Kaczmarek
2014-05-16 15:19 ` [PATCH 3/4] android/gatt: Add support to read connection RSSI Andrzej Kaczmarek
2014-05-16 17:42 ` Szymon Janc [this message]
2014-05-16 15:19 ` [PATCH 4/4] android/gatt: Add proper read_remote_rssi implementation Andrzej Kaczmarek
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=1769707.WSk76j6M5p@athlon \
--to=szymon.janc@gmail.com \
--cc=andrzej.kaczmarek@tieto.com \
--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).