From 30b054d0e0431ced51da861aeb1effbfb0f952c7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 6 Jun 2010 15:18:57 -0700 Subject: [PATCH] Add support for Option specific radio settings --- Makefile.am | 3 +- drivers/hsomodem/hsomodem.c | 2 + drivers/hsomodem/hsomodem.h | 3 + drivers/hsomodem/radio-settings.c | 209 ++++++++++++++++++++++++++++++ 4 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 drivers/hsomodem/radio-settings.c diff --git a/Makefile.am b/Makefile.am index bc021f43..f350a61e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,7 +189,8 @@ builtin_modules += hsomodem builtin_sources += drivers/atmodem/atutil.h \ drivers/hsomodem/hsomodem.h \ drivers/hsomodem/hsomodem.c \ - drivers/hsomodem/gprs-context.c + drivers/hsomodem/gprs-context.c \ + drivers/hsomodem/radio-settings.c builtin_modules += stemodem builtin_sources += drivers/atmodem/atutil.h \ diff --git a/drivers/hsomodem/hsomodem.c b/drivers/hsomodem/hsomodem.c index ba50d8c5..026226b5 100644 --- a/drivers/hsomodem/hsomodem.c +++ b/drivers/hsomodem/hsomodem.c @@ -35,6 +35,7 @@ static int hsomodem_init(void) { hso_gprs_context_init(); + hso_radio_settings_init(); return 0; } @@ -42,6 +43,7 @@ static int hsomodem_init(void) static void hsomodem_exit(void) { hso_gprs_context_exit(); + hso_radio_settings_exit(); } OFONO_PLUGIN_DEFINE(hsomodem, "HSO modem driver", VERSION, diff --git a/drivers/hsomodem/hsomodem.h b/drivers/hsomodem/hsomodem.h index c6747b4b..b75fafcd 100644 --- a/drivers/hsomodem/hsomodem.h +++ b/drivers/hsomodem/hsomodem.h @@ -23,3 +23,6 @@ extern void hso_gprs_context_init(); extern void hso_gprs_context_exit(); + +extern void hso_radio_settings_init(); +extern void hso_radio_settings_exit(); diff --git a/drivers/hsomodem/radio-settings.c b/drivers/hsomodem/radio-settings.c new file mode 100644 index 00000000..0b6a874c --- /dev/null +++ b/drivers/hsomodem/radio-settings.c @@ -0,0 +1,209 @@ +/* + * + * 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 +#endif + +#define _GNU_SOURCE +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "gatchat.h" +#include "gatresult.h" + +#include "hsomodem.h" + +static const char *none_prefix[] = { NULL }; +static const char *opsys_prefix[] = { "_OPSYS:", NULL }; + +struct radio_settings_data { + GAtChat *chat; +}; + +static void opsys_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, "_OPSYS:") == 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_GSM; + break; + case 1: + mode = OFONO_RADIO_ACCESS_MODE_UMTS; + break; + case 2: + case 3: + case 5: + mode = OFONO_RADIO_ACCESS_MODE_ANY; + break; + default: + CALLBACK_WITH_FAILURE(cb, -1, cbd->data); + return; + } + + CALLBACK_WITH_SUCCESS(cb, mode, cbd->data); +} + +static void hso_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_OPSYS?", opsys_prefix, + opsys_query_cb, cbd, g_free) == 0) { + CALLBACK_WITH_FAILURE(cb, -1, data); + g_free(cbd); + } +} + +static void opsys_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 hso_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 = 5; + break; + case OFONO_RADIO_ACCESS_MODE_GSM: + value = 0; + break; + case OFONO_RADIO_ACCESS_MODE_UMTS: + value = 1; + break; + default: + CALLBACK_WITH_FAILURE(cb, data); + g_free(cbd); + return; + } + + snprintf(buf, sizeof(buf), "AT_OPSYS=%u,2", value); + + if (g_at_chat_send(rsd->chat, buf, none_prefix, + opsys_modify_cb, cbd, g_free) == 0) { + CALLBACK_WITH_FAILURE(cb, data); + g_free(cbd); + } +} + +static void opsys_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 hso_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_OPSYS=?", opsys_prefix, + opsys_support_cb, rs, NULL); + + return 0; +} + +static void hso_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 = "hsomodem", + .probe = hso_radio_settings_probe, + .remove = hso_radio_settings_remove, + .query_rat_mode = hso_query_rat_mode, + .set_rat_mode = hso_set_rat_mode +}; + +void hso_radio_settings_init() +{ + ofono_radio_settings_driver_register(&driver); +} + +void hso_radio_settings_exit() +{ + ofono_radio_settings_driver_unregister(&driver); +}