espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.85k stars 7.32k forks source link

ESP32 cannot connect to a smartphone (IDFGH-4223) #6082

Open enimzuk opened 4 years ago

enimzuk commented 4 years ago

Environment

Problem Description

Hello,

We're developing MITM project which is supposed to stream audio from a smartphone to another headset both connected to one ESP32. It is based on BTStack develop branch: https://github.com/bluekitchen/btstack and its MITM sample: https://bluekitchen-gmbh.com/files/aug-global/a2dp_mitm_demo.c

The headset is Philips SHB 5250. We're not sure that this behavior will reproduce with all types of headsets. The smartphone is iphone 7 plus or Samsung galaxy S7. It doesn't look like it depends on a phone model.

First we initiate a connection to the headset from ESP32. Then we initiate a connection to the smartphone from ESP32.

We use the following write link policy fix to make sure that ESP32 stays in Master role when connected to the headset. Only in this role configuration it has enough throughput to stream audio with this headset.

When we connect the headset we use the hci command of btstack to disable role switches after receiving HCI_EVENT_CONNECTION_COMPLETE event for the headset connection, e.g.

hci_send_cmd(&hci_write_link_policy_settings, mitm_context.a2dp_source_con_handle, LM_LINK_POLICY_DISABLE_ALL_LM_MODES) where LM_LINK_POLICY_DISABLE_ALL_LM_MODES is 0.

The headset connects successfully and ESP32 is in master role.

After that we try to connect the smartphone to start streaming audio from the smartphone to the headset. However, the smartphone cannot connect.

HCI log doesn't provide much information to understand the issue. BTStack developers say that the actual issue is with ESP32.

The following is also notable. We can connect both the headset and the smartphone without such issues if for example:

  1. First we connect the smartphone and then we connect the headset with the fix mentioned above. The connections are established and the streaming is working fine. ESP32 is in Master role.
  2. First we connect the headset and then the smartphone without the fix mentioned above. The connections are established but ESP32 is in Slave role for the headset connection in this case. Therefore, it cannot steam audio fast enough.

Expected Behavior

ESP32 connects to the smartphone after the headset is connected with the write link policy fix.

Actual Behavior

ESP32 cannot connect to the smartphone after the headset is connected with the write link policy fix.

Steps to reproduce

  1. Get latest btstack from develop branch https://github.com/bluekitchen/btstack
  2. Compile and run mitm sample https://bluekitchen-gmbh.com/files/aug-global/a2dp_mitm_demo.c
  3. Connect headset using console command 'h'
  4. Connect smartphone using console command 'p'

Code to reproduce this issue

BTStack from develop branch: https://github.com/bluekitchen/btstack Sample application: https://bluekitchen-gmbh.com/files/aug-global/a2dp_mitm_demo.c

Debug Logs

logs.zip

https://drive.google.com/drive/folders/1CvIkjiJ7Vm39Pt4G_zFrzuJe27FIgKxL?usp=sharing OR https://drive.google.com/drive/folders/1gd4sZkBdaDjndkYJ6Qta42DEmzMBjncU?usp=sharing

Thanks!

Alvin1Zhang commented 4 years ago

Thanks for reporting.

mringwal commented 4 years ago

Hi there

A few details:

Quick summary from HCI view:

Asides from trying to reproduce this, could you review the BTDM sources if there is anything suspicious about this use of link policies? the goal was to enforce the connection to headset to stay in master role.

Thanks Matthias

munho-espressif commented 3 years ago

Hi @mringwal

  1. Why did the developer of BTStack say that the actual issue is with ESP32?
  2. I can't open your log because I don't have a corresponding application.

Thanks

mringwal commented 3 years ago

Hi @munho-espressif

The connection to the smartphone fails with a link layer error. However, it only happens if there's already a connection to the specific Philips headset. If there's no second connection, or, the second connection is to some other speaker, the connection to the smartphone is established as expected. So, the connection seems to fail only if there other connection of the ESP32 is to this headphone. (that's why it seems that the ESP32 Link Layer is causing this issue. The headset should not have any influence on other connections od the ESP32)

You can open the log files with Wireshark.

Best Matthias

munho-espressif commented 3 years ago

Hi @mringwal

Ok, I will try to reproduce your issue.

Thanks

mringwal commented 3 years ago

@munho-espressif That would be great. Asides from getting the same headphone, I don't know this could be reproduced - as mentioned, it doesn't happen with other headsets.

ghost commented 3 years ago

@mringwal Thanks for your patience. We have bought the Philips SHB 5250 and will look into the problem tomorrow.

xiongweichao commented 3 years ago

Hi, @mringwal

First, we start the connection to the headset from ESP32. Then we started connecting to different smartphone from the ESP32, and there might be a connection failure. So I think it might have something to do with phone compatibility.

Thanks

ghost commented 3 years ago

@xiongweichao

Please provide the device list which cannot be connected after successfully connecting to Philips SHB 5250. Thanks.

mringwal commented 3 years ago

Hi. The issue was reported by @enimzuk He originally reported issues with an iPhone 7 Plus and a Samsung Galaxy S7.

I would assume it's somehow related to the Philips headset that tries to become master, but this is rejected in the example application. If that's true, it should also happen with other smartphones.

My reason is like this: if the second connection fails if the fist connection is with this Philips headset, but not with another headset, then the ESP32 is responsible for this. The connection to the headset should have no impact on the new one to the smartphone.

Have you been able to reproduce this? Do you also have a Bluetooth sniffer and are able to understand what's actually going on?

Thanks

mringwal commented 3 years ago

@enimzuk Hi. Could you try with current esp-idf again? I've just rested a similar, but different issue from Jan 2020, and that one has been fixed by Espressif.

xiongweichao commented 3 years ago

Hi, @mringwal

The secure connection is not supported by ESP32. The ESP32 could not establish a connection with HUAWEI P30 when tested with A2DP_MITM_DEMO. The reason why the connection failed is shown in the figure. ESP32 is in master role.

Thanks. btstack_a2dp_mitm_huaweip30

xiongweichao commented 4 months ago

Hi @enimzuk @mringwal Would you please kindly help share updates if this issue still exists? Thanks!

mringwal commented 4 months ago

@enimzuk You still around? I wasn't able to reproduce this at the time.