Some ublox modems can be connected over a serial port. Add support
for this connection method.
---
 plugins/ublox.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/plugins/ublox.c b/plugins/ublox.c
index 1ca0030a..a2ed8133 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -129,6 +129,59 @@ static GAtChat *open_device(struct ofono_modem *modem,
        return chat;
 }
 
+static GAtChat *open_serial_device(struct ofono_modem *modem,
+                                const char *key, char *debug)
+{
+       DBG(" open_serial_device %p", modem);
+
+        const char *device;
+        GAtSyntax *syntax;
+        GIOChannel *channel;
+        GAtChat *chat;
+        GHashTable *options;
+
+        device = ofono_modem_get_string(modem, key);
+        if (device == NULL)
+        {
+                DBG("device = NULL");
+                return NULL;
+        }
+        DBG("%s %s", key, device);
+
+        options = g_hash_table_new(g_str_hash, g_str_equal);
+        if (options == NULL)
+                return NULL;
+
+        g_hash_table_insert(options, "Baud", "115200");
+        g_hash_table_insert(options, "Parity", "none");
+        g_hash_table_insert(options, "StopBits", "1");
+        g_hash_table_insert(options, "DataBits", "8");
+        g_hash_table_insert(options, "XonXoff", "on");
+        g_hash_table_insert(options, "Local", "on");
+        g_hash_table_insert(options, "RtsCts", "off");
+        g_hash_table_insert(options, "Read", "on");
+
+        channel = g_at_tty_open(device, options);
+        g_hash_table_destroy(options);
+
+        if (channel == NULL)
+                return NULL;
+
+        syntax = g_at_syntax_new_gsm_permissive();
+        chat = g_at_chat_new(channel, syntax);
+        g_at_syntax_unref(syntax);
+
+        g_io_channel_unref(channel);
+
+        if (chat == NULL)
+                return NULL;
+
+        if (getenv("OFONO_AT_DEBUG"))
+                g_at_chat_set_debug(chat, ublox_debug, debug);
+
+        return chat;
+}
+
 static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 {
        struct ofono_modem *modem = user_data;
@@ -261,7 +314,7 @@ static int ublox_enable(struct ofono_modem *modem)
         * the 'Device' attribute instead...
         */
        if (data->aux == NULL) {
-               data->aux = open_device(modem, "Device", "Aux: ");
+               data->aux = open_serial_device(modem, "Device", "Aux: ");
                if (data->aux == NULL)
                        return -EINVAL;
        }
-- 
2.20.1

_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono

Reply via email to