aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2013-01-26 17:31:31 -0500
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>2013-02-01 12:50:17 -0500
commita10f27cf4272033d148d91ff12bb8f4b67dfaca4 (patch)
tree9192e008995b9e27a71a7664c5a4ad539a57dec1 /net/bluetooth
parent056341c8cb677356eb2c20a82e788ccb51c6a37b (diff)
Bluetooth: Simplify UUID16 list generation for EIR
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>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/mgmt.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 1e906d8d86ac..02827af1aef0 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -438,9 +438,8 @@ static u32 get_current_settings(struct hci_dev *hdev)
438static void create_eir(struct hci_dev *hdev, u8 *data) 438static void create_eir(struct hci_dev *hdev, u8 *data)
439{ 439{
440 u8 *ptr = data; 440 u8 *ptr = data;
441 u8 *uuids_start;
441 u16 eir_len = 0; 442 u16 eir_len = 0;
442 u16 uuid16_list[HCI_MAX_EIR_LENGTH / sizeof(u16)];
443 int i, truncated = 0;
444 struct bt_uuid *uuid; 443 struct bt_uuid *uuid;
445 size_t name_len; 444 size_t name_len;
446 445
@@ -485,7 +484,7 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
485 ptr += 10; 484 ptr += 10;
486 } 485 }
487 486
488 memset(uuid16_list, 0, sizeof(uuid16_list)); 487 uuids_start = NULL;
489 488
490 /* Group all UUID16 types */ 489 /* Group all UUID16 types */
491 list_for_each_entry(uuid, &hdev->uuids, list) { 490 list_for_each_entry(uuid, &hdev->uuids, list) {
@@ -501,39 +500,24 @@ static void create_eir(struct hci_dev *hdev, u8 *data)
501 if (uuid16 == PNP_INFO_SVCLASS_ID) 500 if (uuid16 == PNP_INFO_SVCLASS_ID)
502 continue; 501 continue;
503 502
503 if (!uuids_start) {
504 uuids_start = ptr;
505 uuids_start[0] = 1;
506 uuids_start[1] = EIR_UUID16_ALL;
507 ptr += 2;
508 eir_len += 2;
509 }
510
504 /* Stop if not enough space to put next UUID */ 511 /* Stop if not enough space to put next UUID */
505 if (eir_len + 2 + sizeof(u16) > HCI_MAX_EIR_LENGTH) { 512 if (eir_len + 2 + sizeof(u16) > HCI_MAX_EIR_LENGTH) {
506 truncated = 1; 513 uuids_start[1] = EIR_UUID16_SOME;
507 break; 514 break;
508 } 515 }
509 516
510 /* Check for duplicates */ 517 *ptr++ = (uuid16 & 0x00ff);
511 for (i = 0; uuid16_list[i] != 0; i++) 518 *ptr++ = (uuid16 & 0xff00) >> 8;
512 if (uuid16_list[i] == uuid16) 519 eir_len += sizeof(uuid16);
513 break; 520 uuids_start[0] += sizeof(uuid16);
514
515 if (uuid16_list[i] == 0) {
516 uuid16_list[i] = uuid16;
517 eir_len += sizeof(u16);
518 }
519 }
520
521 if (uuid16_list[0] != 0) {
522 u8 *length = ptr;
523
524 /* EIR Data type */
525 ptr[1] = truncated ? EIR_UUID16_SOME : EIR_UUID16_ALL;
526
527 ptr += 2;
528 eir_len += 2;
529
530 for (i = 0; uuid16_list[i] != 0; i++) {
531 *ptr++ = (uuid16_list[i] & 0x00ff);
532 *ptr++ = (uuid16_list[i] & 0xff00) >> 8;
533 }
534
535 /* EIR Data length */
536 *length = (i * sizeof(u16)) + 1;
537 } 521 }
538} 522}
539 523