@@ -927,13 +927,6 @@ static struct mgmt_pending_cmd *pending_find(u16 opcode, struct hci_dev *hdev)
927927 return mgmt_pending_find (HCI_CHANNEL_CONTROL , opcode , hdev );
928928}
929929
930- static struct mgmt_pending_cmd * pending_find_data (u16 opcode ,
931- struct hci_dev * hdev ,
932- const void * data )
933- {
934- return mgmt_pending_find_data (HCI_CHANNEL_CONTROL , opcode , hdev , data );
935- }
936-
937930u8 mgmt_get_adv_discov_flags (struct hci_dev * hdev )
938931{
939932 struct mgmt_pending_cmd * cmd ;
@@ -6702,82 +6695,76 @@ static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data,
67026695 return err ;
67036696}
67046697
6705- static int clock_info_cmd_complete (struct mgmt_pending_cmd * cmd , u8 status )
6698+ static void get_clock_info_complete (struct hci_dev * hdev , void * data , int err )
67066699{
6707- struct hci_conn * conn = cmd -> user_data ;
6700+ struct mgmt_pending_cmd * cmd = data ;
6701+ struct mgmt_cp_get_clock_info * cp = cmd -> param ;
67086702 struct mgmt_rp_get_clock_info rp ;
6709- struct hci_dev * hdev ;
6710- int err ;
6703+ struct hci_conn * conn = cmd -> user_data ;
6704+ u8 status = mgmt_status (err );
6705+
6706+ bt_dev_dbg (hdev , "err %d" , err );
67116707
67126708 memset (& rp , 0 , sizeof (rp ));
6713- memcpy (& rp .addr , cmd -> param , sizeof (rp .addr ));
6709+ bacpy (& rp .addr .bdaddr , & cp -> addr .bdaddr );
6710+ rp .addr .type = cp -> addr .type ;
67146711
6715- if (status )
6712+ if (err )
67166713 goto complete ;
67176714
6718- hdev = hci_dev_get (cmd -> index );
6719- if (hdev ) {
6720- rp .local_clock = cpu_to_le32 (hdev -> clock );
6721- hci_dev_put (hdev );
6722- }
6715+ rp .local_clock = cpu_to_le32 (hdev -> clock );
67236716
67246717 if (conn ) {
67256718 rp .piconet_clock = cpu_to_le32 (conn -> clock );
67266719 rp .accuracy = cpu_to_le16 (conn -> clock_accuracy );
6727- }
6728-
6729- complete :
6730- err = mgmt_cmd_complete (cmd -> sk , cmd -> index , cmd -> opcode , status , & rp ,
6731- sizeof (rp ));
6732-
6733- if (conn ) {
67346720 hci_conn_drop (conn );
67356721 hci_conn_put (conn );
67366722 }
67376723
6738- return err ;
6724+ complete :
6725+ mgmt_cmd_complete (cmd -> sk , cmd -> index , cmd -> opcode , status , & rp ,
6726+ sizeof (rp ));
6727+
6728+ mgmt_pending_free (cmd );
67396729}
67406730
6741- static void get_clock_info_complete (struct hci_dev * hdev , u8 status , u16 opcode )
6731+ static int get_clock_info_sync (struct hci_dev * hdev , void * data )
67426732{
6743- struct hci_cp_read_clock * hci_cp ;
6744- struct mgmt_pending_cmd * cmd ;
6745- struct hci_conn * conn ;
6746-
6747- bt_dev_dbg ( hdev , "status %u" , status ) ;
6733+ struct mgmt_pending_cmd * cmd = data ;
6734+ struct mgmt_cp_get_clock_info * cp = cmd -> param ;
6735+ struct hci_cp_read_clock hci_cp ;
6736+ struct hci_conn * conn = cmd -> user_data ;
6737+ int err ;
67486738
6749- hci_dev_lock (hdev );
6739+ memset (& hci_cp , 0 , sizeof (hci_cp ));
6740+ err = hci_read_clock_sync (hdev , & hci_cp );
67506741
6751- hci_cp = hci_sent_cmd_data (hdev , HCI_OP_READ_CLOCK );
6752- if (!hci_cp )
6753- goto unlock ;
6742+ if (conn ) {
6743+ /* Make sure connection still exists */
6744+ conn = hci_conn_hash_lookup_ba (hdev , ACL_LINK ,
6745+ & cp -> addr .bdaddr );
67546746
6755- if (hci_cp -> which ) {
6756- u16 handle = __le16_to_cpu (hci_cp -> handle );
6757- conn = hci_conn_hash_lookup_handle (hdev , handle );
6758- } else {
6759- conn = NULL ;
6747+ if (conn && conn == cmd -> user_data &&
6748+ conn -> state == BT_CONNECTED ) {
6749+ hci_cp .handle = cpu_to_le16 (conn -> handle );
6750+ hci_cp .which = 0x01 ; /* Piconet clock */
6751+ err = hci_read_clock_sync (hdev , & hci_cp );
6752+ } else if (cmd -> user_data ) {
6753+ hci_conn_drop (cmd -> user_data );
6754+ hci_conn_put (cmd -> user_data );
6755+ cmd -> user_data = NULL ;
6756+ }
67606757 }
67616758
6762- cmd = pending_find_data (MGMT_OP_GET_CLOCK_INFO , hdev , conn );
6763- if (!cmd )
6764- goto unlock ;
6765-
6766- cmd -> cmd_complete (cmd , mgmt_status (status ));
6767- mgmt_pending_remove (cmd );
6768-
6769- unlock :
6770- hci_dev_unlock (hdev );
6759+ return err ;
67716760}
67726761
67736762static int get_clock_info (struct sock * sk , struct hci_dev * hdev , void * data ,
6774- u16 len )
6763+ u16 len )
67756764{
67766765 struct mgmt_cp_get_clock_info * cp = data ;
67776766 struct mgmt_rp_get_clock_info rp ;
6778- struct hci_cp_read_clock hci_cp ;
67796767 struct mgmt_pending_cmd * cmd ;
6780- struct hci_request req ;
67816768 struct hci_conn * conn ;
67826769 int err ;
67836770
@@ -6815,31 +6802,25 @@ static int get_clock_info(struct sock *sk, struct hci_dev *hdev, void *data,
68156802 conn = NULL ;
68166803 }
68176804
6818- cmd = mgmt_pending_add (sk , MGMT_OP_GET_CLOCK_INFO , hdev , data , len );
6819- if (!cmd ) {
6805+ cmd = mgmt_pending_new (sk , MGMT_OP_GET_CLOCK_INFO , hdev , data , len );
6806+ if (!cmd )
68206807 err = - ENOMEM ;
6821- goto unlock ;
6822- }
6823-
6824- cmd -> cmd_complete = clock_info_cmd_complete ;
6808+ else
6809+ err = hci_cmd_sync_queue (hdev , get_clock_info_sync , cmd ,
6810+ get_clock_info_complete );
68256811
6826- hci_req_init (& req , hdev );
6812+ if (err < 0 ) {
6813+ err = mgmt_cmd_complete (sk , hdev -> id , MGMT_OP_GET_CLOCK_INFO ,
6814+ MGMT_STATUS_FAILED , & rp , sizeof (rp ));
68276815
6828- memset ( & hci_cp , 0 , sizeof ( hci_cp ));
6829- hci_req_add ( & req , HCI_OP_READ_CLOCK , sizeof ( hci_cp ), & hci_cp );
6816+ if ( cmd )
6817+ mgmt_pending_free ( cmd );
68306818
6831- if (conn ) {
6819+ } else if (conn ) {
68326820 hci_conn_hold (conn );
68336821 cmd -> user_data = hci_conn_get (conn );
6834-
6835- hci_cp .handle = cpu_to_le16 (conn -> handle );
6836- hci_cp .which = 0x01 ; /* Piconet clock */
6837- hci_req_add (& req , HCI_OP_READ_CLOCK , sizeof (hci_cp ), & hci_cp );
68386822 }
68396823
6840- err = hci_req_run (& req , get_clock_info_complete );
6841- if (err < 0 )
6842- mgmt_pending_remove (cmd );
68436824
68446825unlock :
68456826 hci_dev_unlock (hdev );
0 commit comments