console-server: Add PTY support for testing purposes

Different TTY device types have different configuration options. The
existing code kinda smooshes the differences between UARTs and VUARTs
together. PTYs do not require the configuration applicable to either
UARTs or VUARTs. Given this, separate out and be explict about the
concepts and configuration required for all three types.

This in turn, with some further patches, allows testing of obmc-console
using `socat`:

https://amboar.github.io/notes/2023/05/02/testing-obmc-console-with-socat.html

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I3c1ce610132fce8ef6b5324ed3b4e0c86395e433
diff --git a/console-dbus.c b/console-dbus.c
index 3b24061..d1dd674 100644
--- a/console-dbus.c
+++ b/console-dbus.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <assert.h>
 #include <errno.h>
 #include <err.h>
 
@@ -42,7 +43,7 @@
 			continue;
 		}
 
-		rc = handler->baudrate(handler, console->tty_baud);
+		rc = handler->baudrate(handler, console->tty.uart.baud);
 		if (rc) {
 			warnx("Can't set terminal baudrate for handler %s",
 			      handler->name);
@@ -75,7 +76,8 @@
 		return sd_bus_reply_method_return(msg, "x", -EINVAL);
 	}
 
-	console->tty_baud = speed;
+	assert(console->tty.type == TTY_DEVICE_UART);
+	console->tty.uart.baud = speed;
 	tty_change_baudrate(console);
 
 	return sd_bus_reply_method_return(msg, "x", r);
@@ -92,9 +94,10 @@
 	uint32_t baudrate;
 	int r;
 
-	baudrate = parse_baud_to_int(console->tty_baud);
+	assert(console->tty.type == TTY_DEVICE_UART);
+	baudrate = parse_baud_to_int(console->tty.uart.baud);
 	if (!baudrate) {
-		warnx("Invalid baud rate: '%d'", console->tty_baud);
+		warnx("Invalid baud rate: '%d'", console->tty.uart.baud);
 	}
 
 	r = sd_bus_message_append(reply, "u", baudrate);
@@ -162,12 +165,15 @@
 		return;
 	}
 
-	/* Register tty interface */
-	r = sd_bus_add_object_vtable(console->bus, NULL, obj_name, TTY_INTF,
-				     console_tty_vtable, console);
-	if (r < 0) {
-		warnx("Failed to issue method call: %s", strerror(-r));
-		return;
+	if (console->tty.type == TTY_DEVICE_UART) {
+		/* Register tty interface */
+		r = sd_bus_add_object_vtable(console->bus, NULL, obj_name,
+					     TTY_INTF, console_tty_vtable,
+					     console);
+		if (r < 0) {
+			warnx("Failed to issue method call: %s", strerror(-r));
+			return;
+		}
 	}
 
 	/* Register access interface */