All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/5] cdmaphonesim: Add CDMA SMS Support
@ 2010-12-09  0:35 Lei Yu
  2010-12-20 20:42 ` Denis Kenzior
  0 siblings, 1 reply; 5+ messages in thread
From: Lei Yu @ 2010-12-09  0:35 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 10483 bytes --]

---
 Makefile.am               |    9 ++
 configure.ac              |    6 +
 plugins/cdmaphonesim.c    |  344 +++++++++++++++++++++++++++++++++++++++++++++
 plugins/cdmaphonesim.conf |   14 ++
 4 files changed, 373 insertions(+), 0 deletions(-)
 create mode 100644 plugins/cdmaphonesim.c
 create mode 100644 plugins/cdmaphonesim.conf

diff --git a/Makefile.am b/Makefile.am
index 400d4c0..44a6395 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -249,6 +249,15 @@ builtin_sources += drivers/cdma-atmodem/atmodem.h \
 			drivers/cdma-atmodem/sms.c
 endif
 
+if CDMAPHONESIM
+builtin_modules += cdmaphonesim
+builtin_sources += plugins/cdmaphonesim.c
+
+if DATAFILES
+conf_DATA += plugins/cdmaphonesim.conf
+endif
+endif
+
 builtin_modules += g1
 builtin_sources += plugins/g1.c
 
diff --git a/configure.ac b/configure.ac
index abbd8cc..a85344f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -171,6 +171,12 @@ AC_ARG_ENABLE(cdmaatmodem, AC_HELP_STRING([--disable-cdma-atmodem],
 					[enable_cdma_atmodem=${enableval}])
 AM_CONDITIONAL(CDMA_ATMODEM, test "${enable_cdma_atmodem}" != "no")
 
+AC_ARG_ENABLE(cdmaphonesim, AC_HELP_STRING([--disable-cdma-phonesim],
+				[disable CDMA Phone simulator support]),
+					[enable_cdma_phonesim=${enableval}])
+AM_CONDITIONAL(CDMAPHONESIM, test "${enable_cdma-phonesim}" != "no" &&
+					test "${enable_cdma_atmodem}" != "no")
+
 AC_ARG_ENABLE(isimodem, AC_HELP_STRING([--disable-isimodem],
 				[disable PhoNet/ISI modem support]),
 					[enable_isimodem=${enableval}])
diff --git a/plugins/cdmaphonesim.c b/plugins/cdmaphonesim.c
new file mode 100644
index 0000000..566f82b
--- /dev/null
+++ b/plugins/cdmaphonesim.c
@@ -0,0 +1,344 @@
+/*
+ * This file is part of oFono - Open Source Telephony
+ *
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * 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 <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <glib.h>
+#include <gatmux.h>
+#include <gatchat.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/cdma-sms.h>
+
+#include <drivers/cdma-atmodem/atutil.h>
+
+struct cdmaphonesim_data {
+	GAtChat *chat;
+};
+
+static int cdmaphonesim_probe(struct ofono_modem *modem)
+{
+	struct cdmaphonesim_data *data;
+
+	DBG("%p", modem);
+
+	data = g_try_new0(struct cdmaphonesim_data, 1);
+	if (data == NULL)
+		return -ENOMEM;
+
+	ofono_modem_set_data(modem, data);
+
+	return 0;
+}
+
+static void cdmaphonesim_remove(struct ofono_modem *modem)
+{
+	struct cdmaphonesim_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	g_free(data);
+	ofono_modem_set_data(modem, NULL);
+}
+
+static void cdmaphonesim_debug(const char *str, void *user_data)
+{
+	ofono_info("%s", str);
+}
+
+static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
+	DBG("");
+
+	ofono_modem_set_powered(modem, ok);
+}
+
+static void cdmaphonesim_disconnected(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct cdmaphonesim_data *data = ofono_modem_get_data(modem);
+
+	DBG("");
+
+	ofono_modem_set_powered(modem, FALSE);
+
+	g_at_chat_unref(data->chat);
+	data->chat = NULL;
+}
+
+static int cdmaphonesim_enable(struct ofono_modem *modem)
+{
+	struct cdmaphonesim_data *data = ofono_modem_get_data(modem);
+	GIOChannel *io;
+	GAtSyntax *syntax;
+	struct sockaddr_in addr;
+	const char *address;
+	int sk, err, port;
+
+	DBG("%p", modem);
+
+	address = ofono_modem_get_string(modem, "Address");
+	if (address == NULL)
+		return -EINVAL;
+
+	port = ofono_modem_get_integer(modem, "Port");
+	if (port < 0)
+		return -EINVAL;
+
+	sk = socket(PF_INET, SOCK_STREAM, 0);
+	if (sk < 0)
+		return -EINVAL;
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sin_family = AF_INET;
+	addr.sin_addr.s_addr = inet_addr(address);
+	addr.sin_port = htons(port);
+
+	err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
+	if (err < 0) {
+		close(sk);
+		return err;
+	}
+
+	io = g_io_channel_unix_new(sk);
+	if (io == NULL) {
+		close(sk);
+		return -ENOMEM;
+	}
+
+	syntax = g_at_syntax_new_gsmv1();
+
+	data->chat = g_at_chat_new(io, syntax);
+
+	g_at_syntax_unref(syntax);
+	g_io_channel_unref(io);
+
+	if (data->chat == NULL)
+		return -ENOMEM;
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_chat_set_debug(data->chat, cdmaphonesim_debug, NULL);
+
+	g_at_chat_set_disconnect_function(data->chat,
+					cdmaphonesim_disconnected, modem);
+
+	g_at_chat_send(data->chat, "AT+CFUN=1", NULL,
+					cfun_set_on_cb, modem, NULL);
+
+	return -EINPROGRESS;
+}
+
+static int cdmaphonesim_disable(struct ofono_modem *modem)
+{
+	struct cdmaphonesim_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	g_at_chat_unref(data->chat);
+	data->chat = NULL;
+
+	return 0;
+}
+
+static void cdmaphonesim_pre_sim(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+}
+
+static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_modem_online_cb_t callback = cbd->cb;
+	struct ofono_error error;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	callback(&error, cbd->data);
+}
+
+static void cdmaphonesim_set_online(struct ofono_modem *modem,
+									ofono_bool_t online,
+									ofono_modem_online_cb_t cb,
+									void *user_data)
+{
+	struct cdmaphonesim_data *data = ofono_modem_get_data(modem);
+	struct cb_data *cbd = cb_data_new(cb, user_data);
+	char const *command = online ? "AT+CFUN=1" : "AT+CFUN=4";
+
+	DBG("modem %p %s", modem, online ? "online" : "offline");
+
+	if (cbd == NULL)
+		goto error;
+
+	if (g_at_chat_send(data->chat, command, NULL,
+				set_online_cb, cbd, g_free))
+		return;
+
+error:
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, cbd->data);
+}
+
+static void cdmaphonesim_post_online(struct ofono_modem *modem)
+{
+	struct cdmaphonesim_data *data = ofono_modem_get_data(modem);
+
+    ofono_cdmasms_create(modem, 0, "cdma-atmodem", data->chat);
+}
+
+static struct ofono_modem_driver cdmaphonesim_driver = {
+	.name		= "cdmaphonesim",
+	.probe		= cdmaphonesim_probe,
+	.remove		= cdmaphonesim_remove,
+	.enable		= cdmaphonesim_enable,
+	.disable	= cdmaphonesim_disable,
+	.pre_sim	= cdmaphonesim_pre_sim,
+	.set_online	= cdmaphonesim_set_online,
+	.post_online	= cdmaphonesim_post_online,
+};
+
+static struct ofono_modem *create_modem(GKeyFile *keyfile, const char *group)
+{
+	struct ofono_modem *modem;
+	char *value;
+
+	DBG("group %s", group);
+
+	modem = ofono_modem_create(group, "cdmaphonesim");
+	if (modem == NULL)
+		return NULL;
+
+	value = g_key_file_get_string(keyfile, group, "Address", NULL);
+	if (value == NULL)
+		goto error;
+
+	ofono_modem_set_string(modem, "Address", value);
+	g_free(value);
+
+	value = g_key_file_get_string(keyfile, group, "Port", NULL);
+	if (value == NULL)
+		goto error;
+
+	ofono_modem_set_integer(modem, "Port", atoi(value));
+	g_free(value);
+
+	value = g_key_file_get_string(keyfile, group, "Modem", NULL);
+	if (value != NULL) {
+		ofono_modem_set_string(modem, "Modem", value);
+		g_free(value);
+	}
+
+	value = g_key_file_get_string(keyfile, group, "Multiplexer", NULL);
+	if (value != NULL) {
+		ofono_modem_set_string(modem, "Multiplexer", value);
+		g_free(value);
+	}
+
+	DBG("%p", modem);
+
+	return modem;
+
+error:
+	ofono_error("Missing address or port setting for %s", group);
+
+	ofono_modem_remove(modem);
+
+	return NULL;
+}
+
+static GSList *modem_list;
+
+static void parse_config(const char *filename)
+{
+	GKeyFile *keyfile;
+	GError *err = NULL;
+	char **modems;
+	int i;
+
+	DBG("filename %s", filename);
+
+	keyfile = g_key_file_new();
+
+	g_key_file_set_list_separator(keyfile, ',');
+
+	if (!g_key_file_load_from_file(keyfile, filename, 0, &err)) {
+		ofono_warn("Reading of %s failed: %s", filename, err->message);
+		g_error_free(err);
+		goto done;
+	}
+
+	modems = g_key_file_get_groups(keyfile, NULL);
+
+	for (i = 0; modems[i]; i++) {
+		struct ofono_modem *modem;
+
+		modem = create_modem(keyfile, modems[i]);
+		if (modem == NULL)
+			continue;
+
+		modem_list = g_slist_prepend(modem_list, modem);
+
+		ofono_modem_register(modem);
+	}
+
+	g_strfreev(modems);
+
+done:
+	g_key_file_free(keyfile);
+}
+
+
+static int cdmaphonesim_init(void)
+{
+	int err;
+
+	err = ofono_modem_driver_register(&cdmaphonesim_driver);
+	if (err < 0)
+		return err;
+
+	parse_config(CONFIGDIR "/cdmaphonesim.conf");
+	return 0;
+}
+
+static void cdmaphonesim_exit(void)
+{
+	ofono_modem_driver_unregister(&cdmaphonesim_driver);
+}
+
+OFONO_PLUGIN_DEFINE(cdmaphonesim, "CDMA PhoneSIM driver", VERSION,
+	OFONO_PLUGIN_PRIORITY_DEFAULT, cdmaphonesim_init, cdmaphonesim_exit)
diff --git a/plugins/cdmaphonesim.conf b/plugins/cdmaphonesim.conf
new file mode 100644
index 0000000..9b8bdac
--- /dev/null
+++ b/plugins/cdmaphonesim.conf
@@ -0,0 +1,14 @@
+# This is a sample file for the cdmaphonesim configuration
+#
+# It should be installed in your oFono system directory,
+# e.g. /etc/ofono/cdmaphonesim.conf
+#
+# Each group is parsed as a modem device
+#
+# Each group shall@least define the address and port
+#   Address = <valid IPv4 address format>
+#   Port = <valid TCP port>
+
+#[cdmaphonesim]
+#Address=127.0.0.1
+#Port=12345
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/5] cdmaphonesim: Add CDMA SMS Support
  2010-12-09  0:35 [PATCH 4/5] cdmaphonesim: Add CDMA SMS Support Lei Yu
@ 2010-12-20 20:42 ` Denis Kenzior
  2010-12-20 21:53   ` Lei Yu
  0 siblings, 1 reply; 5+ messages in thread
From: Denis Kenzior @ 2010-12-20 20:42 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 700 bytes --]

Hi Lei,

On 12/08/2010 06:35 PM, Lei Yu wrote:
> ---
>  Makefile.am               |    9 ++
>  configure.ac              |    6 +
>  plugins/cdmaphonesim.c    |  344 +++++++++++++++++++++++++++++++++++++++++++++
>  plugins/cdmaphonesim.conf |   14 ++
>  4 files changed, 373 insertions(+), 0 deletions(-)
>  create mode 100644 plugins/cdmaphonesim.c
>  create mode 100644 plugins/cdmaphonesim.conf
> 

Have you considered adding a CDMA/GSM selector to phonesim.conf instead?
 So e.g. a new configuration key called 'Type' where type can be 'gsm'
or 'cdma'.

That way you can share much of the phonesim plugin plumbing and only
populate the atoms differently...

Regards,
-Denis

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/5] cdmaphonesim: Add CDMA SMS Support
  2010-12-20 20:42 ` Denis Kenzior
@ 2010-12-20 21:53   ` Lei Yu
  2010-12-20 22:32     ` Denis Kenzior
  0 siblings, 1 reply; 5+ messages in thread
From: Lei Yu @ 2010-12-20 21:53 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1553 bytes --]

Hi Denis,

On 12/20/2010 12:42 PM, ext Denis Kenzior wrote:
> Hi Lei,
>
> On 12/08/2010 06:35 PM, Lei Yu wrote:
>> ---
>>   Makefile.am               |    9 ++
>>   configure.ac              |    6 +
>>   plugins/cdmaphonesim.c    |  344 +++++++++++++++++++++++++++++++++++++++++++++
>>   plugins/cdmaphonesim.conf |   14 ++
>>   4 files changed, 373 insertions(+), 0 deletions(-)
>>   create mode 100644 plugins/cdmaphonesim.c
>>   create mode 100644 plugins/cdmaphonesim.conf
>>
>
> Have you considered adding a CDMA/GSM selector to phonesim.conf instead?
>   So e.g. a new configuration key called 'Type' where type can be 'gsm'
> or 'cdma'.
>
> That way you can share much of the phonesim plugin plumbing and only
> populate the atoms differently...
>

We thought about this briefly but decided not pursuing that path at this 
stage of CDMA development mainly due to following reasons: a). We think 
it may make more sense to let CDMA development evolving a bit more on 
its own and then evaluate to see for which part it makes sense
to merge. We are afraid merging too early will make the phonesim.c code 
looking ugly with a lot of if/else down the road. We are planning to 
evaluate things like this when we have at least a few CDMA atoms 
implemented. b). We definitely would like to cause as little disruption 
to GSM as possible at this stage of CDMA development.

I am definitely looking forward to hearing more from you and other 
people and open for any changes.

> Regards,
> -Denis

Regards,
Lei

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/5] cdmaphonesim: Add CDMA SMS Support
  2010-12-20 21:53   ` Lei Yu
@ 2010-12-20 22:32     ` Denis Kenzior
  2010-12-20 23:14       ` Lei Yu
  0 siblings, 1 reply; 5+ messages in thread
From: Denis Kenzior @ 2010-12-20 22:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1298 bytes --]

Hi Lei,

>>
>> Have you considered adding a CDMA/GSM selector to phonesim.conf instead?
>>   So e.g. a new configuration key called 'Type' where type can be 'gsm'
>> or 'cdma'.
>>
>> That way you can share much of the phonesim plugin plumbing and only
>> populate the atoms differently...
>>
> 
> We thought about this briefly but decided not pursuing that path at this
> stage of CDMA development mainly due to following reasons: a). We think
> it may make more sense to let CDMA development evolving a bit more on
> its own and then evaluate to see for which part it makes sense
> to merge. We are afraid merging too early will make the phonesim.c code
> looking ugly with a lot of if/else down the road. We are planning to
> evaluate things like this when we have at least a few CDMA atoms
> implemented. b). We definitely would like to cause as little disruption
> to GSM as possible at this stage of CDMA development.

Ok I'm still waffling on this one but I can accept a temporary cdma
phonesim plugin for now.

Can you make sure to strip it down some more? For instance you can omit
Multiplexer and Modem configure key handling.

And having a separate configure option for cdma phonesim seems unneeded.
 Lump this one with --enable-phonesim.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/5] cdmaphonesim: Add CDMA SMS Support
  2010-12-20 22:32     ` Denis Kenzior
@ 2010-12-20 23:14       ` Lei Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Lei Yu @ 2010-12-20 23:14 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1581 bytes --]

On 12/20/2010 02:32 PM, ext Denis Kenzior wrote:
> Hi Lei,
>
>>>
>>> Have you considered adding a CDMA/GSM selector to phonesim.conf instead?
>>>    So e.g. a new configuration key called 'Type' where type can be 'gsm'
>>> or 'cdma'.
>>>
>>> That way you can share much of the phonesim plugin plumbing and only
>>> populate the atoms differently...
>>>
>>
>> We thought about this briefly but decided not pursuing that path at this
>> stage of CDMA development mainly due to following reasons: a). We think
>> it may make more sense to let CDMA development evolving a bit more on
>> its own and then evaluate to see for which part it makes sense
>> to merge. We are afraid merging too early will make the phonesim.c code
>> looking ugly with a lot of if/else down the road. We are planning to
>> evaluate things like this when we have at least a few CDMA atoms
>> implemented. b). We definitely would like to cause as little disruption
>> to GSM as possible at this stage of CDMA development.
>
> Ok I'm still waffling on this one but I can accept a temporary cdma
> phonesim plugin for now.
>

As you can see I am also waffling on this. :-) I will stick with 
separate cdma phonesim plugin for now.

> Can you make sure to strip it down some more? For instance you can omit
> Multiplexer and Modem configure key handling.
>

Yes, I will strip it down more.

> And having a separate configure option for cdma phonesim seems unneeded.
>   Lump this one with --enable-phonesim.
>

Yes, I will do this.

> Regards,
> -Denis

Regards,
Lei

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-12-20 23:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-09  0:35 [PATCH 4/5] cdmaphonesim: Add CDMA SMS Support Lei Yu
2010-12-20 20:42 ` Denis Kenzior
2010-12-20 21:53   ` Lei Yu
2010-12-20 22:32     ` Denis Kenzior
2010-12-20 23:14       ` Lei Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.