soft_uart: make osmo_soft_uart_alloc() accept *cfg

Let the API user pass their own default config when allocating
a soft-UART.  Make the default config publicly accessible.

Change-Id: I7e78d60c747a8805064d5e4bacfd47a30bc65cba
Related: OS#4396
diff --git a/include/osmocom/core/soft_uart.h b/include/osmocom/core/soft_uart.h
index 71846ed..2b9d67f 100644
--- a/include/osmocom/core/soft_uart.h
+++ b/include/osmocom/core/soft_uart.h
@@ -72,9 +72,12 @@
 	void (*status_change_cb)(void *priv, unsigned int status);
 };
 
+extern const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg;
+
 struct osmo_soft_uart;
 
-struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name);
+struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name,
+					    const struct osmo_soft_uart_cfg *cfg);
 void osmo_soft_uart_free(struct osmo_soft_uart *suart);
 int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_soft_uart_cfg *cfg);
 int osmo_soft_uart_set_rx(struct osmo_soft_uart *suart, bool enable);
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index e2aef39..a9d25fb 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -439,6 +439,7 @@
 osmo_sock_set_priority;
 osmo_sock_unix_init;
 osmo_sock_unix_init_ofd;
+osmo_soft_uart_default_cfg;
 osmo_soft_uart_alloc;
 osmo_soft_uart_free;
 osmo_soft_uart_configure;
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index 2f09845..5b58848 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -50,15 +50,12 @@
 };
 
 /*! Default soft-UART configuration (8-N-1) */
-static struct osmo_soft_uart_cfg suart_default_cfg = {
+const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg = {
 	.num_data_bits = 8,
 	.num_stop_bits = 1,
 	.parity_mode = OSMO_SUART_PARITY_NONE,
 	.rx_buf_size = 1024,
 	.rx_timeout_ms = 100,
-	.priv = NULL,
-	.rx_cb = NULL,
-	.status_change_cb = NULL,
 };
 
 /*************************************************************************
@@ -226,14 +223,18 @@
 /*! Allocate a soft-UART instance.
  * \param[in] ctx parent talloc context.
  * \param[in] name name of the soft-UART instance.
+ * \param[in] cfg initial configuration of the soft-UART instance.
  * \returns pointer to allocated soft-UART instance; NULL on error. */
-struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name)
+struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name,
+					    const struct osmo_soft_uart_cfg *cfg)
 {
 	struct osmo_soft_uart *suart = talloc_zero(ctx, struct osmo_soft_uart);
 	if (!suart)
 		return NULL;
 	suart->name = talloc_strdup(suart, name);
-	suart->cfg = suart_default_cfg;
+
+	OSMO_ASSERT(cfg != NULL);
+	suart->cfg = *cfg;
 
 	return suart;
 }