@@ -6094,23 +6094,18 @@ static int set_bredr(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
60946094 return err ;
60956095}
60966096
6097- static void sc_enable_complete (struct hci_dev * hdev , u8 status , u16 opcode )
6097+ static void set_secure_conn_complete (struct hci_dev * hdev , void * data , int err )
60986098{
6099- struct mgmt_pending_cmd * cmd ;
6099+ struct mgmt_pending_cmd * cmd = data ;
61006100 struct mgmt_mode * cp ;
61016101
6102- bt_dev_dbg (hdev , "status %u" , status );
6103-
6104- hci_dev_lock (hdev );
6102+ bt_dev_dbg (hdev , "err %d" , err );
61056103
6106- cmd = pending_find (MGMT_OP_SET_SECURE_CONN , hdev );
6107- if (!cmd )
6108- goto unlock ;
6104+ if (err ) {
6105+ u8 mgmt_err = mgmt_status (err );
61096106
6110- if (status ) {
6111- mgmt_cmd_status (cmd -> sk , cmd -> index , cmd -> opcode ,
6112- mgmt_status (status ));
6113- goto remove ;
6107+ mgmt_cmd_status (cmd -> sk , cmd -> index , cmd -> opcode , mgmt_err );
6108+ goto done ;
61146109 }
61156110
61166111 cp = cmd -> param ;
@@ -6130,21 +6125,30 @@ static void sc_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode)
61306125 break ;
61316126 }
61326127
6133- send_settings_rsp (cmd -> sk , MGMT_OP_SET_SECURE_CONN , hdev );
6128+ send_settings_rsp (cmd -> sk , cmd -> opcode , hdev );
61346129 new_settings (hdev , cmd -> sk );
61356130
6136- remove :
6137- mgmt_pending_remove (cmd );
6138- unlock :
6139- hci_dev_unlock (hdev );
6131+ done :
6132+ mgmt_pending_free (cmd );
6133+ }
6134+
6135+ static int set_secure_conn_sync (struct hci_dev * hdev , void * data )
6136+ {
6137+ struct mgmt_pending_cmd * cmd = data ;
6138+ struct mgmt_mode * cp = cmd -> param ;
6139+ u8 val = !!cp -> val ;
6140+
6141+ /* Force write of val */
6142+ hci_dev_set_flag (hdev , HCI_SC_ENABLED );
6143+
6144+ return hci_write_sc_support_sync (hdev , val );
61406145}
61416146
61426147static int set_secure_conn (struct sock * sk , struct hci_dev * hdev ,
61436148 void * data , u16 len )
61446149{
61456150 struct mgmt_mode * cp = data ;
61466151 struct mgmt_pending_cmd * cmd ;
6147- struct hci_request req ;
61486152 u8 val ;
61496153 int err ;
61506154
@@ -6163,7 +6167,7 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
61636167
61646168 if (cp -> val != 0x00 && cp -> val != 0x01 && cp -> val != 0x02 )
61656169 return mgmt_cmd_status (sk , hdev -> id , MGMT_OP_SET_SECURE_CONN ,
6166- MGMT_STATUS_INVALID_PARAMS );
6170+ MGMT_STATUS_INVALID_PARAMS );
61676171
61686172 hci_dev_lock (hdev );
61696173
@@ -6194,12 +6198,6 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
61946198 goto failed ;
61956199 }
61966200
6197- if (pending_find (MGMT_OP_SET_SECURE_CONN , hdev )) {
6198- err = mgmt_cmd_status (sk , hdev -> id , MGMT_OP_SET_SECURE_CONN ,
6199- MGMT_STATUS_BUSY );
6200- goto failed ;
6201- }
6202-
62036201 val = !!cp -> val ;
62046202
62056203 if (val == hci_dev_test_flag (hdev , HCI_SC_ENABLED ) &&
@@ -6208,18 +6206,18 @@ static int set_secure_conn(struct sock *sk, struct hci_dev *hdev,
62086206 goto failed ;
62096207 }
62106208
6211- cmd = mgmt_pending_add (sk , MGMT_OP_SET_SECURE_CONN , hdev , data , len );
6212- if (!cmd ) {
6209+ cmd = mgmt_pending_new (sk , MGMT_OP_SET_SECURE_CONN , hdev , data , len );
6210+ if (!cmd )
62136211 err = - ENOMEM ;
6214- goto failed ;
6215- }
6212+ else
6213+ err = hci_cmd_sync_queue (hdev , set_secure_conn_sync , cmd ,
6214+ set_secure_conn_complete );
62166215
6217- hci_req_init (& req , hdev );
6218- hci_req_add (& req , HCI_OP_WRITE_SC_SUPPORT , 1 , & val );
6219- err = hci_req_run (& req , sc_enable_complete );
62206216 if (err < 0 ) {
6221- mgmt_pending_remove (cmd );
6222- goto failed ;
6217+ mgmt_cmd_status (sk , hdev -> id , MGMT_OP_SET_SECURE_CONN ,
6218+ MGMT_STATUS_FAILED );
6219+ if (cmd )
6220+ mgmt_pending_free (cmd );
62236221 }
62246222
62256223failed :
0 commit comments