@@ -509,6 +509,7 @@ static int clcc_finish(struct at_client *hf_at, enum at_result result,
509509 clear_call_without_clcc (hf );
510510 }
511511
512+ atomic_clear_bit (hf -> flags , BT_HFP_HF_FLAG_USR_CLCC_CMD );
512513 atomic_clear_bit (hf -> flags , BT_HFP_HF_FLAG_CLCC_PENDING );
513514
514515 return 0 ;
@@ -529,32 +530,36 @@ static void clear_call_clcc_state(struct bt_hfp_hf *hf)
529530 }
530531}
531532
532- static void hf_query_current_calls (struct bt_hfp_hf * hf )
533+ static int hf_query_current_calls (struct bt_hfp_hf * hf )
533534{
534535 int err ;
535536
536537 LOG_DBG ("" );
537538
538539 if (!hf ) {
539540 LOG_ERR ("No HF connection found" );
540- return ;
541+ return - EINVAL ;
541542 }
542543
543544 if (!atomic_test_bit (hf -> flags , BT_HFP_HF_FLAG_CONNECTED )) {
544- return ;
545+ return - ENOTCONN ;
545546 }
546547
547548 if (!(hf -> ag_features & BT_HFP_AG_FEATURE_ECS )) {
548- return ;
549+ return - ENOTSUP ;
549550 }
550551
551552 if (!(hf -> hf_features & BT_HFP_HF_FEATURE_ECS )) {
552- return ;
553+ return - ENOTSUP ;
553554 }
554555
555556 if (atomic_test_and_set_bit (hf -> flags , BT_HFP_HF_FLAG_CLCC_PENDING )) {
556557 k_work_reschedule (& hf -> deferred_work , K_MSEC (HF_ENHANCED_CALL_STATUS_TIMEOUT ));
557- return ;
558+ return 0 ;
559+ }
560+
561+ if (atomic_test_and_clear_bit (hf -> flags , BT_HFP_HF_FLAG_USR_CLCC_PND )) {
562+ atomic_set_bit (hf -> flags , BT_HFP_HF_FLAG_USR_CLCC_CMD );
558563 }
559564
560565 clear_call_clcc_state (hf );
@@ -563,6 +568,8 @@ static void hf_query_current_calls(struct bt_hfp_hf *hf)
563568 if (err < 0 ) {
564569 LOG_ERR ("Fail to query current calls on %p" , hf );
565570 }
571+
572+ return err ;
566573}
567574
568575static void hf_call_state_update (struct bt_hfp_hf_call * call , int state )
@@ -812,20 +819,6 @@ static int clcc_handle(struct at_client *hf_at)
812819 return err ;
813820 }
814821
815- if (new_call ) {
816- set_call_incoming_flag (call , dir == BT_HFP_CLCC_DIR_INCOMING );
817- }
818-
819- if (atomic_test_bit (call -> flags , BT_HFP_HF_CALL_INCOMING ) ||
820- atomic_test_bit (call -> flags , BT_HFP_HF_CALL_INCOMING_3WAY )) {
821- incoming = true;
822- }
823-
824- if (incoming != (dir == BT_HFP_CLCC_DIR_INCOMING )) {
825- LOG_ERR ("Call dir of HF is not aligned with AG" );
826- return 0 ;
827- }
828-
829822 err = at_get_number (hf_at , & status );
830823 if (err < 0 ) {
831824 LOG_ERR ("Error getting status" );
@@ -846,19 +839,48 @@ static int clcc_handle(struct at_client *hf_at)
846839
847840 number = at_get_string (hf_at );
848841
849- if (number ) {
842+ if (number != NULL ) {
850843 (void )at_get_number (hf_at , & type );
851844 }
852845
846+ if (atomic_test_bit (hf -> flags , BT_HFP_HF_FLAG_USR_CLCC_CMD ) &&
847+ (bt_hf -> query_call != NULL )) {
848+ struct bt_hfp_hf_current_call current_call ;
849+
850+ current_call .index = (uint8_t )index ;
851+ current_call .dir = (enum bt_hfp_hf_call_dir )dir ;
852+ current_call .status = (enum bt_hfp_hf_call_status )status ;
853+ current_call .mode = (enum bt_hfp_hf_call_mode )mode ;
854+ current_call .multiparty = mpty > 0 ? true : false;
855+ current_call .number = number ;
856+ current_call .type = (uint8_t )type ;
857+
858+ bt_hf -> query_call (hf , & current_call );
859+ }
860+
861+ LOG_DBG ("CLCC idx %d dir %d status %d mode %d mpty %d number %s type %d" ,
862+ index , dir , status , mode , mpty , number , type );
863+
864+ if (new_call ) {
865+ set_call_incoming_flag (call , dir == BT_HFP_CLCC_DIR_INCOMING );
866+ }
867+
868+ if (atomic_test_bit (call -> flags , BT_HFP_HF_CALL_INCOMING ) ||
869+ atomic_test_bit (call -> flags , BT_HFP_HF_CALL_INCOMING_3WAY )) {
870+ incoming = true;
871+ }
872+
873+ if (incoming != (dir == BT_HFP_CLCC_DIR_INCOMING )) {
874+ LOG_ERR ("Call dir of HF is not aligned with AG" );
875+ return 0 ;
876+ }
877+
853878 if (new_call ) {
854879 new_call_state_update (call , incoming , status );
855880 } else {
856881 call_state_update (call , status );
857882 }
858883
859- LOG_DBG ("CLCC idx %d dir %d status %d mode %d mpty %d number %s type %d" ,
860- index , dir , status , mode , mpty , number , type );
861-
862884 return 0 ;
863885}
864886#endif /* CONFIG_BT_HFP_HF_ECS */
@@ -1054,8 +1076,12 @@ static void bt_hf_deferred_work(struct k_work *work)
10541076{
10551077 struct k_work_delayable * dwork = k_work_delayable_from_work (work );
10561078 struct bt_hfp_hf * hf = CONTAINER_OF (dwork , struct bt_hfp_hf , deferred_work );
1079+ int err ;
10571080
1058- hf_query_current_calls (hf );
1081+ err = hf_query_current_calls (hf );
1082+ if (err != 0 ) {
1083+ LOG_ERR ("Failed to query current calls: %d" , err );
1084+ }
10591085}
10601086
10611087static void set_all_calls_held_state (struct bt_hfp_hf * hf , bool held )
@@ -4273,3 +4299,28 @@ int bt_hfp_hf_disconnect(struct bt_hfp_hf *hf)
42734299
42744300 return bt_rfcomm_dlc_disconnect (& hf -> rfcomm_dlc );
42754301}
4302+
4303+ int bt_hfp_hf_query_list_of_current_calls (struct bt_hfp_hf * hf )
4304+ {
4305+ int err ;
4306+
4307+ if ((hf == NULL ) || (bt_hf == NULL ) || (bt_hf -> query_call == NULL )) {
4308+ return - EINVAL ;
4309+ }
4310+
4311+ if (!IS_ENABLED (CONFIG_BT_HFP_HF_ECS )) {
4312+ return - ENOTSUP ;
4313+ }
4314+
4315+ if (atomic_test_and_set_bit (hf -> flags , BT_HFP_HF_FLAG_USR_CLCC_PND )) {
4316+ return - EBUSY ;
4317+ }
4318+
4319+ err = hf_query_current_calls (hf );
4320+ if (err != 0 ) {
4321+ atomic_clear_bit (hf -> flags , BT_HFP_HF_FLAG_USR_CLCC_PND );
4322+ LOG_ERR ("Failed to query current calls, err %d" , err );
4323+ }
4324+
4325+ return err ;
4326+ }
0 commit comments