---
 src/mm-port-serial.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/mm-port-serial.h |  5 +++++
 2 files changed, 55 insertions(+)

diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c
index f2b97a02..e55f9062 100644
--- a/src/mm-port-serial.c
+++ b/src/mm-port-serial.c
@@ -1778,6 +1778,56 @@ mm_port_serial_flash (MMPortSerial *self,
 
 /*****************************************************************************/
 
+gboolean
+mm_port_serial_set_flow_control (MMPortSerial   *self,
+                                 MMFlowControl   flow_control,
+                                 GError        **error)
+{
+    struct termios options;
+    gboolean       had_xon_xoff;
+    gboolean       had_rts_cts;
+
+    /* retrieve current settings */
+    memset (&options, 0, sizeof (struct termios));
+    if (tcgetattr (self->priv->fd, &options) != 0) {
+        g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+                     "couldn't get serial port attributes: %s", g_strerror 
(errno));
+        return FALSE;
+    }
+
+    /* clear all flow control flags */
+
+    had_xon_xoff = !!(options.c_iflag & (IXON | IXOFF));
+    options.c_iflag &= ~(IXON | IXOFF | IXANY);
+
+    had_rts_cts  = !!(options.c_cflag & (CRTSCTS));
+    options.c_cflag &= ~(CRTSCTS);
+
+    /* setup the requested flags */
+    switch (flow_control) {
+        case MM_FLOW_CONTROL_XON_XOFF:
+            mm_dbg ("(%s): enabling XON/XOFF flow control", mm_port_get_device 
(MM_PORT (self)));
+            options.c_iflag |= (IXON | IXOFF | IXANY);
+            break;
+        case MM_FLOW_CONTROL_RTS_CTS:
+            mm_dbg ("(%s): enabling RTS/CTS flow control", mm_port_get_device 
(MM_PORT (self)));
+            options.c_cflag |= (CRTSCTS);
+            break;
+        case MM_FLOW_CONTROL_NONE:
+            if (had_xon_xoff)
+                mm_dbg ("(%s): disabling XON/XOFF flow control", 
mm_port_get_device (MM_PORT (self)));
+            if (had_rts_cts)
+                mm_dbg ("(%s): disabling RTS/CTS flow control", 
mm_port_get_device (MM_PORT (self)));
+            break;
+        default:
+            g_assert_not_reached ();
+    }
+
+    return internal_tcsetattr (self, self->priv->fd, &options, error);
+}
+
+/*****************************************************************************/
+
 MMPortSerial *
 mm_port_serial_new (const char *name, MMPortType ptype)
 {
diff --git a/src/mm-port-serial.h b/src/mm-port-serial.h
index 708e3912..223b9ce1 100644
--- a/src/mm-port-serial.h
+++ b/src/mm-port-serial.h
@@ -21,6 +21,7 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
+#include "mm-modem-helpers.h"
 #include "mm-port.h"
 
 #define MM_TYPE_PORT_SERIAL            (mm_port_serial_get_type ())
@@ -150,4 +151,8 @@ GByteArray *mm_port_serial_command_finish (MMPortSerial 
*self,
                                            GAsyncResult *res,
                                            GError **error);
 
+gboolean mm_port_serial_set_flow_control (MMPortSerial   *self,
+                                          MMFlowControl   flow_control,
+                                          GError        **error);
+
 #endif /* MM_PORT_SERIAL_H */
-- 
2.12.0

_______________________________________________
ModemManager-devel mailing list
ModemManager-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel

Reply via email to