2009-05-22 11:57:18 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2009 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gdbus.h>
|
|
|
|
|
|
|
|
#include "ofono.h"
|
|
|
|
|
|
|
|
#include "dbus-gsm.h"
|
|
|
|
#include "modem.h"
|
|
|
|
#include "driver.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "util.h"
|
2009-06-18 08:46:08 +00:00
|
|
|
#include "smsutil.h"
|
2009-05-22 11:57:18 +00:00
|
|
|
#include "sim.h"
|
2009-07-10 23:56:44 +00:00
|
|
|
#include "simutil.h"
|
2009-05-22 11:57:18 +00:00
|
|
|
|
|
|
|
#define SIM_MANAGER_INTERFACE "org.ofono.SimManager"
|
|
|
|
|
2009-07-10 19:34:24 +00:00
|
|
|
static gboolean sim_op_next(gpointer user_data);
|
|
|
|
static gboolean sim_op_retrieve_next(gpointer user);
|
|
|
|
|
|
|
|
struct sim_file_op {
|
|
|
|
int id;
|
|
|
|
enum ofono_sim_file_structure structure;
|
|
|
|
int length;
|
|
|
|
int record_length;
|
|
|
|
int current;
|
|
|
|
ofono_sim_file_read_cb_t cb;
|
|
|
|
void *userdata;
|
|
|
|
};
|
|
|
|
|
2009-05-22 11:57:18 +00:00
|
|
|
struct sim_manager_data {
|
|
|
|
struct ofono_sim_ops *ops;
|
|
|
|
int flags;
|
|
|
|
DBusMessage *pending;
|
|
|
|
char *imsi;
|
2009-05-26 23:04:31 +00:00
|
|
|
GSList *own_numbers;
|
2009-07-09 21:52:54 +00:00
|
|
|
GSList *ready_notify;
|
2009-07-09 22:06:59 +00:00
|
|
|
gboolean ready;
|
2009-07-10 19:34:24 +00:00
|
|
|
GQueue *simop_q;
|
2009-07-09 21:52:54 +00:00
|
|
|
|
2009-06-21 01:40:48 +00:00
|
|
|
GSList *spdi;
|
|
|
|
|
2009-07-05 03:14:15 +00:00
|
|
|
GSList *opl;
|
|
|
|
int opl_num;
|
|
|
|
int opl_size;
|
|
|
|
int opl_current;
|
2009-05-22 11:57:18 +00:00
|
|
|
};
|
|
|
|
|
2009-06-18 08:59:13 +00:00
|
|
|
static char **get_own_numbers(GSList *own_numbers)
|
2009-05-26 23:04:31 +00:00
|
|
|
{
|
2009-06-18 08:59:13 +00:00
|
|
|
int nelem = 0;
|
2009-05-26 23:04:31 +00:00
|
|
|
GSList *l;
|
2009-06-18 08:59:13 +00:00
|
|
|
struct ofono_phone_number *num;
|
2009-05-26 23:04:31 +00:00
|
|
|
char **ret;
|
|
|
|
|
2009-06-18 08:59:13 +00:00
|
|
|
if (own_numbers)
|
|
|
|
nelem = g_slist_length(own_numbers);
|
2009-05-26 23:04:31 +00:00
|
|
|
|
|
|
|
ret = g_new0(char *, nelem + 1);
|
|
|
|
|
|
|
|
nelem = 0;
|
|
|
|
for (l = own_numbers; l; l = l->next) {
|
|
|
|
num = l->data;
|
|
|
|
|
2009-06-18 08:59:13 +00:00
|
|
|
ret[nelem++] = g_strdup(phone_number_to_string(num));
|
2009-05-26 23:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-10 19:34:24 +00:00
|
|
|
static void sim_file_op_free(struct sim_file_op *node)
|
|
|
|
{
|
|
|
|
g_free(node);
|
|
|
|
}
|
|
|
|
|
2009-05-22 11:57:18 +00:00
|
|
|
static struct sim_manager_data *sim_manager_create()
|
|
|
|
{
|
|
|
|
return g_try_new0(struct sim_manager_data, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sim_manager_destroy(gpointer userdata)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = userdata;
|
|
|
|
struct sim_manager_data *data = modem->sim_manager;
|
|
|
|
|
|
|
|
if (data->imsi) {
|
|
|
|
g_free(data->imsi);
|
|
|
|
data->imsi = NULL;
|
|
|
|
}
|
2009-05-26 18:48:42 +00:00
|
|
|
|
2009-05-26 23:04:31 +00:00
|
|
|
if (data->own_numbers) {
|
|
|
|
g_slist_foreach(data->own_numbers, (GFunc)g_free, NULL);
|
|
|
|
g_slist_free(data->own_numbers);
|
|
|
|
data->own_numbers = NULL;
|
2009-05-22 11:57:18 +00:00
|
|
|
}
|
2009-05-26 18:48:42 +00:00
|
|
|
|
2009-07-10 19:34:24 +00:00
|
|
|
if (data->simop_q) {
|
|
|
|
g_queue_foreach(data->simop_q, (GFunc)sim_file_op_free, NULL);
|
|
|
|
g_queue_free(data->simop_q);
|
|
|
|
data->simop_q = NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-21 01:40:48 +00:00
|
|
|
if (data->spdi) {
|
|
|
|
g_slist_foreach(data->spdi, (GFunc)g_free, NULL);
|
|
|
|
g_slist_free(data->spdi);
|
|
|
|
data->spdi = NULL;
|
|
|
|
}
|
2009-07-05 03:14:15 +00:00
|
|
|
|
|
|
|
if (data->opl) {
|
|
|
|
g_slist_foreach(data->opl, (GFunc)g_free, NULL);
|
|
|
|
g_slist_free(data->opl);
|
|
|
|
data->opl = NULL;
|
|
|
|
}
|
2009-05-22 11:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBusMessage *sim_get_properties(DBusConnection *conn,
|
|
|
|
DBusMessage *msg, void *data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = data;
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
DBusMessage *reply;
|
|
|
|
DBusMessageIter iter;
|
|
|
|
DBusMessageIter dict;
|
2009-06-18 08:59:13 +00:00
|
|
|
char **own_numbers;
|
2009-05-22 11:57:18 +00:00
|
|
|
|
|
|
|
reply = dbus_message_new_method_return(msg);
|
|
|
|
if (!reply)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dbus_message_iter_init_append(reply, &iter);
|
|
|
|
|
|
|
|
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
|
|
|
|
PROPERTIES_ARRAY_SIGNATURE,
|
|
|
|
&dict);
|
|
|
|
|
2009-05-26 23:04:31 +00:00
|
|
|
if (sim->imsi)
|
|
|
|
dbus_gsm_dict_append(&dict, "SubscriberIdentity",
|
|
|
|
DBUS_TYPE_STRING, &sim->imsi);
|
|
|
|
|
2009-06-18 08:59:13 +00:00
|
|
|
own_numbers = get_own_numbers(sim->own_numbers);
|
2009-05-26 23:04:31 +00:00
|
|
|
|
2009-06-18 08:59:13 +00:00
|
|
|
dbus_gsm_dict_append_array(&dict, "SubscriberNumbers",
|
|
|
|
DBUS_TYPE_STRING, &own_numbers);
|
|
|
|
dbus_gsm_free_string_array(own_numbers);
|
2009-05-22 11:57:18 +00:00
|
|
|
|
|
|
|
dbus_message_iter_close_container(&iter, &dict);
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GDBusMethodTable sim_manager_methods[] = {
|
|
|
|
{ "GetProperties", "", "a{sv}", sim_get_properties },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static GDBusSignalTable sim_manager_signals[] = { { } };
|
|
|
|
|
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
static void sim_msisdn_read_cb(struct ofono_modem *modem, int ok,
|
|
|
|
enum ofono_sim_file_structure structure,
|
|
|
|
int length, int record,
|
|
|
|
const unsigned char *data,
|
|
|
|
int record_length, void *userdata)
|
2009-05-22 11:57:18 +00:00
|
|
|
{
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
2009-07-14 17:49:12 +00:00
|
|
|
int total;
|
2009-06-18 08:59:13 +00:00
|
|
|
struct ofono_phone_number *ph;
|
2009-06-18 03:44:56 +00:00
|
|
|
int number_len;
|
|
|
|
int ton_npi;
|
2009-05-22 11:57:18 +00:00
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
if (!ok)
|
|
|
|
return;
|
2009-05-22 11:57:18 +00:00
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (length < 14 || record_length < 14 || length < record_length)
|
|
|
|
return;
|
2009-05-26 23:04:31 +00:00
|
|
|
|
2009-07-14 17:49:12 +00:00
|
|
|
total = length / record_length;
|
|
|
|
|
2009-06-18 03:44:56 +00:00
|
|
|
/* Skip Alpha-Identifier field */
|
2009-07-10 23:54:20 +00:00
|
|
|
data += record_length - 14;
|
2009-06-18 03:44:56 +00:00
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
number_len = *data++;
|
|
|
|
ton_npi = *data++;
|
2009-06-18 03:44:56 +00:00
|
|
|
|
|
|
|
if (number_len > 11 || ton_npi == 0xff)
|
2009-07-10 23:54:20 +00:00
|
|
|
goto check;
|
2009-06-18 03:44:56 +00:00
|
|
|
|
2009-06-18 08:59:13 +00:00
|
|
|
ph = g_new(struct ofono_phone_number, 1);
|
2009-06-18 03:44:56 +00:00
|
|
|
|
2009-06-18 08:59:13 +00:00
|
|
|
ph->type = bit_field(ton_npi, 4, 3);
|
2009-06-18 08:46:08 +00:00
|
|
|
|
|
|
|
/* BCD coded, however the TON/NPI is given by the first byte */
|
|
|
|
number_len = (number_len - 1) * 2;
|
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
extract_bcd_number(data, number_len, ph->number);
|
2009-06-18 03:44:56 +00:00
|
|
|
|
|
|
|
sim->own_numbers = g_slist_prepend(sim->own_numbers, ph);
|
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
check:
|
|
|
|
if (record == total && sim->own_numbers) {
|
|
|
|
char **own_numbers;
|
|
|
|
DBusConnection *conn = dbus_gsm_connection();
|
2009-05-26 23:04:31 +00:00
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
/* All records retrieved */
|
|
|
|
sim->own_numbers = g_slist_reverse(sim->own_numbers);
|
2009-05-22 11:57:18 +00:00
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
own_numbers = get_own_numbers(sim->own_numbers);
|
2009-05-22 11:57:18 +00:00
|
|
|
|
2009-07-10 23:54:20 +00:00
|
|
|
dbus_gsm_signal_array_property_changed(conn, modem->path,
|
|
|
|
SIM_MANAGER_INTERFACE,
|
|
|
|
"SubscriberNumbers",
|
|
|
|
DBUS_TYPE_STRING,
|
|
|
|
&own_numbers);
|
|
|
|
dbus_gsm_free_string_array(own_numbers);
|
|
|
|
}
|
2009-05-22 11:57:18 +00:00
|
|
|
}
|
|
|
|
|
2009-07-10 23:28:53 +00:00
|
|
|
static void sim_ready(struct ofono_modem *modem)
|
|
|
|
{
|
2009-07-10 23:54:20 +00:00
|
|
|
ofono_sim_read(modem, SIM_EFMSISDN_FILEID, sim_msisdn_read_cb, NULL);
|
2009-07-10 23:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sim_imsi_cb(const struct ofono_error *error, const char *imsi,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = data;
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
|
|
|
|
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
|
|
|
|
ofono_error("Unable to read IMSI, emergency calls only");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sim->imsi = g_strdup(imsi);
|
|
|
|
|
2009-07-14 17:41:16 +00:00
|
|
|
ofono_sim_set_ready(modem);
|
2009-07-10 23:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean sim_retrieve_imsi(void *user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
|
|
|
|
if (!sim->ops->read_imsi) {
|
|
|
|
ofono_error("IMSI retrieval not implemented,"
|
|
|
|
" only emergency calls will be available");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sim->ops->read_imsi(modem, sim_imsi_cb, modem);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-07-10 19:34:24 +00:00
|
|
|
static void sim_op_error(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
struct sim_file_op *op = g_queue_pop_head(sim->simop_q);
|
|
|
|
|
|
|
|
op->cb(modem, 0, 0, 0, 0, 0, 0, op->userdata);
|
|
|
|
|
|
|
|
sim_file_op_free(op);
|
|
|
|
|
|
|
|
if (g_queue_get_length(sim->simop_q) > 0)
|
|
|
|
g_timeout_add(0, sim_op_next, modem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sim_op_retrieve_cb(const struct ofono_error *error,
|
|
|
|
const unsigned char *data, int len, void *user)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user;
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
struct sim_file_op *op = g_queue_peek_head(sim->simop_q);
|
|
|
|
int total = op->length / op->record_length;
|
|
|
|
|
2009-07-10 23:54:05 +00:00
|
|
|
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
|
|
|
|
if (op->current == 1)
|
|
|
|
sim_op_error(modem);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
op->cb(modem, 1, op->structure, op->length, op->current,
|
|
|
|
data, op->record_length, op->userdata);
|
2009-07-10 19:34:24 +00:00
|
|
|
|
|
|
|
if (op->current == total) {
|
|
|
|
op = g_queue_pop_head(sim->simop_q);
|
|
|
|
|
|
|
|
sim_file_op_free(op);
|
|
|
|
|
|
|
|
if (g_queue_get_length(sim->simop_q) > 0)
|
|
|
|
g_timeout_add(0, sim_op_next, modem);
|
|
|
|
} else {
|
|
|
|
op->current += 1;
|
|
|
|
g_timeout_add(0, sim_op_retrieve_next, modem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean sim_op_retrieve_next(gpointer user)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user;
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
struct sim_file_op *op = g_queue_peek_head(sim->simop_q);
|
|
|
|
|
|
|
|
switch (op->structure) {
|
|
|
|
case OFONO_SIM_FILE_STRUCTURE_TRANSPARENT:
|
|
|
|
if (!sim->ops->read_file_transparent) {
|
|
|
|
sim_op_error(modem);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sim->ops->read_file_transparent(modem, op->id, 0, op->length,
|
|
|
|
sim_op_retrieve_cb, modem);
|
|
|
|
break;
|
|
|
|
case OFONO_SIM_FILE_STRUCTURE_FIXED:
|
|
|
|
if (!sim->ops->read_file_linear) {
|
|
|
|
sim_op_error(modem);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sim->ops->read_file_linear(modem, op->id, op->current,
|
|
|
|
op->record_length,
|
|
|
|
sim_op_retrieve_cb, modem);
|
|
|
|
break;
|
|
|
|
case OFONO_SIM_FILE_STRUCTURE_CYCLIC:
|
|
|
|
if (!sim->ops->read_file_cyclic) {
|
|
|
|
sim_op_error(modem);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sim->ops->read_file_cyclic(modem, op->id, op->current,
|
|
|
|
op->record_length,
|
|
|
|
sim_op_retrieve_cb, modem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ofono_error("Unrecognized file structure, this can't happen");
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sim_op_info_cb(const struct ofono_error *error, int length,
|
|
|
|
enum ofono_sim_file_structure structure,
|
|
|
|
int record_length, void *data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = data;
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
struct sim_file_op *op = g_queue_peek_head(sim->simop_q);
|
|
|
|
|
|
|
|
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
|
|
|
|
sim_op_error(modem);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
op->structure = structure;
|
|
|
|
op->length = length;
|
2009-07-14 18:09:00 +00:00
|
|
|
|
|
|
|
if (structure == OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
|
|
|
|
op->record_length = length;
|
|
|
|
else
|
|
|
|
op->record_length = record_length;
|
|
|
|
|
2009-07-10 19:34:24 +00:00
|
|
|
op->current = 1;
|
|
|
|
|
|
|
|
g_timeout_add(0, sim_op_retrieve_next, modem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean sim_op_next(gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_modem *modem = user_data;
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
struct sim_file_op *op;
|
|
|
|
|
|
|
|
if (!sim->simop_q)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
op = g_queue_peek_head(sim->simop_q);
|
|
|
|
|
|
|
|
sim->ops->read_file_info(modem, op->id, sim_op_info_cb, modem);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ofono_sim_read(struct ofono_modem *modem, int id,
|
|
|
|
ofono_sim_file_read_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct sim_manager_data *sim = modem->sim_manager;
|
|
|
|
struct sim_file_op *op;
|
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!sim->ops)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!sim->ops->read_file_info)
|
|
|
|
return -1;
|
|
|
|
|
2009-07-10 23:29:11 +00:00
|
|
|
/* TODO: We must first check the EFust table to see whether
|
|
|
|
* this file can be read at all
|
|
|
|
*/
|
|
|
|
|
2009-07-10 19:34:24 +00:00
|
|
|
if (!sim->simop_q)
|
|
|
|
sim->simop_q = g_queue_new();
|
|
|
|
|
|
|
|
op = g_new0(struct sim_file_op, 1);
|
|
|
|
|
|
|
|
op->id = id;
|
|
|
|
op->cb = cb;
|
|
|
|
op->userdata = data;
|
|
|
|
|
|
|
|
g_queue_push_tail(sim->simop_q, op);
|
|
|
|
|
|
|
|
if (g_queue_get_length(sim->simop_q) == 1)
|
|
|
|
g_timeout_add(0, sim_op_next, modem);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ofono_sim_write(struct ofono_modem *modem, int id,
|
|
|
|
enum ofono_sim_file_structure structure, int record,
|
|
|
|
const unsigned char *data, int length)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-22 11:57:18 +00:00
|
|
|
static void initialize_sim_manager(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
DBusConnection *conn = dbus_gsm_connection();
|
|
|
|
|
|
|
|
if (!g_dbus_register_interface(conn, modem->path,
|
|
|
|
SIM_MANAGER_INTERFACE,
|
|
|
|
sim_manager_methods,
|
|
|
|
sim_manager_signals,
|
|
|
|
NULL, modem,
|
|
|
|
sim_manager_destroy)) {
|
|
|
|
ofono_error("Could not register SIMManager interface");
|
|
|
|
sim_manager_destroy(modem);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofono_debug("SIMManager interface for modem: %s created",
|
|
|
|
modem->path);
|
|
|
|
|
|
|
|
modem_add_interface(modem, SIM_MANAGER_INTERFACE);
|
|
|
|
|
2009-07-10 23:28:53 +00:00
|
|
|
ofono_sim_ready_notify_register(modem, sim_ready);
|
2009-07-05 03:14:15 +00:00
|
|
|
|
2009-07-10 23:28:53 +00:00
|
|
|
/* Perform SIM initialization according to 3GPP 31.102 Section 5.1.1.2
|
|
|
|
* The assumption here is that if sim manager is being initialized,
|
|
|
|
* then sim commands are implemented, and the sim manager is then
|
|
|
|
* responsible for checking the PIN, reading the IMSI and signaling
|
|
|
|
* SIM ready condition.
|
|
|
|
*
|
|
|
|
* The procedure according to 31.102 is roughly:
|
|
|
|
* Read EFecc
|
|
|
|
* Read EFli and EFpl
|
|
|
|
* SIM Pin check
|
|
|
|
* Read EFust
|
|
|
|
* Read EFest
|
|
|
|
* Read IMSI
|
|
|
|
*
|
|
|
|
* At this point we signal the SIM ready condition and allow
|
|
|
|
* arbitrary files to be written or read, assuming their presence
|
|
|
|
* in the EFust
|
|
|
|
*/
|
|
|
|
g_timeout_add(0, sim_retrieve_imsi, modem);
|
2009-05-22 11:57:18 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 22:16:00 +00:00
|
|
|
const char *ofono_sim_get_imsi(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return modem->sim_manager->imsi;
|
|
|
|
}
|
|
|
|
|
2009-07-09 21:54:10 +00:00
|
|
|
int ofono_sim_ready_notify_register(struct ofono_modem *modem,
|
|
|
|
ofono_sim_ready_notify_cb_t cb)
|
|
|
|
{
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
modem->sim_manager->ready_notify =
|
|
|
|
g_slist_append(modem->sim_manager->ready_notify, cb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ofono_sim_ready_notify_unregister(struct ofono_modem *modem,
|
|
|
|
ofono_sim_ready_notify_cb_t cb)
|
|
|
|
{
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
modem->sim_manager->ready_notify =
|
|
|
|
g_slist_remove(modem->sim_manager->ready_notify, cb);
|
|
|
|
}
|
|
|
|
|
2009-07-09 22:06:59 +00:00
|
|
|
int ofono_sim_get_ready(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (modem->sim_manager->ready == TRUE)
|
|
|
|
return 1;
|
|
|
|
|
2009-07-09 21:54:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-09 22:06:59 +00:00
|
|
|
void ofono_sim_set_ready(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (modem->sim_manager->ready == TRUE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
modem->sim_manager->ready = TRUE;
|
|
|
|
|
|
|
|
for (l = modem->sim_manager->ready_notify; l; l = l->next) {
|
|
|
|
ofono_sim_ready_notify_cb_t cb = l->data;
|
|
|
|
|
|
|
|
cb(modem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 11:57:18 +00:00
|
|
|
int ofono_sim_manager_register(struct ofono_modem *modem,
|
|
|
|
struct ofono_sim_ops *ops)
|
|
|
|
{
|
|
|
|
if (modem == NULL)
|
|
|
|
return -1;
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (ops == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
modem->sim_manager->ops = ops;
|
|
|
|
|
|
|
|
initialize_sim_manager(modem);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ofono_sim_manager_unregister(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
DBusConnection *conn = dbus_gsm_connection();
|
|
|
|
|
|
|
|
g_dbus_unregister_interface(conn, modem->path,
|
|
|
|
SIM_MANAGER_INTERFACE);
|
|
|
|
modem_remove_interface(modem, SIM_MANAGER_INTERFACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ofono_sim_manager_init(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
modem->sim_manager = sim_manager_create();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ofono_sim_manager_exit(struct ofono_modem *modem)
|
|
|
|
{
|
|
|
|
if (modem->sim_manager == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(modem->sim_manager);
|
|
|
|
|
|
|
|
modem->sim_manager = 0;
|
|
|
|
}
|