nRF5340 Audio: Unicast Client Discovery Fails with -12 When Connecting to Headset

Hi Nordic team,

I'm working with the nrf5340_audio source code from the nRF Connect SDK and have compiled the project as a gateway. When I try to connect to a headset, I'm seeing the following logs:

-- [00:01:11.738,037] <inf> main: Received Command: connect AC:BF:71:77:35:D2 
-- [00:01:11.738,067] <inf> main: MAC address AC:BF:71:77:35:D2 is valid.
-- [00:01:11.738,098] <inf> main: Attempting to connect to AC:BF:71:77:35:D2...
-- [00:01:11.738,098] <inf> bt_mgmt_scan: Scanning started...
-- [00:01:12.042,724] <inf> bt_mgmt_scan: Device found: AC:BF:71:77:35:D2 (public) (Type: Public, RSSI: -52 dBm)
-- [00:01:16.739,135] <inf> bt_mgmt_scan: Device is advertising with type: Public
-- [00:01:16.739,776] <inf> bt_mgmt: Connection initiated index : 0 
Sending UART Response: connect AC:BF:71:77:35:D2
-- [00:01:16.808,563] <inf> bt_mgmt: MTU exchanged: 23/23
-- [00:01:16.808,746] <inf> bt_mgmt: Connected: AC:BF:71:77:35:D2 (public) (index 0)
-- [00:01:16.808,776] <inf> main: Connection event. Num connections: 1
Sending UART Response: Success: Connected Successfully OKEY
-- [00:01:16.812,011] <inf> bt_mgmt: Security level: 1
-- [00:01:17.060,394] <inf> bt_mgmt: MTU exchanged: 247/65
-- [00:01:17.110,931] <inf> bt_mgmt: Pairing request from AC:BF:71:77:35:D2 (public)
-- [00:01:17.110,931] <inf> bt_mgmt: Initiator key distribution: 0x03
-- [00:01:17.110,931] <inf> bt_mgmt: Responder key distribution: 0x03
-- [00:01:17.920,410] <inf> bt_mgmt: Security changed: AC:BF:71:77:35:D2 (public) level 2
-- [00:01:17.920,440] <inf> main: Security changed
-- [00:01:17.972,747] <inf> bt_mgmt: Pairing complete with AC:BF:71:77:35:D2 (public) (Bonded: Yes)
Security level: 2
-- [00:01:17.980,590] <wrn> unicast_client: Got err: 0 from conn: 0x200047c8
-- [00:01:18.170,257] <inf> bt_vol_ctlr: VCS discover finished
-- [00:01:19.380,310] <wrn> unicast_client: More than one sink endpoint found, idx 0 is used by default
-- [00:01:19.580,261] <wrn> bt_bap_unicast_client: No space left to parse ASE
-- [00:01:19.580,261] <err> unicast_client: Discovery failed: -12

From what I understand, the -12 error is -ENOMEM (Not enough core ) , but I’m not sure why this is happening.

How can I resolve this issue?

Is it related to buffer size or too many ASEs from the headset?

Any suggestions would be appreciated.

Thanks!

 

Parents
  • Hi,

    Are you using an Audio DK for this? Is this the default nrf5340_audio application/sample? What NCS version are you using? 

    And is the headset another a DK, a custom board, or an actual headset supporting LE Audio?

    Regards,

    Elfving

  • Hi,
    Thanks for the response.

    Are you using an Audio DK for this? Is this the default nrf5340_audio application/sample? What NCS version are you using? 

    Yes, I am using the nRF5340 Audio DK and running the default nrf5340_audio sample application compiled in gateway mode. The NCS version I’m using is v2.9.0.

    And is the headset another a DK, a custom board, or an actual headset supporting LE Audio?

    As for the headset, I’m using an actual LE Audio headset (not a DK or custom board).as I need to test with different LE Audio headsets.


    Best regards,
    Yash

  • Hi Elfving,

    Yes, I am absolutely sure that I’m using the nrf5340_audio sample from the Nordic SDK, not any of the samples from the Zephyr folder.

    Best regards
    Yash

  • Can you try adding these configurations and see if it helps? 

    CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT=20

    CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT=20

    And are you using an nrf5340 for this?

    Regards and have a good week-end,

    Elfving

  • Hi Elfving,

    Thanks for the suggestion!
    I tried adding the following configs as you suggested:

    CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT=20

    CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT=20

    However, after doing that, I now get the following error during runtime:

    -- [00:00:00.261,016] <inf> main: Starting BLE Client on nRF5340
    -- [00:00:00.272,033] <inf> board_version: Compatible board/HW version found: 1.1.0
    -- [00:00:00.496,948] <inf> bt_mgmt: Bluetooth initialized
    -- [00:00:00.499,145] <inf> bt_mgmt: Successfully registered all callbacks
    -- [00:00:00.500,152] <inf> bt_mgmt: Bluetooth started successfully.
    -- [00:00:00.502,349] <inf> bt_mgmt_adv: Advertising started
    -- [00:00:01.004,333] <inf> audio_usb: Ready for USB host to send/receive.
    -- [00:00:25.561,248] <inf> main: Received Command: connect AC:BF:21:51:25:40
    
    -- [00:00:25.561,309] <inf> main: MAC address AC:BF:21:51:25:40 is valid.
    
    -- [00:00:25.561,309] <inf> main: Attempting to connect to AC:BF:21:51:25:40
    
    -- [00:00:25.561,340] <inf> bt_mgmt_scan: Scanning started...
    -- [00:00:25.607,299] <inf> bt_mgmt_scan: Device found: AC:BF:21:51:25:40 (public) (Type: Public, RSSI: -61 dBm)
    
    -- [00:00:30.562,408] <inf> bt_mgmt_scan: Device is advertising with type: Public
    -- [00:00:30.563,049] <inf> bt_mgmt: Connection initiated index : 0 
                                                                         
    Sending UART Response: connect AC:BF:21:51:25:40
    UART TX Done
    -- [00:00:31.307,800] <inf> bt_mgmt: MTU exchanged: 23/23
    
    -- [00:00:31.308,013] <inf> bt_mgmt: Connected:  AC:BF:21:51:25:40 (public) (index 0)
    -- [00:00:31.308,044] <inf> main: Connection event. Num connections: 1
    -- [00:00:31.311,279] <inf> bt_mgmt: Security level: 1
    -- [00:00:31.710,021] <inf> bt_mgmt: MTU exchanged: 247/65
    -- [00:00:31.759,735] <inf> bt_mgmt: Pairing request from AC:BF:21:51:25:40 (public)
    -- [00:00:31.759,735] <inf> bt_mgmt: Initiator key distribution: 0x03
    -- [00:00:31.759,765] <inf> bt_mgmt: Responder key distribution: 0x03
    -- [00:00:32.599,578] <inf> bt_mgmt: Security changed: AC:BF:21:51:25:40 (public) level 2
    -- [00:00:32.599,609] <inf> main: Security changed
    -- [00:00:32.642,913] <inf> bt_mgmt: Pairing complete with AC:BF:21:51:25:40 (public) (Bonded: Yes)
    
    Security level: 2
    -- [00:00:32.651,123] <wrn> unicast_client: Got err: 0 from conn: 0x20004908
    -- [00:00:32.799,438] <inf> bt_vol_ctlr: VCS discover finished
    -- [00:00:33.649,291] <inf> unicast_client: location_cb : dir 1 loc 3
    
    -- [00:00:33.819,366] <inf> unicast_client: conn:AC:BF:21:51:25:40 (public), snk ctx 4039 src ctx 579
    -- [00:00:34.039,337] <inf> unicast_client: Sink #0: ep 0x20006114
    -- [00:00:34.139,343] <inf> unicast_client: Sink #1: ep 0x200061fc
    -- [00:00:34.229,339] <inf> unicast_client: Sink #2: ep 0x200062e4
    -- [00:00:34.329,345] <inf> unicast_client: Sink #3: ep 0x200063cc
    -- [00:00:34.659,271] <inf> unicast_client: Discovered 2 sink endpoint(s) for device 0
    
    -- [00:00:35.199,340] <inf> unicast_client: conn: AC:BF:21:51:25:40 (public), snk ctx 4039 src ctx 579
    -- [00:00:35.399,322] <inf> unicast_client: Source #0: ep 0x200064b4
    -- [00:00:35.519,348] <inf> unicast_client: Source #1: ep 0x2000659c
    -- [00:00:35.849,304] <inf> unicast_client: Discovered 2 source endpoint(s) for device 0
    -- [00:00:35.850,616] <wrn> bt_hci_core: opcode 0x2062 status 0x07 
    -- [00:00:35.850,616] <wrn> bt_iso: Unexpected response to hci_le_set_cig_params
    -- [00:00:35.850,646] <err> bt_bap_unicast_client: bt_iso_cig_create failed: -5
    -- [00:00:35.850,677] <err> unicast_client: Failed to create unicast group: -5
    -- [00:00:35.850,677] <err> unicast_client: Failed to start unicast sink audio: -22

    In my case, the headset exposes 4 sink endpoints and 2 source endpoints, which I assume might be contributing to this issue. It seems like the increased count is causing CIG creation to fail.

    Yes, I am using the nRF5340  for this setup.

    Let me know if there's a recommended way to handle multiple endpoints, or if I should try tuning the count values further.

    Appreciate your help !

    Best regards,
    Yash

  • Hi again Yash, and thanks for waiting during the Easter holidays.

    Has there been any development on this case in the meantime?

    For this testcase, do you happen to be using earbuds from Samsung, and also enabled bidirectional feature? Could you try enabling CONFIG_BT_AUDIO_EP_PRINT=y, and sharing the log again?

    Regards,

    Elfving

  • Hi Elfving,

    Thanks for following up, and hope you had a great Easter break.

    I enabled CONFIG_BT_AUDIO_EP_PRINT=y as you suggested — it printed out the Audio Endpoint Stream information as expected.

    While investigating, I noticed that in unicast_client.c, the following arrays were originally sized based on ARRAY_SIZE(unicast_servers[cig_index][0]):

    struct bt_bap_unicast_group_stream_pair_param pair_params[ARRAY_SIZE(unicast_servers[cig_index][0])];
    struct bt_bap_unicast_group_stream_param group_stream_params[(ARRAY_SIZE(unicast_servers[cig_index][0]) * 2)];
    
     struct bt_bap_unicast_group_param group_param;
    		 for (int i = 0; i < ARRAY_SIZE(group_stream_params); i++)
    		 {
    			 /* Every other stream should be sink or source */
    			 if ((i % 2) == 0)
    			 {
    				 group_stream_params[i].qos = &lc3_preset_sink.qos;
    				 group_stream_params[i].stream =
    					 &unicast_servers[cig_index][0][device_iterator]
    						  .cap_sink_stream.bap_stream;
    			 }
    			 else
    			 {
    				 group_stream_params[i].qos = &lc3_preset_source.qos;
    				 group_stream_params[i].stream =
    					 &unicast_servers[cig_index][0][device_iterator]
    						  .cap_source_stream.bap_stream;
    				 device_iterator++;
    			 }
    		 }
     
    		 for (int i = 0; i < ARRAY_SIZE(pair_params); i++)
    		 {
    			 if (unicast_server->sink_ep)
    			 {
    				 pair_params[i].tx_param = &group_stream_params[stream_iterator];
    			 }
    			 else
    			 {
    				 pair_params[i].tx_param = NULL;
    			 }
    			 stream_iterator++;
     
    			 if (unicast_server->source_ep)
    			 {
    				 pair_params[i].rx_param = &group_stream_params[stream_iterator];
    			 }
    			 else
    			 {
    				 pair_params[i].rx_param = NULL;
    			 }
     
    			 stream_iterator++;
    		 }
     


    When I increased the sink and source ASE counts, the CIG group creation started failing with an invalid argument error.

    As a workaround for testing, I hardcoded this value.

    With this hardcoded setup, the connection and audio streaming worked fine — it seemed to pick one sink and one source, ignoring the extra discovered ASEs.

    Question :
    How can I properly generalize this so it dynamically handles any number of sink and source ASEs discovered on the headset side, instead of hardcoding array sizes?
    Is there a recommended or clean way to allocate or size these buffers based on the actual number of ASEs discovered, while ensuring bt_bap_unicast_group_create works reliably?


    Additionally, I set the following to enable dual stream support:

    static struct bt_bap_lc3_preset lc3_preset_sink = BT_BAP_LC3_UNICAST_PRESET_NRF5340_AUDIO_SINK_DUAL;
    
    And defined:
    
    #define BT_BAP_LC3_UNICAST_PRESET_NRF5340_AUDIO_SINK_DUAL                     \
        BT_BAP_LC3_PRESET_CONFIGURABLE((BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT), \
                                       BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED,           \
                                       CONFIG_BT_AUDIO_BITRATE_UNICAST_SINK)
    


    This seems to enable two streams — one for left and one for right.

    Question:
    Is this the intended behavior — that setting both BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT triggers two streams (one for each channel)?
    Or is this behavior dependent on the connected headset's ASE configuration and capabilities?

    -- [00:00:00.260,864] <inf> main: Starting BLE Client on nRF5340
    -- [00:00:00.501,617] <inf> bt_mgmt: Bluetooth initialized
    -- [00:00:00.505,676] <inf> bt_mgmt: Successfully registered all callbacks
    -- [00:00:00.506,683] <inf> bt_mgmt: Bluetooth started successfully.
    -- [00:00:00.508,850] <inf> bt_mgmt_adv: Advertising started
    -- [00:00:14.960,968] <inf> main: Received Command: connect DD:BF:71:23:26:49
    -- [00:00:14.961,029] <inf> main: Attempting to connect to DD:BF:71:23:26:49...
    -- [00:00:14.961,029] <inf> bt_mgmt_scan: Scanning started...
    -- [00:00:15.670,806] <inf> bt_mgmt_scan: Device found: DD:BF:71:23:26:49 (public) (Type: Public, RSSI: -59 dBm)
    -- [00:00:19.962,829] <inf> bt_mgmt: Connection initiated index : 0 
    -- [00:00:20.007,293] <inf> bt_mgmt: MTU exchanged: 23/23
    -- [00:00:20.008,972] <inf> bt_mgmt: Connected: DD:BF:71:23:26:49 (public) (index 0)
    -- [00:00:20.009,002] <inf> main: Connection event. Num connections: 1
    -- [00:00:20.012,237] <inf> bt_mgmt: Security level: 1
    -- [00:00:20.079,040] <inf> bt_mgmt: Security changed: DD:BF:71:23:26:49 (public) level 2
    -- [00:00:20.079,071] <inf> main: Security changed
    -- [00:00:20.118,988] <inf> bt_mgmt: MTU exchanged: 247/65
    -- [00:00:20.278,991] <wrn> unicast_client: Got err: 0 from conn: 0x20004960
    -- [00:00:20.439,208] <inf> bt_vol_ctlr: VCS discover finished
    -- [00:00:20.540,496] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:20.540,496] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:20.778,991] <inf> unicast_client: location_cb : dir 1 loc 3
    -- [00:00:20.999,053] <inf> unicast_client: conn: DD:BF:71:23:26:49 (public), snk ctx 4047 src ctx 587
    -- [00:00:21.179,016] <wrn> unicast_client: Endpoint discover : Line : 927: Num Sink endpoint : 536896956
    -- [00:00:21.269,012] <wrn> unicast_client: Num Sink endpoint : 1
    -- [00:00:21.269,012] <wrn> unicast_client: More than one sink endpoint found, idx 0 is used by default
    -- [00:00:21.389,007] <wrn> unicast_client: Num Sink endpoint : 1
    -- [00:00:21.389,007] <wrn> unicast_client: More than one sink endpoint found, idx 0 is used by default
    -- [00:00:21.529,022] <wrn> unicast_client: Num Sink endpoint : 1
    -- [00:00:21.529,022] <wrn> unicast_client: More than one sink endpoint found, idx 0 is used by default
    -- [00:00:21.868,957] <inf> unicast_client: Sink codec index : 0
    -- [00:00:21.868,957] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.868,957] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:21.868,988] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.868,988] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.868,988] <inf> unicast_client: ========================
    
    -- [00:00:21.868,988] <inf> unicast_client: Sink codec index : 1
    -- [00:00:21.868,988] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.868,988] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:21.869,018] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,018] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,018] <inf> unicast_client: ========================
    
    -- [00:00:21.869,018] <inf> unicast_client: Sink codec index : 2
    -- [00:00:21.869,018] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.869,018] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:21.869,049] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,049] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,049] <inf> unicast_client: ========================
    
    -- [00:00:21.869,049] <inf> unicast_client: Sink codec index : 3
    -- [00:00:21.869,049] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.869,049] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:21.869,079] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,079] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,079] <inf> unicast_client: ========================
    
    -- [00:00:21.869,079] <inf> unicast_client: Sink codec index : 4
    -- [00:00:21.869,079] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.869,079] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:21.869,110] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,110] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,110] <inf> unicast_client: ========================
    
    -- [00:00:21.869,110] <inf> unicast_client: Check codec num caps : 2 
    
    -- [00:00:21.869,110] <inf> unicast_client: Discovered 2 sink endpoint(s) for device 0
    -- [00:00:21.960,479] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:21.960,510] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:22.238,983] <inf> unicast_client: location_cb : dir 2 loc 1
    
    -- [00:00:22.459,045] <inf> unicast_client: conn: DD:BF:71:23:26:49 (public), snk ctx 4047 src ctx 587
    -- [00:00:22.608,978] <wrn> unicast_client: Endpoint discover : Line : 1138: Num Source endpoint : 536898116
    -- [00:00:22.708,953] <wrn> unicast_client: More than one source endpoint found, idx 0 is used by default
    -- [00:00:22.949,493] <inf> unicast_client: Source codec index : 0
    -- [00:00:22.949,493] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,493] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:22.949,493] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,523] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,523] <inf> unicast_client: ========================
    
    -- [00:00:22.949,554] <inf> unicast_client: Source codec index : 1
    -- [00:00:22.949,554] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,554] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:22.949,554] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,554] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,554] <inf> unicast_client: ========================
    
    -- [00:00:22.949,584] <inf> unicast_client: Source codec index : 2
    -- [00:00:22.949,584] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,584] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:22.949,584] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,584] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,584] <inf> unicast_client: ========================
    
    -- [00:00:22.949,615] <inf> unicast_client: Source codec index : 3
    -- [00:00:22.949,615] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,615] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:22.949,615] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,615] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,615] <inf> unicast_client: ========================
    
    -- [00:00:22.949,645] <inf> unicast_client: Source codec index : 4
    -- [00:00:22.949,645] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,645] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:22.949,645] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,645] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,645] <inf> unicast_client: ========================
    
    -- [00:00:22.949,676] <inf> unicast_client: Discovered 2 source endpoint(s) for device 0
    -- [00:00:22.969,940] <inf> unicast_client: LEFT sink stream configured
    -- [00:00:22.969,970] <inf> le_audio: LC3 codec config for sink:
    -- [00:00:22.969,970] <inf> le_audio:   Frequency: 24000 Hz
    -- [00:00:22.969,970] <inf> le_audio:   Duration: 10000 us
    -- [00:00:22.969,970] <inf> le_audio:   Channel allocation: 0x1
    -- [00:00:22.969,970] <inf> le_audio:   Octets per frame: 60 (48000 bps)
    -- [00:00:22.970,001] <inf> le_audio:   Frames per SDU: 1
    -- [00:00:22.999,481] <inf> unicast_client: LEFT source stream configured
    -- [00:00:22.999,511] <inf> le_audio: LC3 codec config for source:
    -- [00:00:22.999,511] <inf> le_audio:   Frequency: 24000 Hz
    -- [00:00:22.999,542] <inf> le_audio:   Duration: 10000 us
    -- [00:00:22.999,542] <inf> le_audio:   Channel allocation: 0x1
    -- [00:00:22.999,542] <inf> le_audio:   Octets per frame: 60 (48000 bps)
    -- [00:00:22.999,542] <inf> le_audio:   Frames per SDU: 1
    -- [00:00:23.139,373] <inf> unicast_client: Set LEFT to PD: 40000
    -- [00:00:23.139,953] <inf> unicast_client: Set LEFT to PD: 35000
    -- [00:00:23.409,393] <inf> unicast_client: Stream enabled: 0x20015390
    -- [00:00:23.589,385] <inf> unicast_client: Stream enabled: 0x20015490
    -- [00:00:24.038,879] <inf> unicast_client: Stream 0x20015384 started
    -- [00:00:24.489,410] <inf> unicast_client: Stream 0x20015484 started


    Thanks for your help, and I look forward to your feedback!

    Best regards,
    Yash

Reply
  • Hi Elfving,

    Thanks for following up, and hope you had a great Easter break.

    I enabled CONFIG_BT_AUDIO_EP_PRINT=y as you suggested — it printed out the Audio Endpoint Stream information as expected.

    While investigating, I noticed that in unicast_client.c, the following arrays were originally sized based on ARRAY_SIZE(unicast_servers[cig_index][0]):

    struct bt_bap_unicast_group_stream_pair_param pair_params[ARRAY_SIZE(unicast_servers[cig_index][0])];
    struct bt_bap_unicast_group_stream_param group_stream_params[(ARRAY_SIZE(unicast_servers[cig_index][0]) * 2)];
    
     struct bt_bap_unicast_group_param group_param;
    		 for (int i = 0; i < ARRAY_SIZE(group_stream_params); i++)
    		 {
    			 /* Every other stream should be sink or source */
    			 if ((i % 2) == 0)
    			 {
    				 group_stream_params[i].qos = &lc3_preset_sink.qos;
    				 group_stream_params[i].stream =
    					 &unicast_servers[cig_index][0][device_iterator]
    						  .cap_sink_stream.bap_stream;
    			 }
    			 else
    			 {
    				 group_stream_params[i].qos = &lc3_preset_source.qos;
    				 group_stream_params[i].stream =
    					 &unicast_servers[cig_index][0][device_iterator]
    						  .cap_source_stream.bap_stream;
    				 device_iterator++;
    			 }
    		 }
     
    		 for (int i = 0; i < ARRAY_SIZE(pair_params); i++)
    		 {
    			 if (unicast_server->sink_ep)
    			 {
    				 pair_params[i].tx_param = &group_stream_params[stream_iterator];
    			 }
    			 else
    			 {
    				 pair_params[i].tx_param = NULL;
    			 }
    			 stream_iterator++;
     
    			 if (unicast_server->source_ep)
    			 {
    				 pair_params[i].rx_param = &group_stream_params[stream_iterator];
    			 }
    			 else
    			 {
    				 pair_params[i].rx_param = NULL;
    			 }
     
    			 stream_iterator++;
    		 }
     


    When I increased the sink and source ASE counts, the CIG group creation started failing with an invalid argument error.

    As a workaround for testing, I hardcoded this value.

    With this hardcoded setup, the connection and audio streaming worked fine — it seemed to pick one sink and one source, ignoring the extra discovered ASEs.

    Question :
    How can I properly generalize this so it dynamically handles any number of sink and source ASEs discovered on the headset side, instead of hardcoding array sizes?
    Is there a recommended or clean way to allocate or size these buffers based on the actual number of ASEs discovered, while ensuring bt_bap_unicast_group_create works reliably?


    Additionally, I set the following to enable dual stream support:

    static struct bt_bap_lc3_preset lc3_preset_sink = BT_BAP_LC3_UNICAST_PRESET_NRF5340_AUDIO_SINK_DUAL;
    
    And defined:
    
    #define BT_BAP_LC3_UNICAST_PRESET_NRF5340_AUDIO_SINK_DUAL                     \
        BT_BAP_LC3_PRESET_CONFIGURABLE((BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT), \
                                       BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED,           \
                                       CONFIG_BT_AUDIO_BITRATE_UNICAST_SINK)
    


    This seems to enable two streams — one for left and one for right.

    Question:
    Is this the intended behavior — that setting both BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT triggers two streams (one for each channel)?
    Or is this behavior dependent on the connected headset's ASE configuration and capabilities?

    -- [00:00:00.260,864] <inf> main: Starting BLE Client on nRF5340
    -- [00:00:00.501,617] <inf> bt_mgmt: Bluetooth initialized
    -- [00:00:00.505,676] <inf> bt_mgmt: Successfully registered all callbacks
    -- [00:00:00.506,683] <inf> bt_mgmt: Bluetooth started successfully.
    -- [00:00:00.508,850] <inf> bt_mgmt_adv: Advertising started
    -- [00:00:14.960,968] <inf> main: Received Command: connect DD:BF:71:23:26:49
    -- [00:00:14.961,029] <inf> main: Attempting to connect to DD:BF:71:23:26:49...
    -- [00:00:14.961,029] <inf> bt_mgmt_scan: Scanning started...
    -- [00:00:15.670,806] <inf> bt_mgmt_scan: Device found: DD:BF:71:23:26:49 (public) (Type: Public, RSSI: -59 dBm)
    -- [00:00:19.962,829] <inf> bt_mgmt: Connection initiated index : 0 
    -- [00:00:20.007,293] <inf> bt_mgmt: MTU exchanged: 23/23
    -- [00:00:20.008,972] <inf> bt_mgmt: Connected: DD:BF:71:23:26:49 (public) (index 0)
    -- [00:00:20.009,002] <inf> main: Connection event. Num connections: 1
    -- [00:00:20.012,237] <inf> bt_mgmt: Security level: 1
    -- [00:00:20.079,040] <inf> bt_mgmt: Security changed: DD:BF:71:23:26:49 (public) level 2
    -- [00:00:20.079,071] <inf> main: Security changed
    -- [00:00:20.118,988] <inf> bt_mgmt: MTU exchanged: 247/65
    -- [00:00:20.278,991] <wrn> unicast_client: Got err: 0 from conn: 0x20004960
    -- [00:00:20.439,208] <inf> bt_vol_ctlr: VCS discover finished
    -- [00:00:20.540,496] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:20.540,496] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:20.778,991] <inf> unicast_client: location_cb : dir 1 loc 3
    -- [00:00:20.999,053] <inf> unicast_client: conn: DD:BF:71:23:26:49 (public), snk ctx 4047 src ctx 587
    -- [00:00:21.179,016] <wrn> unicast_client: Endpoint discover : Line : 927: Num Sink endpoint : 536896956
    -- [00:00:21.269,012] <wrn> unicast_client: Num Sink endpoint : 1
    -- [00:00:21.269,012] <wrn> unicast_client: More than one sink endpoint found, idx 0 is used by default
    -- [00:00:21.389,007] <wrn> unicast_client: Num Sink endpoint : 1
    -- [00:00:21.389,007] <wrn> unicast_client: More than one sink endpoint found, idx 0 is used by default
    -- [00:00:21.529,022] <wrn> unicast_client: Num Sink endpoint : 1
    -- [00:00:21.529,022] <wrn> unicast_client: More than one sink endpoint found, idx 0 is used by default
    -- [00:00:21.868,957] <inf> unicast_client: Sink codec index : 0
    -- [00:00:21.868,957] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.868,957] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:21.868,988] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.868,988] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.868,988] <inf> unicast_client: ========================
    
    -- [00:00:21.868,988] <inf> unicast_client: Sink codec index : 1
    -- [00:00:21.868,988] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.868,988] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:21.869,018] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,018] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,018] <inf> unicast_client: ========================
    
    -- [00:00:21.869,018] <inf> unicast_client: Sink codec index : 2
    -- [00:00:21.869,018] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.869,018] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:21.869,049] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,049] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,049] <inf> unicast_client: ========================
    
    -- [00:00:21.869,049] <inf> unicast_client: Sink codec index : 3
    -- [00:00:21.869,049] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.869,049] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:21.869,079] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,079] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,079] <inf> unicast_client: ========================
    
    -- [00:00:21.869,079] <inf> unicast_client: Sink codec index : 4
    -- [00:00:21.869,079] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:21.869,079] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:21.869,110] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:21.869,110] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:21.869,110] <inf> unicast_client: ========================
    
    -- [00:00:21.869,110] <inf> unicast_client: Check codec num caps : 2 
    
    -- [00:00:21.869,110] <inf> unicast_client: Discovered 2 sink endpoint(s) for device 0
    -- [00:00:21.960,479] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:21.960,510] <inf> unicast_client: PAC RECORD CB CALLED 
    -- [00:00:22.238,983] <inf> unicast_client: location_cb : dir 2 loc 1
    
    -- [00:00:22.459,045] <inf> unicast_client: conn: DD:BF:71:23:26:49 (public), snk ctx 4047 src ctx 587
    -- [00:00:22.608,978] <wrn> unicast_client: Endpoint discover : Line : 1138: Num Source endpoint : 536898116
    -- [00:00:22.708,953] <wrn> unicast_client: More than one source endpoint found, idx 0 is used by default
    -- [00:00:22.949,493] <inf> unicast_client: Source codec index : 0
    -- [00:00:22.949,493] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,493] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:22.949,493] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,523] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,523] <inf> unicast_client: ========================
    
    -- [00:00:22.949,554] <inf> unicast_client: Source codec index : 1
    -- [00:00:22.949,554] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,554] <inf> unicast_client: Codec ID          : 0x06
    
    -- [00:00:22.949,554] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,554] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,554] <inf> unicast_client: ========================
    
    -- [00:00:22.949,584] <inf> unicast_client: Source codec index : 2
    -- [00:00:22.949,584] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,584] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:22.949,584] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,584] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,584] <inf> unicast_client: ========================
    
    -- [00:00:22.949,615] <inf> unicast_client: Source codec index : 3
    -- [00:00:22.949,615] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,615] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:22.949,615] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,615] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,615] <inf> unicast_client: ========================
    
    -- [00:00:22.949,645] <inf> unicast_client: Source codec index : 4
    -- [00:00:22.949,645] <inf> unicast_client: === Codec Capability ===
    
    -- [00:00:22.949,645] <inf> unicast_client: Codec ID          : 0x00
    
    -- [00:00:22.949,645] <inf> unicast_client: Codec CID         : 0x0000
    
    -- [00:00:22.949,645] <inf> unicast_client: Codec VID         : 0x0000
    
    -- [00:00:22.949,645] <inf> unicast_client: ========================
    
    -- [00:00:22.949,676] <inf> unicast_client: Discovered 2 source endpoint(s) for device 0
    -- [00:00:22.969,940] <inf> unicast_client: LEFT sink stream configured
    -- [00:00:22.969,970] <inf> le_audio: LC3 codec config for sink:
    -- [00:00:22.969,970] <inf> le_audio:   Frequency: 24000 Hz
    -- [00:00:22.969,970] <inf> le_audio:   Duration: 10000 us
    -- [00:00:22.969,970] <inf> le_audio:   Channel allocation: 0x1
    -- [00:00:22.969,970] <inf> le_audio:   Octets per frame: 60 (48000 bps)
    -- [00:00:22.970,001] <inf> le_audio:   Frames per SDU: 1
    -- [00:00:22.999,481] <inf> unicast_client: LEFT source stream configured
    -- [00:00:22.999,511] <inf> le_audio: LC3 codec config for source:
    -- [00:00:22.999,511] <inf> le_audio:   Frequency: 24000 Hz
    -- [00:00:22.999,542] <inf> le_audio:   Duration: 10000 us
    -- [00:00:22.999,542] <inf> le_audio:   Channel allocation: 0x1
    -- [00:00:22.999,542] <inf> le_audio:   Octets per frame: 60 (48000 bps)
    -- [00:00:22.999,542] <inf> le_audio:   Frames per SDU: 1
    -- [00:00:23.139,373] <inf> unicast_client: Set LEFT to PD: 40000
    -- [00:00:23.139,953] <inf> unicast_client: Set LEFT to PD: 35000
    -- [00:00:23.409,393] <inf> unicast_client: Stream enabled: 0x20015390
    -- [00:00:23.589,385] <inf> unicast_client: Stream enabled: 0x20015490
    -- [00:00:24.038,879] <inf> unicast_client: Stream 0x20015384 started
    -- [00:00:24.489,410] <inf> unicast_client: Stream 0x20015484 started


    Thanks for your help, and I look forward to your feedback!

    Best regards,
    Yash

Children
No Data
Related