Linux bluetooth development
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Vishal Agarwal <vishal.agarwal@stericsson.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] Bluetooth: eir_append_data should take care of padding
Date: Wed, 25 Apr 2012 12:05:05 +0300	[thread overview]
Message-ID: <20120425090505.GA25179@x220> (raw)
In-Reply-To: <1335340311-25057-1-git-send-email-vishal.agarwal@stericsson.com>

Hi Vishal,

On Wed, Apr 25, 2012, Vishal Agarwal wrote:
> EIR data received from controller might contain padding zeros.
> In this case data should be appended in the starting of padding
> instead of at the end of padding. Data added after the padding will
> be discarded by user space.
> 
> Signed-off-by: Vishal Agarwal <vishal.agarwal@stericsson.com>
> ---
>  include/net/bluetooth/hci_core.h |   21 +++++++++++++++++----
>  1 files changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index ef6e654..9e42e2b 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -938,11 +938,24 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
>  static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
>  				  u8 data_len)
>  {
> -	eir[eir_len++] = sizeof(type) + data_len;
> -	eir[eir_len++] = type;
> -	memcpy(&eir[eir_len], data, data_len);
> -	eir_len += data_len;
> +	u8 field_len;
> +	size_t parsed = 0;
> +
> +	while (parsed < eir_len - 1) {
> +		field_len = eir[0];
>  
> +		if (field_len == 0) {
> +			eir[0] = sizeof(type) + data_len;
> +			eir[1] = type;
> +			memcpy(&eir[2], data, data_len);
> +			/* data_len + 1 byte for size + 1 byte for type */
> +			eir_len = parsed + data_len + 2;
> +			break;
> +		}
> +
> +		parsed += field_len + 1;
> +		eir += field_len + 1;
> +	}
>  	return eir_len;

I don't really see the point of this. The eir_len parameter passed to
this function is supposed to be the length of the significant
(non-padded) data. I.e. it should already indicate the start of the
padded zeroes. If you see misuse of this somewhere please submit a patch
for that instead.

Johan

  reply	other threads:[~2012-04-25  9:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-25  7:51 [PATCH] Bluetooth: eir_append_data should take care of padding Vishal Agarwal
2012-04-25  9:05 ` Johan Hedberg [this message]
2012-04-25  9:57   ` vishal agarwal
2012-04-25 10:14     ` Johan Hedberg
2012-04-25 12:00       ` vishal agarwal
2012-04-25 12:10         ` Johan Hedberg
2012-04-25  9:59   ` vishal agarwal

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=20120425090505.GA25179@x220 \
    --to=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=vishal.agarwal@stericsson.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