@@ -2980,6 +2980,33 @@ static int sdp_get_param_item(struct bt_sdp_uuid_desc *pd_item, uint16_t *param)
2980
2980
return 0 ;
2981
2981
}
2982
2982
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
+
2983
3010
int bt_sdp_get_proto_param (const struct net_buf * buf , enum bt_sdp_proto proto ,
2984
3011
uint16_t * param )
2985
3012
{
@@ -3059,36 +3086,13 @@ int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile,
3059
3086
int bt_sdp_get_features (const struct net_buf * buf , uint16_t * features )
3060
3087
{
3061
3088
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 ;
3087
3090
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 ;
3091
3095
}
3092
3096
3093
- return 0 ;
3097
+ return sdp_get_u16_data ( & attr , features ) ;
3094
3098
}
0 commit comments