Change baudrate dynamically through dbus
Create a dbus interface so that user can change baudrate dynamically.
With this feature, SOL can still work correctly when BIOS switch uart
from high speed uart to normal uart.
Tested By:
Run busctl introspect xyz.openbmc_project.console /xyz/openbmc_project/console
the property baudrate show the current baudrate.
Run busctl call xyz.openbmc_project.console /xyz/openbmc_project/console
xyz.openbmc_project.console setBaudRate x 9600
The property baudrate show 9600 now. After change BIOS console redirection
to 9600 baudrate and change putty client also to 9600. SOL and serial port can
work correctly.
Change-Id: I2045f47520275a0b5bb9242af78a64e5aac8ea8a
Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
diff --git a/tty-handler.c b/tty-handler.c
index 6248054..a6e622d 100644
--- a/tty-handler.c
+++ b/tty-handler.c
@@ -181,15 +181,8 @@
}
static int set_terminal_baud(struct tty_handler *th, const char *tty_name,
- const char *desired_baud) {
+ speed_t speed) {
struct termios term_options;
- speed_t speed;
-
- if (config_parse_baud(&speed, desired_baud) != 0) {
- fprintf(stderr, "%s is not a valid baud rate for terminal %s\n",
- desired_baud, tty_name);
- return -1;
- }
if (tcgetattr(th->fd, &term_options) < 0) {
warn("Can't get config for %s", tty_name);
@@ -205,7 +198,6 @@
warn("Couldn't commit terminal options for %s", tty_name);
return -1;
}
- printf("Set %s terminal baud rate to %s\n", tty_name, desired_baud);
return 0;
}
@@ -236,6 +228,7 @@
struct config *config __attribute__((unused)))
{
struct tty_handler *th = to_tty_handler(handler);
+ speed_t desired_speed;
const char *tty_name;
const char *tty_baud;
char *tty_path;
@@ -260,10 +253,18 @@
th->fd_flags = fcntl(th->fd, F_GETFL, 0);
tty_baud = config_get_value(config, "local-tty-baud");
- if (tty_baud != NULL)
- if (set_terminal_baud(th, tty_name, tty_baud) != 0)
- fprintf(stderr, "Couldn't set baud rate for %s to %s\n",
+ if (tty_baud != NULL) {
+ rc = config_parse_baud(&desired_speed, tty_baud);
+ if (rc) {
+ fprintf(stderr, "%s is not a valid baud rate\n",
+ tty_baud);
+ } else {
+ rc = set_terminal_baud(th, tty_name, desired_speed);
+ if (rc)
+ fprintf(stderr, "Couldn't set baud rate for %s to %s\n",
tty_name, tty_baud);
+ }
+ }
if (make_terminal_raw(th, tty_name) != 0)
fprintf(stderr, "Couldn't make %s a raw terminal\n", tty_name);
@@ -285,11 +286,29 @@
close(th->fd);
}
+static int tty_baudrate(struct handler *handler, speed_t baudrate)
+{
+ const char *tty_name = "local-tty";
+ struct tty_handler *th = to_tty_handler(handler);
+
+ if (baudrate == 0) {
+ return -1;
+ }
+
+ if (set_terminal_baud(th, tty_name, baudrate) != 0) {
+ fprintf(stderr, "Couldn't set baud rate for %s to %d\n",
+ tty_name, baudrate);
+ return -1;
+ }
+ return 0;
+}
+
static struct tty_handler tty_handler = {
.handler = {
.name = "tty",
.init = tty_init,
.fini = tty_fini,
+ .baudrate = tty_baudrate,
},
};