2009-08-24 12:47:17 +00:00
|
|
|
/*
|
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* oFono - Open Source Telephony
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* 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.
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
2010-10-14 07:50:08 +00:00
|
|
|
* 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
|
2009-08-24 12:47:17 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
#include <gisi/message.h>
|
2009-08-24 12:47:17 +00:00
|
|
|
#include <gisi/client.h>
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/sim.h>
|
2009-09-18 06:43:34 +00:00
|
|
|
#include "simutil.h"
|
2009-08-24 12:47:17 +00:00
|
|
|
|
2010-01-08 08:53:42 +00:00
|
|
|
#include "isimodem.h"
|
|
|
|
#include "isiutil.h"
|
|
|
|
#include "sim.h"
|
|
|
|
#include "debug.h"
|
2009-08-24 12:47:17 +00:00
|
|
|
|
2010-11-16 15:00:06 +00:00
|
|
|
#define SIM_MAX_SPN_LENGTH 16
|
|
|
|
|
2009-08-24 12:47:17 +00:00
|
|
|
struct sim_data {
|
|
|
|
GIsiClient *client;
|
2010-05-27 16:12:46 +00:00
|
|
|
gboolean registered;
|
2009-08-24 12:47:17 +00:00
|
|
|
};
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
struct sim_imsi {
|
|
|
|
uint8_t length;
|
|
|
|
uint8_t imsi[8];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sim_iccid {
|
|
|
|
uint8_t id[10];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sim_spn {
|
2010-11-16 15:00:06 +00:00
|
|
|
uint16_t name[SIM_MAX_SPN_LENGTH + 1];
|
|
|
|
uint8_t disp_home;
|
|
|
|
uint8_t disp_roam;
|
2010-11-14 16:34:27 +00:00
|
|
|
};
|
|
|
|
|
2010-05-25 20:37:04 +00:00
|
|
|
struct file_info {
|
2010-05-25 21:06:12 +00:00
|
|
|
int fileid;
|
|
|
|
int length;
|
|
|
|
int structure;
|
|
|
|
int record_length;
|
2010-11-16 15:00:06 +00:00
|
|
|
uint8_t access[3];
|
|
|
|
uint8_t file_status;
|
2010-05-25 20:37:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Returns file info */
|
|
|
|
static gboolean fake_file_info(gpointer user)
|
2009-09-18 06:43:34 +00:00
|
|
|
{
|
|
|
|
struct isi_cb_data *cbd = user;
|
|
|
|
ofono_sim_file_info_cb_t cb = cbd->cb;
|
2010-05-25 20:37:04 +00:00
|
|
|
struct file_info const *fi = cbd->user;
|
2009-09-18 06:43:34 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Returning static file info for %04X", fi->fileid);
|
2010-11-16 15:00:06 +00:00
|
|
|
CALLBACK_WITH_SUCCESS(cb, fi->length, fi->structure, fi->record_length,
|
2010-10-14 21:02:52 +00:00
|
|
|
fi->access, fi->file_status, cbd->data);
|
2009-09-18 06:43:34 +00:00
|
|
|
g_free(cbd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-24 12:47:17 +00:00
|
|
|
static void isi_read_file_info(struct ofono_sim *sim, int fileid,
|
|
|
|
ofono_sim_file_info_cb_t cb, void *data)
|
|
|
|
{
|
2010-05-25 20:37:04 +00:00
|
|
|
int i;
|
|
|
|
static struct file_info const info[] = {
|
2010-10-14 21:02:52 +00:00
|
|
|
{ SIM_EFSPN_FILEID, 17, 0, 0, { 0x0f, 0xff, 0xff }, 1 },
|
|
|
|
{ SIM_EF_ICCID_FILEID, 10, 0, 0, { 0x0f, 0xff, 0xff }, 1 },
|
2010-05-25 20:37:04 +00:00
|
|
|
};
|
|
|
|
int N = sizeof(info) / sizeof(info[0]);
|
|
|
|
struct isi_cb_data *cbd;
|
|
|
|
|
|
|
|
for (i = 0; i < N; i++) {
|
|
|
|
if (fileid == info[i].fileid) {
|
2011-01-03 15:45:56 +00:00
|
|
|
cbd = isi_cb_data_new((void *) &info[i], cb, data);
|
2010-05-25 20:37:04 +00:00
|
|
|
g_idle_add(fake_file_info, cbd);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-18 06:43:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Fileid %04X not implemented", fileid);
|
2010-10-14 21:02:52 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL, 0, data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
static gboolean check_response_status(const GIsiMessage *msg, uint8_t msgid,
|
|
|
|
uint8_t service)
|
2009-09-18 06:43:34 +00:00
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
uint8_t type;
|
|
|
|
uint8_t cause;
|
|
|
|
|
|
|
|
if (g_isi_msg_error(msg) < 0) {
|
|
|
|
DBG("Error: %s", strerror(-g_isi_msg_error(msg)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-09-18 06:43:34 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
if (g_isi_msg_id(msg) != msgid) {
|
|
|
|
DBG("Unexpected msg: %s",
|
|
|
|
sim_message_id_name(g_isi_msg_id(msg)));
|
|
|
|
return FALSE;
|
2009-09-18 06:43:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
if (!g_isi_msg_data_get_byte(msg, 1, &cause) || cause != SIM_SERV_OK) {
|
|
|
|
DBG("Request failed: %s", sim_isi_cause_name(cause));
|
2010-05-27 16:12:46 +00:00
|
|
|
return FALSE;
|
2010-11-14 16:34:27 +00:00
|
|
|
}
|
2009-09-18 06:43:34 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
if (!g_isi_msg_data_get_byte(msg, 0, &type) || type != service) {
|
|
|
|
DBG("Unexpected service: 0x%02X", type);
|
|
|
|
return FALSE;
|
2010-01-12 08:58:08 +00:00
|
|
|
}
|
2010-11-14 16:34:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-01-12 08:58:08 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
static void spn_resp_cb(const GIsiMessage *msg, void *data)
|
|
|
|
{
|
|
|
|
struct isi_cb_data *cbd = data;
|
|
|
|
ofono_sim_read_cb_t cb = cbd->cb;
|
|
|
|
|
|
|
|
const struct sim_spn *resp = NULL;
|
|
|
|
size_t len = sizeof(struct sim_spn);
|
|
|
|
|
2010-11-16 15:00:06 +00:00
|
|
|
uint8_t spn[SIM_MAX_SPN_LENGTH + 1];
|
2010-11-14 16:34:27 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!check_response_status(msg, SIM_SERV_PROV_NAME_RESP,
|
2010-12-15 10:03:52 +00:00
|
|
|
SIM_ST_READ_SERV_PROV_NAME))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_isi_msg_data_get_struct(msg, 2, (const void **) &resp, len))
|
|
|
|
goto error;
|
2010-05-25 20:37:04 +00:00
|
|
|
|
2009-09-18 06:43:34 +00:00
|
|
|
/* Set display condition bits */
|
2010-11-16 15:00:06 +00:00
|
|
|
spn[0] = (resp->disp_home & 0x01) | ((resp->disp_roam & 0x01) << 1);
|
2010-11-14 16:34:27 +00:00
|
|
|
|
2010-11-16 15:00:06 +00:00
|
|
|
/* Convert from a NULL-terminated UCS-2 string to ASCII */
|
|
|
|
for (i = 0; i < SIM_MAX_SPN_LENGTH; i++) {
|
2010-12-15 10:03:52 +00:00
|
|
|
uint16_t c = resp->name[i] >> 8 | resp->name[i] << 8;
|
|
|
|
|
|
|
|
if (c == 0)
|
|
|
|
c = 0xFF;
|
|
|
|
else if (!g_ascii_isprint(c))
|
|
|
|
c = '?';
|
|
|
|
|
|
|
|
spn[i + 1] = c;
|
2009-09-18 06:43:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 15:00:06 +00:00
|
|
|
CALLBACK_WITH_SUCCESS(cb, spn, sizeof(spn), cbd->data);
|
2010-12-15 10:03:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
|
2009-09-18 06:43:34 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:12:46 +00:00
|
|
|
static gboolean isi_read_spn(struct ofono_sim *sim, struct isi_cb_data *cbd)
|
2009-08-24 12:47:17 +00:00
|
|
|
{
|
2010-01-12 08:58:08 +00:00
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-09-18 06:43:34 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
const uint8_t msg[] = {
|
2010-01-12 08:58:08 +00:00
|
|
|
SIM_SERV_PROV_NAME_REQ,
|
|
|
|
SIM_ST_READ_SERV_PROV_NAME,
|
|
|
|
0
|
|
|
|
};
|
2009-09-18 06:43:34 +00:00
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (sd == NULL)
|
2010-10-19 08:28:06 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2011-01-04 15:48:33 +00:00
|
|
|
return g_isi_client_send(sd->client, msg, sizeof(msg),
|
|
|
|
spn_resp_cb, cbd, g_free);
|
2010-05-25 20:37:04 +00:00
|
|
|
}
|
2010-01-12 08:58:08 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
static void read_iccid_resp_cb(const GIsiMessage *msg, void *data)
|
2010-05-25 20:37:04 +00:00
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
struct isi_cb_data *cbd = data;
|
2010-05-25 20:37:04 +00:00
|
|
|
ofono_sim_read_cb_t cb = cbd->cb;
|
2010-11-14 16:34:27 +00:00
|
|
|
struct sim_iccid *icc;
|
|
|
|
size_t len = sizeof(struct sim_iccid);
|
2010-05-25 20:37:04 +00:00
|
|
|
|
2010-12-15 10:03:52 +00:00
|
|
|
if (!check_response_status(msg, SIM_READ_FIELD_RESP, ICC))
|
|
|
|
goto error;
|
2010-05-25 20:37:04 +00:00
|
|
|
|
2010-12-15 10:03:52 +00:00
|
|
|
if (!g_isi_msg_data_get_struct(msg, 2, (const void **) &icc, len))
|
|
|
|
goto error;
|
2010-05-25 20:37:04 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
CALLBACK_WITH_SUCCESS(cb, icc->id, 10, cbd->data);
|
2010-12-15 10:03:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
|
2010-05-25 20:37:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 16:12:46 +00:00
|
|
|
static gboolean isi_read_iccid(struct ofono_sim *sim, struct isi_cb_data *cbd)
|
2010-05-25 20:37:04 +00:00
|
|
|
{
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2010-11-14 16:34:27 +00:00
|
|
|
|
|
|
|
const uint8_t req[] = {
|
|
|
|
SIM_READ_FIELD_REQ,
|
2010-11-16 15:00:06 +00:00
|
|
|
ICC,
|
2010-11-14 16:34:27 +00:00
|
|
|
};
|
2010-05-25 20:37:04 +00:00
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (sd == NULL)
|
2010-10-19 08:28:06 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2011-01-04 15:48:33 +00:00
|
|
|
return g_isi_client_send(sd->client, req, sizeof(req),
|
|
|
|
read_iccid_resp_cb, cbd, g_free);
|
2010-05-25 20:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_read_file_transparent(struct ofono_sim *sim, int fileid,
|
|
|
|
int start, int length,
|
|
|
|
ofono_sim_read_cb_t cb, void *data)
|
|
|
|
{
|
2010-11-16 15:00:06 +00:00
|
|
|
struct isi_cb_data *cbd;
|
2011-01-04 15:48:33 +00:00
|
|
|
gboolean done;
|
2010-05-25 20:37:04 +00:00
|
|
|
|
2010-11-16 15:00:06 +00:00
|
|
|
cbd = isi_cb_data_new(sim, cb, data);
|
2010-12-01 13:46:57 +00:00
|
|
|
if (cbd == NULL)
|
2010-11-14 16:34:27 +00:00
|
|
|
goto error;
|
2010-05-25 20:37:04 +00:00
|
|
|
|
|
|
|
switch (fileid) {
|
|
|
|
case SIM_EFSPN_FILEID:
|
2011-01-04 15:48:33 +00:00
|
|
|
done = isi_read_spn(sim, cbd);
|
|
|
|
break;
|
2010-05-25 20:37:04 +00:00
|
|
|
|
|
|
|
case SIM_EF_ICCID_FILEID:
|
2011-01-04 15:48:33 +00:00
|
|
|
done = isi_read_iccid(sim, cbd);
|
|
|
|
break;
|
2010-05-25 21:06:12 +00:00
|
|
|
|
2011-01-04 15:48:33 +00:00
|
|
|
default:
|
|
|
|
done = FALSE;
|
2010-05-25 20:37:04 +00:00
|
|
|
}
|
2010-01-12 08:58:08 +00:00
|
|
|
|
2011-01-04 15:48:33 +00:00
|
|
|
if (done)
|
|
|
|
return;
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Fileid %04X not implemented", fileid);
|
|
|
|
|
|
|
|
error:
|
2009-09-12 15:58:18 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
2010-01-12 08:58:08 +00:00
|
|
|
g_free(cbd);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_read_file_linear(struct ofono_sim *sim, int fileid,
|
|
|
|
int record, int length,
|
|
|
|
ofono_sim_read_cb_t cb, void *data)
|
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Fileid %04X not implemented", fileid);
|
2009-09-12 15:58:18 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_read_file_cyclic(struct ofono_sim *sim, int fileid,
|
|
|
|
int record, int length,
|
|
|
|
ofono_sim_read_cb_t cb, void *data)
|
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Fileid %04X not implemented", fileid);
|
2009-09-12 15:58:18 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_write_file_transparent(struct ofono_sim *sim, int fileid,
|
|
|
|
int start, int length,
|
|
|
|
const unsigned char *value,
|
|
|
|
ofono_sim_write_cb_t cb, void *data)
|
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Fileid %04X not implemented", fileid);
|
2009-09-12 15:58:18 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_write_file_linear(struct ofono_sim *sim, int fileid,
|
|
|
|
int record, int length,
|
|
|
|
const unsigned char *value,
|
|
|
|
ofono_sim_write_cb_t cb, void *data)
|
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Fileid %04X not implemented", fileid);
|
2009-09-12 15:58:18 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_write_file_cyclic(struct ofono_sim *sim, int fileid,
|
|
|
|
int length, const unsigned char *value,
|
|
|
|
ofono_sim_write_cb_t cb, void *data)
|
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
DBG("Fileid %04X not implemented", fileid);
|
2009-09-12 15:58:18 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
static void imsi_resp_cb(const GIsiMessage *msg, void *data)
|
2009-09-12 15:58:18 +00:00
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
struct isi_cb_data *cbd = data;
|
2009-09-12 15:58:18 +00:00
|
|
|
ofono_sim_imsi_cb_t cb = cbd->cb;
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
struct sim_imsi *resp;
|
|
|
|
size_t len = sizeof(struct sim_imsi);
|
2009-09-12 15:58:18 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
char imsi[SIM_MAX_IMSI_LENGTH + 1];
|
|
|
|
size_t i, j;
|
2009-09-12 15:58:18 +00:00
|
|
|
|
2010-12-15 10:03:52 +00:00
|
|
|
if (!check_response_status(msg, SIM_IMSI_RESP_READ_IMSI, READ_IMSI))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_isi_msg_data_get_struct(msg, 2, (const void **) &resp, len))
|
|
|
|
goto error;
|
2009-09-12 15:58:18 +00:00
|
|
|
|
|
|
|
/* Ignore the low-order semi-octet of the first byte */
|
2010-11-14 16:34:27 +00:00
|
|
|
imsi[0] = ((resp->imsi[0] & 0xF0) >> 4) + '0';
|
2009-09-14 11:33:31 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
for (i = 1, j = 1; i < resp->length && j < SIM_MAX_IMSI_LENGTH; i++) {
|
2009-09-12 15:58:18 +00:00
|
|
|
char nibble;
|
|
|
|
|
2010-11-16 15:00:06 +00:00
|
|
|
imsi[j++] = (resp->imsi[i] & 0x0F) + '0';
|
2010-11-14 16:34:27 +00:00
|
|
|
nibble = (resp->imsi[i] & 0xF0) >> 4;
|
2009-09-12 15:58:18 +00:00
|
|
|
if (nibble != 0x0F)
|
2009-09-14 11:33:31 +00:00
|
|
|
imsi[j++] = nibble + '0';
|
2009-09-12 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
2009-09-14 11:33:31 +00:00
|
|
|
imsi[j] = '\0';
|
2009-09-12 15:58:18 +00:00
|
|
|
CALLBACK_WITH_SUCCESS(cb, imsi, cbd->data);
|
2010-12-15 10:03:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void isi_read_imsi(struct ofono_sim *sim,
|
|
|
|
ofono_sim_imsi_cb_t cb, void *data)
|
|
|
|
{
|
2009-09-12 15:58:18 +00:00
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
|
|
|
struct isi_cb_data *cbd = isi_cb_data_new(sim, cb, data);
|
2010-11-16 15:00:06 +00:00
|
|
|
|
|
|
|
const uint8_t msg[] = {
|
2009-09-12 15:58:18 +00:00
|
|
|
SIM_IMSI_REQ_READ_IMSI,
|
|
|
|
READ_IMSI
|
|
|
|
};
|
2011-01-04 15:48:33 +00:00
|
|
|
size_t len = sizeof(msg);
|
2009-09-12 15:58:18 +00:00
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (cbd == NULL || sd == NULL)
|
2009-09-12 15:58:18 +00:00
|
|
|
goto error;
|
|
|
|
|
2011-01-04 15:48:33 +00:00
|
|
|
if (g_isi_client_send(sd->client, msg, len, imsi_resp_cb, cbd, g_free))
|
2009-09-12 15:58:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, data);
|
2010-01-12 08:58:08 +00:00
|
|
|
g_free(cbd);
|
2009-09-12 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
2010-04-13 10:49:11 +00:00
|
|
|
static void isi_sim_register(struct ofono_sim *sim)
|
2009-09-12 15:58:18 +00:00
|
|
|
{
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
if (sd && !sd->registered) {
|
2010-05-27 16:12:46 +00:00
|
|
|
sd->registered = TRUE;
|
2010-04-13 10:49:11 +00:00
|
|
|
ofono_sim_register(sim);
|
|
|
|
ofono_sim_inserted_notify(sim, TRUE);
|
|
|
|
}
|
|
|
|
}
|
2010-01-12 08:58:08 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
static void read_hplmn_resp_cb(const GIsiMessage *msg, void *data)
|
2010-04-13 10:49:11 +00:00
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
struct ofono_sim *sim = data;
|
2010-04-13 10:49:11 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
if (!check_response_status(msg, SIM_NETWORK_INFO_RESP, READ_HPLMN))
|
|
|
|
return;
|
2010-04-13 10:49:11 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
isi_sim_register(sim);
|
2010-04-13 10:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void isi_read_hplmn(struct ofono_sim *sim)
|
|
|
|
{
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2010-11-16 15:00:06 +00:00
|
|
|
|
|
|
|
const uint8_t req[] = {
|
2010-04-13 10:49:11 +00:00
|
|
|
SIM_NETWORK_INFO_REQ,
|
|
|
|
READ_HPLMN, 0
|
|
|
|
};
|
2011-01-04 15:48:33 +00:00
|
|
|
size_t len = sizeof(req);
|
2010-04-13 10:49:11 +00:00
|
|
|
|
2010-12-01 13:46:57 +00:00
|
|
|
if (sd == NULL)
|
2010-11-14 16:34:27 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-04 15:48:33 +00:00
|
|
|
g_isi_client_send(sd->client, req, len, read_hplmn_resp_cb, sim, NULL);
|
2010-04-13 10:49:11 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
static void sim_ind_cb(const GIsiMessage *msg, void *data)
|
2010-04-13 10:49:11 +00:00
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
struct ofono_sim *sim = data;
|
2010-04-13 10:49:11 +00:00
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2010-11-14 16:34:27 +00:00
|
|
|
uint8_t status;
|
2010-04-13 10:49:11 +00:00
|
|
|
|
2010-12-01 13:46:57 +00:00
|
|
|
if (sd == NULL || g_isi_msg_id(msg) != SIM_IND || sd->registered)
|
2010-04-13 10:49:11 +00:00
|
|
|
return;
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
if (!g_isi_msg_data_get_byte(msg, 0, &status))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (status) {
|
2010-04-13 10:49:11 +00:00
|
|
|
case SIM_ST_PIN:
|
|
|
|
isi_sim_register(sim);
|
|
|
|
break;
|
2010-11-14 16:34:27 +00:00
|
|
|
|
2010-04-13 10:49:11 +00:00
|
|
|
case SIM_ST_INFO:
|
|
|
|
isi_read_hplmn(sim);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
static void sim_reachable_cb(const GIsiMessage *msg, void *data)
|
2010-04-13 10:49:11 +00:00
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
struct ofono_sim *sim = data;
|
2010-04-13 10:49:11 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
if (g_isi_msg_error(msg) < 0)
|
2010-04-13 10:49:11 +00:00
|
|
|
return;
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
ISI_VERSION_DBG(msg);
|
2010-04-13 10:49:11 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
/* Check if SIM is ready by reading HPLMN */
|
2010-04-13 10:49:11 +00:00
|
|
|
isi_read_hplmn(sim);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 02:39:02 +00:00
|
|
|
static int isi_sim_probe(struct ofono_sim *sim, unsigned int vendor,
|
|
|
|
void *user)
|
2009-08-24 12:47:17 +00:00
|
|
|
{
|
2010-11-14 16:34:27 +00:00
|
|
|
GIsiModem *modem = user;
|
|
|
|
struct sim_data *sd;
|
2009-08-24 12:47:17 +00:00
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
sd = g_try_new0(struct sim_data, 1);
|
2010-11-27 19:38:56 +00:00
|
|
|
if (sd == NULL)
|
2009-08-24 12:47:17 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
sd->client = g_isi_client_create(modem, PN_SIM);
|
|
|
|
if (sd->client == NULL) {
|
|
|
|
g_free(sd);
|
2009-08-24 12:47:17 +00:00
|
|
|
return -ENOMEM;
|
2010-11-14 16:34:27 +00:00
|
|
|
}
|
2009-08-24 12:47:17 +00:00
|
|
|
|
2009-09-12 15:58:18 +00:00
|
|
|
ofono_sim_set_data(sim, sd);
|
|
|
|
|
2011-01-27 07:36:51 +00:00
|
|
|
g_isi_client_ind_subscribe(sd->client, SIM_IND, sim_ind_cb, sim);
|
2010-11-14 16:34:27 +00:00
|
|
|
g_isi_client_verify(sd->client, sim_reachable_cb, sim, NULL);
|
2009-08-24 12:47:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 03:27:08 +00:00
|
|
|
static void isi_sim_remove(struct ofono_sim *sim)
|
2009-08-24 12:47:17 +00:00
|
|
|
{
|
|
|
|
struct sim_data *data = ofono_sim_get_data(sim);
|
|
|
|
|
2010-11-14 16:34:27 +00:00
|
|
|
ofono_sim_set_data(sim, NULL);
|
|
|
|
|
2010-11-27 19:38:56 +00:00
|
|
|
if (data == NULL)
|
2010-04-27 12:10:55 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_isi_client_destroy(data->client);
|
|
|
|
g_free(data);
|
2009-08-24 12:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_sim_driver driver = {
|
2009-09-02 03:35:14 +00:00
|
|
|
.name = "isimodem",
|
2009-08-24 12:47:17 +00:00
|
|
|
.probe = isi_sim_probe,
|
|
|
|
.remove = isi_sim_remove,
|
|
|
|
.read_file_info = isi_read_file_info,
|
|
|
|
.read_file_transparent = isi_read_file_transparent,
|
|
|
|
.read_file_linear = isi_read_file_linear,
|
|
|
|
.read_file_cyclic = isi_read_file_cyclic,
|
|
|
|
.write_file_transparent = isi_write_file_transparent,
|
|
|
|
.write_file_linear = isi_write_file_linear,
|
|
|
|
.write_file_cyclic = isi_write_file_cyclic,
|
2010-04-13 10:49:11 +00:00
|
|
|
.read_imsi = isi_read_imsi,
|
2009-08-24 12:47:17 +00:00
|
|
|
};
|
|
|
|
|
2011-01-12 10:52:14 +00:00
|
|
|
void isi_sim_init(void)
|
2009-08-24 12:47:17 +00:00
|
|
|
{
|
|
|
|
ofono_sim_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
2011-01-12 10:52:14 +00:00
|
|
|
void isi_sim_exit(void)
|
2009-08-24 12:47:17 +00:00
|
|
|
{
|
|
|
|
ofono_sim_driver_unregister(&driver);
|
|
|
|
}
|