@@ -1207,6 +1207,80 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
12071207 return err ;
12081208}
12091209
1210+ void role_changed (struct bt_conn * conn , uint8_t status )
1211+ {
1212+ struct bt_conn_info info ;
1213+ int err ;
1214+
1215+ bt_shell_print ("Role changed (HCI status 0x%02x)" , status );
1216+
1217+ err = bt_conn_get_info (conn , & info );
1218+ if (err ) {
1219+ bt_shell_print ("Failed to get info" );
1220+ return ;
1221+ }
1222+
1223+ bt_shell_print ("Current role is: %s" , get_conn_role_str (info .role ));
1224+ }
1225+
1226+ static int cmd_switch_role (const struct shell * sh , size_t argc , char * argv [])
1227+ {
1228+ int err ;
1229+ const char * action ;
1230+ uint8_t role ;
1231+
1232+ if (!default_conn ) {
1233+ shell_print (sh , "Not connected" );
1234+ return - ENOEXEC ;
1235+ }
1236+
1237+ action = argv [1 ];
1238+
1239+ if (!strcmp (action , "central" )) {
1240+ role = BT_HCI_ROLE_CENTRAL ;
1241+ } else if (!strcmp (action , "peripheral" )) {
1242+ role = BT_HCI_ROLE_PERIPHERAL ;
1243+ } else {
1244+ shell_help (sh );
1245+ return SHELL_CMD_HELP_PRINTED ;
1246+ }
1247+
1248+ err = bt_conn_br_switch_role (default_conn , role );
1249+
1250+ if (err ) {
1251+ shell_error (sh , "fail to change role (err %d)" , err );
1252+ }
1253+
1254+ return 0 ;
1255+ }
1256+
1257+ static int cmd_set_role_switchable (const struct shell * sh , size_t argc , char * argv [])
1258+ {
1259+ int err = 0 ;
1260+ bool enable ;
1261+
1262+ if (!default_conn ) {
1263+ shell_print (sh , "Not connected" );
1264+ return - ENOEXEC ;
1265+ }
1266+
1267+ enable = shell_strtobool (argv [1 ], 10 , & err );
1268+ if (err ) {
1269+ shell_help (sh );
1270+ return SHELL_CMD_HELP_PRINTED ;
1271+ }
1272+
1273+ err = bt_conn_br_set_role_switch_enable (default_conn , enable );
1274+
1275+ if (err ) {
1276+ shell_error (sh , "fail to set role switchable (err %d)" , err );
1277+ } else {
1278+ shell_print (sh , "success" );
1279+ }
1280+
1281+ return 0 ;
1282+ }
1283+
12101284static int cmd_default_handler (const struct shell * sh , size_t argc , char * * argv )
12111285{
12121286 if (argc == 1 ) {
@@ -1270,6 +1344,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(br_cmds,
12701344 SHELL_CMD_ARG (oob , NULL , NULL , cmd_oob , 1 , 0 ),
12711345 SHELL_CMD_ARG (pscan , NULL , "<value: on, off>" , cmd_connectable , 2 , 0 ),
12721346 SHELL_CMD_ARG (sdp - find , NULL , "<HFPAG, HFPHF>" , cmd_sdp_find_record , 2 , 0 ),
1347+ SHELL_CMD_ARG (switch - role , NULL , "<value: central, peripheral>" , cmd_switch_role , 2 , 0 ),
1348+ SHELL_CMD_ARG (set - role - switchable , NULL , "<value: enable, disable>" ,
1349+ cmd_set_role_switchable , 2 , 0 ),
12731350 SHELL_SUBCMD_SET_END
12741351);
12751352
0 commit comments