Skip to content

Commit 91ec38d

Browse files
jonas-5ae29ccfriedt
authored andcommitted
Bluetooth: Classic: SDP: Replace magic numbers
Replace magic UUID sizes with `sizeof(uint8_t) + BT_UUID_SIZE_{16,32,128}`. Signed-off-by: Jonas Spinner <[email protected]>
1 parent 9d7aa28 commit 91ec38d

File tree

1 file changed

+12
-12
lines changed
  • subsys/bluetooth/host/classic

1 file changed

+12
-12
lines changed

subsys/bluetooth/host/classic/sdp.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,19 +1523,19 @@ static int sdp_client_ss_search(struct bt_sdp_client *session,
15231523
switch (param->uuid->type) {
15241524
case BT_UUID_TYPE_16:
15251525
/* Seq length */
1526-
net_buf_add_u8(buf, 0x03);
1526+
net_buf_add_u8(buf, sizeof(uint8_t) + BT_UUID_SIZE_16);
15271527
/* Seq type */
15281528
net_buf_add_u8(buf, BT_SDP_UUID16);
15291529
/* Seq value */
15301530
net_buf_add_be16(buf, BT_UUID_16(param->uuid)->val);
15311531
break;
15321532
case BT_UUID_TYPE_32:
1533-
net_buf_add_u8(buf, 0x05);
1533+
net_buf_add_u8(buf, sizeof(uint8_t) + BT_UUID_SIZE_32);
15341534
net_buf_add_u8(buf, BT_SDP_UUID32);
15351535
net_buf_add_be32(buf, BT_UUID_32(param->uuid)->val);
15361536
break;
15371537
case BT_UUID_TYPE_128:
1538-
net_buf_add_u8(buf, 0x11);
1538+
net_buf_add_u8(buf, sizeof(uint8_t) + BT_UUID_SIZE_128);
15391539
net_buf_add_u8(buf, BT_SDP_UUID128);
15401540
sys_memcpy_swap(uuid128, BT_UUID_128(param->uuid)->val, sizeof(uuid128));
15411541
net_buf_add_mem(buf, uuid128, sizeof(uuid128));
@@ -1630,19 +1630,19 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session,
16301630
switch (param->uuid->type) {
16311631
case BT_UUID_TYPE_16:
16321632
/* Seq length */
1633-
net_buf_add_u8(buf, 0x03);
1633+
net_buf_add_u8(buf, sizeof(uint8_t) + BT_UUID_SIZE_16);
16341634
/* Seq type */
16351635
net_buf_add_u8(buf, BT_SDP_UUID16);
16361636
/* Seq value */
16371637
net_buf_add_be16(buf, BT_UUID_16(param->uuid)->val);
16381638
break;
16391639
case BT_UUID_TYPE_32:
1640-
net_buf_add_u8(buf, 0x05);
1640+
net_buf_add_u8(buf, sizeof(uint8_t) + BT_UUID_SIZE_32);
16411641
net_buf_add_u8(buf, BT_SDP_UUID32);
16421642
net_buf_add_be32(buf, BT_UUID_32(param->uuid)->val);
16431643
break;
16441644
case BT_UUID_TYPE_128:
1645-
net_buf_add_u8(buf, 0x11);
1645+
net_buf_add_u8(buf, sizeof(uint8_t) + BT_UUID_SIZE_128);
16461646
net_buf_add_u8(buf, BT_SDP_UUID128);
16471647
sys_memcpy_swap(uuid128, BT_UUID_128(param->uuid)->val, sizeof(uuid128));
16481648
net_buf_add_mem(buf, uuid128, sizeof(uuid128));
@@ -2494,23 +2494,23 @@ static inline ssize_t sdp_get_uuid_len(const uint8_t *data, size_t len)
24942494

24952495
switch (data[0]) {
24962496
case BT_SDP_UUID16:
2497-
if (len < 3) {
2497+
if (len < (sizeof(uint8_t) + BT_UUID_SIZE_16)) {
24982498
break;
24992499
}
25002500

2501-
return 3;
2501+
return sizeof(uint8_t) + BT_UUID_SIZE_16;
25022502
case BT_SDP_UUID32:
2503-
if (len < 5) {
2503+
if (len < (sizeof(uint8_t) + BT_UUID_SIZE_32)) {
25042504
break;
25052505
}
25062506

2507-
return 5;
2507+
return sizeof(uint8_t) + BT_UUID_SIZE_32;
25082508
case BT_SDP_UUID128:
2509-
if (len < (BT_UUID_SIZE_128 + sizeof(uint8_t))) {
2509+
if (len < (sizeof(uint8_t) + BT_UUID_SIZE_128)) {
25102510
break;
25112511
}
25122512

2513-
return BT_UUID_SIZE_128 + sizeof(uint8_t);
2513+
return sizeof(uint8_t) + BT_UUID_SIZE_128;
25142514
default:
25152515
LOG_ERR("Invalid/unhandled DTD 0x%02x", data[0]);
25162516
return -EINVAL;

0 commit comments

Comments
 (0)