Skip to content

Commit ff2503c

Browse files
chengkai15henrikbrixandersen
authored andcommitted
Bluetooth: SDP: wrap sdp attr item into u16 common func
Wrap sdp attr item into u16 common function, and it would help to add pnp etc info Signed-off-by: Kai Cheng <[email protected]>
1 parent c552847 commit ff2503c

File tree

1 file changed

+33
-29
lines changed
  • subsys/bluetooth/host/classic

1 file changed

+33
-29
lines changed

subsys/bluetooth/host/classic/sdp.c

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,33 @@ static int sdp_get_param_item(struct bt_sdp_uuid_desc *pd_item, uint16_t *param)
29802980
return 0;
29812981
}
29822982

2983+
static int sdp_get_u16_data(const struct bt_sdp_attr_item *attr, uint16_t *u16)
2984+
{
2985+
const uint8_t *p;
2986+
2987+
if (!u16) {
2988+
LOG_ERR("Invalid pointer.");
2989+
return -EINVAL;
2990+
}
2991+
2992+
/* assert 16bit can be read safely */
2993+
if (attr->len != (sizeof(uint8_t) + sizeof(*u16))) {
2994+
LOG_ERR("Invalid data length %u", attr->len);
2995+
return -EMSGSIZE;
2996+
}
2997+
2998+
p = attr->val;
2999+
__ASSERT(p != NULL, "attr->val cannot be NULL");
3000+
if (p[0] != BT_SDP_UINT16) {
3001+
LOG_ERR("Invalid DTD 0x%02x", p[0]);
3002+
return -EINVAL;
3003+
}
3004+
3005+
*u16 = sys_get_be16(++p);
3006+
3007+
return 0;
3008+
}
3009+
29833010
int bt_sdp_get_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto,
29843011
uint16_t *param)
29853012
{
@@ -3059,36 +3086,13 @@ int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile,
30593086
int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features)
30603087
{
30613088
struct bt_sdp_attr_item attr;
3062-
const uint8_t *p;
3063-
int res;
3064-
3065-
res = bt_sdp_get_attr(buf, &attr, BT_SDP_ATTR_SUPPORTED_FEATURES);
3066-
if (res < 0) {
3067-
LOG_WRN("Attribute 0x%04x not found, err %d", BT_SDP_ATTR_SUPPORTED_FEATURES, res);
3068-
return res;
3069-
}
3070-
3071-
p = attr.val;
3072-
BT_ASSERT(p);
3073-
3074-
if (p[0] != BT_SDP_UINT16) {
3075-
LOG_ERR("Invalid DTD 0x%02x", p[0]);
3076-
return -EINVAL;
3077-
}
3078-
3079-
/* assert 16bit can be read safely */
3080-
if (attr.len < 3) {
3081-
LOG_ERR("Data length too short %u", attr.len);
3082-
return -EMSGSIZE;
3083-
}
3084-
3085-
*features = sys_get_be16(++p);
3086-
p += sizeof(uint16_t);
3089+
int err;
30873090

3088-
if (p - attr.val != attr.len) {
3089-
LOG_ERR("Invalid data length %u", attr.len);
3090-
return -EMSGSIZE;
3091+
err = bt_sdp_get_attr(buf, &attr, BT_SDP_ATTR_SUPPORTED_FEATURES);
3092+
if (err < 0) {
3093+
LOG_WRN("Attribute 0x%04x not found, err %d", BT_SDP_ATTR_SUPPORTED_FEATURES, err);
3094+
return err;
30913095
}
30923096

3093-
return 0;
3097+
return sdp_get_u16_data(&attr, features);
30943098
}

0 commit comments

Comments
 (0)