2525#ifndef BT_USING_AG
2626 U8 g_flag_auto_answer_call = 1 ;
2727#endif
28+ /*******************************************device info func start**********************************************/
29+ static void bt_hfp_ag_app_init_device_info (bts2_hfp_ag_inst_data * ag_data )
30+ {
31+ if (ag_data -> devices_info )
32+ {
33+ for (int i = 0 ; i < CFG_MAX_HFP_CONN_NUM ; i ++ )
34+ {
35+ bmemset (& ag_data -> devices_info [i ], 0x00 , sizeof (bts2_hfp_ag_device_info ));
36+ ag_data -> devices_info [i ].call_state = HFP_CALL_IDLE ;
37+ ag_data -> devices_info [i ].is_use = 1 ;
38+ ag_data -> devices_info [i ].mux_id = 0xff ;
39+ ag_data -> devices_info [i ].pre_profile_state = HFP_DEVICE_DISCONNECTED ;
40+ ag_data -> devices_info [i ].profile_state = HFP_DEVICE_DISCONNECTED ;
41+ ag_data -> devices_info [i ].srv_chnl = 0xff ;
42+ }
43+ }
44+ }
45+
46+ static bts2_hfp_ag_device_info * bt_hfp_ag_app_get_device_by_mux_id (bts2_hfp_ag_inst_data * ag_data , U8 mux_id )
47+ {
48+ if (ag_data -> devices_info )
49+ {
50+ for (int i = 0 ; i < CFG_MAX_HFP_CONN_NUM ; i ++ )
51+ {
52+ if (ag_data -> devices_info [i ].mux_id == mux_id )
53+ {
54+ return & ag_data -> devices_info [i ];
55+ }
56+ }
57+ }
58+ return NULL ;
59+ }
60+
61+ static bts2_hfp_ag_device_info * bt_hfp_ag_app_alloc_device (bts2_hfp_ag_inst_data * ag_data )
62+ {
63+ if (ag_data -> devices_info )
64+ {
65+ for (int i = 0 ; i < CFG_MAX_HFP_CONN_NUM ; i ++ )
66+ {
67+ if (ag_data -> devices_info [i ].is_use )
68+ {
69+ ag_data -> devices_info [i ].is_use = 0 ;
70+ return & ag_data -> devices_info [i ];
71+ }
72+ }
73+ }
74+ return NULL ;
75+ }
2876
77+ static void bt_hfp_ag_app_dealloc_device (bts2_hfp_ag_device_info * device )
78+ {
79+ if (device )
80+ {
81+ bmemset (device , 0x00 , sizeof (bts2_hfp_ag_device_info ));
82+ device -> call_state = HFP_CALL_IDLE ;
83+ device -> is_use = 1 ;
84+ device -> mux_id = 0xff ;
85+ device -> pre_profile_state = HFP_DEVICE_DISCONNECTED ;
86+ device -> profile_state = HFP_DEVICE_DISCONNECTED ;
87+ device -> srv_chnl = 0xff ;
88+ }
89+ }
90+
91+ static bts2_hfp_ag_device_info * bt_hfp_ag_app_get_busy_device (bts2_hfp_ag_inst_data * ag_data )
92+ {
93+ if (ag_data -> devices_info )
94+ {
95+ for (int i = 0 ; i < CFG_MAX_HFP_CONN_NUM ; i ++ )
96+ {
97+ if (ag_data -> devices_info [i ].is_use == 0 )
98+ {
99+ return & ag_data -> devices_info [i ];
100+ }
101+ }
102+ }
103+ return NULL ;
104+ }
105+
106+ /*******************************************device info func end************************************************/
29107/*******************************************add for ag func test start**********************************/
30108static hfp_phone_call_info_t g_remote_calls_info ;
31109hfp_cind_status_t g_cind_states ;
@@ -138,7 +216,7 @@ hfp_phone_call_info_t *bt_hfp_ag_app_get_remote_call_info()
138216}
139217/*******************************************add for ag func test end**********************************/
140218
141- /*******************************************static func**********************************/
219+ /*******************************************static func********************************************** /
142220static void bt_hfp_ag_app_profile_service_update (bts2_hfp_ag_inst_data * ag_data , bts2_ag_st new_state )
143221{
144222 ag_data -> old_st = ag_data -> st ;
@@ -210,12 +288,25 @@ static void bt_hfp_ag_app_device_state_changed(bts2_app_stru *bts2_app_data, BTS
210288 case HFP_AG_APP_OPENING :
211289 case HFP_AG_APP_OPEN :
212290 {
213- p_data -> pre_profile_state = p_data -> profile_state ;
214- p_data -> profile_state = con_msg -> device_state ;
291+ bts2_hfp_ag_device_info * device_info = bt_hfp_ag_app_get_device_by_mux_id (p_data , con_msg -> mux_id );
292+ if (device_info == NULL )
293+ {
294+ device_info = bt_hfp_ag_app_alloc_device (p_data );
295+ if (device_info )
296+ {
297+ device_info -> mux_id = con_msg -> mux_id ;
298+ device_info -> ag_bd = con_msg -> bd ;
299+ }
300+ }
215301
216- if (p_data -> profile_state == p_data -> pre_profile_state )
302+ if (device_info )
217303 {
218- return ;
304+ device_info -> pre_profile_state = device_info -> profile_state ;
305+ device_info -> profile_state = con_msg -> device_state ;
306+ if (device_info -> profile_state == device_info -> pre_profile_state )
307+ {
308+ return ;
309+ }
219310 }
220311
221312 if (con_msg -> device_state == HFP_DEVICE_CONNECTED )
@@ -247,6 +338,12 @@ static void bt_hfp_ag_app_device_state_changed(bts2_app_stru *bts2_app_data, BTS
247338 profile_state .res = con_msg -> res ;
248339 profile_state .profile_channel = con_msg -> mux_id ;
249340 bt_profile_update_connection_state (BT_NOTIFY_HFP_AG , BT_NOTIFY_AG_PROFILE_DISCONNECTED ,& profile_state );
341+
342+ if (device_info )
343+ {
344+ bt_hfp_ag_app_dealloc_device (device_info );
345+ }
346+
250347#ifdef AUDIO_USING_MANAGER
251348 BTS2S_HF_AUDIO_INFO msg ;
252349 hfp_ag_audio_opt (& msg , 0 );
@@ -259,6 +356,18 @@ static void bt_hfp_ag_app_device_state_changed(bts2_app_stru *bts2_app_data, BTS
259356 {
260357 if (con_msg -> device_state == HFP_DEVICE_DISCONNECTED )
261358 {
359+ bts2_hfp_ag_device_info * device_info = bt_hfp_ag_app_get_device_by_mux_id (p_data , con_msg -> mux_id );
360+ if (device_info )
361+ {
362+ bt_hfp_ag_app_dealloc_device (device_info );
363+ device_info = NULL ;
364+ }
365+
366+ device_info = bt_hfp_ag_app_get_busy_device (p_data );
367+ if (device_info && (device_info -> profile_state != HFP_DEVICE_DISCONNECTED ))
368+ {
369+ bt_hfp_ag_disconnect_request (& device_info -> ag_bd );
370+ }
262371 hfp_ag_deregister ();
263372 }
264373 break ;
@@ -508,7 +617,6 @@ static void bt_hfp_ag_app_at_cmd_hdl(BTS2S_AG_AT_CMD_INFO *at_cmd)
508617 break ;
509618 }
510619 }
511-
512620}
513621
514622/*******************************************func API **********************************/
@@ -537,7 +645,6 @@ void bt_hfp_ag_msg_hdl(bts2_app_stru *bts2_app_data)
537645 BTS2S_AG_CONN_RES * con_msg ;
538646 con_msg = (BTS2S_AG_CONN_RES * )bts2_app_data -> recv_msg ;
539647
540-
541648 bt_hfp_ag_app_device_state_changed (bts2_app_data , con_msg );
542649 //USER_TRACE("BTS2MU_AG_CONN_STATE state: %d res: %d type %d", con_msg->device_state, con_msg->res, con_msg->type);
543650 break ;
@@ -660,10 +767,11 @@ void bt_hfp_ag_app_init(bts2_app_stru *bts2_app_data)
660767{
661768 if (bts2_app_data )
662769 {
663- bts2_app_data -> hfp_ag_inst .srv_chnl = 0xff ;
664- bts2_app_data -> hfp_ag_inst .profile_state = HFP_DEVICE_DISCONNECTED ;
665- bts2_app_data -> hfp_ag_inst .pre_profile_state = HFP_DEVICE_DISCONNECTED ;
666- bts2_app_data -> hfp_ag_inst .call_state = HFP_CALL_IDLE ;
770+ // bts2_app_data->hfp_ag_inst.srv_chnl = 0xff;
771+ // bts2_app_data->hfp_ag_inst.profile_state = HFP_DEVICE_DISCONNECTED;
772+ // bts2_app_data->hfp_ag_inst.pre_profile_state = HFP_DEVICE_DISCONNECTED;
773+ // bts2_app_data->hfp_ag_inst.call_state = HFP_CALL_IDLE;
774+ bt_hfp_ag_app_init_device_info (& bts2_app_data -> hfp_ag_inst );
667775 bt_hfp_ag_app_profile_service_update (& bts2_app_data -> hfp_ag_inst , HFP_AG_APP_INIT );
668776 bmemset (& g_remote_calls_info , 0x00 , sizeof (hfp_phone_call_info_t ));
669777#ifdef AUDIO_USING_MANAGER
@@ -680,12 +788,12 @@ void bt_hfp_start_profile_service(bts2_app_stru *bts2_app_data)
680788 {
681789 case HFP_AG_APP_INIT :
682790 {
683- U32 features = (U32 )(HFP_AG_FEAT_ECNR | \
791+ U32 features = (U32 )(HFP_AG_FEAT_ECNR | \
684792 HFP_AG_FEAT_INBAND | \
685793 HFP_AG_FEAT_REJECT | \
686- HFP_AG_FEAT_ECS | \
794+ HFP_AG_FEAT_ECS | \
687795 HFP_AG_FEAT_EXTERR | \
688- HFP_AG_FEAT_CODEC | \
796+ HFP_AG_FEAT_CODEC | \
689797 HFP_AG_FEAT_ESCO );
690798 hfp_ag_register (features );
691799 bt_hfp_ag_app_profile_service_update (ptr , HFP_AG_APP_OPENING );
@@ -727,9 +835,10 @@ void bt_hfp_stop_profile_service(bts2_app_stru *bts2_app_data)
727835 }
728836 case HFP_AG_APP_OPEN :
729837 {
730- if (ptr -> profile_state != HFP_DEVICE_DISCONNECTED )
838+ bts2_hfp_ag_device_info * device_info = bt_hfp_ag_app_get_busy_device (ptr );
839+ if (device_info && (device_info -> profile_state != HFP_DEVICE_DISCONNECTED ))
731840 {
732- bt_hfp_ag_disconnect_request (NULL );
841+ bt_hfp_ag_disconnect_request (& device_info -> ag_bd );
733842 }
734843 else
735844 {
0 commit comments