bluekitchen / btstack

Dual-mode Bluetooth stack, with small memory footprint.
http://bluekitchen-gmbh.com
Other
1.69k stars 607 forks source link

Multiple HFP connections / single call, callsetup, callheld status #614

Closed amorniroli closed 3 months ago

amorniroli commented 3 months ago

Describe the bug

Inside hfp_hf.c I've noticed these three variables which are declared as "singleton".

static hfp_call_status_t      hfp_hf_call_status;
static hfp_callsetup_status_t hfp_hf_callsetup_status;
static hfp_callheld_status_t  hfp_hf_callheld_status;

Some BT stack events (e.g. HFP_SUBEVENT_START_RINGING) are not triggered if, for example, we have two mobile phones connected to the controller, and 1 call is already ringing.

To Reproduce

If needed, I'll provide example in the form of 'btstack_main' to reproduce the issue.

As pseudo code:

Expected behavior I'd expect that both START_RINGING would have been routed correctly.

HCI Packet Logs I can produce it if needed.

Environment: (please complete the following information):

Additional context I think the problem is that the check is done on "singleton" variable and not real HFP context status

e.g.

                bool ringing_old = hfp_is_ringing(hfp_hf_callsetup_status);
                bool ringing_new = hfp_is_ringing(new_hf_callsetup_status);
                if (ringing_old != ringing_new){
                    if (ringing_new){
                        hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_START_RINGING);
                    } else {
                        hfp_emit_simple_event(hfp_connection, HFP_SUBEVENT_STOP_RINGING);
                    } 
                }     
mringwal commented 3 months ago

You're definitely right about the problem of tracking the call state of multiple mobile phones in a single variable. On a first glance, moving these into the per connection state might already be sufficient. We'll give it a try next week.

mringwal commented 3 months ago

Hi @amorniroli Could you try our changes on develop. We merely moved the globals into the per connection struct and initialized them on connect. Please let me know how this works for two phones, thanks!

amorniroli commented 3 months ago

Hi @amorniroli Could you try our changes on develop. We merely moved the globals into the per connection struct and initialized them on connect. Please let me know how this works for two phones, thanks!

Hi @mringwal , thanks for the fix: it's working as expected.

mringwal commented 3 months ago

Great. Thanks for validating the fix.