@@ -5608,29 +5608,25 @@ static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data,
5608
5608
return err ;
5609
5609
}
5610
5610
5611
- static void enable_advertising_instance (struct hci_dev * hdev , u8 status ,
5612
- u16 opcode )
5611
+ static void enable_advertising_instance (struct hci_dev * hdev , int err )
5613
5612
{
5614
- bt_dev_dbg (hdev , "status %u" , status );
5613
+ if (err )
5614
+ bt_dev_err (hdev , "failed to re-configure advertising %d" , err );
5615
+ else
5616
+ bt_dev_dbg (hdev , "status %d" , err );
5615
5617
}
5616
5618
5617
- static void set_advertising_complete (struct hci_dev * hdev , u8 status ,
5618
- u16 opcode )
5619
+ static void set_advertising_complete (struct hci_dev * hdev , void * data , int err )
5619
5620
{
5620
5621
struct cmd_lookup match = { NULL , hdev };
5621
- struct hci_request req ;
5622
5622
u8 instance ;
5623
5623
struct adv_info * adv_instance ;
5624
- int err ;
5625
-
5626
- hci_dev_lock (hdev );
5624
+ u8 status = mgmt_status (err );
5627
5625
5628
5626
if (status ) {
5629
- u8 mgmt_err = mgmt_status (status );
5630
-
5631
5627
mgmt_pending_foreach (MGMT_OP_SET_ADVERTISING , hdev ,
5632
- cmd_status_rsp , & mgmt_err );
5633
- goto unlock ;
5628
+ cmd_status_rsp , & status );
5629
+ return ;
5634
5630
}
5635
5631
5636
5632
if (hci_dev_test_flag (hdev , HCI_LE_ADV ))
@@ -5662,38 +5658,62 @@ static void set_advertising_complete(struct hci_dev *hdev, u8 status,
5662
5658
*/
5663
5659
if (hci_dev_test_flag (hdev , HCI_ADVERTISING ) ||
5664
5660
list_empty (& hdev -> adv_instances ))
5665
- goto unlock ;
5661
+ return ;
5666
5662
5667
5663
instance = hdev -> cur_adv_instance ;
5668
5664
if (!instance ) {
5669
5665
adv_instance = list_first_entry_or_null (& hdev -> adv_instances ,
5670
5666
struct adv_info , list );
5671
5667
if (!adv_instance )
5672
- goto unlock ;
5668
+ return ;
5673
5669
5674
5670
instance = adv_instance -> instance ;
5675
5671
}
5676
5672
5677
- hci_req_init (& req , hdev );
5673
+ err = hci_schedule_adv_instance_sync (hdev , instance , true);
5674
+
5675
+ enable_advertising_instance (hdev , err );
5676
+ }
5678
5677
5679
- err = __hci_req_schedule_adv_instance (& req , instance , true);
5678
+ static int set_adv_sync (struct hci_dev * hdev , void * data )
5679
+ {
5680
+ struct mgmt_pending_cmd * cmd = data ;
5681
+ struct mgmt_mode * cp = cmd -> param ;
5682
+ u8 val = !!cp -> val ;
5680
5683
5681
- if (!err )
5682
- err = hci_req_run (& req , enable_advertising_instance );
5684
+ if (cp -> val == 0x02 )
5685
+ hci_dev_set_flag (hdev , HCI_ADVERTISING_CONNECTABLE );
5686
+ else
5687
+ hci_dev_clear_flag (hdev , HCI_ADVERTISING_CONNECTABLE );
5683
5688
5684
- if (err )
5685
- bt_dev_err (hdev , "failed to re-configure advertising" );
5689
+ cancel_adv_timeout (hdev );
5686
5690
5687
- unlock :
5688
- hci_dev_unlock (hdev );
5691
+ if (val ) {
5692
+ /* Switch to instance "0" for the Set Advertising setting.
5693
+ * We cannot use update_[adv|scan_rsp]_data() here as the
5694
+ * HCI_ADVERTISING flag is not yet set.
5695
+ */
5696
+ hdev -> cur_adv_instance = 0x00 ;
5697
+
5698
+ if (ext_adv_capable (hdev )) {
5699
+ hci_start_ext_adv_sync (hdev , 0x00 );
5700
+ } else {
5701
+ hci_update_adv_data_sync (hdev , 0x00 );
5702
+ hci_update_scan_rsp_data_sync (hdev , 0x00 );
5703
+ hci_enable_advertising_sync (hdev );
5704
+ }
5705
+ } else {
5706
+ hci_disable_advertising_sync (hdev );
5707
+ }
5708
+
5709
+ return 0 ;
5689
5710
}
5690
5711
5691
5712
static int set_advertising (struct sock * sk , struct hci_dev * hdev , void * data ,
5692
5713
u16 len )
5693
5714
{
5694
5715
struct mgmt_mode * cp = data ;
5695
5716
struct mgmt_pending_cmd * cmd ;
5696
- struct hci_request req ;
5697
5717
u8 val , status ;
5698
5718
int err ;
5699
5719
@@ -5759,40 +5779,13 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
5759
5779
}
5760
5780
5761
5781
cmd = mgmt_pending_add (sk , MGMT_OP_SET_ADVERTISING , hdev , data , len );
5762
- if (!cmd ) {
5782
+ if (!cmd )
5763
5783
err = - ENOMEM ;
5764
- goto unlock ;
5765
- }
5766
-
5767
- hci_req_init (& req , hdev );
5768
-
5769
- if (cp -> val == 0x02 )
5770
- hci_dev_set_flag (hdev , HCI_ADVERTISING_CONNECTABLE );
5771
5784
else
5772
- hci_dev_clear_flag (hdev , HCI_ADVERTISING_CONNECTABLE );
5773
-
5774
- cancel_adv_timeout (hdev );
5785
+ err = hci_cmd_sync_queue (hdev , set_adv_sync , cmd ,
5786
+ set_advertising_complete );
5775
5787
5776
- if (val ) {
5777
- /* Switch to instance "0" for the Set Advertising setting.
5778
- * We cannot use update_[adv|scan_rsp]_data() here as the
5779
- * HCI_ADVERTISING flag is not yet set.
5780
- */
5781
- hdev -> cur_adv_instance = 0x00 ;
5782
-
5783
- if (ext_adv_capable (hdev )) {
5784
- __hci_req_start_ext_adv (& req , 0x00 );
5785
- } else {
5786
- __hci_req_update_adv_data (& req , 0x00 );
5787
- __hci_req_update_scan_rsp_data (& req , 0x00 );
5788
- __hci_req_enable_advertising (& req );
5789
- }
5790
- } else {
5791
- __hci_req_disable_advertising (& req );
5792
- }
5793
-
5794
- err = hci_req_run (& req , set_advertising_complete );
5795
- if (err < 0 )
5788
+ if (err < 0 && cmd )
5796
5789
mgmt_pending_remove (cmd );
5797
5790
5798
5791
unlock :
0 commit comments