@@ -5608,29 +5608,25 @@ static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data,
56085608 return err ;
56095609}
56105610
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 )
56135612{
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 );
56155617}
56165618
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 )
56195620{
56205621 struct cmd_lookup match = { NULL , hdev };
5621- struct hci_request req ;
56225622 u8 instance ;
56235623 struct adv_info * adv_instance ;
5624- int err ;
5625-
5626- hci_dev_lock (hdev );
5624+ u8 status = mgmt_status (err );
56275625
56285626 if (status ) {
5629- u8 mgmt_err = mgmt_status (status );
5630-
56315627 mgmt_pending_foreach (MGMT_OP_SET_ADVERTISING , hdev ,
5632- cmd_status_rsp , & mgmt_err );
5633- goto unlock ;
5628+ cmd_status_rsp , & status );
5629+ return ;
56345630 }
56355631
56365632 if (hci_dev_test_flag (hdev , HCI_LE_ADV ))
@@ -5662,38 +5658,62 @@ static void set_advertising_complete(struct hci_dev *hdev, u8 status,
56625658 */
56635659 if (hci_dev_test_flag (hdev , HCI_ADVERTISING ) ||
56645660 list_empty (& hdev -> adv_instances ))
5665- goto unlock ;
5661+ return ;
56665662
56675663 instance = hdev -> cur_adv_instance ;
56685664 if (!instance ) {
56695665 adv_instance = list_first_entry_or_null (& hdev -> adv_instances ,
56705666 struct adv_info , list );
56715667 if (!adv_instance )
5672- goto unlock ;
5668+ return ;
56735669
56745670 instance = adv_instance -> instance ;
56755671 }
56765672
5677- hci_req_init (& req , hdev );
5673+ err = hci_schedule_adv_instance_sync (hdev , instance , true);
5674+
5675+ enable_advertising_instance (hdev , err );
5676+ }
56785677
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 ;
56805683
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 );
56835688
5684- if (err )
5685- bt_dev_err (hdev , "failed to re-configure advertising" );
5689+ cancel_adv_timeout (hdev );
56865690
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 ;
56895710}
56905711
56915712static int set_advertising (struct sock * sk , struct hci_dev * hdev , void * data ,
56925713 u16 len )
56935714{
56945715 struct mgmt_mode * cp = data ;
56955716 struct mgmt_pending_cmd * cmd ;
5696- struct hci_request req ;
56975717 u8 val , status ;
56985718 int err ;
56995719
@@ -5759,40 +5779,13 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
57595779 }
57605780
57615781 cmd = mgmt_pending_add (sk , MGMT_OP_SET_ADVERTISING , hdev , data , len );
5762- if (!cmd ) {
5782+ if (!cmd )
57635783 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 );
57715784 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 );
57755787
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 )
57965789 mgmt_pending_remove (cmd );
57975790
57985791unlock :
0 commit comments