nrf5340 audio broadcast sink sync fail when connecting with app through BLE

Hello,

I'm using an NRF5340 audio broadcast sink, and the nRF Connect SDK version is v3.4.0.

I've added ble connection related definitions to the code to allow the mobile app to connect to the NRF5340 audio broadcast sink via BLE.

CONFIG_APP_CONTROL=y
CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_ATT_PREPARE_COUNT=3
CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION=n
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
CONFIG_BLE_ACL_SUP_TIMEOUT=0
CONFIG_BT_MAX_CONN=2

During testing, I found that when connected to the app through ble, the broadcast sink cannot sync with the broadcast source, and occurring "invalid parameter error."

Here is the error log.

rtt:~$ ASSERTION FAIL [attr] @ WEST_TOPDIR/zephyr/subsys/bluetooth/host/gatt.c:3343
        invalid parameter

HS [00:00:23.684,265] <inf> bt_mgmt_scan: Broadcast source NRF5340_BROADCASTER found, id: 0xdffe3d
HS [00:00:23.841,583] <inf> bt_mgmt_scan: PA synced to name: NRF5340_BROADCASTER, id: 0xdffe3d, addr: 00:02:5B:00:FF:03 (public)
HS [00:00:23.847,137] <err> error_handler: Assert post action: file: WEST_TOPDIR/zephyr/subsys/bluetooth/host/gatt.c, line 3343
HS [00:00:23.847,167] <err> error_handler: Caught system error -- reason 0. Entering infinite loop
rtt:~$ 

However, if not connected to the app through ble, the broadcast sink can successfully sync with the broadcast source, but after syncing, it cannot connect to the app through ble.

I previously used nRF Connect SDK v2.2.0 to achieve the same functionality without this problem. How can I modify the code to allow the v3.4.0 broadcast sink to simultaneously sync with the source and connect to the app through ble?

Parents Reply Children
  • Thank you for your reply.

    Now I've added `CONFIG_BT_MAX_CONN` to both `prj.conf` and `overlay-broadcast_sink.conf`. Without connecting to the app via BLE, the broadcast sink can sync with the broadcast source, and after synchronization, it can connect to the app via BLE. However, if it connects to the app via BLE first, it still cannot synchronize with the broadcast source.

    In short, currently, synchronizing with the broadcast source first and then connecting to the app via BLE succeeds, but connecting to the app via BLE first and then synchronizing with the broadcast source causes problems.

    where bt_gatt_is_subscribed() is being called from, do you know?

    `bt_gatt_is_subscribed` is called from `set_receive_state_changed_cb` in bap_scan_delegator.c.

    Also, do you get the same error if you keep CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION enabled?

    If `CONFIG_BT_GATT_ENFORCE_SUBSCRIPTION` is enabled, BLE read/write operations after connecting to the app via BLE will have problems, so I'm not considering enabling it.

  • Thanks, knowing that the call is made from set_receive_state_changed_cb() helps narrow down the problem. I will check with the developers who are more familiar with this codebase to get their thoughts. In the meantime, you could try skipping notifications when the attr pointer is NULL.

    static void set_receive_state_changed_cb(struct bt_conn *conn, void *data)
    {
    	struct bass_recv_state_internal *internal_state = data;
    	struct bass_recv_state_flags *flags = &internal_state->flags[bt_conn_index(conn)];
    	struct bt_conn_info conn_info;
    	int err;
    	
    	if (internal_state->attr == NULL) {
    		return;
    	}
    	...

  • Update: I discussed this with one of the developers who confirmed that this is a bug. It was fixed by Bluetooth: BAP: SD: Notify only bonded devices on reconnect by Thalley · Pull Request #106981 · zeph…. Unfortunately, it has not been back ported to nRF Connect SDK v3.4.x, but they will look into doing that. 

    In the meantime you may consider one of the following workarounds proposed by the developer:

    The suggested workaround in the devzone ticket 

     if (internal_state->attr == NULL) {
    return;
    }

    Is the simplest solution for the specific issue (i.e. set_receive_state_changed_cb could be called before bt_bap_scan_delegator_register. 

    Alternative solutions would be to call bt_bap_scan_delegator_register before establishing any connections (which is also idea to do so that new connections can actually discover the service). 

  • Thanks for your assistance. This method works.

    Now I can connect to the app via BLE and sync the source simultaneously, regardless of the order.

Related