3
* oFono - Open Source Telephony
5
* Copyright (C) 2008-2009 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
33
#include <ofono/log.h>
34
#include <ofono/modem.h>
38
#include "gatresult.h"
42
static const char *clck_prefix[] = { "+CLCK:", NULL };
43
static const char *none_prefix[] = { NULL };
45
static void clck_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
47
struct cb_data *cbd = user_data;
48
ofono_call_barring_cb_t cb = cbd->cb;
49
struct ofono_error error;
51
int status_mask, status, class, line;
53
dump_response("clck_query_cb", ok, result);
54
decode_at_error(&error, g_at_result_final_response(result));
58
g_at_result_iter_init(&iter, result);
59
while (g_at_result_iter_next(&iter, "+CLCK:")) {
62
if (!g_at_result_iter_next_number(&iter, &status))
65
if (!g_at_result_iter_next_number(&iter, &class)) {
75
status_mask &= ~class;
78
cb(&error, status_mask, cbd->data);
81
static void at_call_barring_query(struct ofono_modem *modem, const char *lock,
82
int cls, ofono_call_barring_cb_t cb,
85
struct at_data *at = ofono_modem_get_userdata(modem);
86
struct cb_data *cbd = cb_data_new(modem, cb, data);
90
if (!cbd || strlen(lock) != 2)
93
len = sprintf(buf, "AT+CLCK=\"%s\",2", lock);
95
if (g_at_chat_send(at->parser, buf, clck_prefix,
96
clck_query_cb, cbd, g_free) > 0)
104
DECLARE_FAILURE(error);
109
static void clck_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
111
struct cb_data *cbd = user_data;
112
ofono_generic_cb_t cb = cbd->cb;
113
struct ofono_error error;
115
dump_response("clck_set_cb", ok, result);
116
decode_at_error(&error, g_at_result_final_response(result));
117
cb(&error, cbd->data);
120
static void at_call_barring_set(struct ofono_modem *modem, const char *lock,
121
int enable, const char *passwd, int cls,
122
ofono_generic_cb_t cb, void *data)
124
struct at_data *at = ofono_modem_get_userdata(modem);
125
struct cb_data *cbd = cb_data_new(modem, cb, data);
129
if (!cbd || strlen(lock) != 2 || (cls && !passwd))
132
len = snprintf(buf, sizeof(buf), "AT+CLCK=\"%s\",%i", lock, enable);
134
len += snprintf(buf + len, sizeof(buf) - len,
136
/* Assume cls == 7 means use defaults */
138
len += snprintf(buf + len, sizeof(buf) - len,
142
if (g_at_chat_send(at->parser, buf, none_prefix,
143
clck_set_cb, cbd, g_free) > 0)
151
DECLARE_FAILURE(error);
156
static void cpwd_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
158
struct cb_data *cbd = user_data;
159
ofono_generic_cb_t cb = cbd->cb;
160
struct ofono_error error;
162
dump_response("cpwd_set_cb", ok, result);
163
decode_at_error(&error, g_at_result_final_response(result));
164
cb(&error, cbd->data);
167
static void at_call_barring_set_passwd(struct ofono_modem *modem,
169
const char *old_passwd, const char *new_passwd,
170
ofono_generic_cb_t cb, void *data)
172
struct at_data *at = ofono_modem_get_userdata(modem);
173
struct cb_data *cbd = cb_data_new(modem, cb, data);
176
if (!cbd || strlen(lock) != 2)
179
snprintf(buf, sizeof(buf), "AT+CPWD=\"%s\",\"%s\",\"%s\"",
180
lock, old_passwd, new_passwd);
182
if (g_at_chat_send(at->parser, buf, none_prefix,
183
cpwd_set_cb, cbd, g_free) > 0)
191
DECLARE_FAILURE(error);
196
static struct ofono_call_barring_ops ops = {
197
.set = at_call_barring_set,
198
.query = at_call_barring_query,
199
.set_passwd = at_call_barring_set_passwd,
202
void at_call_barring_init(struct ofono_modem *modem)
204
ofono_call_barring_register(modem, &ops);
207
void at_call_barring_exit(struct ofono_modem *modem)
209
ofono_call_barring_unregister(modem);