Skip to content

Commit 613655e

Browse files
akshhrcarlescufi
authored andcommitted
bluetooth: host: Replaced bt_uuid_create_le with bt_uuid_create
Endianness bug fix in bt_uuid_create function. Replaced bt_uuid_create_le with bt_uuid_create which handles both UUID from air and internal varaiable. Fixed bug with endianess in case of big endian targets. Signed-off-by: Akshatha Harishchandra <[email protected]>
1 parent 351bef1 commit 613655e

File tree

3 files changed

+15
-55
lines changed

3 files changed

+15
-55
lines changed

include/bluetooth/uuid.h

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -465,37 +465,23 @@ struct bt_uuid_128 {
465465
*/
466466
int bt_uuid_cmp(const struct bt_uuid *u1, const struct bt_uuid *u2);
467467

468-
/** @brief Copy UUID from packet data (LE) to internal bt_uuid.
469-
*
470-
* Copy UUID from packet data in little endian format to internal bt_uuid
471-
* format. The data_len parameter is used to determine whether the received
472-
* UUID is of 16 or 128 bit format (length 2 or 16). 32 bit format is not
473-
* allowed over the air.
474-
*
475-
* @param uuid Pointer to where to write the Bluetooth UUID
476-
* @param data pointer to location of the UUID in the packet
477-
* @param data_len length of the UUID in the packet
478-
*
479-
* @return true if the data was valid and the UUID was successfully created.
480-
*/
481-
bool bt_uuid_create_le(struct bt_uuid *uuid, const u8_t *data, u8_t data_len);
482-
483468
/** @brief Copy UUID from internal variable to internal bt_uuid.
484469
*
485-
* Copy UUID from internal variable pointer to internal bt_uuid format.
486-
* The data parameter points to a variable (originally stored in bt_uuid_128,
487-
* bt_uuid_32 or bt_uuid_16 format) and therefore take into account of
488-
* alignment of the val member.
470+
* Copy little endian format UUID from packet data or internal variable
471+
* pointer to internal bt_uuid format.The data parameter points to a variable
472+
* (originally stored in bt_uuid_128, bt_uuid_32 or bt_uuid_16 format)
473+
* and therefore take into account of alignment of the val member.
489474
* The data_len parameter is used to determine whether to copy the UUID from
490475
* 16, 32 or 128 bit format (length 2, 4 or 16).
476+
* 32 bit format is not allowed over the air.
491477
*
492478
* @param uuid Pointer to where to write the Bluetooth UUID
493-
* @param data pointer to location of the UUID variable
494-
* @param data_len length of the UUID in the packet
479+
* @param data pointer to location of the UUID variable/in the packet
480+
* @param data_len length of the UUID variable/in the packet
495481
*
496482
* @return true if the data was valid and the UUID was successfully created.
497483
*/
498-
bool bt_uuid_create(struct bt_uuid *uuid, u8_t *data, u8_t data_len);
484+
bool bt_uuid_create(struct bt_uuid *uuid, const u8_t *data, u8_t data_len);
499485

500486
#if defined(CONFIG_BT_DEBUG)
501487
/** @brief Convert Bluetooth UUID to string.

subsys/bluetooth/host/att.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,7 @@ static u8_t find_type_cb(const struct bt_gatt_attr *attr, void *user_data)
615615
struct bt_uuid_128 ref_uuid;
616616
struct bt_uuid_128 recvd_uuid;
617617

618-
if (!bt_uuid_create_le(&recvd_uuid.uuid, data->value,
619-
data->value_len)) {
618+
if (!bt_uuid_create(&recvd_uuid.uuid, data->value, data->value_len)) {
620619
BT_WARN("Unable to create UUID: size %u", data->value_len);
621620
goto skip;
622621
}
@@ -904,7 +903,7 @@ static u8_t att_read_type_req(struct bt_att *att, struct net_buf *buf)
904903

905904
start_handle = sys_le16_to_cpu(req->start_handle);
906905
end_handle = sys_le16_to_cpu(req->end_handle);
907-
if (!bt_uuid_create_le(&u.uuid, req->uuid, uuid_len)) {
906+
if (!bt_uuid_create(&u.uuid, req->uuid, uuid_len)) {
908907
return BT_ATT_ERR_UNLIKELY;
909908
}
910909

@@ -1211,7 +1210,7 @@ static u8_t att_read_group_req(struct bt_att *att, struct net_buf *buf)
12111210
start_handle = sys_le16_to_cpu(req->start_handle);
12121211
end_handle = sys_le16_to_cpu(req->end_handle);
12131212

1214-
if (!bt_uuid_create_le(&u.uuid, req->uuid, uuid_len)) {
1213+
if (!bt_uuid_create(&u.uuid, req->uuid, uuid_len)) {
12151214
return BT_ATT_ERR_UNLIKELY;
12161215
}
12171216

subsys/bluetooth/host/uuid.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,21 @@ int bt_uuid_cmp(const struct bt_uuid *u1, const struct bt_uuid *u2)
8080
return -EINVAL;
8181
}
8282

83-
bool bt_uuid_create_le(struct bt_uuid *uuid, const u8_t *data, u8_t data_len)
83+
bool bt_uuid_create(struct bt_uuid *uuid, const u8_t *data, u8_t data_len)
8484
{
85-
/* Copy UUID from packet data to internal bt_uuid */
85+
/* Copy UUID from packet data/internal variable to internal bt_uuid */
8686
switch (data_len) {
8787
case 2:
8888
uuid->type = BT_UUID_TYPE_16;
8989
BT_UUID_16(uuid)->val = sys_get_le16(data);
9090
break;
91-
case 16:
92-
uuid->type = BT_UUID_TYPE_128;
93-
memcpy(&BT_UUID_128(uuid)->val, data, 16);
94-
break;
95-
default:
96-
return false;
97-
}
98-
return true;
99-
}
100-
101-
bool bt_uuid_create(struct bt_uuid *uuid, u8_t *data, u8_t data_len)
102-
{
103-
/* Copy UUID from internal variable to internal bt_uuid */
104-
union {
105-
u16_t *u16;
106-
u32_t *u32;
107-
u8_t *u128;
108-
} v;
109-
110-
v.u128 = data;
111-
switch (data_len) {
112-
case 2:
113-
uuid->type = BT_UUID_TYPE_16;
114-
BT_UUID_16(uuid)->val = *v.u16;
115-
break;
11691
case 4:
11792
uuid->type = BT_UUID_TYPE_32;
118-
BT_UUID_32(uuid)->val = *v.u32;
93+
BT_UUID_32(uuid)->val = sys_get_le32(data);
11994
break;
12095
case 16:
12196
uuid->type = BT_UUID_TYPE_128;
122-
memcpy(&BT_UUID_128(uuid)->val, v.u128, 16);
97+
memcpy(&BT_UUID_128(uuid)->val, data, 16);
12398
break;
12499
default:
125100
return false;

0 commit comments

Comments
 (0)