1515#include <zephyr/bluetooth/audio/tbs.h>
1616#include <zephyr/bluetooth/audio/ccp.h>
1717#include <zephyr/shell/shell.h>
18+ #include <zephyr/shell/shell_string_conv.h>
1819
1920static struct bt_ccp_call_control_server_bearer
2021 * bearers [CONFIG_BT_CCP_CALL_CONTROL_SERVER_BEARER_COUNT ];
@@ -79,6 +80,81 @@ static int cmd_ccp_call_control_server_init(const struct shell *sh, size_t argc,
7980 return 0 ;
8081}
8182
83+ static int validate_and_get_index (const struct shell * sh , const char * index_arg )
84+ {
85+ unsigned long index ;
86+ int err = 0 ;
87+
88+ index = shell_strtoul (index_arg , 0 , & err );
89+ if (err != 0 ) {
90+ shell_error (sh , "Could not parse index: %d" , err );
91+
92+ return - ENOEXEC ;
93+ }
94+
95+ if (index >= CONFIG_BT_TBS_BEARER_COUNT ) {
96+ shell_error (sh , "Invalid index: %lu" , index );
97+
98+ return - ENOEXEC ;
99+ }
100+
101+ return (int )index ;
102+ }
103+
104+ static int cmd_ccp_call_control_server_set_bearer_name (const struct shell * sh , size_t argc ,
105+ char * argv [])
106+ {
107+ unsigned long index = 0 ;
108+ const char * name ;
109+ int err = 0 ;
110+
111+ if (argc > 2 ) {
112+ index = validate_and_get_index (sh , argv [1 ]);
113+ if (index < 0 ) {
114+ return index ;
115+ }
116+ }
117+
118+ name = argv [argc - 1 ];
119+
120+ err = bt_ccp_call_control_server_set_bearer_provider_name (bearers [index ], name );
121+ if (err != 0 ) {
122+ shell_error (sh , "Failed to set bearer[%lu] name: %d" , index , err );
123+
124+ return - ENOEXEC ;
125+ }
126+
127+ shell_print (sh , "Bearer[%lu] name: %s" , index , name );
128+
129+ return 0 ;
130+ }
131+
132+ static int cmd_ccp_call_control_server_get_bearer_name (const struct shell * sh , size_t argc ,
133+ char * argv [])
134+ {
135+ unsigned long index = 0 ;
136+ const char * name ;
137+ int err = 0 ;
138+
139+ if (argc > 1 ) {
140+ index = validate_and_get_index (sh , argv [1 ]);
141+ if (index < 0 ) {
142+ return index ;
143+ }
144+ }
145+
146+ err = bt_ccp_call_control_server_get_bearer_provider_name (bearers [index ], & name );
147+ if (err != 0 ) {
148+ shell_error (sh , "Failed to get bearer[%lu] name: %d" , index , err );
149+
150+ return - ENOEXEC ;
151+ }
152+
153+ shell_print (sh , "Bearer[%lu] name: %s" , index , name );
154+
155+ return 0 ;
156+ }
157+
82158static int cmd_ccp_call_control_server (const struct shell * sh , size_t argc , char * * argv )
83159{
84160 if (argc > 1 ) {
@@ -93,6 +169,11 @@ static int cmd_ccp_call_control_server(const struct shell *sh, size_t argc, char
93169SHELL_STATIC_SUBCMD_SET_CREATE (ccp_call_control_server_cmds ,
94170 SHELL_CMD_ARG (init , NULL , "Initialize CCP Call Control Server" ,
95171 cmd_ccp_call_control_server_init , 1 , 0 ),
172+ SHELL_CMD_ARG (set_bearer_name , NULL ,
173+ "Set bearer name [index] <name>" ,
174+ cmd_ccp_call_control_server_set_bearer_name , 2 , 1 ),
175+ SHELL_CMD_ARG (get_bearer_name , NULL , "Get bearer name [index]" ,
176+ cmd_ccp_call_control_server_get_bearer_name , 1 , 1 ),
96177 SHELL_SUBCMD_SET_END );
97178
98179SHELL_CMD_ARG_REGISTER (ccp_call_control_server , & ccp_call_control_server_cmds ,
0 commit comments