@@ -974,6 +974,27 @@ void path_loss_threshold_report(struct bt_conn *conn,
974
974
}
975
975
#endif
976
976
977
+ #if defined(CONFIG_BT_SUBRATING )
978
+ void subrate_changed (struct bt_conn * conn ,
979
+ const struct bt_conn_le_subrate_changed * params )
980
+ {
981
+ if (params -> status == BT_HCI_ERR_SUCCESS ) {
982
+ shell_print (ctx_shell , "Subrate parameters changed: "
983
+ "Subrate Factor: %d "
984
+ "Continuation Number: %d "
985
+ "Peripheral latency: 0x%04x "
986
+ "Supervision timeout: 0x%04x (%d ms)" ,
987
+ params -> factor ,
988
+ params -> continuation_number ,
989
+ params -> peripheral_latency ,
990
+ params -> supervision_timeout ,
991
+ params -> supervision_timeout * 10 );
992
+ } else {
993
+ shell_print (ctx_shell , "Subrate change failed (HCI status 0x%02x)" , params -> status );
994
+ }
995
+ }
996
+ #endif
997
+
977
998
static struct bt_conn_cb conn_callbacks = {
978
999
.connected = connected ,
979
1000
.disconnected = disconnected ,
@@ -1000,6 +1021,9 @@ static struct bt_conn_cb conn_callbacks = {
1000
1021
#if defined(CONFIG_BT_PATH_LOSS_MONITORING )
1001
1022
.path_loss_threshold_report = path_loss_threshold_report ,
1002
1023
#endif
1024
+ #if defined(CONFIG_BT_SUBRATING )
1025
+ .subrate_changed = subrate_changed ,
1026
+ #endif
1003
1027
};
1004
1028
#endif /* CONFIG_BT_CONN */
1005
1029
@@ -3019,6 +3043,74 @@ static int cmd_set_path_loss_reporting_enable(const struct shell *sh, size_t arg
3019
3043
}
3020
3044
#endif
3021
3045
3046
+ #if defined(CONFIG_BT_SUBRATING )
3047
+ static int cmd_subrate_set_defaults (const struct shell * sh , size_t argc , char * argv [])
3048
+ {
3049
+ int err = 0 ;
3050
+
3051
+ for (size_t argn = 1 ; argn < argc ; argn ++ ) {
3052
+ (void )shell_strtoul (argv [argn ], 10 , & err );
3053
+
3054
+ if (err ) {
3055
+ shell_help (sh );
3056
+ shell_error (sh , "Could not parse input number %d" , argn );
3057
+ return SHELL_CMD_HELP_PRINTED ;
3058
+ }
3059
+ }
3060
+
3061
+ const struct bt_conn_le_subrate_param params = {
3062
+ .subrate_min = shell_strtoul (argv [1 ], 10 , & err ),
3063
+ .subrate_max = shell_strtoul (argv [2 ], 10 , & err ),
3064
+ .max_latency = shell_strtoul (argv [3 ], 10 , & err ),
3065
+ .continuation_number = shell_strtoul (argv [4 ], 10 , & err ),
3066
+ .supervision_timeout = shell_strtoul (argv [5 ], 10 , & err ) * 100 , /* 10ms units */
3067
+ };
3068
+
3069
+ err = bt_conn_le_subrate_set_defaults (& params );
3070
+ if (err ) {
3071
+ shell_error (sh , "bt_conn_le_subrate_set_defaults returned error %d" , err );
3072
+ return - ENOEXEC ;
3073
+ }
3074
+
3075
+ return 0 ;
3076
+ }
3077
+
3078
+ static int cmd_subrate_request (const struct shell * sh , size_t argc , char * argv [])
3079
+ {
3080
+ int err = 0 ;
3081
+
3082
+ if (default_conn == NULL ) {
3083
+ shell_error (sh , "Conn handle error, at least one connection is required." );
3084
+ return - ENOEXEC ;
3085
+ }
3086
+
3087
+ for (size_t argn = 1 ; argn < argc ; argn ++ ) {
3088
+ (void )shell_strtoul (argv [argn ], 10 , & err );
3089
+
3090
+ if (err ) {
3091
+ shell_help (sh );
3092
+ shell_error (sh , "Could not parse input number %d" , argn );
3093
+ return SHELL_CMD_HELP_PRINTED ;
3094
+ }
3095
+ }
3096
+
3097
+ const struct bt_conn_le_subrate_param params = {
3098
+ .subrate_min = shell_strtoul (argv [1 ], 10 , & err ),
3099
+ .subrate_max = shell_strtoul (argv [2 ], 10 , & err ),
3100
+ .max_latency = shell_strtoul (argv [3 ], 10 , & err ),
3101
+ .continuation_number = shell_strtoul (argv [4 ], 10 , & err ),
3102
+ .supervision_timeout = shell_strtoul (argv [5 ], 10 , & err ) * 100 , /* 10ms units */
3103
+ };
3104
+
3105
+ err = bt_conn_le_subrate_request (default_conn , & params );
3106
+ if (err ) {
3107
+ shell_error (sh , "bt_conn_le_subrate_request returned error %d" , err );
3108
+ return - ENOEXEC ;
3109
+ }
3110
+
3111
+ return 0 ;
3112
+ }
3113
+ #endif
3022
3114
3023
3115
#if defined(CONFIG_BT_CONN )
3024
3116
#if defined(CONFIG_BT_CENTRAL )
@@ -3315,6 +3407,12 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
3315
3407
info .le .data_len -> tx_max_time ,
3316
3408
info .le .data_len -> rx_max_len ,
3317
3409
info .le .data_len -> rx_max_time );
3410
+ #endif
3411
+ #if defined(CONFIG_BT_SUBRATING )
3412
+ shell_print (ctx_shell , "LE Subrating: Subrate Factor: %d"
3413
+ " Continuation Number: %d" ,
3414
+ info .le .subrate -> factor ,
3415
+ info .le .subrate -> continuation_number );
3318
3416
#endif
3319
3417
}
3320
3418
@@ -4716,6 +4814,16 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
4716
4814
SHELL_CMD_ARG (path - loss - monitoring - enable , NULL , "<enable: true, false>" ,
4717
4815
cmd_set_path_loss_reporting_enable , 2 , 0 ),
4718
4816
#endif
4817
+ #if defined(CONFIG_BT_SUBRATING )
4818
+ SHELL_CMD_ARG (subrate - set - defaults , NULL ,
4819
+ "<min subrate factor> <max subrate factor> <max peripheral latency> "
4820
+ "<min continuation number> <supervision timeout (seconds)>" ,
4821
+ cmd_subrate_set_defaults , 6 , 0 ),
4822
+ SHELL_CMD_ARG (subrate - request , NULL ,
4823
+ "<min subrate factor> <max subrate factor> <max peripheral latency> "
4824
+ "<min continuation number> <supervision timeout (seconds)>" ,
4825
+ cmd_subrate_request , 6 , 0 ),
4826
+ #endif
4719
4827
#if defined(CONFIG_BT_BROADCASTER )
4720
4828
SHELL_CMD_ARG (advertise , NULL ,
4721
4829
"<type: off, on, nconn> [mode: discov, non_discov] "
0 commit comments