summaryrefslogtreecommitdiffstats
path: root/drivers/dunmodem
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2011-07-28 00:02:11 +0200
committerMarcel Holtmann <marcel@holtmann.org>2011-07-28 00:02:11 +0200
commit5a3a691199e5cb263faa87b66d15509b8a09fe59 (patch)
tree59645282cd662448572e09c99f98f98016ae2ad3 /drivers/dunmodem
parenta159a0f9fcc648f09a0da48577933c91cae50a5d (diff)
downloadofono-5a3a691199e5cb263faa87b66d15509b8a09fe59.tar.bz2
dunmodem: Add support for dialup network registration
Diffstat (limited to 'drivers/dunmodem')
-rw-r--r--drivers/dunmodem/dunmodem.c3
-rw-r--r--drivers/dunmodem/dunmodem.h3
-rw-r--r--drivers/dunmodem/network-registration.c126
3 files changed, 132 insertions, 0 deletions
diff --git a/drivers/dunmodem/dunmodem.c b/drivers/dunmodem/dunmodem.c
index b1ac2aca..67d62577 100644
--- a/drivers/dunmodem/dunmodem.c
+++ b/drivers/dunmodem/dunmodem.c
@@ -34,11 +34,14 @@
static int dunmodem_init(void)
{
+ dun_netreg_init();
+
return 0;
}
static void dunmodem_exit(void)
{
+ dun_netreg_exit();
}
OFONO_PLUGIN_DEFINE(dunmodem, "Dialup modem driver", VERSION,
diff --git a/drivers/dunmodem/dunmodem.h b/drivers/dunmodem/dunmodem.h
index 90deb948..9a878410 100644
--- a/drivers/dunmodem/dunmodem.h
+++ b/drivers/dunmodem/dunmodem.h
@@ -20,3 +20,6 @@
*/
#include <drivers/atmodem/atutil.h>
+
+extern void dun_netreg_init(void);
+extern void dun_netreg_exit(void);
diff --git a/drivers/dunmodem/network-registration.c b/drivers/dunmodem/network-registration.c
new file mode 100644
index 00000000..df24b5cb
--- /dev/null
+++ b/drivers/dunmodem/network-registration.c
@@ -0,0 +1,126 @@
+/*
+ *
+ * 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 <glib.h>
+#include <gatchat.h>
+#include <gatresult.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/netreg.h>
+
+#include "common.h"
+#include "dunmodem.h"
+
+static const char *cops_prefix[] = { "+COPS:", NULL };
+
+struct netreg_data {
+ GAtChat *chat;
+};
+
+static void dun_registration_status(struct ofono_netreg *netreg,
+ ofono_netreg_status_cb_t cb, void *data)
+{
+ int status = NETWORK_REGISTRATION_STATUS_REGISTERED;
+
+ DBG("");
+
+ CALLBACK_WITH_SUCCESS(cb, status, -1, -1, -1, data);
+}
+
+static void dun_current_operator(struct ofono_netreg *netreg,
+ ofono_netreg_operator_cb_t cb, void *data)
+{
+ struct ofono_network_operator op;
+
+ DBG("");
+
+ op.name[0] = '\0';
+ op.mcc[0] = '\0';
+ op.mnc[0] = '\0';
+ op.status = 2;
+ op.tech = -1;
+
+ CALLBACK_WITH_SUCCESS(cb, &op, data);
+}
+
+static void cops_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct ofono_netreg *netreg = user_data;
+
+ if (!ok)
+ return;
+
+ ofono_netreg_register(netreg);
+}
+
+static int dun_netreg_probe(struct ofono_netreg *netreg,
+ unsigned int vendor, void *user_data)
+{
+ GAtChat *chat = user_data;
+ struct netreg_data *nd;
+
+ nd = g_try_new0(struct netreg_data, 1);
+ if (nd == NULL)
+ return -ENOMEM;
+
+ nd->chat = g_at_chat_clone(chat);
+
+ ofono_netreg_set_data(netreg, nd);
+
+ g_at_chat_send(nd->chat, "AT+COPS=0", cops_prefix,
+ cops_cb, netreg, NULL);
+
+ return 0;
+}
+
+static void dun_netreg_remove(struct ofono_netreg *netreg)
+{
+ struct netreg_data *nd = ofono_netreg_get_data(netreg);
+
+ ofono_netreg_set_data(netreg, NULL);
+
+ g_free(nd);
+}
+
+static struct ofono_netreg_driver driver = {
+ .name = "dunmodem",
+ .probe = dun_netreg_probe,
+ .remove = dun_netreg_remove,
+ .registration_status = dun_registration_status,
+ .current_operator = dun_current_operator,
+};
+
+void dun_netreg_init(void)
+{
+ ofono_netreg_driver_register(&driver);
+}
+
+void dun_netreg_exit(void)
+{
+ ofono_netreg_driver_unregister(&driver);
+}