From c155a91313bc7499fddd857e894998a8bf38609c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 8 Sep 2009 09:24:52 +0200 Subject: [PATCH] Add option to phonesim to run with or without multiplexer --- plugins/modemconf.c | 6 ++++++ plugins/phonesim.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/plugins/modemconf.c b/plugins/modemconf.c index b306a4ce..4795749a 100644 --- a/plugins/modemconf.c +++ b/plugins/modemconf.c @@ -60,6 +60,12 @@ static int set_address(struct ofono_modem *modem, g_free(value); } + value = g_key_file_get_string(keyfile, group, "Multiplexer", NULL); + if (value) { + ofono_modem_set_string(modem, "Multiplexer", value); + g_free(value); + } + return 0; } diff --git a/plugins/phonesim.c b/plugins/phonesim.c index 650e4676..d5e6bbed 100644 --- a/plugins/phonesim.c +++ b/plugins/phonesim.c @@ -32,6 +32,7 @@ #include #include +#include #include #define OFONO_API_SUBJECT_TO_CHANGE @@ -55,8 +56,10 @@ #include struct phonesim_data { + GAtMux *mux; GAtChat *chat; gboolean calypso; + gboolean use_mux; }; static int phonesim_probe(struct ofono_modem *modem) @@ -122,6 +125,10 @@ static int phonesim_enable(struct ofono_modem *modem) if (!g_strcmp0(value, "calypso")) data->calypso = TRUE; + value = ofono_modem_get_string(modem, "Multiplexer"); + if (!g_strcmp0(value, "internal")) + data->use_mux = TRUE; + sk = socket(PF_INET, SOCK_STREAM, 0); if (sk < 0) return -EINVAL; @@ -143,15 +150,33 @@ static int phonesim_enable(struct ofono_modem *modem) return -ENOMEM; } + if (data->use_mux) { + data->mux = g_at_mux_new(io); + if (!data->mux) + return -ENOMEM; + + if (getenv("OFONO_AT_DEBUG")) + g_at_mux_set_debug(data->mux, phonesim_debug, NULL); + } + 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); + if (data->mux) + data->chat = g_at_mux_create_chat(data->mux, syntax); + else + data->chat = g_at_chat_new(io, syntax); + g_at_syntax_unref(syntax); if (!data->chat) { + if (data->mux) { + g_at_mux_unref(data->mux); + data->mux = NULL; + } + g_io_channel_unref(io); return -ENOMEM; } @@ -186,6 +211,13 @@ static int phonesim_disable(struct ofono_modem *modem) g_at_chat_unref(data->chat); data->chat = NULL; + if (data->mux) { + g_at_mux_shutdown(data->mux); + + g_at_mux_unref(data->mux); + data->mux = NULL; + } + return 0; }