summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-09-08 03:01:52 +0200
committerMarcel Holtmann <marcel@holtmann.org>2009-09-08 03:01:52 +0200
commit0910ee73495196280a3acab1dfb649a8ceb7140e (patch)
tree338d0853aad324d4e60dfbad7102f2c649e95eff
parent02eacb65afbbdf224bd61d228aa9601f528f35a8 (diff)
downloadofono-0910ee73495196280a3acab1dfb649a8ceb7140e.tar.bz2
Add support for using phonesim and calypso for testing
-rw-r--r--plugins/modemconf.c24
-rw-r--r--plugins/phonesim.c98
2 files changed, 90 insertions, 32 deletions
diff --git a/plugins/modemconf.c b/plugins/modemconf.c
index c15286de..b306a4ce 100644
--- a/plugins/modemconf.c
+++ b/plugins/modemconf.c
@@ -38,22 +38,28 @@ static GSList *modem_list = NULL;
static int set_address(struct ofono_modem *modem,
GKeyFile *keyfile, const char *group)
{
- char *address, *port;
+ char *value;
- address = g_key_file_get_string(keyfile, group, "Address", NULL);
- if (address) {
- ofono_modem_set_string(modem, "Address", address);
- g_free(address);
+ value = g_key_file_get_string(keyfile, group, "Address", NULL);
+ if (value) {
+ ofono_modem_set_string(modem, "Address", value);
+ g_free(value);
} else
ofono_modem_set_string(modem, "Address", "127.0.0.1");
- port = g_key_file_get_string(keyfile, group, "Port", NULL);
- if (port) {
- ofono_modem_set_integer(modem, "Port", atoi(port));
- g_free(port);
+ value = g_key_file_get_string(keyfile, group, "Port", NULL);
+ if (value) {
+ ofono_modem_set_integer(modem, "Port", atoi(value));
+ g_free(value);
} else
ofono_modem_set_integer(modem, "Port", 12345);
+ value = g_key_file_get_string(keyfile, group, "Modem", NULL);
+ if (value) {
+ ofono_modem_set_string(modem, "Modem", value);
+ g_free(value);
+ }
+
return 0;
}
diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index 66807567..1f94976e 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -52,13 +52,35 @@
#include <ofono/ussd.h>
#include <ofono/voicecall.h>
+struct phonesim_data {
+ GAtChat *chat;
+ gboolean calypso;
+};
+
static int phonesim_probe(struct ofono_modem *modem)
{
+ struct phonesim_data *data;
+
+ DBG("%p", modem);
+
+ data = g_try_new0(struct phonesim_data, 1);
+ if (!data)
+ return -ENOMEM;
+
+ ofono_modem_set_data(modem, data);
+
return 0;
}
static void phonesim_remove(struct ofono_modem *modem)
{
+ struct phonesim_data *data = ofono_modem_get_data(modem);
+
+ DBG("%p", modem);
+
+ ofono_modem_set_data(modem, NULL);
+
+ g_free(data);
}
static void phonesim_debug(const char *str, void *user_data)
@@ -66,13 +88,22 @@ static void phonesim_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 int phonesim_enable(struct ofono_modem *modem)
{
+ struct phonesim_data *data = ofono_modem_get_data(modem);
GIOChannel *io;
- GAtChat *chat;
GAtSyntax *syntax;
struct sockaddr_in addr;
- const char *address;
+ const char *address, *value;
int sk, err, port;
DBG("%p", modem);
@@ -85,6 +116,10 @@ static int phonesim_enable(struct ofono_modem *modem)
if (port < 0)
return -EINVAL;
+ value = ofono_modem_get_string(modem, "Modem");
+ if (!g_strcmp0(value, "calypso"))
+ data->calypso = TRUE;
+
sk = socket(PF_INET, SOCK_STREAM, 0);
if (sk < 0)
return -EINVAL;
@@ -106,57 +141,74 @@ static int phonesim_enable(struct ofono_modem *modem)
return -ENOMEM;
}
- syntax = g_at_syntax_new_gsmv1();
- chat = g_at_chat_new(io, syntax);
+ if (data->calypso)
+ syntax = g_at_syntax_new_gsm_permissive();
+ else
+ syntax = g_at_syntax_new_gsmv1();
+
+ data->chat = g_at_chat_new(io, syntax);
g_at_syntax_unref(syntax);
- if (!chat) {
+ if (!data->chat) {
g_io_channel_unref(io);
return -ENOMEM;
}
if (getenv("OFONO_AT_DEBUG"))
- g_at_chat_set_debug(chat, phonesim_debug, NULL);
+ g_at_chat_set_debug(data->chat, phonesim_debug, NULL);
- g_io_channel_unref(io);
+ if (data->calypso) {
+ g_at_chat_set_wakeup_command(data->chat, "\r", 1000, 5000);
+
+ g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL);
- ofono_modem_set_data(modem, chat);
+ g_at_chat_send(data->chat, "AT+CFUN=1", NULL,
+ cfun_set_on_cb, modem, NULL);
+ }
+
+ g_io_channel_unref(io);
return 0;
}
static int phonesim_disable(struct ofono_modem *modem)
{
- GAtChat *chat = ofono_modem_get_data(modem);
+ struct phonesim_data *data = ofono_modem_get_data(modem);
DBG("%p", modem);
ofono_modem_set_data(modem, NULL);
- g_at_chat_unref(chat);
+ g_at_chat_shutdown(data->chat);
+
+ g_at_chat_unref(data->chat);
+ data->chat = NULL;
return 0;
}
static void phonesim_populate(struct ofono_modem *modem)
{
- GAtChat *chat = ofono_modem_get_data(modem);
+ struct phonesim_data *data = ofono_modem_get_data(modem);
struct ofono_message_waiting *mw;
DBG("%p", modem);
- ofono_devinfo_create(modem, 0, "atmodem", chat);
- ofono_ussd_create(modem, 0, "atmodem", chat);
- ofono_sim_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_voicecall_create(modem, 0, "atmodem", chat);
- ofono_call_meter_create(modem, 0, "atmodem", chat);
- ofono_call_barring_create(modem, 0, "atmodem", chat);
- ofono_ssn_create(modem, 0, "atmodem", chat);
- ofono_sms_create(modem, 0, "atmodem", chat);
- ofono_phonebook_create(modem, 0, "atmodem", chat);
+ ofono_devinfo_create(modem, 0, "atmodem", data->chat);
+ ofono_ussd_create(modem, 0, "atmodem", data->chat);
+ ofono_sim_create(modem, 0, "atmodem", data->chat);
+ ofono_call_forwarding_create(modem, 0, "atmodem", data->chat);
+ ofono_call_settings_create(modem, 0, "atmodem", data->chat);
+ ofono_netreg_create(modem, 0, "atmodem", data->chat);
+ ofono_voicecall_create(modem, 0, "atmodem", data->chat);
+ ofono_call_meter_create(modem, 0, "atmodem", data->chat);
+ ofono_call_barring_create(modem, 0, "atmodem", data->chat);
+ ofono_ssn_create(modem, 0, "atmodem", data->chat);
+
+ if (!data->calypso) {
+ ofono_sms_create(modem, 0, "atmodem", data->chat);
+ ofono_phonebook_create(modem, 0, "atmodem", data->chat);
+ }
mw = ofono_message_waiting_create(modem);
if (mw)