@@ -1902,18 +1902,17 @@ static int set_hs(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
19021902 return err ;
19031903}
19041904
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 )
19061906{
19071907 struct cmd_lookup match = { NULL , hdev };
1908+ u8 status = mgmt_status (err );
19081909
1909- hci_dev_lock (hdev );
1910+ bt_dev_dbg (hdev , "err %d" , err );
19101911
19111912 if (status ) {
1912- u8 mgmt_err = mgmt_status (status );
1913-
19141913 mgmt_pending_foreach (MGMT_OP_SET_LE , hdev , cmd_status_rsp ,
1915- & mgmt_err );
1916- goto unlock ;
1914+ & status );
1915+ return ;
19171916 }
19181917
19191918 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)
19221921
19231922 if (match .sk )
19241923 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 );
19251944
19261945 /* Make sure the controller has a good default for
19271946 * advertising data. Restrict the update to when LE
19281947 * has actually been enabled. During power on, the
19291948 * update in powered_update_hci will take care of it.
19301949 */
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 )) {
19341951 if (ext_adv_capable (hdev )) {
1935- int err ;
1952+ int status ;
19361953
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 );
19401957 } 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 );
19431960 }
1944- hci_req_run ( & req , NULL );
1961+
19451962 hci_update_passive_scan (hdev );
19461963 }
19471964
1948- unlock :
1949- hci_dev_unlock (hdev );
1965+ return err ;
19501966}
19511967
19521968static int set_le (struct sock * sk , struct hci_dev * hdev , void * data , u16 len )
19531969{
19541970 struct mgmt_mode * cp = data ;
1955- struct hci_cp_write_le_host_supported hci_cp ;
19561971 struct mgmt_pending_cmd * cmd ;
1957- struct hci_request req ;
19581972 int err ;
19591973 u8 val , enabled ;
19601974
@@ -2024,33 +2038,20 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
20242038 }
20252039
20262040 cmd = mgmt_pending_add (sk , MGMT_OP_SET_LE , hdev , data , len );
2027- if (!cmd ) {
2041+ if (!cmd )
20282042 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 );
20352046
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 );
20422050
2043- if (ext_adv_capable ( hdev ) )
2044- __hci_req_clear_ext_adv_sets ( & req );
2051+ if (cmd )
2052+ mgmt_pending_remove ( cmd );
20452053 }
20462054
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-
20542055unlock :
20552056 hci_dev_unlock (hdev );
20562057 return err ;
0 commit comments