3
* oFono - Open Source Telephony
5
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6
* Copyright (C) 2013 Jolla Ltd
7
* Copyright (C) 2013 Canonical Ltd
8
* Contact: Jussi Kangas <jussi.kangas@tieto.com>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License version 2 as
12
* published by the Free Software Foundation.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37
#include <ofono/log.h>
38
#include <ofono/modem.h>
39
#include <ofono/call-settings.h>
43
#include "grilrequest.h"
44
#include "grilreply.h"
47
#include "ril_constants.h"
50
struct settings_data {
54
static void ril_set_cb(struct ril_msg *message, gpointer user_data)
56
struct cb_data *cbd = user_data;
57
struct ofono_call_settings *cs = cbd->user;
58
struct settings_data *sd = ofono_call_settings_get_data(cs);
59
ofono_call_settings_set_cb_t cb = cbd->cb;
61
if (message->error == RIL_E_SUCCESS) {
62
g_ril_print_response_no_args(sd->ril, message);
63
CALLBACK_WITH_SUCCESS(cb, cbd->data);
65
CALLBACK_WITH_FAILURE(cb, cbd->data);
69
static void ril_cw_set(struct ofono_call_settings *cs, int mode, int cls,
70
ofono_call_settings_set_cb_t cb, void *data)
72
struct settings_data *sd = ofono_call_settings_get_data(cs);
73
struct cb_data *cbd = cb_data_new(cb, data, cs);
77
g_ril_request_set_call_waiting(sd->ril, mode, cls, &rilp);
79
ret = g_ril_send(sd->ril, RIL_REQUEST_SET_CALL_WAITING, &rilp,
80
ril_set_cb, cbd, g_free);
82
/* In case of error free cbd and return the cb with failure */
85
CALLBACK_WITH_FAILURE(cb, data);
89
static void ril_cw_query_cb(struct ril_msg *message, gpointer user_data)
91
struct cb_data *cbd = user_data;
92
struct ofono_call_settings *cs = cbd->user;
93
struct settings_data *sd = ofono_call_settings_get_data(cs);
94
ofono_call_settings_status_cb_t cb = cbd->cb;
96
if (message->error == RIL_E_SUCCESS) {
99
res = g_ril_reply_parse_query_call_waiting(sd->ril, message);
101
CALLBACK_WITH_SUCCESS(cb, res, cbd->data);
103
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
107
static void ril_cw_query(struct ofono_call_settings *cs, int cls,
108
ofono_call_settings_status_cb_t cb, void *data)
110
struct settings_data *sd = ofono_call_settings_get_data(cs);
111
struct cb_data *cbd = cb_data_new(cb, data, cs);
115
g_ril_request_query_call_waiting(sd->ril, cls, &rilp);
117
ret = g_ril_send(sd->ril, RIL_REQUEST_QUERY_CALL_WAITING, &rilp,
118
ril_cw_query_cb, cbd, g_free);
120
/* In case of error free cbd and return the cb with failure */
123
CALLBACK_WITH_FAILURE(cb, -1, data);
127
static void ril_clip_query_cb(struct ril_msg *message, gpointer user_data)
129
struct cb_data *cbd = user_data;
130
struct ofono_call_settings *cs = cbd->user;
131
struct settings_data *sd = ofono_call_settings_get_data(cs);
132
ofono_call_settings_status_cb_t cb = cbd->cb;
134
if (message->error == RIL_E_SUCCESS) {
137
res = g_ril_reply_parse_query_clip(sd->ril, message);
139
CALLBACK_WITH_SUCCESS(cb, res, cbd->data);
141
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
145
static void ril_clip_query(struct ofono_call_settings *cs,
146
ofono_call_settings_status_cb_t cb, void *data)
148
struct settings_data *sd = ofono_call_settings_get_data(cs);
149
struct cb_data *cbd = cb_data_new(cb, data, cs);
152
ret = g_ril_send(sd->ril, RIL_REQUEST_QUERY_CLIP, NULL,
153
ril_clip_query_cb, cbd, g_free);
155
/* In case of error free cbd and return the cb with failure */
158
CALLBACK_WITH_FAILURE(cb, -1, data);
162
static void ril_clir_query_cb(struct ril_msg *message, gpointer user_data)
164
struct cb_data *cbd = user_data;
165
struct ofono_call_settings *cs = cbd->user;
166
struct settings_data *sd = ofono_call_settings_get_data(cs);
167
ofono_call_settings_clir_cb_t cb = cbd->cb;
168
struct reply_clir *rclir;
170
if (message->error != RIL_E_SUCCESS) {
171
ofono_error("%s: Reply failure: %s", __func__,
172
ril_error_to_string(message->error));
176
rclir = g_ril_reply_parse_get_clir(sd->ril, message);
178
ofono_error("%s: parse error", __func__);
182
CALLBACK_WITH_SUCCESS(cb, rclir->status, rclir->provisioned, cbd->data);
184
g_ril_reply_free_get_clir(rclir);
189
CALLBACK_WITH_FAILURE(cb, -1, -1, cbd->data);
192
static void ril_clir_query(struct ofono_call_settings *cs,
193
ofono_call_settings_clir_cb_t cb, void *data)
195
struct settings_data *sd = ofono_call_settings_get_data(cs);
196
struct cb_data *cbd = cb_data_new(cb, data, cs);
199
ret = g_ril_send(sd->ril, RIL_REQUEST_GET_CLIR, NULL,
200
ril_clir_query_cb, cbd, g_free);
204
CALLBACK_WITH_FAILURE(cb, -1, -1, data);
209
static void ril_clir_set(struct ofono_call_settings *cs, int mode,
210
ofono_call_settings_set_cb_t cb, void *data)
212
struct settings_data *sd = ofono_call_settings_get_data(cs);
213
struct cb_data *cbd = cb_data_new(cb, data, cs);
217
g_ril_request_set_clir(sd->ril, mode, &rilp);
219
ret = g_ril_send(sd->ril, RIL_REQUEST_SET_CLIR, &rilp,
220
ril_set_cb, cbd, g_free);
224
CALLBACK_WITH_FAILURE(cb, data);
228
static gboolean ril_delayed_register(gpointer user_data)
230
struct ofono_call_settings *cs = user_data;
232
ofono_call_settings_register(cs);
237
static int ril_call_settings_probe(struct ofono_call_settings *cs,
238
unsigned int vendor, void *user)
241
struct settings_data *sd = g_new0(struct settings_data, 1);
243
sd->ril = g_ril_clone(ril);
245
ofono_call_settings_set_data(cs, sd);
247
g_idle_add(ril_delayed_register, cs);
252
static void ril_call_settings_remove(struct ofono_call_settings *cs)
254
struct settings_data *sd = ofono_call_settings_get_data(cs);
255
ofono_call_settings_set_data(cs, NULL);
257
g_ril_unref(sd->ril);
261
static struct ofono_call_settings_driver driver = {
263
.probe = ril_call_settings_probe,
264
.remove = ril_call_settings_remove,
265
.clip_query = ril_clip_query,
266
.cw_query = ril_cw_query,
267
.cw_set = ril_cw_set,
268
.clir_query = ril_clir_query,
269
.clir_set = ril_clir_set
272
* Not supported in RIL API
273
* .colp_query = ril_colp_query,
274
* .colr_query = ril_colr_query
278
void ril_call_settings_init(void)
280
ofono_call_settings_driver_register(&driver);
283
void ril_call_settings_exit(void)
285
ofono_call_settings_driver_unregister(&driver);