@@ -3414,23 +3414,26 @@ int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip)
34143414 sizeof (ev ), skip );
34153415}
34163416
3417- static void set_default_phy_complete (struct hci_dev * hdev , u8 status ,
3418- u16 opcode , struct sk_buff * skb )
3417+ static void set_default_phy_complete (struct hci_dev * hdev , void * data , int err )
34193418{
3420- struct mgmt_pending_cmd * cmd ;
3421-
3422- bt_dev_dbg ( hdev , " status 0x%02x" , status );
3419+ struct mgmt_pending_cmd * cmd = data ;
3420+ struct sk_buff * skb = cmd -> skb ;
3421+ u8 status = mgmt_status ( err );
34233422
3424- hci_dev_lock (hdev );
3423+ if (!status ) {
3424+ if (!skb )
3425+ status = MGMT_STATUS_FAILED ;
3426+ else if (IS_ERR (skb ))
3427+ status = mgmt_status (PTR_ERR (skb ));
3428+ else
3429+ status = mgmt_status (skb -> data [0 ]);
3430+ }
34253431
3426- cmd = pending_find (MGMT_OP_SET_PHY_CONFIGURATION , hdev );
3427- if (!cmd )
3428- goto unlock ;
3432+ bt_dev_dbg (hdev , "status %d" , status );
34293433
34303434 if (status ) {
34313435 mgmt_cmd_status (cmd -> sk , hdev -> id ,
3432- MGMT_OP_SET_PHY_CONFIGURATION ,
3433- mgmt_status (status ));
3436+ MGMT_OP_SET_PHY_CONFIGURATION , status );
34343437 } else {
34353438 mgmt_cmd_complete (cmd -> sk , hdev -> id ,
34363439 MGMT_OP_SET_PHY_CONFIGURATION , 0 ,
@@ -3439,19 +3442,56 @@ static void set_default_phy_complete(struct hci_dev *hdev, u8 status,
34393442 mgmt_phy_configuration_changed (hdev , cmd -> sk );
34403443 }
34413444
3445+ if (skb && !IS_ERR (skb ))
3446+ kfree_skb (skb );
3447+
34423448 mgmt_pending_remove (cmd );
3449+ }
34433450
3444- unlock :
3445- hci_dev_unlock (hdev );
3451+ static int set_default_phy_sync (struct hci_dev * hdev , void * data )
3452+ {
3453+ struct mgmt_pending_cmd * cmd = data ;
3454+ struct mgmt_cp_set_phy_configuration * cp = cmd -> param ;
3455+ struct hci_cp_le_set_default_phy cp_phy ;
3456+ u32 selected_phys = __le32_to_cpu (cp -> selected_phys );
3457+
3458+ memset (& cp_phy , 0 , sizeof (cp_phy ));
3459+
3460+ if (!(selected_phys & MGMT_PHY_LE_TX_MASK ))
3461+ cp_phy .all_phys |= 0x01 ;
3462+
3463+ if (!(selected_phys & MGMT_PHY_LE_RX_MASK ))
3464+ cp_phy .all_phys |= 0x02 ;
3465+
3466+ if (selected_phys & MGMT_PHY_LE_1M_TX )
3467+ cp_phy .tx_phys |= HCI_LE_SET_PHY_1M ;
3468+
3469+ if (selected_phys & MGMT_PHY_LE_2M_TX )
3470+ cp_phy .tx_phys |= HCI_LE_SET_PHY_2M ;
3471+
3472+ if (selected_phys & MGMT_PHY_LE_CODED_TX )
3473+ cp_phy .tx_phys |= HCI_LE_SET_PHY_CODED ;
3474+
3475+ if (selected_phys & MGMT_PHY_LE_1M_RX )
3476+ cp_phy .rx_phys |= HCI_LE_SET_PHY_1M ;
3477+
3478+ if (selected_phys & MGMT_PHY_LE_2M_RX )
3479+ cp_phy .rx_phys |= HCI_LE_SET_PHY_2M ;
3480+
3481+ if (selected_phys & MGMT_PHY_LE_CODED_RX )
3482+ cp_phy .rx_phys |= HCI_LE_SET_PHY_CODED ;
3483+
3484+ cmd -> skb = __hci_cmd_sync (hdev , HCI_OP_LE_SET_DEFAULT_PHY ,
3485+ sizeof (cp_phy ), & cp_phy , HCI_CMD_TIMEOUT );
3486+
3487+ return 0 ;
34463488}
34473489
34483490static int set_phy_configuration (struct sock * sk , struct hci_dev * hdev ,
34493491 void * data , u16 len )
34503492{
34513493 struct mgmt_cp_set_phy_configuration * cp = data ;
3452- struct hci_cp_le_set_default_phy cp_phy ;
34533494 struct mgmt_pending_cmd * cmd ;
3454- struct hci_request req ;
34553495 u32 selected_phys , configurable_phys , supported_phys , unconfigure_phys ;
34563496 u16 pkt_type = (HCI_DH1 | HCI_DM1 );
34573497 bool changed = false;
@@ -3555,44 +3595,20 @@ static int set_phy_configuration(struct sock *sk, struct hci_dev *hdev,
35553595
35563596 cmd = mgmt_pending_add (sk , MGMT_OP_SET_PHY_CONFIGURATION , hdev , data ,
35573597 len );
3558- if (!cmd ) {
3598+ if (!cmd )
35593599 err = - ENOMEM ;
3560- goto unlock ;
3561- }
3562-
3563- hci_req_init (& req , hdev );
3564-
3565- memset (& cp_phy , 0 , sizeof (cp_phy ));
3566-
3567- if (!(selected_phys & MGMT_PHY_LE_TX_MASK ))
3568- cp_phy .all_phys |= 0x01 ;
3569-
3570- if (!(selected_phys & MGMT_PHY_LE_RX_MASK ))
3571- cp_phy .all_phys |= 0x02 ;
3572-
3573- if (selected_phys & MGMT_PHY_LE_1M_TX )
3574- cp_phy .tx_phys |= HCI_LE_SET_PHY_1M ;
3575-
3576- if (selected_phys & MGMT_PHY_LE_2M_TX )
3577- cp_phy .tx_phys |= HCI_LE_SET_PHY_2M ;
3578-
3579- if (selected_phys & MGMT_PHY_LE_CODED_TX )
3580- cp_phy .tx_phys |= HCI_LE_SET_PHY_CODED ;
3581-
3582- if (selected_phys & MGMT_PHY_LE_1M_RX )
3583- cp_phy .rx_phys |= HCI_LE_SET_PHY_1M ;
3584-
3585- if (selected_phys & MGMT_PHY_LE_2M_RX )
3586- cp_phy .rx_phys |= HCI_LE_SET_PHY_2M ;
3587-
3588- if (selected_phys & MGMT_PHY_LE_CODED_RX )
3589- cp_phy .rx_phys |= HCI_LE_SET_PHY_CODED ;
3600+ else
3601+ err = hci_cmd_sync_queue (hdev , set_default_phy_sync , cmd ,
3602+ set_default_phy_complete );
35903603
3591- hci_req_add (& req , HCI_OP_LE_SET_DEFAULT_PHY , sizeof (cp_phy ), & cp_phy );
3604+ if (err < 0 ) {
3605+ err = mgmt_cmd_status (sk , hdev -> id ,
3606+ MGMT_OP_SET_PHY_CONFIGURATION ,
3607+ MGMT_STATUS_FAILED );
35923608
3593- err = hci_req_run_skb ( & req , set_default_phy_complete );
3594- if ( err < 0 )
3595- mgmt_pending_remove ( cmd );
3609+ if ( cmd )
3610+ mgmt_pending_remove ( cmd );
3611+ }
35963612
35973613unlock :
35983614 hci_dev_unlock (hdev );
0 commit comments