summaryrefslogtreecommitdiff
path: root/drivers/gemaltomodem
diff options
context:
space:
mode:
authorVincent Cesson <vincent.cesson@smile.fr>2017-01-18 12:32:04 +0100
committerDenis Kenzior <denkenz@gmail.com>2017-01-19 13:34:36 -0600
commitc0c7c92a82224ed23f5fce245a8570601994a888 (patch)
tree0d994b13024fefd7d2ed9a8a2d431e4204d0fb05 /drivers/gemaltomodem
parente8c80cbe8b32827f1fdff1a360cc5611e2b86159 (diff)
downloadofono-c0c7c92a82224ed23f5fce245a8570601994a888.tar.gz
drivers: Add gemaltomodem driver to handle GNSS
Add a new location-reporting driver for Gemalto Cinterion modems based on telit implementation + use it in gemalto plugin. It supports activation of GNSS engine (Request) with command AT^SGPSC. This driver is tested on PHS8. NMEA frames are accessible on /dev/ttyUSB1.
Diffstat (limited to 'drivers/gemaltomodem')
-rw-r--r--drivers/gemaltomodem/gemaltomodem.c49
-rw-r--r--drivers/gemaltomodem/gemaltomodem.h25
-rw-r--r--drivers/gemaltomodem/location-reporting.c237
3 files changed, 311 insertions, 0 deletions
diff --git a/drivers/gemaltomodem/gemaltomodem.c b/drivers/gemaltomodem/gemaltomodem.c
new file mode 100644
index 00000000..91cf238a
--- /dev/null
+++ b/drivers/gemaltomodem/gemaltomodem.c
@@ -0,0 +1,49 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 Vincent Cesson. 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 <glib.h>
+#include <gatchat.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/types.h>
+
+#include "gemaltomodem.h"
+
+static int gemaltomodem_init(void)
+{
+ gemalto_location_reporting_init();
+
+ return 0;
+}
+
+static void gemaltomodem_exit(void)
+{
+ gemalto_location_reporting_exit();
+}
+
+OFONO_PLUGIN_DEFINE(gemaltomodem, "Gemalto modem driver", VERSION,
+ OFONO_PLUGIN_PRIORITY_DEFAULT,
+ gemaltomodem_init, gemaltomodem_exit)
diff --git a/drivers/gemaltomodem/gemaltomodem.h b/drivers/gemaltomodem/gemaltomodem.h
new file mode 100644
index 00000000..7ea1e8fb
--- /dev/null
+++ b/drivers/gemaltomodem/gemaltomodem.h
@@ -0,0 +1,25 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 Vincent Cesson. 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
+ *
+ */
+
+#include <drivers/atmodem/atutil.h>
+
+extern void gemalto_location_reporting_init();
+extern void gemalto_location_reporting_exit();
diff --git a/drivers/gemaltomodem/location-reporting.c b/drivers/gemaltomodem/location-reporting.c
new file mode 100644
index 00000000..bcfe00e5
--- /dev/null
+++ b/drivers/gemaltomodem/location-reporting.c
@@ -0,0 +1,237 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2017 Vincent Cesson. 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
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/location-reporting.h>
+
+#include "gatchat.h"
+#include "gatresult.h"
+#include "gattty.h"
+
+#include "gemaltomodem.h"
+
+static const char *sgpsc_prefix[] = { "^SGPSC:", NULL };
+
+struct gps_data {
+ GAtChat *chat;
+};
+
+static void gemalto_gps_disable_cb(gboolean ok, GAtResult *result,
+ gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ struct ofono_location_reporting *lr = cbd->user;
+ ofono_location_reporting_disable_cb_t cb = cbd->cb;
+
+ DBG("lr=%p, ok=%d", lr, ok);
+
+ if (!ok) {
+ struct ofono_error error;
+
+ decode_at_error(&error, g_at_result_final_response(result));
+ cb(&error, cbd->data);
+
+ return;
+ }
+
+ CALLBACK_WITH_SUCCESS(cb, cbd->data);
+}
+
+static void gemalto_location_reporting_disable(
+ struct ofono_location_reporting *lr,
+ ofono_location_reporting_disable_cb_t cb,
+ void *data)
+{
+ struct gps_data *gd = ofono_location_reporting_get_data(lr);
+ struct cb_data *cbd = cb_data_new(cb, data);
+
+ DBG("lr=%p", lr);
+
+ cbd->user = lr;
+
+ if (g_at_chat_send(gd->chat, "AT^SGPSC=\"Engine\",0", sgpsc_prefix,
+ gemalto_gps_disable_cb, cbd, g_free) > 0)
+ return;
+
+ CALLBACK_WITH_FAILURE(cb, data);
+
+ g_free(cbd);
+}
+
+static int enable_data_stream(struct ofono_location_reporting *lr)
+{
+ struct ofono_modem *modem;
+ const char *gps_dev;
+ GHashTable *options;
+ GIOChannel *channel;
+ int fd;
+
+ modem = ofono_location_reporting_get_modem(lr);
+ gps_dev = ofono_modem_get_string(modem, "GPS");
+
+ options = g_hash_table_new(g_str_hash, g_str_equal);
+ if (options == NULL)
+ return -1;
+
+ g_hash_table_insert(options, "Baud", "115200");
+
+ channel = g_at_tty_open(gps_dev, options);
+
+ g_hash_table_destroy(options);
+
+ if (channel == NULL)
+ return -1;
+
+ fd = g_io_channel_unix_get_fd(channel);
+
+ g_io_channel_set_close_on_unref(channel, FALSE);
+ g_io_channel_unref(channel);
+
+ return fd;
+}
+
+static void gemalto_sgpsc_cb(gboolean ok, GAtResult *result,
+ gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ ofono_location_reporting_enable_cb_t cb = cbd->cb;
+ struct ofono_location_reporting *lr = cbd->user;
+ struct ofono_error error;
+ int fd;
+
+ DBG("lr=%p ok=%d", lr, ok);
+
+ decode_at_error(&error, g_at_result_final_response(result));
+
+ if (!ok) {
+ cb(&error, -1, cbd->data);
+
+ return;
+ }
+
+ fd = enable_data_stream(lr);
+
+ if (fd < 0) {
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+
+ return;
+ }
+
+ cb(&error, fd, cbd->data);
+ close(fd);
+}
+
+static void gemalto_location_reporting_enable(struct ofono_location_reporting *lr,
+ ofono_location_reporting_enable_cb_t cb,
+ void *data)
+{
+ struct gps_data *gd = ofono_location_reporting_get_data(lr);
+ struct cb_data *cbd = cb_data_new(cb, data);
+
+ DBG("lr=%p", lr);
+
+ cbd->user = lr;
+
+ if (g_at_chat_send(gd->chat, "AT^SGPSC=\"Engine\",2", sgpsc_prefix,
+ gemalto_sgpsc_cb, cbd, NULL) > 0)
+ return;
+
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ g_free(cbd);
+}
+
+static void gemalto_location_reporting_support_cb(gboolean ok, GAtResult *result,
+ gpointer user_data)
+{
+ struct ofono_location_reporting *lr = user_data;
+
+ if (!ok) {
+ ofono_location_reporting_remove(lr);
+
+ return;
+ }
+
+ ofono_location_reporting_register(lr);
+}
+
+static int gemalto_location_reporting_probe(struct ofono_location_reporting *lr,
+ unsigned int vendor, void *data)
+{
+ GAtChat *chat = data;
+ struct gps_data *gd;
+
+ gd = g_try_new0(struct gps_data, 1);
+ if (gd == NULL)
+ return -ENOMEM;
+
+ gd->chat = g_at_chat_clone(chat);
+
+ ofono_location_reporting_set_data(lr, gd);
+
+ g_at_chat_send(gd->chat, "AT^SGPSC=?", sgpsc_prefix,
+ gemalto_location_reporting_support_cb,
+ lr, NULL);
+
+ return 0;
+}
+
+static void gemalto_location_reporting_remove(struct ofono_location_reporting *lr)
+{
+ struct gps_data *gd = ofono_location_reporting_get_data(lr);
+
+ ofono_location_reporting_set_data(lr, NULL);
+
+ g_at_chat_unref(gd->chat);
+ g_free(gd);
+}
+
+static struct ofono_location_reporting_driver driver = {
+ .name = "gemaltomodem",
+ .type = OFONO_LOCATION_REPORTING_TYPE_NMEA,
+ .probe = gemalto_location_reporting_probe,
+ .remove = gemalto_location_reporting_remove,
+ .enable = gemalto_location_reporting_enable,
+ .disable = gemalto_location_reporting_disable,
+};
+
+void gemalto_location_reporting_init()
+{
+ ofono_location_reporting_driver_register(&driver);
+}
+
+void gemalto_location_reporting_exit()
+{
+ ofono_location_reporting_driver_unregister(&driver);
+}