~cyphermox/ubuntu/natty/ofono/release-0.41

« back to all changes in this revision

Viewing changes to drivers/atmodem/sim-auth.c

  • Committer: Mathieu Trudel-Lapierre
  • Date: 2011-02-11 02:17:20 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: mathieu-tl@ubuntu.com-20110211021720-cvxc3erw1keomunj
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2011  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
 
 
29
#include <glib.h>
 
30
 
 
31
#include <ofono/modem.h>
 
32
#include <ofono/sim-auth.h>
 
33
 
 
34
#include "gatchat.h"
 
35
#include "gatresult.h"
 
36
#include "simutil.h"
 
37
#include "vendor.h"
 
38
 
 
39
#include "atmodem.h"
 
40
 
 
41
struct sim_auth_data {
 
42
        GAtChat *chat;
 
43
        unsigned int vendor;
 
44
};
 
45
 
 
46
static const char *cuad_prefix[] = { "+CUAD:", NULL };
 
47
 
 
48
static void at_discover_apps_cb(gboolean ok, GAtResult *result,
 
49
                                gpointer user_data)
 
50
{
 
51
        struct cb_data *cbd = user_data;
 
52
        GAtResultIter iter;
 
53
        ofono_sim_list_apps_cb_t cb = cbd->cb;
 
54
        struct ofono_error error;
 
55
        const unsigned char *dataobj;
 
56
        gint linelen;
 
57
        unsigned char *buffer;
 
58
        int len;
 
59
 
 
60
        decode_at_error(&error, g_at_result_final_response(result));
 
61
 
 
62
        if (!ok) {
 
63
                cb(&error, NULL, 0, cbd->data);
 
64
                return;
 
65
        }
 
66
 
 
67
        g_at_result_iter_init(&iter, result);
 
68
 
 
69
        len = 0;
 
70
        while (g_at_result_iter_next(&iter, "+CUAD:")) {
 
71
                if (!g_at_result_iter_next_hexstring(&iter, NULL, &linelen))
 
72
                        goto error;
 
73
 
 
74
                len += linelen;
 
75
        }
 
76
 
 
77
        g_at_result_iter_init(&iter, result);
 
78
 
 
79
        buffer = g_malloc(len);
 
80
        len = 0;
 
81
 
 
82
        while (g_at_result_iter_next(&iter, "+CUAD:")) {
 
83
                g_at_result_iter_next_hexstring(&iter, &dataobj, &linelen);
 
84
                memcpy(buffer + len, dataobj, linelen);
 
85
                len += linelen;
 
86
        }
 
87
 
 
88
        cb(&error, buffer, len, cbd->data);
 
89
 
 
90
        g_free(buffer);
 
91
        return;
 
92
 
 
93
error:
 
94
        CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
 
95
}
 
96
 
 
97
static void at_discover_apps(struct ofono_sim_auth *sa,
 
98
                                ofono_sim_list_apps_cb_t cb,
 
99
                                void *data)
 
100
{
 
101
        struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
 
102
        struct cb_data *cbd = cb_data_new(cb, data);
 
103
 
 
104
        if (g_at_chat_send(sad->chat, "AT+CUAD", cuad_prefix,
 
105
                                        at_discover_apps_cb, cbd, g_free) > 0)
 
106
                return;
 
107
 
 
108
        g_free(cbd);
 
109
 
 
110
        CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
 
111
}
 
112
 
 
113
static gboolean at_sim_auth_register(gpointer user)
 
114
{
 
115
        struct ofono_sim_auth *sa = user;
 
116
 
 
117
        ofono_sim_auth_register(sa);
 
118
 
 
119
        return FALSE;
 
120
}
 
121
 
 
122
static int at_sim_auth_probe(struct ofono_sim_auth *sa, unsigned int vendor,
 
123
                                void *data)
 
124
{
 
125
        GAtChat *chat = data;
 
126
        struct sim_auth_data *sad;
 
127
 
 
128
        sad = g_new0(struct sim_auth_data, 1);
 
129
        sad->chat = g_at_chat_clone(chat);
 
130
        sad->vendor = vendor;
 
131
 
 
132
        ofono_sim_auth_set_data(sa, sad);
 
133
        g_idle_add(at_sim_auth_register, sa);
 
134
 
 
135
        return 0;
 
136
}
 
137
 
 
138
static void at_sim_auth_remove(struct ofono_sim_auth *sa)
 
139
{
 
140
        struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
 
141
 
 
142
        ofono_sim_auth_set_data(sa, NULL);
 
143
 
 
144
        g_at_chat_unref(sad->chat);
 
145
        g_free(sad);
 
146
}
 
147
 
 
148
static struct ofono_sim_auth_driver driver = {
 
149
        .name           = "atmodem",
 
150
        .probe          = at_sim_auth_probe,
 
151
        .remove         = at_sim_auth_remove,
 
152
        .list_apps      = at_discover_apps,
 
153
};
 
154
 
 
155
void at_sim_auth_init(void)
 
156
{
 
157
        ofono_sim_auth_driver_register(&driver);
 
158
}
 
159
 
 
160
void at_sim_auth_exit(void)
 
161
{
 
162
        ofono_sim_auth_driver_unregister(&driver);
 
163
}