linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@gmail.com>
To: Szymon Janc <szymon.janc@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v2 1/7] android/bluetooth: Add helper for finding device with android address
Date: Tue, 24 Jun 2014 22:45:29 +0200	[thread overview]
Message-ID: <1850993.QsL8CxT3Rs@athlon> (raw)
In-Reply-To: <1403533714-5188-1-git-send-email-szymon.janc@tieto.com>

On Monday 23 June 2014 16:28:28 Szymon Janc wrote:
> ---
>  android/bluetooth.c | 67
> ++++++++++++++++++++++++++++++----------------------- 1 file changed, 38
> insertions(+), 29 deletions(-)
> 
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index fc5d529..d42fe8c 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -477,6 +477,24 @@ static struct device *get_device(const bdaddr_t
> *bdaddr, uint8_t type) return dev;
>  }
> 
> +static struct device *find_device_android(const uint8_t *addr)
> +{
> +	bdaddr_t bdaddr;
> +
> +	android2bdaddr(addr, &bdaddr);
> +
> +	return find_device(&bdaddr);
> +}
> +
> +static struct device *get_device_android(const uint8_t *addr)
> +{
> +	bdaddr_t bdaddr;
> +
> +	android2bdaddr(addr, &bdaddr);
> +
> +	return get_device(&bdaddr, BDADDR_BREDR);
> +}
> +
>  static  void send_adapter_property(uint8_t type, uint16_t len, const void
> *val) {
>  	uint8_t buf[BASELEN_PROP_CHANGED + len];
> @@ -3865,13 +3883,11 @@ static void handle_create_bond_cmd(const void *buf,
> uint16_t len) uint8_t status;
>  	struct mgmt_cp_pair_device cp;
> 
> -	cp.io_cap = DEFAULT_IO_CAPABILITY;
> -	android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
> -
> -	/* type is used only as fallback when device is not in cache */
> -	dev = get_device(&cp.addr.bdaddr, BDADDR_BREDR);
> +	dev = get_device_android(cmd->bdaddr);
> 
> +	cp.io_cap = DEFAULT_IO_CAPABILITY;
>  	cp.addr.type = select_device_bearer(dev);
> +	bacpy(&cp.addr.bdaddr, &dev->bdaddr);
> 
>  	if (device_is_paired(dev, cp.addr.type)) {
>  		status = HAL_STATUS_FAILED;
> @@ -3901,15 +3917,14 @@ static void handle_cancel_bond_cmd(const void *buf,
> uint16_t len) struct device *dev;
>  	uint8_t status;
> 
> -	android2bdaddr(cmd->bdaddr, &cp.bdaddr);
> -
> -	dev = find_device(&cp.bdaddr);
> +	dev = find_device_android(cmd->bdaddr);
>  	if (!dev) {
>  		status = HAL_STATUS_FAILED;
>  		goto failed;
>  	}
> 
>  	cp.type = select_device_bearer(dev);
> +	bacpy(&cp.bdaddr, &dev->bdaddr);
> 
>  	if (mgmt_reply(mgmt_if, MGMT_OP_CANCEL_PAIR_DEVICE,
>  					adapter.index, sizeof(cp), &cp,
> @@ -3951,15 +3966,15 @@ static void handle_remove_bond_cmd(const void *buf,
> uint16_t len) struct device *dev;
>  	uint8_t status;
> 
> -	cp.disconnect = 1;
> -	android2bdaddr(cmd->bdaddr, &cp.addr.bdaddr);
> -
> -	dev = find_device(&cp.addr.bdaddr);
> +	dev = find_device_android(cmd->bdaddr);
>  	if (!dev) {
>  		status = HAL_STATUS_FAILED;
>  		goto failed;
>  	}
> 
> +	cp.disconnect = 1;
> +	bacpy(&cp.addr.bdaddr, &dev->bdaddr);
> +
>  	if (dev->le_paired) {
>  		cp.addr.type = dev->bdaddr_type;
> 
> @@ -4098,24 +4113,27 @@ static uint8_t user_passkey_reply(const bdaddr_t
> *bdaddr, bool accept, static void handle_ssp_reply_cmd(const void *buf,
> uint16_t len)
>  {
>  	const struct hal_cmd_ssp_reply *cmd = buf;
> -	bdaddr_t bdaddr;
> +	struct device *dev;
>  	uint8_t status;
>  	char addr[18];
> 
>  	/* TODO should parameters sanity be verified here? */
> 
> -	android2bdaddr(cmd->bdaddr, &bdaddr);
> -	ba2str(&bdaddr, addr);
> +	dev = find_device_android(cmd->bdaddr);
> +	if (!dev)
> +		return;
> +
> +	ba2str(&dev->bdaddr, addr);
> 
>  	DBG("%s variant %u accept %u", addr, cmd->ssp_variant, cmd->accept);
> 
>  	switch (cmd->ssp_variant) {
>  	case HAL_SSP_VARIANT_CONFIRM:
>  	case HAL_SSP_VARIANT_CONSENT:
> -		status = user_confirm_reply(&bdaddr, cmd->accept);
> +		status = user_confirm_reply(&dev->bdaddr, cmd->accept);
>  		break;
>  	case HAL_SSP_VARIANT_ENTRY:
> -		status = user_passkey_reply(&bdaddr, cmd->accept,
> +		status = user_passkey_reply(&dev->bdaddr, cmd->accept,
>  								cmd->passkey);
>  		break;
>  	case HAL_SSP_VARIANT_NOTIF:
> @@ -4355,11 +4373,8 @@ static void handle_get_remote_device_props_cmd(const
> void *buf, uint16_t len) const struct hal_cmd_get_remote_device_props *cmd
> = buf;
>  	struct device *dev;
>  	uint8_t status;
> -	bdaddr_t addr;
> -
> -	android2bdaddr(cmd->bdaddr, &addr);
> 
> -	dev = find_device(&addr);
> +	dev = find_device_android(cmd->bdaddr);
>  	if (!dev) {
>  		status = HAL_STATUS_INVALID;
>  		goto failed;
> @@ -4379,11 +4394,8 @@ static void handle_get_remote_device_prop_cmd(const
> void *buf, uint16_t len) const struct hal_cmd_get_remote_device_prop *cmd =
> buf;
>  	struct device *dev;
>  	uint8_t status;
> -	bdaddr_t addr;
> -
> -	android2bdaddr(cmd->bdaddr, &addr);
> 
> -	dev = find_device(&addr);
> +	dev = find_device_android(cmd->bdaddr);
>  	if (!dev) {
>  		status = HAL_STATUS_INVALID;
>  		goto failed;
> @@ -4461,7 +4473,6 @@ static void handle_set_remote_device_prop_cmd(const
> void *buf, uint16_t len) const struct hal_cmd_set_remote_device_prop *cmd =
> buf;
>  	struct device *dev;
>  	uint8_t status;
> -	bdaddr_t addr;
> 
>  	if (len != sizeof(*cmd) + cmd->len) {
>  		error("Invalid set remote device prop cmd (0x%x), terminating",
> @@ -4470,9 +4481,7 @@ static void handle_set_remote_device_prop_cmd(const
> void *buf, uint16_t len) return;
>  	}
> 
> -	android2bdaddr(cmd->bdaddr, &addr);
> -
> -	dev = find_device(&addr);
> +	dev = find_device_android(cmd->bdaddr);
>  	if (!dev) {
>  		status = HAL_STATUS_INVALID;
>  		goto failed;

Applied.

-- 
Szymon K. Janc
szymon.janc@gmail.com

      parent reply	other threads:[~2014-06-24 20:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-23 14:28 [PATCH v2 1/7] android/bluetooth: Add helper for finding device with android address Szymon Janc
2014-06-23 14:28 ` [PATCH v2 2/7] android/bluetooth: Pass device to send_bond_state_change function Szymon Janc
2014-06-23 14:28 ` [PATCH v2 3/7] android/bluetooth: Fix passing address type to SSP replies Szymon Janc
2014-06-23 14:28 ` [PATCH v2 4/7] android/bluetooth: Add get_device_android_addr helper Szymon Janc
2014-06-23 14:28 ` [PATCH v2 5/7] android/bluetooth: Map RPA to Identity address on New IRK event Szymon Janc
2014-06-23 14:28 ` [PATCH v2 6/7] android/gatt: Use proper address when connecting Szymon Janc
2014-06-23 14:28 ` [PATCH v2 7/7] android/bluetooth: Log error if loading LTKs or IRKs failed Szymon Janc
2014-06-24 20:45 ` Szymon Janc [this message]

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=1850993.QsL8CxT3Rs@athlon \
    --to=szymon.janc@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=szymon.janc@tieto.com \
    /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).