@@ -1659,55 +1659,7 @@ static int sdp_client_ssa_search(struct bt_sdp_client *session,
1659
1659
session -> tid );
1660
1660
}
1661
1661
1662
- static void sdp_client_params_iterator (struct bt_sdp_client * session );
1663
-
1664
- static int sdp_client_discover (struct bt_sdp_client * session )
1665
- {
1666
- const struct bt_sdp_discover_params * param ;
1667
- int err ;
1668
-
1669
- /*
1670
- * Select proper user params, if session->param is invalid it means
1671
- * getting new UUID from top of to be resolved params list. Otherwise
1672
- * the context is in a middle of partial SDP PDU responses and cached
1673
- * value from context can be used.
1674
- */
1675
- if (!session -> param ) {
1676
- param = GET_PARAM (sys_slist_peek_head (& session -> reqs ));
1677
- } else {
1678
- param = session -> param ;
1679
- }
1680
-
1681
- if (!param ) {
1682
- struct bt_l2cap_chan * chan = & session -> chan .chan ;
1683
-
1684
- LOG_WRN ("No more request, disconnect channel" );
1685
- /* No UUID items, disconnect channel */
1686
- return bt_l2cap_chan_disconnect (chan );
1687
- }
1688
-
1689
- switch (param -> type ) {
1690
- case BT_SDP_DISCOVER_SERVICE_SEARCH :
1691
- err = sdp_client_ss_search (session , param );
1692
- break ;
1693
- case BT_SDP_DISCOVER_SERVICE_ATTR :
1694
- err = sdp_client_sa_search (session , param );
1695
- break ;
1696
- case BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR :
1697
- err = sdp_client_ssa_search (session , param );
1698
- break ;
1699
- default :
1700
- err = - EINVAL ;
1701
- break ;
1702
- }
1703
-
1704
- if (err ) {
1705
- /* Get next UUID and start resolving it */
1706
- sdp_client_params_iterator (session );
1707
- }
1708
-
1709
- return 0 ;
1710
- }
1662
+ static int sdp_client_discover (struct bt_sdp_client * session );
1711
1663
1712
1664
static void sdp_client_params_iterator (struct bt_sdp_client * session )
1713
1665
{
@@ -1910,6 +1862,56 @@ static void sdp_client_notify_result(struct bt_sdp_client *session,
1910
1862
}
1911
1863
}
1912
1864
1865
+ static int sdp_client_discover (struct bt_sdp_client * session )
1866
+ {
1867
+ const struct bt_sdp_discover_params * param ;
1868
+ int err ;
1869
+
1870
+ /*
1871
+ * Select proper user params, if session->param is invalid it means
1872
+ * getting new UUID from top of to be resolved params list. Otherwise
1873
+ * the context is in a middle of partial SDP PDU responses and cached
1874
+ * value from context can be used.
1875
+ */
1876
+ if (!session -> param ) {
1877
+ param = GET_PARAM (sys_slist_peek_head (& session -> reqs ));
1878
+ } else {
1879
+ param = session -> param ;
1880
+ }
1881
+
1882
+ if (!param ) {
1883
+ struct bt_l2cap_chan * chan = & session -> chan .chan ;
1884
+
1885
+ LOG_WRN ("No more request, disconnect channel" );
1886
+ /* No UUID items, disconnect channel */
1887
+ return bt_l2cap_chan_disconnect (chan );
1888
+ }
1889
+
1890
+ switch (param -> type ) {
1891
+ case BT_SDP_DISCOVER_SERVICE_SEARCH :
1892
+ err = sdp_client_ss_search (session , param );
1893
+ break ;
1894
+ case BT_SDP_DISCOVER_SERVICE_ATTR :
1895
+ err = sdp_client_sa_search (session , param );
1896
+ break ;
1897
+ case BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR :
1898
+ err = sdp_client_ssa_search (session , param );
1899
+ break ;
1900
+ default :
1901
+ err = - EINVAL ;
1902
+ break ;
1903
+ }
1904
+
1905
+ if (err ) {
1906
+ /* Notify the result */
1907
+ sdp_client_notify_result (session , UUID_NOT_RESOLVED );
1908
+ /* Get next UUID and start resolving it */
1909
+ sdp_client_params_iterator (session );
1910
+ }
1911
+
1912
+ return 0 ;
1913
+ }
1914
+
1913
1915
static int sdp_client_receive_ss (struct bt_sdp_client * session , struct net_buf * buf )
1914
1916
{
1915
1917
struct bt_sdp_pdu_cstate * cstate ;
@@ -1921,7 +1923,7 @@ static int sdp_client_receive_ss(struct bt_sdp_client *session, struct net_buf *
1921
1923
/* Check the buffer len for the total_count field */
1922
1924
if (buf -> len < sizeof (total_count )) {
1923
1925
LOG_ERR ("Invalid frame payload length" );
1924
- return 0 ;
1926
+ return - EINVAL ;
1925
1927
}
1926
1928
1927
1929
/* Get total service record count. */
@@ -1930,40 +1932,40 @@ static int sdp_client_receive_ss(struct bt_sdp_client *session, struct net_buf *
1930
1932
/* Check the buffer len for the current_count field */
1931
1933
if (buf -> len < sizeof (current_count )) {
1932
1934
LOG_ERR ("Invalid frame payload length" );
1933
- return 0 ;
1935
+ return - EINVAL ;
1934
1936
}
1935
1937
1936
1938
/* Get current service record count. */
1937
1939
current_count = net_buf_pull_be16 (buf );
1938
1940
/* Check valid of current service record count */
1939
1941
if (current_count > total_count ) {
1940
1942
LOG_ERR ("Invalid current service record count" );
1941
- return 0 ;
1943
+ return - EINVAL ;
1942
1944
}
1943
1945
1944
1946
received_count = session -> rec_buf -> len / SDP_RECORD_HANDLE_SIZE ;
1945
1947
if ((received_count + current_count ) > total_count ) {
1946
1948
LOG_ERR ("Excess data received" );
1947
- return 0 ;
1949
+ return - EINVAL ;
1948
1950
}
1949
1951
1950
1952
record_len = current_count * SDP_RECORD_HANDLE_SIZE ;
1951
1953
if (record_len >= buf -> len ) {
1952
1954
LOG_ERR ("Invalid packet" );
1953
- return 0 ;
1955
+ return - EINVAL ;
1954
1956
}
1955
1957
1956
1958
/* Get PDU continuation state */
1957
1959
cstate = (struct bt_sdp_pdu_cstate * )(buf -> data + record_len );
1958
1960
1959
1961
if (cstate -> length > BT_SDP_MAX_PDU_CSTATE_LEN ) {
1960
1962
LOG_ERR ("Invalid SDP PDU Continuation State length %u" , cstate -> length );
1961
- return 0 ;
1963
+ return - EINVAL ;
1962
1964
}
1963
1965
1964
1966
if ((record_len + SDP_CONT_STATE_LEN_SIZE + cstate -> length ) > buf -> len ) {
1965
1967
LOG_ERR ("Invalid payload length" );
1966
- return 0 ;
1968
+ return - EINVAL ;
1967
1969
}
1968
1970
1969
1971
/*
@@ -1972,16 +1974,13 @@ static int sdp_client_receive_ss(struct bt_sdp_client *session, struct net_buf *
1972
1974
* valid and this is the first response frame as well.
1973
1975
*/
1974
1976
if (!current_count && cstate -> length == 0U && session -> cstate .length == 0U ) {
1975
- LOG_DBG ("Service record handle 0x%x not found" , session -> param -> handle );
1976
- /* Call user UUID handler */
1977
- sdp_client_notify_result (session , UUID_NOT_RESOLVED );
1978
- net_buf_pull (buf , sizeof (cstate -> length ));
1979
- goto iterate ;
1977
+ LOG_WRN ("Service record handle 0x%x not found" , session -> param -> handle );
1978
+ return - EINVAL ;
1980
1979
}
1981
1980
1982
1981
if (record_len > net_buf_tailroom (session -> rec_buf )) {
1983
1982
LOG_WRN ("Not enough room for getting records data" );
1984
- goto iterate ;
1983
+ return - EINVAL ;
1985
1984
}
1986
1985
1987
1986
net_buf_add_mem (session -> rec_buf , buf -> data , record_len );
@@ -1994,15 +1993,20 @@ static int sdp_client_receive_ss(struct bt_sdp_client *session, struct net_buf *
1994
1993
1995
1994
net_buf_pull (buf , cstate -> length + sizeof (cstate -> length ));
1996
1995
1997
- /* Request for next portion of attributes data */
1998
- return sdp_client_discover (session );
1996
+ /*
1997
+ * Request for next portion of attributes data.
1998
+ * All failure case are handled internally in the function.
1999
+ * Ignore the return value.
2000
+ */
2001
+ (void )sdp_client_discover (session );
2002
+
2003
+ return 0 ;
1999
2004
}
2000
2005
2001
2006
net_buf_pull (buf , sizeof (cstate -> length ));
2002
2007
2003
2008
LOG_DBG ("UUID 0x%s resolved" , bt_uuid_str (session -> param -> uuid ));
2004
2009
sdp_client_notify_result (session , UUID_RESOLVED );
2005
- iterate :
2006
2010
/* Get next UUID and start resolving it */
2007
2011
sdp_client_params_iterator (session );
2008
2012
@@ -2018,33 +2022,33 @@ static int sdp_client_receive_ssa_sa(struct bt_sdp_client *session, struct net_b
2018
2022
/* Check the buffer len for the frame_len field */
2019
2023
if (buf -> len < sizeof (frame_len )) {
2020
2024
LOG_ERR ("Invalid frame payload length" );
2021
- return 0 ;
2025
+ return - EINVAL ;
2022
2026
}
2023
2027
2024
2028
/* Get number of attributes in this frame. */
2025
2029
frame_len = net_buf_pull_be16 (buf );
2026
2030
/* Check valid buf len for attribute list and cont state */
2027
2031
if (buf -> len < frame_len + SDP_CONT_STATE_LEN_SIZE ) {
2028
2032
LOG_ERR ("Invalid frame payload length" );
2029
- return 0 ;
2033
+ return - EINVAL ;
2030
2034
}
2031
2035
/* Check valid range of attributes length */
2032
2036
if (frame_len < 2 ) {
2033
2037
LOG_ERR ("Invalid attributes data length" );
2034
- return 0 ;
2038
+ return - EINVAL ;
2035
2039
}
2036
2040
2037
2041
/* Get PDU continuation state */
2038
2042
cstate = (struct bt_sdp_pdu_cstate * )(buf -> data + frame_len );
2039
2043
2040
2044
if (cstate -> length > BT_SDP_MAX_PDU_CSTATE_LEN ) {
2041
2045
LOG_ERR ("Invalid SDP PDU Continuation State length %u" , cstate -> length );
2042
- return 0 ;
2046
+ return - EINVAL ;
2043
2047
}
2044
2048
2045
2049
if ((frame_len + SDP_CONT_STATE_LEN_SIZE + cstate -> length ) > buf -> len ) {
2046
2050
LOG_ERR ("Invalid frame payload length" );
2047
- return 0 ;
2051
+ return - EINVAL ;
2048
2052
}
2049
2053
2050
2054
/*
@@ -2053,11 +2057,8 @@ static int sdp_client_receive_ssa_sa(struct bt_sdp_client *session, struct net_b
2053
2057
* valid and this is the first response frame as well.
2054
2058
*/
2055
2059
if (frame_len == 2U && cstate -> length == 0U && session -> cstate .length == 0U ) {
2056
- LOG_DBG ("Record for UUID 0x%s not found" , bt_uuid_str (session -> param -> uuid ));
2057
- /* Call user UUID handler */
2058
- sdp_client_notify_result (session , UUID_NOT_RESOLVED );
2059
- net_buf_pull (buf , frame_len + sizeof (cstate -> length ));
2060
- goto iterate ;
2060
+ LOG_WRN ("Record for UUID 0x%s not found" , bt_uuid_str (session -> param -> uuid ));
2061
+ return - EINVAL ;
2061
2062
}
2062
2063
2063
2064
/* Get total value of all attributes to be collected */
@@ -2070,7 +2071,7 @@ static int sdp_client_receive_ssa_sa(struct bt_sdp_client *session, struct net_b
2070
2071
*/
2071
2072
if (total && (frame_len > total )) {
2072
2073
LOG_ERR ("Invalid attribute lists" );
2073
- return 0 ;
2074
+ return - EINVAL ;
2074
2075
}
2075
2076
2076
2077
if (session -> cstate .length == 0U ) {
@@ -2081,7 +2082,7 @@ static int sdp_client_receive_ssa_sa(struct bt_sdp_client *session, struct net_b
2081
2082
2082
2083
if (frame_len > net_buf_tailroom (session -> rec_buf )) {
2083
2084
LOG_WRN ("Not enough room for getting records data" );
2084
- goto iterate ;
2085
+ return - EINVAL ;
2085
2086
}
2086
2087
2087
2088
net_buf_add_mem (session -> rec_buf , buf -> data , frame_len );
@@ -2094,8 +2095,14 @@ static int sdp_client_receive_ssa_sa(struct bt_sdp_client *session, struct net_b
2094
2095
2095
2096
net_buf_pull (buf , cstate -> length + sizeof (cstate -> length ));
2096
2097
2097
- /* Request for next portion of attributes data */
2098
- return sdp_client_discover (session );
2098
+ /*
2099
+ * Request for next portion of attributes data.
2100
+ * All failure case are handled internally in the function.
2101
+ * Ignore the return value.
2102
+ */
2103
+ (void )sdp_client_discover (session );
2104
+
2105
+ return 0 ;
2099
2106
}
2100
2107
2101
2108
if (session -> total_len && (session -> recv_len != session -> total_len )) {
@@ -2108,7 +2115,6 @@ static int sdp_client_receive_ssa_sa(struct bt_sdp_client *session, struct net_b
2108
2115
2109
2116
LOG_DBG ("UUID 0x%s resolved" , bt_uuid_str (session -> param -> uuid ));
2110
2117
sdp_client_notify_result (session , UUID_RESOLVED );
2111
- iterate :
2112
2118
/* Get next UUID and start resolving it */
2113
2119
sdp_client_params_iterator (session );
2114
2120
@@ -2120,6 +2126,7 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
2120
2126
struct bt_sdp_client * session = SDP_CLIENT_CHAN (chan );
2121
2127
struct bt_sdp_hdr * hdr ;
2122
2128
uint16_t len , tid ;
2129
+ int err = - EINVAL ;
2123
2130
2124
2131
LOG_DBG ("session %p buf %p" , session , buf );
2125
2132
@@ -2151,21 +2158,25 @@ static int sdp_client_receive(struct bt_l2cap_chan *chan, struct net_buf *buf)
2151
2158
2152
2159
switch (hdr -> op_code ) {
2153
2160
case BT_SDP_SVC_SEARCH_RSP :
2154
- return sdp_client_receive_ss (session , buf );
2161
+ err = sdp_client_receive_ss (session , buf );
2162
+ break ;
2155
2163
case BT_SDP_SVC_ATTR_RSP :
2156
- __fallthrough ;
2157
2164
case BT_SDP_SVC_SEARCH_ATTR_RSP :
2158
- return sdp_client_receive_ssa_sa (session , buf );
2165
+ err = sdp_client_receive_ssa_sa (session , buf );
2166
+ break ;
2159
2167
case BT_SDP_ERROR_RSP :
2160
2168
LOG_INF ("Invalid SDP request" );
2161
- sdp_client_notify_result (session , UUID_NOT_RESOLVED );
2162
- sdp_client_params_iterator (session );
2163
- return 0 ;
2169
+ break ;
2164
2170
default :
2165
2171
LOG_DBG ("PDU 0x%0x response not handled" , hdr -> op_code );
2166
2172
break ;
2167
2173
}
2168
2174
2175
+ if (err < 0 ) {
2176
+ sdp_client_notify_result (session , UUID_NOT_RESOLVED );
2177
+ sdp_client_params_iterator (session );
2178
+ }
2179
+
2169
2180
return 0 ;
2170
2181
}
2171
2182
0 commit comments