From: Johan Hedberg <johan.hedberg@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 2/6] Bluetooth: Simplify UUID16 list generation for EIR
Date: Thu, 24 Jan 2013 21:03:22 +0200 [thread overview]
Message-ID: <1359054206-19528-3-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1359054206-19528-1-git-send-email-johan.hedberg@gmail.com>
From: Johan Hedberg <johan.hedberg@intel.com>
There's no need to use two separate loops to generate a UUID list for
the EIR data. This patch merges the two loops previously used for the
16-bit UUID list generation into a single loop, thus simplifying the
code a great deal.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/mgmt.c | 46 +++++++++++++++-------------------------------
1 file changed, 15 insertions(+), 31 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 878b4a2..d4e5313 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -438,9 +438,8 @@ static u32 get_current_settings(struct hci_dev *hdev)
static void create_eir(struct hci_dev *hdev, u8 *data)
{
u8 *ptr = data;
+ u8 *uuids_start;
u16 eir_len = 0;
- u16 uuid16_list[HCI_MAX_EIR_LENGTH / sizeof(u16)];
- int i, truncated = 0;
struct bt_uuid *uuid;
size_t name_len;
@@ -485,7 +484,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
ptr += 10;
}
- memset(uuid16_list, 0, sizeof(uuid16_list));
+ uuids_start = NULL;
/* Group all UUID16 types */
list_for_each_entry(uuid, &hdev->uuid16, list) {
@@ -498,39 +497,24 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
if (uuid16 == PNP_INFO_SVCLASS_ID)
continue;
+ if (!uuids_start) {
+ uuids_start = ptr;
+ uuids_start[0] = 1;
+ uuids_start[1] = EIR_UUID16_ALL;
+ ptr += 2;
+ eir_len += 2;
+ }
+
/* Stop if not enough space to put next UUID */
if (eir_len + 2 + sizeof(u16) > HCI_MAX_EIR_LENGTH) {
- truncated = 1;
+ uuids_start[1] = EIR_UUID16_SOME;
break;
}
- /* Check for duplicates */
- for (i = 0; uuid16_list[i] != 0; i++)
- if (uuid16_list[i] == uuid16)
- break;
-
- if (uuid16_list[i] == 0) {
- uuid16_list[i] = uuid16;
- eir_len += sizeof(u16);
- }
- }
-
- if (uuid16_list[0] != 0) {
- u8 *length = ptr;
-
- /* EIR Data type */
- ptr[1] = truncated ? EIR_UUID16_SOME : EIR_UUID16_ALL;
-
- ptr += 2;
- eir_len += 2;
-
- for (i = 0; uuid16_list[i] != 0; i++) {
- *ptr++ = (uuid16_list[i] & 0x00ff);
- *ptr++ = (uuid16_list[i] & 0xff00) >> 8;
- }
-
- /* EIR Data length */
- *length = (i * sizeof(u16)) + 1;
+ *ptr++ = (uuid16 & 0x00ff);
+ *ptr++ = (uuid16 & 0xff00) >> 8;
+ eir_len += sizeof(uuid16);
+ uuids_start[0] += sizeof(uuid16);
}
}
--
1.7.10.4
next prev parent reply other threads:[~2013-01-24 19:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-24 19:03 [PATCH 0/6] Bluetooth: Add 32 and 128 bit EIR UUID support Johan Hedberg
2013-01-24 19:03 ` [PATCH 1/6] Bluetooth: Split UUIDs to three separate lists Johan Hedberg
2013-01-24 19:03 ` Johan Hedberg [this message]
2013-01-24 19:03 ` [PATCH 3/6] Bluetooth: Remove useless eir_len variable from EIR creation Johan Hedberg
2013-01-24 19:03 ` [PATCH 4/6] Bluetooth: Refactor UUID-16 list generation into its own function Johan Hedberg
2013-01-24 20:21 ` Anderson Lizardo
2013-01-24 20:25 ` Anderson Lizardo
2013-01-25 6:37 ` Johan Hedberg
2013-01-24 19:03 ` [PATCH 5/6] Bluetooth: Add support for 32-bit UUIDs in EIR data Johan Hedberg
2013-01-24 19:03 ` [PATCH 6/6] Bluetooth: Add support for 128-bit " Johan Hedberg
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=1359054206-19528-3-git-send-email-johan.hedberg@gmail.com \
--to=johan.hedberg@gmail.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