modem-helpers: reuse nicknames for the flow control tags
And check that the string given in the tag is actually a valid one.
This commit is contained in:
committed by
Dan Williams
parent
fc1beefe92
commit
4c669d3bf4
+15
-5
@@ -255,11 +255,21 @@ mm_base_modem_grab_port (MMBaseModem *self,
|
||||
NULL);
|
||||
|
||||
flow_control_tag = mm_kernel_device_get_property (kernel_device, "ID_MM_TTY_FLOW_CONTROL");
|
||||
if (flow_control_tag)
|
||||
g_object_set (port,
|
||||
MM_PORT_SERIAL_FLOW_CONTROL,
|
||||
mm_parse_flow_control_tag (flow_control_tag),
|
||||
NULL);
|
||||
if (flow_control_tag) {
|
||||
MMFlowControl flow_control;
|
||||
GError *inner_error = NULL;
|
||||
|
||||
flow_control = mm_flow_control_from_string (flow_control_tag, &inner_error);
|
||||
if (flow_control == MM_FLOW_CONTROL_UNKNOWN) {
|
||||
mm_warn ("(%s/%s) unsupported flow control settings in port: %s",
|
||||
subsys, name, inner_error->message);
|
||||
g_error_free (inner_error);
|
||||
} else {
|
||||
g_object_set (port,
|
||||
MM_PORT_SERIAL_FLOW_CONTROL, flow_control,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Net ports... */
|
||||
else if (g_str_equal (subsys, "net")) {
|
||||
|
||||
+16
-12
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "mm-sms-part.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-helper-enums-types.h"
|
||||
#include "mm-log.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -647,22 +648,25 @@ out:
|
||||
}
|
||||
|
||||
MMFlowControl
|
||||
mm_parse_flow_control_tag (const gchar *flow_control_tag)
|
||||
mm_flow_control_from_string (const gchar *str,
|
||||
GError **error)
|
||||
{
|
||||
MMFlowControl flow_control;
|
||||
GFlagsClass *flags_class;
|
||||
guint i;
|
||||
|
||||
if (g_strcmp0 ("xonxoff", flow_control_tag) == 0)
|
||||
flow_control = MM_FLOW_CONTROL_XON_XOFF;
|
||||
else if (g_strcmp0 ("rtscts", flow_control_tag) == 0)
|
||||
flow_control = MM_FLOW_CONTROL_RTS_CTS;
|
||||
else if (g_strcmp0 ("none", flow_control_tag) == 0)
|
||||
flow_control = MM_FLOW_CONTROL_NONE;
|
||||
else {
|
||||
mm_warn ("Cannot parse flow control tag: '%s', setting as unknown", flow_control_tag);
|
||||
flow_control = MM_FLOW_CONTROL_UNKNOWN;
|
||||
flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_FLOW_CONTROL));
|
||||
|
||||
for (i = 0; flags_class->values[i].value_nick; i++) {
|
||||
if (!g_ascii_strcasecmp (str, flags_class->values[i].value_nick))
|
||||
return flags_class->values[i].value;
|
||||
}
|
||||
|
||||
return flow_control;
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_INVALID_ARGS,
|
||||
"Couldn't match '%s' with a valid MMFlowControl value",
|
||||
str);
|
||||
return MM_FLOW_CONTROL_UNKNOWN;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
@@ -112,7 +112,8 @@ typedef enum { /*< underscore_name=mm_flow_control >*/
|
||||
MMFlowControl mm_parse_ifc_test_response (const gchar *response,
|
||||
GError **error);
|
||||
|
||||
MMFlowControl mm_parse_flow_control_tag (const gchar *flow_control);
|
||||
MMFlowControl mm_flow_control_from_string (const gchar *str,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 3GPP specific helpers and utilities */
|
||||
|
||||
+36
-24
@@ -629,6 +629,39 @@ wdm_probe (MMPortProbe *self)
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
static void
|
||||
common_serial_port_setup (MMPortProbe *self,
|
||||
MMPortSerial *serial)
|
||||
{
|
||||
const gchar *flow_control_tag;
|
||||
|
||||
if (mm_kernel_device_has_property (self->priv->port, "ID_MM_TTY_BAUDRATE"))
|
||||
g_object_set (serial,
|
||||
MM_PORT_SERIAL_BAUD, mm_kernel_device_get_property_as_int (self->priv->port, "ID_MM_TTY_BAUDRATE"),
|
||||
NULL);
|
||||
|
||||
flow_control_tag = mm_kernel_device_get_property (self->priv->port, "ID_MM_TTY_FLOW_CONTROL");
|
||||
if (flow_control_tag) {
|
||||
MMFlowControl flow_control;
|
||||
GError *error = NULL;
|
||||
|
||||
flow_control = mm_flow_control_from_string (flow_control_tag, &error);
|
||||
if (flow_control == MM_FLOW_CONTROL_UNKNOWN) {
|
||||
mm_warn ("(%s/%s) Unsupported flow control settings in port: %s",
|
||||
mm_kernel_device_get_subsystem (self->priv->port),
|
||||
mm_kernel_device_get_name (self->priv->port),
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
} else {
|
||||
g_object_set (serial,
|
||||
MM_PORT_SERIAL_FLOW_CONTROL, flow_control,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
/* QCDM */
|
||||
|
||||
@@ -711,7 +744,6 @@ serial_probe_qcdm (MMPortProbe *self)
|
||||
gint len;
|
||||
guint8 marker = 0x7E;
|
||||
PortProbeRunContext *ctx;
|
||||
const gchar *flow_control_tag;
|
||||
|
||||
g_assert (self->priv->task);
|
||||
ctx = g_task_get_task_data (self->priv->task);
|
||||
@@ -748,17 +780,8 @@ serial_probe_qcdm (MMPortProbe *self)
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
if (mm_kernel_device_has_property (self->priv->port, "ID_MM_TTY_BAUDRATE"))
|
||||
g_object_set (ctx->serial,
|
||||
MM_PORT_SERIAL_BAUD, mm_kernel_device_get_property_as_int (self->priv->port, "ID_MM_TTY_BAUDRATE"),
|
||||
NULL);
|
||||
flow_control_tag = mm_kernel_device_get_property (self->priv->port,
|
||||
"ID_MM_TTY_FLOW_CONTROL");
|
||||
if (flow_control_tag)
|
||||
g_object_set (ctx->serial,
|
||||
MM_PORT_SERIAL_FLOW_CONTROL,
|
||||
mm_parse_flow_control_tag (flow_control_tag),
|
||||
NULL);
|
||||
/* Setup port if needed */
|
||||
common_serial_port_setup (self, ctx->serial);
|
||||
|
||||
/* Try to open the port */
|
||||
if (!mm_port_serial_open (ctx->serial, &error)) {
|
||||
@@ -1264,7 +1287,6 @@ serial_open_at (MMPortProbe *self)
|
||||
{
|
||||
GError *error = NULL;
|
||||
PortProbeRunContext *ctx;
|
||||
const gchar *flow_control_tag;
|
||||
|
||||
g_assert (self->priv->task);
|
||||
ctx = g_task_get_task_data (self->priv->task);
|
||||
@@ -1300,17 +1322,7 @@ serial_open_at (MMPortProbe *self)
|
||||
MM_PORT_SERIAL_AT_SEND_LF, ctx->at_send_lf,
|
||||
NULL);
|
||||
|
||||
if (mm_kernel_device_has_property (self->priv->port, "ID_MM_TTY_BAUDRATE"))
|
||||
g_object_set (ctx->serial,
|
||||
MM_PORT_SERIAL_BAUD, mm_kernel_device_get_property_as_int (self->priv->port, "ID_MM_TTY_BAUDRATE"),
|
||||
NULL);
|
||||
flow_control_tag = mm_kernel_device_get_property (self->priv->port,
|
||||
"ID_MM_TTY_FLOW_CONTROL");
|
||||
if (flow_control_tag)
|
||||
g_object_set (ctx->serial,
|
||||
MM_PORT_SERIAL_FLOW_CONTROL,
|
||||
mm_parse_flow_control_tag (flow_control_tag),
|
||||
NULL);
|
||||
common_serial_port_setup (self, ctx->serial);
|
||||
|
||||
parser = mm_serial_parser_v1_new ();
|
||||
mm_serial_parser_v1_add_filter (parser,
|
||||
|
||||
Reference in New Issue
Block a user