@@ -1902,18 +1902,17 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1902
1902
return err ;
1903
1903
}
1904
1904
1905
- static void le_enable_complete (struct hci_dev * hdev , u8 status , u16 opcode )
1905
+ static void set_le_complete (struct hci_dev * hdev , void * data , int err )
1906
1906
{
1907
1907
struct cmd_lookup match = { NULL , hdev };
1908
+ u8 status = mgmt_status (err );
1908
1909
1909
- hci_dev_lock (hdev );
1910
+ bt_dev_dbg (hdev , "err %d" , err );
1910
1911
1911
1912
if (status ) {
1912
- u8 mgmt_err = mgmt_status (status );
1913
-
1914
1913
mgmt_pending_foreach (MGMT_OP_SET_LE , hdev , cmd_status_rsp ,
1915
- & mgmt_err );
1916
- goto unlock ;
1914
+ & status );
1915
+ return ;
1917
1916
}
1918
1917
1919
1918
mgmt_pending_foreach (MGMT_OP_SET_LE , hdev , settings_rsp , & match );
@@ -1922,39 +1921,54 @@ static void le_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)
1922
1921
1923
1922
if (match .sk )
1924
1923
sock_put (match .sk );
1924
+ }
1925
+
1926
+ static int set_le_sync (struct hci_dev * hdev , void * data )
1927
+ {
1928
+ struct mgmt_pending_cmd * cmd = data ;
1929
+ struct mgmt_mode * cp = cmd -> param ;
1930
+ u8 val = !!cp -> val ;
1931
+ int err ;
1932
+
1933
+ if (!val ) {
1934
+ if (hci_dev_test_flag (hdev , HCI_LE_ADV ))
1935
+ hci_disable_advertising_sync (hdev );
1936
+
1937
+ if (ext_adv_capable (hdev ))
1938
+ hci_remove_ext_adv_instance_sync (hdev , 0 , cmd -> sk );
1939
+ } else {
1940
+ hci_dev_set_flag (hdev , HCI_LE_ENABLED );
1941
+ }
1942
+
1943
+ err = hci_write_le_host_supported_sync (hdev , val , 0 );
1925
1944
1926
1945
/* Make sure the controller has a good default for
1927
1946
* advertising data. Restrict the update to when LE
1928
1947
* has actually been enabled. During power on, the
1929
1948
* update in powered_update_hci will take care of it.
1930
1949
*/
1931
- if (hci_dev_test_flag (hdev , HCI_LE_ENABLED )) {
1932
- struct hci_request req ;
1933
- hci_req_init (& req , hdev );
1950
+ if (!err && hci_dev_test_flag (hdev , HCI_LE_ENABLED )) {
1934
1951
if (ext_adv_capable (hdev )) {
1935
- int err ;
1952
+ int status ;
1936
1953
1937
- err = __hci_req_setup_ext_adv_instance ( & req , 0x00 );
1938
- if (!err )
1939
- __hci_req_update_scan_rsp_data ( & req , 0x00 );
1954
+ status = hci_setup_ext_adv_instance_sync ( hdev , 0x00 );
1955
+ if (!status )
1956
+ hci_update_scan_rsp_data_sync ( hdev , 0x00 );
1940
1957
} else {
1941
- __hci_req_update_adv_data ( & req , 0x00 );
1942
- __hci_req_update_scan_rsp_data ( & req , 0x00 );
1958
+ hci_update_adv_data_sync ( hdev , 0x00 );
1959
+ hci_update_scan_rsp_data_sync ( hdev , 0x00 );
1943
1960
}
1944
- hci_req_run ( & req , NULL );
1961
+
1945
1962
hci_update_passive_scan (hdev );
1946
1963
}
1947
1964
1948
- unlock :
1949
- hci_dev_unlock (hdev );
1965
+ return err ;
1950
1966
}
1951
1967
1952
1968
static int set_le (struct sock * sk , struct hci_dev * hdev , void * data , u16 len )
1953
1969
{
1954
1970
struct mgmt_mode * cp = data ;
1955
- struct hci_cp_write_le_host_supported hci_cp ;
1956
1971
struct mgmt_pending_cmd * cmd ;
1957
- struct hci_request req ;
1958
1972
int err ;
1959
1973
u8 val , enabled ;
1960
1974
@@ -2024,33 +2038,20 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
2024
2038
}
2025
2039
2026
2040
cmd = mgmt_pending_add (sk , MGMT_OP_SET_LE , hdev , data , len );
2027
- if (!cmd ) {
2041
+ if (!cmd )
2028
2042
err = - ENOMEM ;
2029
- goto unlock ;
2030
- }
2031
-
2032
- hci_req_init (& req , hdev );
2033
-
2034
- memset (& hci_cp , 0 , sizeof (hci_cp ));
2043
+ else
2044
+ err = hci_cmd_sync_queue (hdev , set_le_sync , cmd ,
2045
+ set_le_complete );
2035
2046
2036
- if (val ) {
2037
- hci_cp .le = val ;
2038
- hci_cp .simul = 0x00 ;
2039
- } else {
2040
- if (hci_dev_test_flag (hdev , HCI_LE_ADV ))
2041
- __hci_req_disable_advertising (& req );
2047
+ if (err < 0 ) {
2048
+ err = mgmt_cmd_status (sk , hdev -> id , MGMT_OP_SET_LE ,
2049
+ MGMT_STATUS_FAILED );
2042
2050
2043
- if (ext_adv_capable ( hdev ) )
2044
- __hci_req_clear_ext_adv_sets ( & req );
2051
+ if (cmd )
2052
+ mgmt_pending_remove ( cmd );
2045
2053
}
2046
2054
2047
- hci_req_add (& req , HCI_OP_WRITE_LE_HOST_SUPPORTED , sizeof (hci_cp ),
2048
- & hci_cp );
2049
-
2050
- err = hci_req_run (& req , le_enable_complete );
2051
- if (err < 0 )
2052
- mgmt_pending_remove (cmd );
2053
-
2054
2055
unlock :
2055
2056
hci_dev_unlock (hdev );
2056
2057
return err ;
0 commit comments