@@ -63,6 +63,11 @@ struct codec_cap_lookup_id_data {
6363
6464static sys_slist_t sink_cbs = SYS_SLIST_STATIC_INIT (& sink_cbs );
6565
66+ /* The mod_src_param is and shall only be used by the BT RX thread. It is statically defined due to
67+ * the size of it, and that it's configurable in size, and can cause stack overflow issues otherwise
68+ */
69+ static struct bt_bap_scan_delegator_mod_src_param mod_src_param ;
70+
6671static void broadcast_sink_cleanup (struct bt_bap_broadcast_sink * sink );
6772
6873static bool find_recv_state_by_sink_cb (const struct bt_bap_scan_delegator_recv_state * recv_state ,
@@ -103,7 +108,6 @@ static bool find_recv_state_by_pa_sync_cb(const struct bt_bap_scan_delegator_rec
103108static void update_recv_state_big_synced (const struct bt_bap_broadcast_sink * sink )
104109{
105110 const struct bt_bap_scan_delegator_recv_state * recv_state ;
106- struct bt_bap_scan_delegator_mod_src_param mod_src_param = {0 };
107111 int err ;
108112
109113 recv_state = bt_bap_scan_delegator_find_state (find_recv_state_by_sink_cb , (void * )sink );
@@ -113,6 +117,8 @@ static void update_recv_state_big_synced(const struct bt_bap_broadcast_sink *sin
113117 return ;
114118 }
115119
120+ (void )memset (& mod_src_param , 0 , sizeof (mod_src_param ));
121+
116122 mod_src_param .num_subgroups = sink -> subgroup_count ;
117123 for (uint8_t i = 0U ; i < sink -> subgroup_count ; i ++ ) {
118124 struct bt_bap_bass_subgroup * subgroup_param = & mod_src_param .subgroups [i ];
@@ -145,7 +151,6 @@ static void update_recv_state_big_synced(const struct bt_bap_broadcast_sink *sin
145151static void update_recv_state_big_cleared (const struct bt_bap_broadcast_sink * sink ,
146152 uint8_t reason )
147153{
148- struct bt_bap_scan_delegator_mod_src_param mod_src_param = { 0 };
149154 const struct bt_bap_scan_delegator_recv_state * recv_state ;
150155 int err ;
151156
@@ -157,6 +162,8 @@ static void update_recv_state_big_cleared(const struct bt_bap_broadcast_sink *si
157162 return ;
158163 }
159164
165+ (void )memset (& mod_src_param , 0 , sizeof (mod_src_param ));
166+
160167 if ((recv_state -> encrypt_state == BT_BAP_BIG_ENC_STATE_BCODE_REQ ||
161168 recv_state -> encrypt_state == BT_BAP_BIG_ENC_STATE_DEC ) &&
162169 reason == BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL ) {
@@ -488,7 +495,6 @@ static void broadcast_sink_add_src(struct bt_bap_broadcast_sink *sink)
488495
489496static bool base_subgroup_meta_cb (const struct bt_bap_base_subgroup * subgroup , void * user_data )
490497{
491- struct bt_bap_scan_delegator_mod_src_param * mod_src_param = user_data ;
492498 struct bt_bap_bass_subgroup * subgroup_param ;
493499 uint8_t * meta ;
494500 int ret ;
@@ -498,19 +504,18 @@ static bool base_subgroup_meta_cb(const struct bt_bap_base_subgroup *subgroup, v
498504 return false;
499505 }
500506
501- subgroup_param = & mod_src_param -> subgroups [mod_src_param -> num_subgroups ++ ];
507+ subgroup_param = & mod_src_param . subgroups [mod_src_param . num_subgroups ++ ];
502508 subgroup_param -> metadata_len = (uint8_t )ret ;
503509 memcpy (subgroup_param -> metadata , meta , subgroup_param -> metadata_len );
504510
505511 return true;
506512}
507513
508- static int update_recv_state_base_copy_meta (const struct bt_bap_base * base ,
509- struct bt_bap_scan_delegator_mod_src_param * param )
514+ static int update_recv_state_base_copy_meta (const struct bt_bap_base * base )
510515{
511516 int err ;
512517
513- err = bt_bap_base_foreach_subgroup (base , base_subgroup_meta_cb , param );
518+ err = bt_bap_base_foreach_subgroup (base , base_subgroup_meta_cb , NULL );
514519 if (err != 0 ) {
515520 LOG_DBG ("Failed to parse subgroups: %d" , err );
516521 return err ;
@@ -522,7 +527,6 @@ static int update_recv_state_base_copy_meta(const struct bt_bap_base *base,
522527static void update_recv_state_base (const struct bt_bap_broadcast_sink * sink ,
523528 const struct bt_bap_base * base )
524529{
525- struct bt_bap_scan_delegator_mod_src_param mod_src_param = { 0 };
526530 const struct bt_bap_scan_delegator_recv_state * recv_state ;
527531 int err ;
528532
@@ -533,7 +537,9 @@ static void update_recv_state_base(const struct bt_bap_broadcast_sink *sink,
533537 return ;
534538 }
535539
536- err = update_recv_state_base_copy_meta (base , & mod_src_param );
540+ (void )memset (& mod_src_param , 0 , sizeof (mod_src_param ));
541+
542+ err = update_recv_state_base_copy_meta (base );
537543 if (err != 0 ) {
538544 LOG_WRN ("Failed to modify Receive State for sink %p: %d" , sink , err );
539545 return ;
@@ -740,7 +746,6 @@ static void pa_term_cb(struct bt_le_per_adv_sync *sync,
740746
741747static void update_recv_state_encryption (const struct bt_bap_broadcast_sink * sink )
742748{
743- struct bt_bap_scan_delegator_mod_src_param mod_src_param = { 0 };
744749 const struct bt_bap_scan_delegator_recv_state * recv_state ;
745750 int err ;
746751
@@ -753,6 +758,8 @@ static void update_recv_state_encryption(const struct bt_bap_broadcast_sink *sin
753758 return ;
754759 }
755760
761+ (void )memset (& mod_src_param , 0 , sizeof (mod_src_param ));
762+
756763 /* Only change the encrypt state, and leave the rest as is */
757764 if (atomic_test_bit (sink -> flags ,
758765 BT_BAP_BROADCAST_SINK_FLAG_BIG_ENCRYPTED )) {
0 commit comments