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>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
static void create_eir(struct hci_dev *hdev, u8 *data)
{
u8 *ptr = data;
static void create_eir(struct hci_dev *hdev, u8 *data)
{
u8 *ptr = data;
- u16 uuid16_list[HCI_MAX_EIR_LENGTH / sizeof(u16)];
- int i, truncated = 0;
struct bt_uuid *uuid;
size_t name_len;
struct bt_uuid *uuid;
size_t name_len;
- memset(uuid16_list, 0, sizeof(uuid16_list));
/* Group all UUID16 types */
list_for_each_entry(uuid, &hdev->uuids, list) {
/* Group all UUID16 types */
list_for_each_entry(uuid, &hdev->uuids, list) {
if (uuid16 == PNP_INFO_SVCLASS_ID)
continue;
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) {
/* Stop if not enough space to put next UUID */
if (eir_len + 2 + sizeof(u16) > HCI_MAX_EIR_LENGTH) {
+ uuids_start[1] = EIR_UUID16_SOME;
- /* 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);