Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v2 4/4] android/gatt: Add disconnect GATT device
Date: Sun, 16 Mar 2014 18:40:17 +0100	[thread overview]
Message-ID: <5305975.WNUtT4HXBi@leonov> (raw)
In-Reply-To: <1394804979-7270-5-git-send-email-lukasz.rymanowski@tieto.com>

Hi,

On Friday 14 of March 2014 14:49:39 Lukasz Rymanowski wrote:
> Disconnect scenarios:
> 
> 1. If there is more then one client for a given gatt_device then
> client id is removed from dev->clients, success response is sent
> together with success disconnect event.
> 
> 2. If there is only one client for a given remote device then we
> do what is decribed above plus clean of gattrib stuff
> 
> 3. In case client_if or conn_id is incorrect, response failed is sent
> ---
>  android/gatt.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 47 insertions(+), 1 deletion(-)
> 
> diff --git a/android/gatt.c b/android/gatt.c
> index 9afdf4b..ce72986 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -112,6 +112,14 @@ static bool match_dev_connect_ready(const void *data,
> const void *user_data) return dev->connect_ready;
>  }
> 
> +static bool match_dev_by_conn_id(const void *data, const void *user_data)
> +{
> +	const struct gatt_device *dev = data;
> +	const int32_t conn_id = PTR_TO_INT(user_data);
> +
> +	return dev->conn_id == conn_id;
> +}
> +
>  static void destroy_device(struct gatt_device *dev)
>  {
>  	queue_destroy(dev->clients, NULL);
> @@ -661,10 +669,48 @@ reply:
> 
>  static void handle_client_disconnect(const void *buf, uint16_t len)
>  {
> +	const struct hal_cmd_gatt_client_disconnect *cmd = buf;
> +	struct gatt_device *dev;
> +	uint8_t status;
> +
>  	DBG("");
> 
> +	dev = queue_find(conn_list, match_dev_by_conn_id,
> +						INT_TO_PTR(cmd->conn_id));
> +	if (!dev) {
> +		status = HAL_STATUS_FAILED;
> +		goto reply;
> +	}
> +
> +	/*Check if client owns this connection */
> +	if (!queue_remove_if(dev->clients, match_by_value,
> +						INT_TO_PTR(cmd->client_if)))
> +		status = HAL_STATUS_FAILED;
> +	else
> +		status = HAL_STATUS_SUCCESS;
> +
> +reply:
>  	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
> -			HAL_OP_GATT_CLIENT_DISCONNECT, HAL_STATUS_FAILED);
> +			HAL_OP_GATT_CLIENT_DISCONNECT, status);
> +
> +	if (status == HAL_STATUS_FAILED)
> +		return;
> +
> +	/* Just send disconnect event. If there is more clients on this
> +	 * device then this is what we shall to do.
> +	 * If this is last client, this is still OK to do because on connect
> +	 * request we do le scan and wait until remote device start
> +	 * advertisement */
> +	send_disconnect_notify((void *)&cmd->client_if, (void *)dev);

This should be function with proper parameters type and if needed extra 
wrapper for list iteration.

> +
> +	/* If there is more clients just return */
> +	if (!queue_isempty(dev->clients))
> +		return;
> +
> +	/* If this is last client do more cleaning */
> +	connection_cleanup(dev);
> +	dev = queue_remove_if(conn_list, match_dev_by_bdaddr, &dev->bdaddr);
> +	destroy_device(dev);
>  }
> 
>  static void handle_client_listen(const void *buf, uint16_t len)

-- 
BR
Szymon Janc

      reply	other threads:[~2014-03-16 17:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-14 13:49 [PATCH v2 0/4] android:Add initial support for GATT Client Lukasz Rymanowski
2014-03-14 13:49 ` [PATCH v2 1/4] android/bluetooth: Add GATT notifications on LE discovery Lukasz Rymanowski
2014-03-16 16:26   ` Szymon Janc
2014-03-16 22:32     ` Lukasz Rymanowski
2014-03-14 13:49 ` [PATCH v2 2/4] android/gatt: Use Core profile for LE scan Lukasz Rymanowski
2014-03-16 16:26   ` Szymon Janc
2014-03-16 22:33     ` Lukasz Rymanowski
2014-03-14 13:49 ` [PATCH v2 3/4] android/gatt: Add GATT Connect Lukasz Rymanowski
2014-03-16 17:32   ` Szymon Janc
2014-03-16 22:39     ` Lukasz Rymanowski
2014-03-14 13:49 ` [PATCH v2 4/4] android/gatt: Add disconnect GATT device Lukasz Rymanowski
2014-03-16 17:40   ` 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=5305975.WNUtT4HXBi@leonov \
    --to=szymon.janc@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=lukasz.rymanowski@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