3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <ofono/log.h>
35 #include <ofono/modem.h>
36 #include <ofono/radio-settings.h>
39 #include "gatresult.h"
43 static const char *none_prefix[] = { NULL };
44 static const char *xrat_prefix[] = { "+XRAT:", NULL };
46 struct radio_settings_data {
50 static void xrat_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
52 struct cb_data *cbd = user_data;
53 ofono_radio_settings_rat_mode_query_cb_t cb = cbd->cb;
54 enum ofono_radio_access_mode mode;
55 struct ofono_error error;
59 decode_at_error(&error, g_at_result_final_response(result));
62 cb(&error, -1, cbd->data);
66 g_at_result_iter_init(&iter, result);
68 if (g_at_result_iter_next(&iter, "+XRAT:") == FALSE)
71 if (g_at_result_iter_next_number(&iter, &value) == FALSE)
74 if (g_at_result_iter_next_number(&iter, &preferred) == FALSE)
79 mode = OFONO_RADIO_ACCESS_MODE_GSM;
82 mode = OFONO_RADIO_ACCESS_MODE_ANY;
85 mode = OFONO_RADIO_ACCESS_MODE_UMTS;
88 CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
92 cb(&error, mode, cbd->data);
97 CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
100 static void ifx_query_rat_mode(struct ofono_radio_settings *rs,
101 ofono_radio_settings_rat_mode_query_cb_t cb,
104 struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
105 struct cb_data *cbd = cb_data_new(cb, data);
107 if (g_at_chat_send(rsd->chat, "AT+XRAT?", xrat_prefix,
108 xrat_query_cb, cbd, g_free) == 0) {
109 CALLBACK_WITH_FAILURE(cb, -1, data);
114 static void xrat_modify_cb(gboolean ok, GAtResult *result, gpointer user_data)
116 struct cb_data *cbd = user_data;
117 ofono_radio_settings_rat_mode_set_cb_t cb = cbd->cb;
118 struct ofono_error error;
120 decode_at_error(&error, g_at_result_final_response(result));
121 cb(&error, cbd->data);
124 static void ifx_set_rat_mode(struct ofono_radio_settings *rs,
125 enum ofono_radio_access_mode mode,
126 ofono_radio_settings_rat_mode_set_cb_t cb,
129 struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
130 struct cb_data *cbd = cb_data_new(cb, data);
132 int value = 1, preferred = 2;
135 case OFONO_RADIO_ACCESS_MODE_ANY:
138 case OFONO_RADIO_ACCESS_MODE_GSM:
141 case OFONO_RADIO_ACCESS_MODE_UMTS:
144 case OFONO_RADIO_ACCESS_MODE_LTE:
149 snprintf(buf, sizeof(buf), "AT+XRAT=%u,%u", value, preferred);
151 snprintf(buf, sizeof(buf), "AT+XRAT=%u", value);
153 if (g_at_chat_send(rsd->chat, buf, none_prefix,
154 xrat_modify_cb, cbd, g_free) > 0)
158 CALLBACK_WITH_FAILURE(cb, data);
162 static void xrat_support_cb(gboolean ok, GAtResult *result, gpointer user_data)
164 struct ofono_radio_settings *rs = user_data;
169 ofono_radio_settings_register(rs);
172 static int ifx_radio_settings_probe(struct ofono_radio_settings *rs,
173 unsigned int vendor, void *data)
175 GAtChat *chat = data;
176 struct radio_settings_data *rsd;
178 rsd = g_try_new0(struct radio_settings_data, 1);
182 rsd->chat = g_at_chat_clone(chat);
184 ofono_radio_settings_set_data(rs, rsd);
186 g_at_chat_send(rsd->chat, "AT+XRAT=?", xrat_prefix,
187 xrat_support_cb, rs, NULL);
192 static void ifx_radio_settings_remove(struct ofono_radio_settings *rs)
194 struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
196 ofono_radio_settings_set_data(rs, NULL);
198 g_at_chat_unref(rsd->chat);
202 static struct ofono_radio_settings_driver driver = {
204 .probe = ifx_radio_settings_probe,
205 .remove = ifx_radio_settings_remove,
206 .query_rat_mode = ifx_query_rat_mode,
207 .set_rat_mode = ifx_set_rat_mode
210 void ifx_radio_settings_init(void)
212 ofono_radio_settings_driver_register(&driver);
215 void ifx_radio_settings_exit(void)
217 ofono_radio_settings_driver_unregister(&driver);