2009-05-22 11:58:49 +00:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
|
*
|
2010-01-02 01:00:10 +00:00
|
|
|
|
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
|
2009-05-22 11:58:49 +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.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
2009-07-29 19:33:58 +00:00
|
|
|
|
#include <ofono/modem.h>
|
2009-08-18 22:05:50 +00:00
|
|
|
|
#include <ofono/sim.h>
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
#include "gatchat.h"
|
|
|
|
|
#include "gatresult.h"
|
2009-10-03 00:25:58 +00:00
|
|
|
|
#include "simutil.h"
|
2009-11-10 06:30:10 +00:00
|
|
|
|
#include "vendor.h"
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
2009-09-04 19:05:15 +00:00
|
|
|
|
#include "atmodem.h"
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
2010-10-15 12:25:50 +00:00
|
|
|
|
#define EF_STATUS_INVALIDATED 0
|
|
|
|
|
#define EF_STATUS_VALID 1
|
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data {
|
|
|
|
|
GAtChat *chat;
|
|
|
|
|
unsigned int vendor;
|
2010-09-25 02:32:40 +00:00
|
|
|
|
guint ready_id;
|
2009-11-10 06:30:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-05-22 11:58:49 +00:00
|
|
|
|
static const char *crsm_prefix[] = { "+CRSM:", NULL };
|
2010-05-12 01:20:53 +00:00
|
|
|
|
static const char *cpin_prefix[] = { "+CPIN:", NULL };
|
|
|
|
|
static const char *clck_prefix[] = { "+CLCK:", NULL };
|
|
|
|
|
static const char *none_prefix[] = { NULL };
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
2009-06-18 03:44:44 +00:00
|
|
|
|
static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
2009-05-22 11:58:49 +00:00
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
GAtResultIter iter;
|
2009-06-18 03:44:44 +00:00
|
|
|
|
ofono_sim_file_info_cb_t cb = cbd->cb;
|
2009-05-22 11:58:49 +00:00
|
|
|
|
struct ofono_error error;
|
2009-06-18 03:44:28 +00:00
|
|
|
|
const guint8 *response;
|
|
|
|
|
gint sw1, sw2, len;
|
2009-06-18 03:44:44 +00:00
|
|
|
|
int flen, rlen;
|
2009-10-02 19:52:52 +00:00
|
|
|
|
int str;
|
2009-07-27 21:53:03 +00:00
|
|
|
|
unsigned char access[3];
|
2010-10-14 21:02:51 +00:00
|
|
|
|
unsigned char file_status;
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
2010-10-15 12:25:50 +00:00
|
|
|
|
cb(&error, -1, -1, -1, NULL, EF_STATUS_INVALIDATED, cbd->data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
2009-10-02 22:59:08 +00:00
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CRSM:"))
|
|
|
|
|
goto error;
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
g_at_result_iter_next_number(&iter, &sw1);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
g_at_result_iter_next_number(&iter, &sw2);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
2009-06-18 03:44:28 +00:00
|
|
|
|
if (!g_at_result_iter_next_hexstring(&iter, &response, &len) ||
|
2009-09-11 17:36:35 +00:00
|
|
|
|
(sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92) ||
|
2010-07-06 22:39:00 +00:00
|
|
|
|
(sw1 == 0x90 && sw2 != 0x00)) {
|
|
|
|
|
memset(&error, 0, sizeof(error));
|
|
|
|
|
|
|
|
|
|
error.type = OFONO_ERROR_TYPE_SIM;
|
|
|
|
|
error.error = (sw1 << 8) | sw2;
|
|
|
|
|
|
2010-10-15 12:25:50 +00:00
|
|
|
|
cb(&error, -1, -1, -1, NULL, EF_STATUS_INVALIDATED, cbd->data);
|
2010-07-06 22:39:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
|
DBG("crsm_info_cb: %02x, %02x, %i", sw1, sw2, len);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
|
2010-10-14 21:02:51 +00:00
|
|
|
|
if (response[0] == 0x62) {
|
2009-10-02 22:59:08 +00:00
|
|
|
|
ok = sim_parse_3g_get_response(response, len, &flen, &rlen,
|
|
|
|
|
&str, access, NULL);
|
2010-10-14 21:02:51 +00:00
|
|
|
|
|
2010-10-15 12:25:50 +00:00
|
|
|
|
file_status = EF_STATUS_VALID;
|
2010-10-14 21:02:51 +00:00
|
|
|
|
}
|
2009-10-02 22:59:08 +00:00
|
|
|
|
else
|
|
|
|
|
ok = sim_parse_2g_get_response(response, len, &flen, &rlen,
|
2010-10-14 21:02:51 +00:00
|
|
|
|
&str, access, &file_status);
|
2009-10-02 22:59:08 +00:00
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
goto error;
|
2009-06-18 03:44:28 +00:00
|
|
|
|
|
2010-10-14 21:02:51 +00:00
|
|
|
|
cb(&error, flen, str, rlen, access, file_status, cbd->data);
|
|
|
|
|
|
2009-10-02 22:59:08 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-10-15 12:25:50 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL,
|
|
|
|
|
EF_STATUS_INVALIDATED, cbd->data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static void at_sim_read_info(struct ofono_sim *sim, int fileid,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
ofono_sim_file_info_cb_t cb,
|
2009-05-22 11:58:49 +00:00
|
|
|
|
void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2010-06-13 09:46:29 +00:00
|
|
|
|
struct cb_data *cbd;
|
2009-05-22 11:58:49 +00:00
|
|
|
|
char buf[64];
|
|
|
|
|
|
2010-06-13 06:10:13 +00:00
|
|
|
|
if (sd->vendor == OFONO_VENDOR_OPTION_HSO) {
|
|
|
|
|
unsigned char access[3] = { 0x00, 0x00, 0x00 };
|
|
|
|
|
|
|
|
|
|
if (fileid == SIM_EFAD_FILEID) {
|
2010-10-15 12:25:50 +00:00
|
|
|
|
CALLBACK_WITH_SUCCESS(cb, 4, 0, 0, access,
|
|
|
|
|
EF_STATUS_VALID, data);
|
2010-06-13 06:10:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-13 09:46:29 +00:00
|
|
|
|
cbd = cb_data_new(cb, data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2009-10-02 22:59:08 +00:00
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CRSM=192,%i", fileid);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-11-10 22:22:27 +00:00
|
|
|
|
if (sd->vendor == OFONO_VENDOR_QUALCOMM_MSM)
|
2009-11-10 06:30:10 +00:00
|
|
|
|
strcat(buf, ",0,0,255"); /* Maximum possible length */
|
|
|
|
|
|
|
|
|
|
if (g_at_chat_send(sd->chat, buf, crsm_prefix,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
at_crsm_info_cb, cbd, g_free) > 0)
|
2009-05-22 11:58:49 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-10-15 12:25:50 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL,
|
|
|
|
|
EF_STATUS_INVALIDATED, data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-18 03:44:44 +00:00
|
|
|
|
static void at_crsm_read_cb(gboolean ok, GAtResult *result,
|
|
|
|
|
gpointer user_data)
|
2009-05-22 11:58:49 +00:00
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
ofono_sim_read_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error;
|
|
|
|
|
const guint8 *response;
|
|
|
|
|
gint sw1, sw2, len;
|
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
cb(&error, NULL, 0, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CRSM:")) {
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_next_number(&iter, &sw1);
|
|
|
|
|
g_at_result_iter_next_number(&iter, &sw2);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2010-07-06 22:39:00 +00:00
|
|
|
|
if ((sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
|
|
|
|
|
(sw1 == 0x90 && sw2 != 0x00)) {
|
|
|
|
|
memset(&error, 0, sizeof(error));
|
|
|
|
|
|
|
|
|
|
error.type = OFONO_ERROR_TYPE_SIM;
|
|
|
|
|
error.error = (sw1 << 8) | sw2;
|
|
|
|
|
|
|
|
|
|
cb(&error, NULL, 0, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_hexstring(&iter, &response, &len)) {
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
|
DBG("crsm_read_cb: %02x, %02x, %d", sw1, sw2, len);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
cb(&error, response, len, cbd->data);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static void at_sim_read_binary(struct ofono_sim *sim, int fileid,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
int start, int length,
|
|
|
|
|
ofono_sim_read_cb_t cb, void *data)
|
2009-05-22 11:58:49 +00:00
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-08-19 23:15:46 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CRSM=176,%i,%i,%i,%i", fileid,
|
|
|
|
|
start >> 8, start & 0xff, length);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
if (g_at_chat_send(sd->chat, buf, crsm_prefix,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
at_crsm_read_cb, cbd, g_free) > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static void at_sim_read_record(struct ofono_sim *sim, int fileid,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
int record, int length,
|
|
|
|
|
ofono_sim_read_cb_t cb, void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-08-19 23:15:46 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CRSM=178,%i,%i,4,%i", fileid,
|
2009-07-10 18:08:24 +00:00
|
|
|
|
record, length);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
if (g_at_chat_send(sd->chat, buf, crsm_prefix,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
at_crsm_read_cb, cbd, g_free) > 0)
|
2009-05-22 11:58:49 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-18 03:44:44 +00:00
|
|
|
|
static void at_crsm_update_cb(gboolean ok, GAtResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
GAtResultIter iter;
|
2009-08-18 22:05:50 +00:00
|
|
|
|
ofono_sim_write_cb_t cb = cbd->cb;
|
2009-06-18 03:44:44 +00:00
|
|
|
|
struct ofono_error error;
|
|
|
|
|
gint sw1, sw2;
|
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CRSM:")) {
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, cbd->data);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_next_number(&iter, &sw1);
|
|
|
|
|
g_at_result_iter_next_number(&iter, &sw2);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-06-18 03:44:44 +00:00
|
|
|
|
if ((sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
|
2009-09-11 17:36:35 +00:00
|
|
|
|
(sw1 == 0x90 && sw2 != 0x00)) {
|
2010-07-06 22:39:00 +00:00
|
|
|
|
memset(&error, 0, sizeof(error));
|
|
|
|
|
|
|
|
|
|
error.type = OFONO_ERROR_TYPE_SIM;
|
|
|
|
|
error.error = (sw1 << 8) | sw2;
|
2009-06-18 03:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
|
DBG("crsm_update_cb: %02x, %02x", sw1, sw2);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static void at_sim_update_binary(struct ofono_sim *sim, int fileid,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
int start, int length,
|
|
|
|
|
const unsigned char *value,
|
2009-08-18 22:05:50 +00:00
|
|
|
|
ofono_sim_write_cb_t cb, void *data)
|
2009-06-18 03:44:44 +00:00
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-08-19 23:15:46 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
char *buf = g_try_new(char, 36 + length * 2);
|
|
|
|
|
int len, ret;
|
|
|
|
|
|
|
|
|
|
if (!cbd || !buf)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
len = sprintf(buf, "AT+CRSM=214,%i,%i,%i,%i,", fileid,
|
|
|
|
|
start >> 8, start & 0xff, length);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-06-18 03:44:44 +00:00
|
|
|
|
for (; length; length--)
|
2009-12-18 00:58:22 +00:00
|
|
|
|
len += sprintf(buf + len, "%02hhX", *value++);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
at_crsm_update_cb, cbd, g_free);
|
|
|
|
|
|
|
|
|
|
g_free(buf);
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static void at_sim_update_record(struct ofono_sim *sim, int fileid,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
int record, int length,
|
|
|
|
|
const unsigned char *value,
|
2009-08-18 22:05:50 +00:00
|
|
|
|
ofono_sim_write_cb_t cb, void *data)
|
2009-06-18 03:44:44 +00:00
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-08-19 23:15:46 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
char *buf = g_try_new(char, 36 + length * 2);
|
|
|
|
|
int len, ret;
|
|
|
|
|
|
|
|
|
|
if (!cbd || !buf)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
len = sprintf(buf, "AT+CRSM=220,%i,%i,4,%i,", fileid,
|
2009-08-05 09:25:21 +00:00
|
|
|
|
record, length);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-06-18 03:44:44 +00:00
|
|
|
|
for (; length; length--)
|
2009-12-18 00:58:22 +00:00
|
|
|
|
len += sprintf(buf + len, "%02hhX", *value++);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
at_crsm_update_cb, cbd, g_free);
|
|
|
|
|
|
|
|
|
|
g_free(buf);
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
2009-06-18 03:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static void at_sim_update_cyclic(struct ofono_sim *sim, int fileid,
|
2009-06-21 01:30:14 +00:00
|
|
|
|
int length, const unsigned char *value,
|
2009-08-18 22:05:50 +00:00
|
|
|
|
ofono_sim_write_cb_t cb, void *data)
|
2009-06-21 01:30:14 +00:00
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-08-19 23:15:46 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
2009-06-21 01:30:14 +00:00
|
|
|
|
char *buf = g_try_new(char, 36 + length * 2);
|
|
|
|
|
int len, ret;
|
|
|
|
|
|
|
|
|
|
if (!cbd || !buf)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
len = sprintf(buf, "AT+CRSM=220,%i,0,3,%i,", fileid, length);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-06-21 01:30:14 +00:00
|
|
|
|
for (; length; length--)
|
2009-12-18 00:58:22 +00:00
|
|
|
|
len += sprintf(buf + len, "%02hhX", *value++);
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
|
2009-06-21 01:30:14 +00:00
|
|
|
|
at_crsm_update_cb, cbd, g_free);
|
|
|
|
|
|
|
|
|
|
g_free(buf);
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-06-21 01:30:14 +00:00
|
|
|
|
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
2009-06-21 01:30:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-22 11:58:49 +00:00
|
|
|
|
static void at_cimi_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
GAtResultIter iter;
|
2009-08-18 22:05:50 +00:00
|
|
|
|
ofono_sim_imsi_cb_t cb = cbd->cb;
|
2009-05-22 11:58:49 +00:00
|
|
|
|
struct ofono_error error;
|
|
|
|
|
const char *imsi;
|
2009-05-29 23:14:40 +00:00
|
|
|
|
int i;
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
2009-07-10 18:10:14 +00:00
|
|
|
|
|
2009-05-22 11:58:49 +00:00
|
|
|
|
if (!ok) {
|
|
|
|
|
cb(&error, NULL, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
2009-05-29 23:14:40 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < g_at_result_num_response_lines(result); i++)
|
|
|
|
|
g_at_result_iter_next(&iter, NULL);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
imsi = g_at_result_iter_raw_line(&iter);
|
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
|
DBG("cimi_cb: %s", imsi);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
cb(&error, imsi, cbd->data);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static void at_read_imsi(struct ofono_sim *sim, ofono_sim_imsi_cb_t cb,
|
2009-05-22 11:58:49 +00:00
|
|
|
|
void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-08-19 23:15:46 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
if (g_at_chat_send(sd->chat, "AT+CIMI", NULL,
|
2009-05-22 11:58:49 +00:00
|
|
|
|
at_cimi_cb, cbd, g_free) > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
|
2009-09-11 17:36:35 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, data);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-17 20:43:22 +00:00
|
|
|
|
static struct {
|
2009-09-21 13:03:56 +00:00
|
|
|
|
enum ofono_sim_password_type type;
|
2009-09-17 20:43:22 +00:00
|
|
|
|
const char *name;
|
|
|
|
|
} const at_sim_name[] = {
|
2010-06-10 01:23:05 +00:00
|
|
|
|
{ OFONO_SIM_PASSWORD_NONE, "READY" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_SIM_PIN, "SIM PIN" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_SIM_PUK, "SIM PUK" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHSIM_PIN, "PH-SIM PIN" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHFSIM_PIN, "PH-FSIM PIN" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHFSIM_PUK, "PH-FSIM PUK" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_SIM_PIN2, "SIM PIN2" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_SIM_PUK2, "SIM PUK2" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHNET_PIN, "PH-NET PIN" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHNET_PUK, "PH-NET PUK" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHNETSUB_PIN, "PH-NETSUB PIN" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHNETSUB_PUK, "PH-NETSUB PUK" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHSP_PIN, "PH-SP PIN" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHSP_PUK, "PH-SP PUK" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHCORP_PIN, "PH-CORP PIN" },
|
|
|
|
|
{ OFONO_SIM_PASSWORD_PHCORP_PUK, "PH-CORP PUK" },
|
2009-09-17 20:43:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
2010-02-08 22:13:43 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(cbd->user);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
ofono_sim_passwd_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error;
|
|
|
|
|
const char *pin_required;
|
2009-09-21 13:03:56 +00:00
|
|
|
|
int pin_type = OFONO_SIM_PASSWORD_INVALID;
|
2009-09-17 20:43:22 +00:00
|
|
|
|
int i;
|
|
|
|
|
int len = sizeof(at_sim_name) / sizeof(*at_sim_name);
|
2010-02-08 22:13:43 +00:00
|
|
|
|
const char *final = g_at_result_final_response(result);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
2010-02-08 22:13:43 +00:00
|
|
|
|
if (sd->vendor == OFONO_VENDOR_WAVECOM && ok && strlen(final) > 7)
|
|
|
|
|
decode_at_error(&error, "OK");
|
|
|
|
|
else
|
|
|
|
|
decode_at_error(&error, final);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
cb(&error, -1, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 22:13:43 +00:00
|
|
|
|
if (sd->vendor == OFONO_VENDOR_WAVECOM) {
|
|
|
|
|
/* +CPIN: <pin> */
|
|
|
|
|
pin_required = final + 7;
|
|
|
|
|
} else {
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
2010-02-08 22:13:43 +00:00
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CPIN:")) {
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
2010-02-08 22:13:43 +00:00
|
|
|
|
g_at_result_iter_next_unquoted_string(&iter, &pin_required);
|
|
|
|
|
}
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
2009-09-21 15:11:07 +00:00
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
if (strcmp(pin_required, at_sim_name[i].name))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
pin_type = at_sim_name[i].type;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
2009-09-21 13:03:56 +00:00
|
|
|
|
if (pin_type == OFONO_SIM_PASSWORD_INVALID) {
|
2009-09-17 20:43:22 +00:00
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
|
DBG("crsm_pin_cb: %s", pin_required);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
cb(&error, pin_type, cbd->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void at_pin_query(struct ofono_sim *sim, ofono_sim_passwd_cb_t cb,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2010-02-08 22:13:43 +00:00
|
|
|
|
cbd->user = sim;
|
|
|
|
|
|
2010-05-12 01:20:53 +00:00
|
|
|
|
if (g_at_chat_send(sd->chat, "AT+CPIN?", cpin_prefix,
|
2009-09-17 20:43:22 +00:00
|
|
|
|
at_cpin_cb, cbd, g_free) > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, data);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-25 02:32:40 +00:00
|
|
|
|
static void at_xsim_notify(GAtResult *result, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
struct sim_data *sd = cbd->user;
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error = { .type = OFONO_ERROR_TYPE_NO_ERROR };
|
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
int state;
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+XSIM:"))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &state))
|
|
|
|
|
return;
|
|
|
|
|
|
atmodem: Update IFX specific SIM ready checking
It seems that the XSIM notification doesn't really send SIM ready
status. It sends ready to attach instead:
> AT+CPIN="0000"\r
< \r\nOK\r\n
< \r\n+XLOCK: "PN",5,0,"PU",5,0,"PP",5,0,"PC",5,0,"PS",5,0\r\n
< \r\n+XSIM: 7\r\n
So either SIM ready or ready to attach is received more to the
post_sim state.
2010-09-29 14:23:29 +00:00
|
|
|
|
switch (state) {
|
|
|
|
|
case 3: /* PIN verified – Ready */
|
|
|
|
|
case 7: /* ready for attach (+COPS) */
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2010-09-25 02:32:40 +00:00
|
|
|
|
return;
|
atmodem: Update IFX specific SIM ready checking
It seems that the XSIM notification doesn't really send SIM ready
status. It sends ready to attach instead:
> AT+CPIN="0000"\r
< \r\nOK\r\n
< \r\n+XLOCK: "PN",5,0,"PU",5,0,"PP",5,0,"PC",5,0,"PS",5,0\r\n
< \r\n+XSIM: 7\r\n
So either SIM ready or ready to attach is received more to the
post_sim state.
2010-09-29 14:23:29 +00:00
|
|
|
|
}
|
2010-09-25 02:32:40 +00:00
|
|
|
|
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
|
|
2010-10-15 13:07:51 +00:00
|
|
|
|
g_at_chat_unregister(sd->chat, sd->ready_id);
|
|
|
|
|
sd->ready_id = 0;
|
2010-09-25 02:32:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-17 13:42:13 +00:00
|
|
|
|
static void at_epev_notify(GAtResult *result, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
struct sim_data *sd = cbd->user;
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error = { .type = OFONO_ERROR_TYPE_NO_ERROR };
|
|
|
|
|
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
|
|
2010-10-15 13:07:51 +00:00
|
|
|
|
g_at_chat_unregister(sd->chat, sd->ready_id);
|
|
|
|
|
sd->ready_id = 0;
|
2010-06-17 13:42:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void at_pin_send_cb(gboolean ok, GAtResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
struct sim_data *sd = cbd->user;
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
2010-09-25 02:32:40 +00:00
|
|
|
|
if (!ok)
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
switch (sd->vendor) {
|
|
|
|
|
case OFONO_VENDOR_IFX:
|
|
|
|
|
/*
|
|
|
|
|
* On the IFX modem, AT+CPIN? can return READY too
|
|
|
|
|
* early and so use +XSIM notification to detect
|
|
|
|
|
* the ready state of the SIM.
|
|
|
|
|
*/
|
|
|
|
|
sd->ready_id = g_at_chat_register(sd->chat, "+XSIM",
|
|
|
|
|
at_xsim_notify,
|
|
|
|
|
FALSE, cbd, g_free);
|
|
|
|
|
return;
|
|
|
|
|
case OFONO_VENDOR_MBM:
|
|
|
|
|
/*
|
|
|
|
|
* On the MBM modem, AT+CPIN? keeps returning SIM PIN
|
|
|
|
|
* for a moment after successful AT+CPIN="..", but then
|
|
|
|
|
* sends *EPEV when that changes.
|
|
|
|
|
*/
|
|
|
|
|
sd->ready_id = g_at_chat_register(sd->chat, "*EPEV",
|
2010-06-17 13:42:13 +00:00
|
|
|
|
at_epev_notify,
|
|
|
|
|
FALSE, cbd, g_free);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-25 02:32:40 +00:00
|
|
|
|
done:
|
2010-06-17 13:42:13 +00:00
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-17 20:43:22 +00:00
|
|
|
|
static void at_pin_send(struct ofono_sim *sim, const char *passwd,
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb, void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
char buf[64];
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2010-06-17 13:42:13 +00:00
|
|
|
|
cbd->user = sd;
|
|
|
|
|
|
2009-09-17 20:43:22 +00:00
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\"", passwd);
|
|
|
|
|
|
2010-05-12 01:20:53 +00:00
|
|
|
|
ret = g_at_chat_send(sd->chat, buf, none_prefix,
|
2010-06-17 13:42:13 +00:00
|
|
|
|
at_pin_send_cb, cbd, NULL);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-16 10:26:26 +00:00
|
|
|
|
static void at_pin_send_puk_cb(gboolean ok, GAtResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
struct sim_data *sd = cbd->user;
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
switch (sd->vendor) {
|
|
|
|
|
case OFONO_VENDOR_IFX:
|
|
|
|
|
/*
|
|
|
|
|
* On the IFX modem, AT+CPIN? can return READY too
|
|
|
|
|
* early and so use +XSIM notification to detect
|
|
|
|
|
* the ready state of the SIM.
|
|
|
|
|
*/
|
|
|
|
|
sd->ready_id = g_at_chat_register(sd->chat, "+XSIM",
|
|
|
|
|
at_xsim_notify,
|
|
|
|
|
FALSE, cbd, g_free);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-17 20:43:22 +00:00
|
|
|
|
static void at_pin_send_puk(struct ofono_sim *sim, const char *puk,
|
|
|
|
|
const char *passwd,
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb, void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
char buf[64];
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2010-10-16 10:26:26 +00:00
|
|
|
|
cbd->user = sd;
|
|
|
|
|
|
2009-09-17 20:43:22 +00:00
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\",\"%s\"", puk, passwd);
|
|
|
|
|
|
2010-05-12 01:20:53 +00:00
|
|
|
|
ret = g_at_chat_send(sd->chat, buf, none_prefix,
|
2010-10-16 10:26:26 +00:00
|
|
|
|
at_pin_send_puk_cb, cbd, NULL);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-16 10:26:26 +00:00
|
|
|
|
static void at_lock_unlock_cb(gboolean ok, GAtResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-17 20:43:22 +00:00
|
|
|
|
static const char *const at_clck_cpwd_fac[] = {
|
2009-09-21 13:03:56 +00:00
|
|
|
|
[OFONO_SIM_PASSWORD_SIM_PIN] = "SC",
|
|
|
|
|
[OFONO_SIM_PASSWORD_SIM_PIN2] = "P2",
|
|
|
|
|
[OFONO_SIM_PASSWORD_PHSIM_PIN] = "PS",
|
|
|
|
|
[OFONO_SIM_PASSWORD_PHFSIM_PIN] = "PF",
|
|
|
|
|
[OFONO_SIM_PASSWORD_PHNET_PIN] = "PN",
|
|
|
|
|
[OFONO_SIM_PASSWORD_PHNETSUB_PIN] = "PU",
|
|
|
|
|
[OFONO_SIM_PASSWORD_PHSP_PIN] = "PP",
|
|
|
|
|
[OFONO_SIM_PASSWORD_PHCORP_PIN] = "PC",
|
2009-09-17 20:43:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-09-22 04:04:53 +00:00
|
|
|
|
static void at_pin_enable(struct ofono_sim *sim,
|
|
|
|
|
enum ofono_sim_password_type passwd_type,
|
|
|
|
|
int enable, const char *passwd,
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb, void *data)
|
2009-09-17 20:43:22 +00:00
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
char buf[64];
|
|
|
|
|
int ret;
|
2009-09-22 04:04:53 +00:00
|
|
|
|
unsigned int len = sizeof(at_clck_cpwd_fac) / sizeof(*at_clck_cpwd_fac);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2009-09-22 04:04:53 +00:00
|
|
|
|
if (passwd_type >= len || !at_clck_cpwd_fac[passwd_type])
|
2009-09-17 20:43:22 +00:00
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CLCK=\"%s\",%i,\"%s\"",
|
|
|
|
|
at_clck_cpwd_fac[passwd_type], enable ? 1 : 0, passwd);
|
|
|
|
|
|
2010-05-12 01:20:53 +00:00
|
|
|
|
ret = g_at_chat_send(sd->chat, buf, none_prefix,
|
2009-11-10 06:30:10 +00:00
|
|
|
|
at_lock_unlock_cb, cbd, g_free);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-21 13:03:56 +00:00
|
|
|
|
static void at_change_passwd(struct ofono_sim *sim,
|
|
|
|
|
enum ofono_sim_password_type passwd_type,
|
2009-09-17 20:43:22 +00:00
|
|
|
|
const char *old, const char *new,
|
|
|
|
|
ofono_sim_lock_unlock_cb_t cb, void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
char buf[64];
|
|
|
|
|
int ret;
|
2009-09-21 13:03:56 +00:00
|
|
|
|
unsigned int len = sizeof(at_clck_cpwd_fac) / sizeof(*at_clck_cpwd_fac);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
2009-09-21 13:03:56 +00:00
|
|
|
|
if (passwd_type >= len ||
|
2009-09-17 20:43:22 +00:00
|
|
|
|
!at_clck_cpwd_fac[passwd_type])
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CPWD=\"%s\",\"%s\",\"%s\"",
|
|
|
|
|
at_clck_cpwd_fac[passwd_type], old, new);
|
|
|
|
|
|
2010-05-12 01:20:53 +00:00
|
|
|
|
ret = g_at_chat_send(sd->chat, buf, none_prefix,
|
2009-11-10 06:30:10 +00:00
|
|
|
|
at_lock_unlock_cb, cbd, g_free);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-09-17 20:43:22 +00:00
|
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-23 22:33:28 +00:00
|
|
|
|
static void at_lock_status_cb(gboolean ok, GAtResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
ofono_sim_locked_cb_t cb = cbd->cb;
|
|
|
|
|
struct ofono_error error;
|
|
|
|
|
int locked;
|
|
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
cb(&error, -1, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CLCK:")) {
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_at_result_iter_next_number(&iter, &locked);
|
|
|
|
|
|
2010-02-08 18:09:01 +00:00
|
|
|
|
DBG("lock_status_cb: %i", locked);
|
2009-09-23 22:33:28 +00:00
|
|
|
|
|
|
|
|
|
cb(&error, locked, cbd->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void at_pin_query_enabled(struct ofono_sim *sim,
|
|
|
|
|
enum ofono_sim_password_type passwd_type,
|
|
|
|
|
ofono_sim_locked_cb_t cb, void *data)
|
|
|
|
|
{
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
2009-09-23 22:33:28 +00:00
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
char buf[64];
|
|
|
|
|
unsigned int len = sizeof(at_clck_cpwd_fac) / sizeof(*at_clck_cpwd_fac);
|
|
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
if (passwd_type >= len || !at_clck_cpwd_fac[passwd_type])
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "AT+CLCK=\"%s\",2",
|
|
|
|
|
at_clck_cpwd_fac[passwd_type]);
|
|
|
|
|
|
2010-05-12 01:20:53 +00:00
|
|
|
|
if (g_at_chat_send(sd->chat, buf, clck_prefix,
|
2009-09-23 22:33:28 +00:00
|
|
|
|
at_lock_status_cb, cbd, g_free) > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
error:
|
2010-08-16 20:02:01 +00:00
|
|
|
|
g_free(cbd);
|
2009-09-23 22:33:28 +00:00
|
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, data);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
static gboolean at_sim_register(gpointer user)
|
|
|
|
|
{
|
|
|
|
|
struct ofono_sim *sim = user;
|
|
|
|
|
|
|
|
|
|
ofono_sim_register(sim);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-02 02:39:02 +00:00
|
|
|
|
static int at_sim_probe(struct ofono_sim *sim, unsigned int vendor,
|
|
|
|
|
void *data)
|
2009-08-18 22:05:50 +00:00
|
|
|
|
{
|
2009-09-01 22:36:27 +00:00
|
|
|
|
GAtChat *chat = data;
|
2009-11-10 06:30:10 +00:00
|
|
|
|
struct sim_data *sd;
|
|
|
|
|
|
|
|
|
|
sd = g_new0(struct sim_data, 1);
|
2010-08-12 21:40:40 +00:00
|
|
|
|
sd->chat = g_at_chat_clone(chat);
|
2009-11-10 06:30:10 +00:00
|
|
|
|
sd->vendor = vendor;
|
2009-09-01 22:36:27 +00:00
|
|
|
|
|
2010-06-18 19:24:18 +00:00
|
|
|
|
switch (sd->vendor) {
|
|
|
|
|
case OFONO_VENDOR_WAVECOM:
|
2010-08-12 21:40:40 +00:00
|
|
|
|
g_at_chat_add_terminator(sd->chat, "+CPIN:", 6, TRUE);
|
2010-06-18 19:24:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case OFONO_VENDOR_MBM:
|
2010-08-12 21:40:40 +00:00
|
|
|
|
g_at_chat_send(sd->chat, "AT*EPEE=1", NULL, NULL, NULL, NULL);
|
2010-06-18 19:24:18 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-02-08 22:13:43 +00:00
|
|
|
|
|
2009-11-10 06:30:10 +00:00
|
|
|
|
ofono_sim_set_data(sim, sd);
|
2009-08-18 22:05:50 +00:00
|
|
|
|
g_idle_add(at_sim_register, sim);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-02 03:27:08 +00:00
|
|
|
|
static void at_sim_remove(struct ofono_sim *sim)
|
2009-08-18 22:05:50 +00:00
|
|
|
|
{
|
2009-11-11 21:58:45 +00:00
|
|
|
|
struct sim_data *sd = ofono_sim_get_data(sim);
|
|
|
|
|
|
|
|
|
|
ofono_sim_set_data(sim, NULL);
|
|
|
|
|
|
2010-08-12 21:40:40 +00:00
|
|
|
|
g_at_chat_unref(sd->chat);
|
2009-11-11 21:58:45 +00:00
|
|
|
|
g_free(sd);
|
2009-08-18 22:05:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct ofono_sim_driver driver = {
|
2009-09-02 03:33:05 +00:00
|
|
|
|
.name = "atmodem",
|
2009-08-18 22:05:50 +00:00
|
|
|
|
.probe = at_sim_probe,
|
|
|
|
|
.remove = at_sim_remove,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
.read_file_info = at_sim_read_info,
|
|
|
|
|
.read_file_transparent = at_sim_read_binary,
|
|
|
|
|
.read_file_linear = at_sim_read_record,
|
2009-06-21 01:30:14 +00:00
|
|
|
|
.read_file_cyclic = at_sim_read_record,
|
2009-06-18 03:44:44 +00:00
|
|
|
|
.write_file_transparent = at_sim_update_binary,
|
|
|
|
|
.write_file_linear = at_sim_update_record,
|
2009-06-21 01:30:14 +00:00
|
|
|
|
.write_file_cyclic = at_sim_update_cyclic,
|
2009-05-22 11:58:49 +00:00
|
|
|
|
.read_imsi = at_read_imsi,
|
2009-09-17 20:43:22 +00:00
|
|
|
|
.query_passwd_state = at_pin_query,
|
|
|
|
|
.send_passwd = at_pin_send,
|
|
|
|
|
.reset_passwd = at_pin_send_puk,
|
|
|
|
|
.lock = at_pin_enable,
|
|
|
|
|
.change_passwd = at_change_passwd,
|
2009-09-23 22:33:28 +00:00
|
|
|
|
.query_locked = at_pin_query_enabled,
|
2009-05-22 11:58:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
void at_sim_init()
|
2009-05-22 11:58:49 +00:00
|
|
|
|
{
|
2009-08-18 22:05:50 +00:00
|
|
|
|
ofono_sim_driver_register(&driver);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 22:05:50 +00:00
|
|
|
|
void at_sim_exit()
|
2009-05-22 11:58:49 +00:00
|
|
|
|
{
|
2009-08-18 22:05:50 +00:00
|
|
|
|
ofono_sim_driver_unregister(&driver);
|
2009-05-22 11:58:49 +00:00
|
|
|
|
}
|