~awe/phablet-extras/ofono-nettime-plugin

« back to all changes in this revision

Viewing changes to drivers/atmodem/call-barring.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2009-08-15 15:55:11 UTC
  • Revision ID: james.westby@ubuntu.com-20090815155511-frst06dijguhyfi4
Tags: upstream-0.3
ImportĀ upstreamĀ versionĀ 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 *
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#define _GNU_SOURCE
 
27
#include <string.h>
 
28
#include <stdlib.h>
 
29
#include <stdio.h>
 
30
 
 
31
#include <glib.h>
 
32
 
 
33
#include <ofono/log.h>
 
34
#include <ofono/modem.h>
 
35
#include "driver.h"
 
36
 
 
37
#include "gatchat.h"
 
38
#include "gatresult.h"
 
39
 
 
40
#include "at.h"
 
41
 
 
42
static const char *clck_prefix[] = { "+CLCK:", NULL };
 
43
static const char *none_prefix[] = { NULL };
 
44
 
 
45
static void clck_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
46
{
 
47
        struct cb_data *cbd = user_data;
 
48
        ofono_call_barring_cb_t cb = cbd->cb;
 
49
        struct ofono_error error;
 
50
        GAtResultIter iter;
 
51
        int status_mask, status, class, line;
 
52
 
 
53
        dump_response("clck_query_cb", ok, result);
 
54
        decode_at_error(&error, g_at_result_final_response(result));
 
55
 
 
56
        status_mask = 0;
 
57
        line = 0;
 
58
        g_at_result_iter_init(&iter, result);
 
59
        while (g_at_result_iter_next(&iter, "+CLCK:")) {
 
60
                line++;
 
61
 
 
62
                if (!g_at_result_iter_next_number(&iter, &status))
 
63
                        continue;
 
64
 
 
65
                if (!g_at_result_iter_next_number(&iter, &class)) {
 
66
                        if (line > 1)
 
67
                                continue;
 
68
                        else
 
69
                                class = 7;
 
70
                }
 
71
 
 
72
                if (status)
 
73
                        status_mask |= class;
 
74
                else
 
75
                        status_mask &= ~class;
 
76
        }
 
77
 
 
78
        cb(&error, status_mask, cbd->data);
 
79
}
 
80
 
 
81
static void at_call_barring_query(struct ofono_modem *modem, const char *lock,
 
82
                                        int cls, ofono_call_barring_cb_t cb,
 
83
                                        void *data)
 
84
{
 
85
        struct at_data *at = ofono_modem_get_userdata(modem);
 
86
        struct cb_data *cbd = cb_data_new(modem, cb, data);
 
87
        char buf[64];
 
88
        int len;
 
89
 
 
90
        if (!cbd || strlen(lock) != 2)
 
91
                goto error;
 
92
 
 
93
        len = sprintf(buf, "AT+CLCK=\"%s\",2", lock);
 
94
 
 
95
        if (g_at_chat_send(at->parser, buf, clck_prefix,
 
96
                                clck_query_cb, cbd, g_free) > 0)
 
97
                return;
 
98
 
 
99
error:
 
100
        if (cbd)
 
101
                g_free(cbd);
 
102
 
 
103
        {
 
104
                DECLARE_FAILURE(error);
 
105
                cb(&error, 0, data);
 
106
        }
 
107
}
 
108
 
 
109
static void clck_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
110
{
 
111
        struct cb_data *cbd = user_data;
 
112
        ofono_generic_cb_t cb = cbd->cb;
 
113
        struct ofono_error error;
 
114
 
 
115
        dump_response("clck_set_cb", ok, result);
 
116
        decode_at_error(&error, g_at_result_final_response(result));
 
117
        cb(&error, cbd->data);
 
118
}
 
119
 
 
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)
 
123
{
 
124
        struct at_data *at = ofono_modem_get_userdata(modem);
 
125
        struct cb_data *cbd = cb_data_new(modem, cb, data);
 
126
        char buf[64];
 
127
        int len;
 
128
 
 
129
        if (!cbd || strlen(lock) != 2 || (cls && !passwd))
 
130
                goto error;
 
131
 
 
132
        len = snprintf(buf, sizeof(buf), "AT+CLCK=\"%s\",%i", lock, enable);
 
133
        if (passwd) {
 
134
                len += snprintf(buf + len, sizeof(buf) - len,
 
135
                                ",\"%s\"", passwd);
 
136
                /* Assume cls == 7 means use defaults */
 
137
                if (cls != 7)
 
138
                        len += snprintf(buf + len, sizeof(buf) - len,
 
139
                                        ",%i", cls);
 
140
        }
 
141
 
 
142
        if (g_at_chat_send(at->parser, buf, none_prefix,
 
143
                                clck_set_cb, cbd, g_free) > 0)
 
144
                return;
 
145
 
 
146
error:
 
147
        if (cbd)
 
148
                g_free(cbd);
 
149
 
 
150
        {
 
151
                DECLARE_FAILURE(error);
 
152
                cb(&error, data);
 
153
        }
 
154
}
 
155
 
 
156
static void cpwd_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
157
{
 
158
        struct cb_data *cbd = user_data;
 
159
        ofono_generic_cb_t cb = cbd->cb;
 
160
        struct ofono_error error;
 
161
 
 
162
        dump_response("cpwd_set_cb", ok, result);
 
163
        decode_at_error(&error, g_at_result_final_response(result));
 
164
        cb(&error, cbd->data);
 
165
}
 
166
 
 
167
static void at_call_barring_set_passwd(struct ofono_modem *modem,
 
168
                                const char *lock,
 
169
                                const char *old_passwd, const char *new_passwd,
 
170
                                ofono_generic_cb_t cb, void *data)
 
171
{
 
172
        struct at_data *at = ofono_modem_get_userdata(modem);
 
173
        struct cb_data *cbd = cb_data_new(modem, cb, data);
 
174
        char buf[64];
 
175
 
 
176
        if (!cbd || strlen(lock) != 2)
 
177
                goto error;
 
178
 
 
179
        snprintf(buf, sizeof(buf), "AT+CPWD=\"%s\",\"%s\",\"%s\"",
 
180
                        lock, old_passwd, new_passwd);
 
181
 
 
182
        if (g_at_chat_send(at->parser, buf, none_prefix,
 
183
                                cpwd_set_cb, cbd, g_free) > 0)
 
184
                return;
 
185
 
 
186
error:
 
187
        if (cbd)
 
188
                g_free(cbd);
 
189
 
 
190
        {
 
191
                DECLARE_FAILURE(error);
 
192
                cb(&error, data);
 
193
        }
 
194
}
 
195
 
 
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,
 
200
};
 
201
 
 
202
void at_call_barring_init(struct ofono_modem *modem)
 
203
{
 
204
        ofono_call_barring_register(modem, &ops);
 
205
}
 
206
 
 
207
void at_call_barring_exit(struct ofono_modem *modem)
 
208
{
 
209
        ofono_call_barring_unregister(modem);
 
210
}