4242#define UNICAST_SINK_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0)
4343#define UNICAST_SRC_SUPPORTED (CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT > 0)
4444
45- struct bt_cap_unicast_group * cap_unicast_group ;
46-
4745#define CAP_UNICAST_CLIENT_STREAM_COUNT ARRAY_SIZE(unicast_streams)
4846
4947static void cap_discover_cb (struct bt_conn * conn , int err ,
@@ -90,13 +88,14 @@ static void unicast_stop_complete_cb(int err, struct bt_conn *conn)
9088 } else {
9189 bt_shell_print ("Unicast stop completed" );
9290
93- if (cap_unicast_group != NULL ) {
94- err = bt_cap_unicast_group_delete (cap_unicast_group );
91+ if (default_unicast_group . is_cap && default_unicast_group . cap_group != NULL ) {
92+ err = bt_cap_unicast_group_delete (default_unicast_group . cap_group );
9593 if (err != 0 ) {
9694 bt_shell_error ("Failed to delete unicast group %p: %d" ,
97- cap_unicast_group , err );
95+ default_unicast_group . cap_group , err );
9896 } else {
99- cap_unicast_group = NULL ;
97+ default_unicast_group .cap_group = NULL ;
98+ default_unicast_group .is_cap = false;
10099 }
101100 }
102101 }
@@ -320,13 +319,15 @@ static int cmd_cap_initiator_unicast_start(const struct shell *sh, size_t argc,
320319 group_param .params_count = pair_cnt ;
321320 group_param .params = pair_params ;
322321
323- if (cap_unicast_group == NULL ) {
324- err = bt_cap_unicast_group_create (& group_param , & cap_unicast_group );
322+ if (default_unicast_group . cap_group == NULL ) {
323+ err = bt_cap_unicast_group_create (& group_param , & default_unicast_group . cap_group );
325324 if (err != 0 ) {
326325 shell_print (sh , "Failed to create group: %d" , err );
327326
328327 return - ENOEXEC ;
329328 }
329+
330+ default_unicast_group .is_cap = true;
330331 }
331332
332333 shell_print (sh , "Starting %zu streams" , start_param .count );
@@ -754,6 +755,7 @@ static int cap_ac_create_unicast_group(const struct cap_unicast_ac_param *param,
754755 size_t snk_stream_cnt = 0U ;
755756 size_t src_stream_cnt = 0U ;
756757 size_t pair_cnt = 0U ;
758+ int err ;
757759
758760 for (size_t i = 0U ; i < snk_cnt ; i ++ ) {
759761 snk_qos [i ] = & snk_uni_streams [i ]-> qos ;
@@ -803,7 +805,12 @@ static int cap_ac_create_unicast_group(const struct cap_unicast_ac_param *param,
803805 group_param .params = pair_params ;
804806 group_param .params_count = pair_cnt ;
805807
806- return bt_cap_unicast_group_create (& group_param , & default_unicast_group .cap_group );
808+ err = bt_cap_unicast_group_create (& group_param , & default_unicast_group .cap_group );
809+ if (err == 0 ) {
810+ default_unicast_group .is_cap = true;
811+ }
812+
813+ return err ;
807814}
808815
809816int cap_ac_unicast (const struct shell * sh , const struct cap_unicast_ac_param * param )
@@ -818,7 +825,7 @@ int cap_ac_unicast(const struct shell *sh, const struct cap_unicast_ac_param *pa
818825 size_t total_cnt ;
819826 int err ;
820827
821- if (cap_unicast_group != NULL ) {
828+ if (default_unicast_group . cap_group != NULL ) {
822829 shell_error (sh , "Unicast Group already exist, please delete first" );
823830 return - ENOEXEC ;
824831 }
@@ -919,11 +926,12 @@ int cap_ac_unicast(const struct shell *sh, const struct cap_unicast_ac_param *pa
919926 if (err != 0 ) {
920927 shell_error (sh , "Failed to start unicast audio: %d" , err );
921928
922- err = bt_cap_unicast_group_delete (cap_unicast_group );
929+ err = bt_cap_unicast_group_delete (default_unicast_group . cap_group );
923930 if (err != 0 ) {
924931 shell_error (sh , "Failed to delete group: %d" , err );
925932 } else {
926- cap_unicast_group = NULL ;
933+ default_unicast_group .cap_group = NULL ;
934+ default_unicast_group .is_cap = false;
927935 }
928936
929937 return - ENOEXEC ;
0 commit comments