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
31
#include <ofono/modem.h>
32
#include <ofono/sim-auth.h>
35
#include "gatresult.h"
41
struct sim_auth_data {
46
static const char *cuad_prefix[] = { "+CUAD:", NULL };
48
static void at_discover_apps_cb(gboolean ok, GAtResult *result,
51
struct cb_data *cbd = user_data;
53
ofono_sim_list_apps_cb_t cb = cbd->cb;
54
struct ofono_error error;
55
const unsigned char *dataobj;
57
unsigned char *buffer;
60
decode_at_error(&error, g_at_result_final_response(result));
63
cb(&error, NULL, 0, cbd->data);
67
g_at_result_iter_init(&iter, result);
70
while (g_at_result_iter_next(&iter, "+CUAD:")) {
71
if (!g_at_result_iter_next_hexstring(&iter, NULL, &linelen))
77
g_at_result_iter_init(&iter, result);
79
buffer = g_malloc(len);
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);
88
cb(&error, buffer, len, cbd->data);
94
CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
97
static void at_discover_apps(struct ofono_sim_auth *sa,
98
ofono_sim_list_apps_cb_t cb,
101
struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
102
struct cb_data *cbd = cb_data_new(cb, data);
104
if (g_at_chat_send(sad->chat, "AT+CUAD", cuad_prefix,
105
at_discover_apps_cb, cbd, g_free) > 0)
110
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
113
static gboolean at_sim_auth_register(gpointer user)
115
struct ofono_sim_auth *sa = user;
117
ofono_sim_auth_register(sa);
122
static int at_sim_auth_probe(struct ofono_sim_auth *sa, unsigned int vendor,
125
GAtChat *chat = data;
126
struct sim_auth_data *sad;
128
sad = g_new0(struct sim_auth_data, 1);
129
sad->chat = g_at_chat_clone(chat);
130
sad->vendor = vendor;
132
ofono_sim_auth_set_data(sa, sad);
133
g_idle_add(at_sim_auth_register, sa);
138
static void at_sim_auth_remove(struct ofono_sim_auth *sa)
140
struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
142
ofono_sim_auth_set_data(sa, NULL);
144
g_at_chat_unref(sad->chat);
148
static struct ofono_sim_auth_driver driver = {
150
.probe = at_sim_auth_probe,
151
.remove = at_sim_auth_remove,
152
.list_apps = at_discover_apps,
155
void at_sim_auth_init(void)
157
ofono_sim_auth_driver_register(&driver);
160
void at_sim_auth_exit(void)
162
ofono_sim_auth_driver_unregister(&driver);