From: "Gix, Brian" <brian.gix@intel.com>
To: "linux-bluetooth@vger.kernel.org"
<linux-bluetooth@vger.kernel.org>,
"Stotland, Inga" <inga.stotland@intel.com>
Cc: "michal.lowas-rzechonek@silvair.com"
<michal.lowas-rzechonek@silvair.com>
Subject: Re: [PATCH BlueZ v2] mesh: Correctly generate NetKey list
Date: Tue, 14 Jan 2020 14:43:50 +0000 [thread overview]
Message-ID: <937f6c4d1f2cf13c619e846a48520a764bcb1012.camel@intel.com> (raw)
In-Reply-To: <20200109215432.28295-1-inga.stotland@intel.com>
Applied
On Thu, 2020-01-09 at 13:54 -0800, Inga Stotland wrote:
> When responding with NetKey List Status, packed NetKey indices into
> 3 octets per pair. If number of NetKeys is odd, append the last key
> index as a 2-octet value.
> ---
> mesh/net.c | 36 ++++++++++++++++++++++++++++--------
> 1 file changed, 28 insertions(+), 8 deletions(-)
>
> diff --git a/mesh/net.c b/mesh/net.c
> index 0a4d2e72c..dfaf7ccef 100644
> --- a/mesh/net.c
> +++ b/mesh/net.c
> @@ -1065,26 +1065,46 @@ bool mesh_net_get_key(struct mesh_net *net, bool new_key, uint16_t idx,
> bool mesh_net_key_list_get(struct mesh_net *net, uint8_t *buf, uint16_t *size)
> {
> const struct l_queue_entry *entry;
> - uint16_t n, buf_size;
> + uint16_t num_keys, req_size, buf_size;
> + struct mesh_subnet *subnet;
>
> if (!net || !buf || !size)
> return false;
>
> buf_size = *size;
> - if (buf_size < l_queue_length(net->subnets) * 2)
> +
> + num_keys = l_queue_length(net->subnets);
> + req_size = (num_keys / 2) * 3 + (num_keys % 2) * 2;
> +
> + if (buf_size < req_size)
> return false;
>
> - n = 0;
> - entry = l_queue_get_entries(net->subnets);
> + *size = req_size;
> +
> + /* Pack NetKey indices in 3 octets */
> + for (entry = l_queue_get_entries(net->subnets); num_keys > 1;) {
> + uint32_t idx_pair;
>
> - for (; entry; entry = entry->next) {
> - struct mesh_subnet *subnet = entry->data;
> + subnet = entry->data;
> + idx_pair = subnet->idx;
> + idx_pair <<= 12;
> +
> + subnet = entry->next->data;
> + idx_pair += subnet->idx;
> +
> + l_put_le32(idx_pair, buf);
> + buf += 3;
> +
> + num_keys -= 2;
> + entry = entry->next->next;
> + }
>
> + /* If odd number of NetKeys, fill in the end of the buffer */
> + if (num_keys % 2) {
> + subnet = entry->data;
> l_put_le16(subnet->idx, buf);
> - n += 2;
> }
>
> - *size = n;
> return true;
> }
>
prev parent reply other threads:[~2020-01-14 14:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-09 21:54 [PATCH BlueZ v2] mesh: Correctly generate NetKey list Inga Stotland
2020-01-14 14:43 ` Gix, Brian [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=937f6c4d1f2cf13c619e846a48520a764bcb1012.camel@intel.com \
--to=brian.gix@intel.com \
--cc=inga.stotland@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=michal.lowas-rzechonek@silvair.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).