Skip to content

Commit 5cd5076

Browse files
author
chaotaoyang
committed
[rel][bug][bt] hfp multi connect
redmine: #10095, REDMINE-10095 ext-redmine: #id, REDMINE-10095 [Description in detail] Change-Id: I04ce58a15543dedf3306a3e64d77a4aceb51c5ab
1 parent 5054fa6 commit 5cd5076

File tree

6 files changed

+1449
-478
lines changed

6 files changed

+1449
-478
lines changed

service/bt/bt_finsh/bts2_app_demo.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extern "C" {
7575

7676

7777
#define CFG_PIN_CODE "0000"
78-
78+
#define CFG_MAX_HFP_CONN_NUM 2
7979

8080
typedef enum
8181
{
@@ -143,6 +143,7 @@ typedef enum
143143
#endif
144144

145145
#ifdef CFG_HFP_AG
146+
146147
typedef enum
147148
{
148149
HFP_AG_APP_INIT, /* Initializing state */
@@ -153,32 +154,49 @@ typedef enum
153154

154155
typedef struct
155156
{
156-
bts2_ag_st st;
157-
bts2_ag_st old_st;
157+
BTS2S_BD_ADDR ag_bd;
158158
hfp_device_state_t profile_state;
159159
hfp_device_state_t pre_profile_state;
160160
hfp_call_state_t call_state;
161161
U8 srv_chnl;
162+
U8 mux_id;
163+
U8 is_use;
164+
} bts2_hfp_ag_device_info;
165+
166+
typedef struct
167+
{
168+
bts2_ag_st st;
169+
bts2_ag_st old_st;
170+
bts2_hfp_ag_device_info devices_info[CFG_MAX_HFP_CONN_NUM];
162171
} bts2_hfp_ag_inst_data;
163172
#endif
164173

165174
#ifdef CFG_HFP_HF
166175
typedef struct
167176
{
168-
bts2_hfp_st st;
177+
hfp_device_state_t profile_state;
178+
hfp_device_state_t pre_profile_state;
169179
/*
170180
profile_type 0 indicate hf connect
171181
profile_type 1 indicate hs connect
172182
*/
173183
U8 profile_type;
174184
U8 srv_chnl;
185+
U8 mux_id;
186+
U8 is_use;
175187
U8 esco_flag;
176188
BOOL voice_flag;
177189

178190
U16 peer_features;
179191
U16 sco_hdl;
180192
BTS2S_BD_ADDR hfp_bd;
181193
bts2_hfp_hf_cind cind_status;
194+
} bts2_hfp_hf_device_info;
195+
196+
typedef struct
197+
{
198+
bts2_hfp_st st;
199+
bts2_hfp_hf_device_info devices_info[CFG_MAX_HFP_CONN_NUM];
182200
} bts2_hfp_hf_inst_data;
183201
#endif
184202

@@ -322,7 +340,6 @@ typedef struct
322340
#ifdef CFG_HFP_HF
323341
bts2_hfp_hf_inst_data *hfp_hf_ptr;
324342
bts2_hfp_hf_inst_data hfp_hf_inst;
325-
U8 esco_flag;
326343
#endif
327344
#ifdef CFG_HFP_AG
328345
bts2_hfp_ag_inst_data hfp_ag_inst;

service/bt/bt_finsh/bts2_app_hfp_ag.c

Lines changed: 125 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,85 @@
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**********************************/
30108
static hfp_phone_call_info_t g_remote_calls_info ;
31109
hfp_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**********************************************/
142220
static 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

Comments
 (0)