summaryrefslogtreecommitdiffstats
path: root/drivers/nwmodem
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-06-06 11:08:16 -0700
committerMarcel Holtmann <marcel@holtmann.org>2010-06-06 11:08:16 -0700
commit5b504e8a0d610a0f23c9d0741908a5d2642cb341 (patch)
treeeccfbe238f5ebd146189160794ac4048537bd5c4 /drivers/nwmodem
parente2024acebdbe4b06fff6e1203e43749bae176fc9 (diff)
downloadofono-5b504e8a0d610a0f23c9d0741908a5d2642cb341.tar.bz2
Add support for Novatel specific radio settings
Diffstat (limited to 'drivers/nwmodem')
-rw-r--r--drivers/nwmodem/nwmodem.c3
-rw-r--r--drivers/nwmodem/nwmodem.h3
-rw-r--r--drivers/nwmodem/radio-settings.c207
3 files changed, 213 insertions, 0 deletions
diff --git a/drivers/nwmodem/nwmodem.c b/drivers/nwmodem/nwmodem.c
index 97694db2..cd97df42 100644
--- a/drivers/nwmodem/nwmodem.c
+++ b/drivers/nwmodem/nwmodem.c
@@ -34,11 +34,14 @@
static int nwmodem_init(void)
{
+ nw_radio_settings_init();
+
return 0;
}
static void nwmodem_exit(void)
{
+ nw_radio_settings_exit();
}
OFONO_PLUGIN_DEFINE(nwmodem, "Novatel modem driver", VERSION,
diff --git a/drivers/nwmodem/nwmodem.h b/drivers/nwmodem/nwmodem.h
index 703fb044..68a829b0 100644
--- a/drivers/nwmodem/nwmodem.h
+++ b/drivers/nwmodem/nwmodem.h
@@ -20,3 +20,6 @@
*/
#include <drivers/atmodem/atutil.h>
+
+extern void nw_radio_settings_init();
+extern void nw_radio_settings_exit();
diff --git a/drivers/nwmodem/radio-settings.c b/drivers/nwmodem/radio-settings.c
new file mode 100644
index 00000000..28836308
--- /dev/null
+++ b/drivers/nwmodem/radio-settings.c
@@ -0,0 +1,207 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2010 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
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/radio-settings.h>
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "nwmodem.h"
+
+static const char *none_prefix[] = { NULL };
+static const char *nwrat_prefix[] = { "$NWRAT:", NULL };
+
+struct radio_settings_data {
+ GAtChat *chat;
+};
+
+static void nwrat_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ ofono_radio_settings_rat_mode_query_cb_t cb = cbd->cb;
+ enum ofono_radio_access_mode mode;
+ GAtResultIter iter;
+ int value;
+
+ if (!ok) {
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ return;
+ }
+
+ g_at_result_iter_init(&iter, result);
+
+ if (g_at_result_iter_next(&iter, "$NWRAT:") == FALSE)
+ return;
+
+ if (g_at_result_iter_next_number(&iter, &value) == FALSE) {
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ return;
+ }
+
+ switch (value) {
+ case 0:
+ mode = OFONO_RADIO_ACCESS_MODE_ANY;
+ break;
+ case 1:
+ mode = OFONO_RADIO_ACCESS_MODE_GSM;
+ break;
+ case 2:
+ mode = OFONO_RADIO_ACCESS_MODE_UMTS;
+ break;
+ default:
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ return;
+ }
+
+ CALLBACK_WITH_SUCCESS(cb, mode, cbd->data);
+}
+
+static void nw_query_rat_mode(struct ofono_radio_settings *rs,
+ ofono_radio_settings_rat_mode_query_cb_t cb,
+ void *data)
+{
+ struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
+ struct cb_data *cbd = cb_data_new(cb, data);
+
+ if (g_at_chat_send(rsd->chat, "AT$NWRAT?", nwrat_prefix,
+ nwrat_query_cb, cbd, g_free) == 0) {
+ CALLBACK_WITH_FAILURE(cb, -1, data);
+ g_free(cbd);
+ }
+}
+
+static void nwrat_modify_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ ofono_radio_settings_rat_mode_set_cb_t cb = cbd->cb;
+
+ if (!ok) {
+ CALLBACK_WITH_FAILURE(cb, cbd->data);
+ return;
+ }
+
+ CALLBACK_WITH_SUCCESS(cb, cbd->data);
+}
+
+static void nw_set_rat_mode(struct ofono_radio_settings *rs,
+ enum ofono_radio_access_mode mode,
+ ofono_radio_settings_rat_mode_set_cb_t cb,
+ void *data)
+{
+ struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
+ struct cb_data *cbd = cb_data_new(cb, data);
+ char buf[20];
+ int value;
+
+ switch (mode) {
+ case OFONO_RADIO_ACCESS_MODE_ANY:
+ value = 0;
+ break;
+ case OFONO_RADIO_ACCESS_MODE_GSM:
+ value = 1;
+ break;
+ case OFONO_RADIO_ACCESS_MODE_UMTS:
+ value = 2;
+ break;
+ default:
+ CALLBACK_WITH_FAILURE(cb, data);
+ g_free(cbd);
+ return;
+ }
+
+ snprintf(buf, sizeof(buf), "AT$NWRAT=%u,2", value);
+
+ if (g_at_chat_send(rsd->chat, buf, none_prefix,
+ nwrat_modify_cb, cbd, g_free) == 0) {
+ CALLBACK_WITH_FAILURE(cb, data);
+ g_free(cbd);
+ }
+}
+
+static void nwrat_support_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct ofono_radio_settings *rs = user_data;
+
+ if (!ok)
+ return;
+
+ ofono_radio_settings_register(rs);
+}
+
+static int nw_radio_settings_probe(struct ofono_radio_settings *rs,
+ unsigned int vendor, void *data)
+{
+ GAtChat *chat = data;
+ struct radio_settings_data *rsd;
+
+ rsd = g_try_new0(struct radio_settings_data, 1);
+ if (!rsd)
+ return -ENOMEM;
+
+ rsd->chat = chat;
+
+ ofono_radio_settings_set_data(rs, rsd);
+
+ g_at_chat_send(rsd->chat, "AT$NWRAT=?", nwrat_prefix,
+ nwrat_support_cb, rs, NULL);
+
+ return 0;
+}
+
+static void nw_radio_settings_remove(struct ofono_radio_settings *rs)
+{
+ struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
+
+ ofono_radio_settings_set_data(rs, NULL);
+ g_free(rsd);
+}
+
+static struct ofono_radio_settings_driver driver = {
+ .name = "nwmodem",
+ .probe = nw_radio_settings_probe,
+ .remove = nw_radio_settings_remove,
+ .query_rat_mode = nw_query_rat_mode,
+ .set_rat_mode = nw_set_rat_mode
+};
+
+void nw_radio_settings_init()
+{
+ ofono_radio_settings_driver_register(&driver);
+}
+
+void nw_radio_settings_exit()
+{
+ ofono_radio_settings_driver_unregister(&driver);
+}