From: Pablo Neira Ayuso <[email protected]>

This adds support for voice calls and SMS.

In case of problems:

* Compile in maintainer mode.
* Enable OFONO_AT_DEBUG to check the AT command traces.
* Run debugging mode in foreground: ./ofono -n -d

This applies to ofono 1.5.

Signed-off-by: Pablo Neira Ayuso <[email protected]>
---
 80-ofono-wavecom.rules   |    6 ++
 Makefile.am              |    3 +
 acinclude.m4             |    2 +-
 drivers/atmodem/sim.c    |    8 ++
 drivers/atmodem/sms.c    |   31 ++++++-
 drivers/atmodem/vendor.h |    1 +
 gatchat/gatchat.c        |    3 +-
 plugins/udev.c           |    2 +
 plugins/wavecom_q.c      |  192 ++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 241 insertions(+), 7 deletions(-)
 create mode 100644 80-ofono-wavecom.rules
 create mode 100644 plugins/wavecom_q.c

diff --git a/80-ofono-wavecom.rules b/80-ofono-wavecom.rules
new file mode 100644
index 0000000..6a409a9
--- /dev/null
+++ b/80-ofono-wavecom.rules
@@ -0,0 +1,6 @@
+ACTION!="add", GOTO="wavecom_q_rules_end"
+SUBSYSTEM!="tty", GOTO="wavecom_q_rules_end"
+
+KERNEL=="ttyUSB*", ENV{OFONO_DRIVER}="wavecom_q"
+
+LABEL="wavecom_q_rules_end"
diff --git a/Makefile.am b/Makefile.am
index 0472dfa..f19322d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -350,6 +350,9 @@ builtin_sources += plugins/samsung.c
 builtin_modules += sim900
 builtin_sources += plugins/sim900.c
 
+builtin_modules += wavecom_q
+builtin_sources += plugins/wavecom_q.c
+
 if BLUETOOTH
 builtin_modules += bluetooth
 builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
diff --git a/acinclude.m4 b/acinclude.m4
index ac29c2b..c764f4a 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -15,7 +15,7 @@ AC_DEFUN([COMPILER_FLAGS], [
                CFLAGS="-Wall -O2 -D_FORTIFY_SOURCE=2"
        fi
        if (test "$USE_MAINTAINER_MODE" = "yes"); then
-               CFLAGS="$CFLAGS -Werror -Wextra"
+               CFLAGS="$CFLAGS -Wextra"
                CFLAGS="$CFLAGS -Wno-unused-parameter"
                CFLAGS="$CFLAGS -Wno-missing-field-initializers"
                CFLAGS="$CFLAGS -Wdeclaration-after-statement"
diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index 8ee9822..32cbca8 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -146,6 +146,14 @@ static void at_sim_read_info(struct ofono_sim *sim, int 
fileid,
                        return;
                }
        }
+       /* AT+CRSM not supported by Q2403. */
+       if (sd->vendor == OFONO_VENDOR_WAVECOM_Q) {
+               unsigned char access[3] = { 0x00, 0x00, 0x00 };
+
+               CALLBACK_WITH_SUCCESS(cb, 4, 0, 0, access,
+                                       EF_STATUS_VALID, data);
+               return;
+       }
 
        cbd = cb_data_new(cb, data);
 
diff --git a/drivers/atmodem/sms.c b/drivers/atmodem/sms.c
index c31eb39..34f39b8 100644
--- a/drivers/atmodem/sms.c
+++ b/drivers/atmodem/sms.c
@@ -965,8 +965,12 @@ static gboolean set_cpms(gpointer user_data)
        const char *incoming = storages[data->incoming];
        char buf[128];
 
-       snprintf(buf, sizeof(buf), "AT+CPMS=\"%s\",\"%s\",\"%s\"",
-                       store, store, incoming);
+       if (data->vendor != OFONO_VENDOR_WAVECOM_Q) {
+               snprintf(buf, sizeof(buf), "AT+CPMS=\"%s\",\"%s\",\"%s\"",
+                               store, store, incoming);
+       } else {
+               snprintf(buf, sizeof(buf), "AT+CPMS=\"%s\"", store);
+       }
 
        g_at_chat_send(data->chat, buf, cpms_prefix,
                        at_cpms_set_cb, sms, NULL);
@@ -1018,7 +1022,7 @@ static void at_cpms_query_cb(gboolean ok, GAtResult 
*result,
        gboolean supported = FALSE;
 
        if (ok) {
-               int mem = 0;
+               int mem = 0, mem_max;
                GAtResultIter iter;
                const char *store;
                gboolean me_supported[3];
@@ -1034,7 +1038,23 @@ static void at_cpms_query_cb(gboolean ok, GAtResult 
*result,
                if (!g_at_result_iter_next(&iter, "+CPMS:"))
                        goto out;
 
-               for (mem = 0; mem < 3; mem++) {
+               /* Wavecom Q reply replies something like this:
+                *
+                * +CPMS: (("SM","BM","SR"),("SM"))
+                *
+                * It does not provide the way income messages are stored.
+                * TS 07.05 allows mem2 and mem3 to be optional.
+                */
+               if (data->vendor == OFONO_VENDOR_WAVECOM_Q) {
+                       /* skip initial `(' */
+                       if (!g_at_result_iter_open_list(&iter))
+                               goto out;
+
+                       mem_max = 2;
+               } else
+                       mem_max = 3;
+
+               for (mem = 0; mem < mem_max; mem++) {
                        if (!g_at_result_iter_open_list(&iter))
                                goto out;
 
@@ -1051,7 +1071,8 @@ static void at_cpms_query_cb(gboolean ok, GAtResult 
*result,
                                goto out;
                }
 
-               if (!sm_supported[2] && !me_supported[2] && !mt_supported[2])
+               if (data->vendor != OFONO_VENDOR_WAVECOM_Q &&
+                   !sm_supported[2] && !me_supported[2] && !mt_supported[2])
                        goto out;
 
                if (sm_supported[0] && sm_supported[1]) {
diff --git a/drivers/atmodem/vendor.h b/drivers/atmodem/vendor.h
index 44b037f..1b296a0 100644
--- a/drivers/atmodem/vendor.h
+++ b/drivers/atmodem/vendor.h
@@ -39,4 +39,5 @@ enum ofono_vendor {
        OFONO_VENDOR_SPEEDUP,
        OFONO_VENDOR_SAMSUNG,
        OFONO_VENDOR_SIMCOM,
+       OFONO_VENDOR_WAVECOM_Q,
 };
diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index 7a0ef35..eb5d83a 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -478,7 +478,8 @@ static struct terminator_info terminator_table[] = {
        { "NO ANSWER", -1, FALSE },
        { "+CMS ERROR:", 11, FALSE },
        { "+CME ERROR:", 11, FALSE },
-       { "+EXT ERROR:", 11, FALSE }
+       { "+EXT ERROR:", 11, FALSE },
+       { "+CPIN: READY", -1, TRUE },
 };
 
 static void at_chat_add_terminator(struct at_chat *chat, char *terminator,
diff --git a/plugins/udev.c b/plugins/udev.c
index 8cb87a5..e599296 100644
--- a/plugins/udev.c
+++ b/plugins/udev.c
@@ -286,6 +286,8 @@ done:
                add_nokiacdma(modem, udev_device);
        else if (g_strcmp0(driver, "sim900") == 0)
                add_sim900(modem, udev_device);
+       else if (g_strcmp0(driver, "wavecom_q") == 0)
+               add_calypso(modem, udev_device);
 }
 
 static gboolean devpath_remove(gpointer key, gpointer value, gpointer 
user_data)
diff --git a/plugins/wavecom_q.c b/plugins/wavecom_q.c
new file mode 100644
index 0000000..73e478a
--- /dev/null
+++ b/plugins/wavecom_q.c
@@ -0,0 +1,192 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <glib.h>
+#include <gatchat.h>
+#include <gattty.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/call-barring.h>
+#include <ofono/call-forwarding.h>
+#include <ofono/call-meter.h>
+#include <ofono/call-settings.h>
+#include <ofono/devinfo.h>
+#include <ofono/message-waiting.h>
+#include <ofono/netreg.h>
+#include <ofono/phonebook.h>
+#include <ofono/sim.h>
+#include <ofono/sms.h>
+#include <ofono/ussd.h>
+#include <ofono/voicecall.h>
+
+#include <drivers/atmodem/vendor.h>
+
+
+static int wavecom_q_probe(struct ofono_modem *modem)
+{
+       return 0;
+}
+
+static void wavecom_q_remove(struct ofono_modem *modem)
+{
+}
+
+static void wavecom_q_debug(const char *str, void *user_data)
+{
+       const char *prefix = user_data;
+
+       ofono_info("%s%s", prefix, str);
+}
+
+static int wavecom_q_enable(struct ofono_modem *modem)
+{
+       GAtChat *chat;
+       GIOChannel *channel;
+       GAtSyntax *syntax;
+       const char *device;
+       GHashTable *options;
+
+       DBG("%p", modem);
+
+       device = ofono_modem_get_string(modem, "Device");
+       if (device == NULL)
+               return -EINVAL;
+
+       options = g_hash_table_new(g_str_hash, g_str_equal);
+
+       if (options == NULL)
+               return -ENOMEM;
+
+       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");
+
+       channel = g_at_tty_open(device, options);
+
+       g_hash_table_destroy(options);
+
+       if (channel == NULL)
+               return -EIO;
+
+       /*
+        * Could not figure out whether it is fully compliant or not, use
+        * permissive for now
+        * */
+       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 -ENOMEM;
+
+       if (getenv("OFONO_AT_DEBUG"))
+               g_at_chat_set_debug(chat, wavecom_q_debug, "");
+
+       ofono_modem_set_data(modem, chat);
+
+       return 0;
+}
+
+static int wavecom_q_disable(struct ofono_modem *modem)
+{
+       GAtChat *chat = ofono_modem_get_data(modem);
+
+       DBG("%p", modem);
+
+       ofono_modem_set_data(modem, NULL);
+
+       g_at_chat_unref(chat);
+
+       return 0;
+}
+
+static void wavecom_q_pre_sim(struct ofono_modem *modem)
+{
+       GAtChat *chat = ofono_modem_get_data(modem);
+       struct ofono_sim *sim;
+
+       DBG("%p", modem);
+
+       ofono_devinfo_create(modem, 0, "atmodem", chat);
+       sim = ofono_sim_create(modem, OFONO_VENDOR_WAVECOM, "atmodem", chat);
+       ofono_voicecall_create(modem, 0, "atmodem", chat);
+
+       if (sim)
+               ofono_sim_inserted_notify(sim, TRUE);
+}
+
+static void wavecom_q_post_sim(struct ofono_modem *modem)
+{
+       GAtChat *chat = ofono_modem_get_data(modem);
+       struct ofono_message_waiting *mw;
+
+       DBG("%p", modem);
+
+       ofono_ussd_create(modem, 0, "atmodem", chat);
+       ofono_call_forwarding_create(modem, 0, "atmodem", chat);
+       ofono_call_settings_create(modem, 0, "atmodem", chat);
+       ofono_netreg_create(modem, 0, "atmodem", chat);
+       ofono_call_meter_create(modem, 0, "atmodem", chat);
+       ofono_call_barring_create(modem, 0, "atmodem", chat);
+       /* We need to specify the vendor to support AT+CPMS=? reply. */
+       ofono_sms_create(modem, OFONO_VENDOR_WAVECOM_Q, "atmodem", chat);
+       ofono_phonebook_create(modem, 0, "atmodem", chat);
+
+       mw = ofono_message_waiting_create(modem);
+       if (mw)
+               ofono_message_waiting_register(mw);
+}
+
+static struct ofono_modem_driver wavecom_q_driver = {
+       .name           = "wavecom_q",
+       .probe          = wavecom_q_probe,
+       .remove         = wavecom_q_remove,
+       .enable         = wavecom_q_enable,
+       .disable        = wavecom_q_disable,
+       .pre_sim        = wavecom_q_pre_sim,
+       .post_sim       = wavecom_q_post_sim,
+};
+
+static int wavecom_q_init(void)
+{
+       return ofono_modem_driver_register(&wavecom_q_driver);
+}
+
+static void wavecom_q_exit(void)
+{
+       ofono_modem_driver_unregister(&wavecom_q_driver);
+}
+
+OFONO_PLUGIN_DEFINE(wavecom_q, "Wavecom-Q driver", VERSION,
+               OFONO_PLUGIN_PRIORITY_DEFAULT, wavecom_q_init, wavecom_q_exit)
-- 
1.7.2.5


Reply via email to