2009-08-13 16:54:26 +00:00
|
|
|
/*
|
|
|
|
* This file is part of oFono - Open Source Telephony
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
*
|
|
|
|
* Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
|
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-08-14 17:10:05 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2009-08-13 16:54:26 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <gisi/client.h>
|
2009-09-14 20:44:50 +00:00
|
|
|
#include <gisi/iter.h>
|
2009-08-13 16:54:26 +00:00
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
2009-08-14 17:10:05 +00:00
|
|
|
#include <ofono/phonebook.h>
|
2009-08-13 16:54:26 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include "isi.h"
|
|
|
|
|
|
|
|
#define PHONEBOOK_TIMEOUT 5
|
|
|
|
#define PN_SIM 0x09
|
|
|
|
|
|
|
|
enum pb_message_id {
|
|
|
|
SIM_PB_REQ_SIM_PB_READ = 0xDC,
|
|
|
|
SIM_PB_RESP_SIM_PB_READ = 0xDD
|
|
|
|
};
|
|
|
|
|
|
|
|
enum pb_service_types {
|
|
|
|
SIM_PB_READ = 0x0F
|
|
|
|
};
|
|
|
|
|
|
|
|
enum pb_sub_block_id {
|
|
|
|
SIM_PB_INFO_REQUEST = 0xE4,
|
|
|
|
SIM_PB_STATUS = 0xFB,
|
|
|
|
SIM_PB_LOCATION = 0xFE,
|
|
|
|
SIM_PB_LOCATION_SEARCH = 0xFF
|
|
|
|
};
|
|
|
|
|
|
|
|
enum pb_type {
|
|
|
|
SIM_PB_ADN = 0xC8
|
|
|
|
};
|
|
|
|
|
|
|
|
enum pb_tag {
|
|
|
|
SIM_PB_ANR = 0xCA,
|
|
|
|
SIM_PB_EMAIL = 0xDD,
|
|
|
|
SIM_PB_SNE = 0xF7
|
|
|
|
};
|
|
|
|
|
|
|
|
enum pb_status {
|
2009-09-14 20:44:50 +00:00
|
|
|
SIM_SERV_OK = 0x01,
|
|
|
|
SIM_SERV_NO_MATCH = 0x16
|
2009-08-13 16:54:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pb_data {
|
2009-08-21 13:30:13 +00:00
|
|
|
GIsiClient *client;
|
2009-08-13 16:54:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int decode_read_response(const unsigned char *msg, size_t len,
|
2009-08-14 17:10:05 +00:00
|
|
|
struct ofono_phonebook *pb)
|
2009-08-13 16:54:26 +00:00
|
|
|
{
|
2009-09-14 20:44:50 +00:00
|
|
|
GIsiSubBlockIter iter;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
|
|
|
char *name = NULL;
|
|
|
|
char *number = NULL;
|
2009-09-14 20:44:50 +00:00
|
|
|
char *sne= NULL;
|
|
|
|
char *anr = NULL;
|
2009-08-13 16:54:26 +00:00
|
|
|
char *email = NULL;
|
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
int location = -1;
|
|
|
|
guint8 status = 0;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (len < 3 || msg[0] != SIM_PB_RESP_SIM_PB_READ)
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (msg[1] != SIM_PB_READ)
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_init(msg+3, len-3, &iter, true))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
while (g_isi_sb_iter_is_valid(&iter)) {
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
switch (g_isi_sb_iter_get_id(&iter)) {
|
2009-08-13 16:54:26 +00:00
|
|
|
|
|
|
|
case SIM_PB_ADN: {
|
2009-09-14 20:44:50 +00:00
|
|
|
guint16 loc;
|
|
|
|
guint8 namelen;
|
|
|
|
guint8 numberlen;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (g_isi_sb_iter_get_len(&iter) < 8)
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_word(&iter, &loc, 4) ||
|
|
|
|
!g_isi_sb_iter_get_byte(&iter, &namelen, 6) ||
|
|
|
|
!g_isi_sb_iter_get_byte(&iter, &numberlen, 7))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
location = loc;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_alpha_tag(&iter, &name,
|
|
|
|
namelen * 2, 8))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_isi_sb_iter_get_alpha_tag(&iter, &number,
|
|
|
|
numberlen * 2, 8 + namelen * 2))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIM_PB_SNE: {
|
2009-09-14 20:44:50 +00:00
|
|
|
guint8 snelen;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (g_isi_sb_iter_get_len(&iter) < 8)
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_byte(&iter, &snelen, 6))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_alpha_tag(&iter, &sne,
|
|
|
|
snelen * 2, 8))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIM_PB_ANR: {
|
2009-09-14 20:44:50 +00:00
|
|
|
guint8 anrlen;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (g_isi_sb_iter_get_len(&iter) < 8)
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_byte(&iter, &anrlen, 6))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_alpha_tag(&iter, &anr,
|
|
|
|
anrlen * 2, 8))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIM_PB_EMAIL: {
|
2009-09-14 20:44:50 +00:00
|
|
|
guint8 emaillen;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (g_isi_sb_iter_get_len(&iter) < 8)
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_byte(&iter, &emaillen, 6))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (!g_isi_sb_iter_get_alpha_tag(&iter, &email,
|
|
|
|
emaillen * 2, 8))
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIM_PB_STATUS:
|
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
if (g_isi_sb_iter_get_len(&iter) < 5)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!g_isi_sb_iter_get_byte(&iter, &status, 4))
|
|
|
|
goto error;
|
|
|
|
|
2009-08-13 16:54:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-09-14 21:10:15 +00:00
|
|
|
DBG("Skipping sub-block: 0x%04X (%zu bytes)",
|
2009-09-14 20:44:50 +00:00
|
|
|
g_isi_sb_iter_get_id(&iter),
|
|
|
|
g_isi_sb_iter_get_len(&iter));
|
2009-08-13 16:54:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-09-14 20:44:50 +00:00
|
|
|
g_isi_sb_iter_next(&iter);
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
2009-08-23 20:16:46 +00:00
|
|
|
|
2009-09-15 08:17:39 +00:00
|
|
|
if (status != SIM_SERV_OK) {
|
|
|
|
DBG("PB read returned status: 0x%02X", status);
|
|
|
|
goto error;
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 08:17:39 +00:00
|
|
|
ofono_phonebook_entry(pb, -1, number, -1, name, -1, NULL,
|
|
|
|
anr, -1, sne, email, NULL, NULL);
|
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
error:
|
2009-08-23 20:16:46 +00:00
|
|
|
g_free(name);
|
|
|
|
g_free(number);
|
2009-09-14 20:44:50 +00:00
|
|
|
g_free(sne);
|
|
|
|
g_free(anr);
|
2009-08-23 20:16:46 +00:00
|
|
|
g_free(email);
|
|
|
|
|
2009-09-14 20:44:50 +00:00
|
|
|
return location;
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-08-21 13:30:13 +00:00
|
|
|
static void read_next_entry(GIsiClient *client, int location, GIsiResponseFunc read_cb, struct isi_cb_data *cbd)
|
2009-08-13 16:54:26 +00:00
|
|
|
{
|
2009-08-14 17:10:05 +00:00
|
|
|
ofono_phonebook_cb_t cb = cbd->cb;
|
2009-08-13 16:54:26 +00:00
|
|
|
const unsigned char msg[] = {
|
|
|
|
SIM_PB_REQ_SIM_PB_READ,
|
|
|
|
SIM_PB_READ,
|
|
|
|
2, /* number of subblocks */
|
|
|
|
0, SIM_PB_LOCATION_SEARCH, /* subblock id */
|
|
|
|
0, 8, /* subblock size */
|
|
|
|
0, SIM_PB_ADN,
|
|
|
|
location >> 8, location & 0xFF, /* read next entry after specified by location */
|
|
|
|
0, SIM_PB_INFO_REQUEST, /* subblock id */
|
|
|
|
0, 16, /* subblock size */
|
|
|
|
4, /* number of tags */
|
|
|
|
0, /* filler */
|
|
|
|
0, SIM_PB_ADN, /* tags */
|
|
|
|
0, SIM_PB_SNE,
|
|
|
|
0, SIM_PB_ANR,
|
|
|
|
0, SIM_PB_EMAIL,
|
|
|
|
0, 0 /* filler */
|
|
|
|
};
|
|
|
|
|
|
|
|
if (location < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (g_isi_request_make(client, msg, sizeof(msg), PHONEBOOK_TIMEOUT,
|
|
|
|
read_cb, cbd))
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2009-09-12 15:57:16 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, cbd->data);
|
|
|
|
g_free(cbd);
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool read_resp_cb(GIsiClient *client, const void *restrict data,
|
|
|
|
size_t len, uint16_t object, void *opaque)
|
|
|
|
{
|
|
|
|
const unsigned char *msg = data;
|
|
|
|
struct isi_cb_data *cbd = opaque;
|
2009-08-14 17:10:05 +00:00
|
|
|
ofono_phonebook_cb_t cb = cbd->cb;
|
2009-08-13 16:54:26 +00:00
|
|
|
int location;
|
|
|
|
|
|
|
|
if(!msg) {
|
|
|
|
DBG("ISI client error: %d", g_isi_client_error(client));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-08-14 17:10:05 +00:00
|
|
|
location = decode_read_response(data, len, cbd->user);
|
2009-08-13 16:54:26 +00:00
|
|
|
if (location != -1) {
|
2009-08-21 13:30:13 +00:00
|
|
|
read_next_entry(client, location, read_resp_cb, cbd);
|
2009-08-20 20:24:07 +00:00
|
|
|
return true;
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 15:57:16 +00:00
|
|
|
CALLBACK_WITH_SUCCESS(cb, cbd->data);
|
|
|
|
goto out;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
|
|
|
error:
|
2009-09-12 15:57:16 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, cbd->data);
|
2009-08-13 16:54:26 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
g_free(cbd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-14 17:10:05 +00:00
|
|
|
static void isi_export_entries(struct ofono_phonebook *pb, const char *storage,
|
|
|
|
ofono_phonebook_cb_t cb, void *data)
|
2009-08-13 16:54:26 +00:00
|
|
|
{
|
2009-08-21 13:30:13 +00:00
|
|
|
struct pb_data *pbd = ofono_phonebook_get_data(pb);
|
2009-09-14 20:44:50 +00:00
|
|
|
struct isi_cb_data *cbd = isi_cb_data_new(pb, cb, data);
|
2009-08-13 16:54:26 +00:00
|
|
|
const unsigned char msg[] = {
|
|
|
|
SIM_PB_REQ_SIM_PB_READ,
|
|
|
|
SIM_PB_READ,
|
|
|
|
2, /* number of subblocks */
|
|
|
|
0, SIM_PB_LOCATION, /* subblock id */
|
|
|
|
0, 8, /* subblock size */
|
|
|
|
0, SIM_PB_ADN,
|
2009-09-14 20:44:50 +00:00
|
|
|
0xFF, 0xFF, /* read first entry in pb */
|
2009-08-13 16:54:26 +00:00
|
|
|
0, SIM_PB_INFO_REQUEST, /* subblock id */
|
|
|
|
0, 16, /* subblock size */
|
|
|
|
4, /* number of tags */
|
|
|
|
0, /* filler */
|
|
|
|
0, SIM_PB_ADN, /* tags */
|
|
|
|
0, SIM_PB_SNE,
|
|
|
|
0, SIM_PB_ANR,
|
|
|
|
0, SIM_PB_EMAIL,
|
|
|
|
0, 0 /* filler */
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!cbd)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (strcmp(storage, "SM"))
|
|
|
|
goto error;
|
|
|
|
|
2009-08-21 13:30:13 +00:00
|
|
|
if (g_isi_request_make(pbd->client, msg, sizeof(msg), PHONEBOOK_TIMEOUT,
|
2009-08-13 16:54:26 +00:00
|
|
|
read_resp_cb, cbd))
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (cbd)
|
|
|
|
g_free(cbd);
|
|
|
|
|
2009-09-12 15:57:16 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-08-14 17:10:05 +00:00
|
|
|
static gboolean isi_phonebook_register(gpointer user)
|
2009-08-13 16:54:26 +00:00
|
|
|
{
|
2009-08-14 17:10:05 +00:00
|
|
|
struct ofono_phonebook *pb = user;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-08-14 17:10:05 +00:00
|
|
|
ofono_phonebook_register(pb);
|
|
|
|
|
|
|
|
return FALSE;
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 10:42:45 +00:00
|
|
|
static void reachable_cb(GIsiClient *client, bool alive, void *opaque)
|
|
|
|
{
|
|
|
|
struct ofono_phonebook *pb = opaque;
|
|
|
|
|
|
|
|
if (alive == true) {
|
|
|
|
DBG("Resource 0x%02X, with version %03d.%03d reachable",
|
|
|
|
g_isi_client_resource(client),
|
|
|
|
g_isi_version_major(client),
|
|
|
|
g_isi_version_minor(client));
|
|
|
|
g_idle_add(isi_phonebook_register, pb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DBG("Unable to bootsrap phonebook driver");
|
|
|
|
}
|
|
|
|
|
2009-09-02 02:39:02 +00:00
|
|
|
static int isi_phonebook_probe(struct ofono_phonebook *pb, unsigned int vendor,
|
2009-09-01 22:32:07 +00:00
|
|
|
void *user)
|
2009-08-13 16:54:26 +00:00
|
|
|
{
|
2009-09-01 22:32:07 +00:00
|
|
|
GIsiModem *idx = user;
|
2009-08-21 13:30:13 +00:00
|
|
|
struct pb_data *data = g_try_new0(struct pb_data, 1);
|
2009-08-21 07:06:40 +00:00
|
|
|
|
2009-08-21 13:30:13 +00:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-08-21 13:30:13 +00:00
|
|
|
data->client = g_isi_client_create(idx, PN_SIM);
|
2009-08-23 20:16:46 +00:00
|
|
|
if (!data->client) {
|
|
|
|
g_free(data);
|
2009-08-21 13:30:13 +00:00
|
|
|
return -ENOMEM;
|
2009-08-23 20:16:46 +00:00
|
|
|
}
|
2009-08-21 13:30:13 +00:00
|
|
|
|
|
|
|
ofono_phonebook_set_data(pb, data);
|
2009-08-14 17:10:05 +00:00
|
|
|
|
2009-09-16 10:42:45 +00:00
|
|
|
if (!g_isi_verify(data->client, reachable_cb, pb))
|
|
|
|
DBG("Unable to verify reachability");
|
2009-08-14 17:10:05 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:27:08 +00:00
|
|
|
static void isi_phonebook_remove(struct ofono_phonebook *pb)
|
2009-08-13 16:54:26 +00:00
|
|
|
{
|
2009-08-21 13:30:13 +00:00
|
|
|
struct pb_data *data = ofono_phonebook_get_data(pb);
|
2009-08-13 16:54:26 +00:00
|
|
|
|
2009-09-14 21:12:28 +00:00
|
|
|
if (data) {
|
2009-08-21 13:30:13 +00:00
|
|
|
g_isi_client_destroy(data->client);
|
|
|
|
g_free(data);
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|
2009-08-14 17:10:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ofono_phonebook_driver driver = {
|
2009-09-02 03:35:14 +00:00
|
|
|
.name = "isimodem",
|
2009-08-14 17:10:05 +00:00
|
|
|
.probe = isi_phonebook_probe,
|
|
|
|
.remove = isi_phonebook_remove,
|
|
|
|
.export_entries = isi_export_entries
|
|
|
|
};
|
|
|
|
|
|
|
|
void isi_phonebook_init()
|
|
|
|
{
|
|
|
|
ofono_phonebook_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void isi_phonebook_exit()
|
|
|
|
{
|
|
|
|
ofono_phonebook_driver_unregister(&driver);
|
2009-08-13 16:54:26 +00:00
|
|
|
}
|