Cleanup EFmsisdn reading patch

This commit is contained in:
Denis Kenzior 2009-06-18 03:46:08 -05:00
parent 314478c756
commit 6fdf580a5d
3 changed files with 25 additions and 157 deletions

View File

@ -39,7 +39,6 @@
#include "at.h"
static const char *crsm_prefix[] = { "+CRSM:", NULL };
static const char *cnum_prefix[] = { "+CNUM:", NULL };
static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
@ -380,93 +379,6 @@ error:
}
}
static void at_cnum_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
GAtResultIter iter;
ofono_own_numbers_cb_t cb = cbd->cb;
struct ofono_error error;
struct ofono_own_number *numbers;
int count;
const char *str;
dump_response("at_cnum_cb", ok, result);
decode_at_error(&error, g_at_result_final_response(result));
if (!ok) {
cb(&error, 0, NULL, cbd->data);
return;
}
g_at_result_iter_init(&iter, result);
for (count = 0; g_at_result_iter_next(&iter, "+CNUM:"); count++);
ofono_debug("Got %i elements", count);
numbers = g_try_new0(struct ofono_own_number, count);
if (!numbers) {
DECLARE_FAILURE(e);
cb(&e, 0, NULL, cbd->data);
return;
}
g_at_result_iter_init(&iter, result);
count = 0;
while (g_at_result_iter_next(&iter, "+CNUM")) {
/* Skip alnum */
g_at_result_iter_skip_next(&iter);
if (!g_at_result_iter_next_string(&iter, &str))
continue;
g_strlcpy(numbers[count].phone_number.number,
str[0] == '+' ? str+1 : str,
OFONO_MAX_PHONE_NUMBER_LENGTH);
g_at_result_iter_next_number(&iter,
&numbers[count].phone_number.type);
numbers[count].speed = -1;
numbers[count].service = -1;
numbers[count].itc = -1;
numbers[count].npi = -1;
g_at_result_iter_skip_next(&iter);
g_at_result_iter_next_number(&iter, &numbers[count].service);
g_at_result_iter_next_number(&iter, &numbers[count].itc);
count++;
}
cb(&error, count, numbers, cbd->data);
g_free(numbers);
}
static void at_read_msisdn(struct ofono_modem *modem, ofono_own_numbers_cb_t cb,
void *data)
{
struct at_data *at = ofono_modem_userdata(modem);
struct cb_data *cbd = cb_data_new(modem, cb, data);
if (!cbd)
goto error;
if (g_at_chat_send(at->parser, "AT+CNUM", cnum_prefix,
at_cnum_cb, cbd, g_free) > 0)
return;
error:
if (cbd)
g_free(cbd);
{
DECLARE_FAILURE(error);
cb(&error, 0, NULL, data);
}
}
static struct ofono_sim_ops ops = {
.read_file_info = at_sim_read_info,
.read_file_transparent = at_sim_read_binary,
@ -474,7 +386,6 @@ static struct ofono_sim_ops ops = {
.write_file_transparent = at_sim_update_binary,
.write_file_linear = at_sim_update_record,
.read_imsi = at_read_imsi,
.read_own_numbers = at_read_msisdn,
};
void at_sim_init(struct ofono_modem *modem)

View File

@ -94,36 +94,6 @@ struct ofono_cf_condition {
int time;
};
/* 27.007 Section 7.1 Subscriber Number */
struct ofono_own_number {
struct ofono_phone_number phone_number;
int speed;
int service;
int itc;
int npi;
};
/* 24.008 Section 10.5.4.7 */
enum ofono_number_type {
OFONO_NUMBER_TYPE_UNKNOWN = 0,
OFONO_NUMBER_TYPE_INTERNATIONAL = 1,
OFONO_NUMBER_TYPE_NATIONAL = 2,
OFONO_NUMBER_TYPE_NETWORK_SPECIFIC = 3,
OFONO_NUMBER_TYPE_DEDICATED_ACCESS = 4,
OFONO_NUMBER_TYPE_RESERVED = 7
};
enum ofono_numbering_plan {
OFONO_NUMBERING_PLAN_UNKNOWN = 0,
OFONO_NUMBERING_PLAN_ISDN = 1,
OFONO_NUMBERING_PLAN_DATA = 3,
OFONO_NUMBERING_PLAN_TELEX = 4,
OFONO_NUMBERING_PLAN_NATIONAL = 8,
OFONO_NUMBERING_PLAN_PRIVATE = 9,
OFONO_NUMBERING_PLAN_RESERVED_CTS = 11,
OFONO_NUMBERING_PLAN_RESERVED = 15
};
/* 51.011 Section 9.3 */
enum ofono_sim_file_structure {
OFONO_SIM_FILE_STRUCTURE_TRANSPARENT = 0,
@ -201,9 +171,6 @@ typedef void (*ofono_sim_read_cb_t)(const struct ofono_error *error,
typedef void (*ofono_imsi_cb_t)(const struct ofono_error *error,
const char *imsi, void *data);
typedef void (*ofono_own_numbers_cb_t)(const struct ofono_error *error, int num,
const struct ofono_own_number *numbers, void *data);
typedef void (*ofono_sca_query_cb_t)(const struct ofono_error *error,
const struct ofono_phone_number *ph,
void *data);
@ -414,8 +381,6 @@ struct ofono_sim_ops {
ofono_generic_cb_t cb, void *data);
void (*read_imsi)(struct ofono_modem *modem,
ofono_imsi_cb_t cb, void *data);
void (*read_own_numbers)(struct ofono_modem *modem,
ofono_own_numbers_cb_t cb, void *data);
};
int ofono_sim_manager_register(struct ofono_modem *modem,

View File

@ -37,10 +37,20 @@
#include "driver.h"
#include "common.h"
#include "util.h"
#include "smsutil.h"
#include "sim.h"
#define SIM_MANAGER_INTERFACE "org.ofono.SimManager"
/* 27.007 Section 7.1 Subscriber Number */
struct own_number {
struct ofono_phone_number phone_number;
int speed;
int service;
int itc;
int npi;
};
struct sim_manager_data {
struct ofono_sim_ops *ops;
int flags;
@ -61,7 +71,7 @@ static char **own_numbers_by_type(GSList *own_numbers, int type)
{
int nelem;
GSList *l;
struct ofono_own_number *num;
struct own_number *num;
char **ret;
if (!own_numbers)
@ -295,7 +305,7 @@ static void sim_msisdn_read_cb(const struct ofono_error *error,
{
struct ofono_modem *modem = data;
struct sim_manager_data *sim = modem->sim_manager;
struct ofono_own_number *ph;
struct own_number *ph;
int number_len;
int ton_npi;
int i, digit;
@ -315,36 +325,18 @@ static void sim_msisdn_read_cb(const struct ofono_error *error,
if (number_len > 11 || ton_npi == 0xff)
goto skip;
ph = g_new(struct ofono_own_number, 1);
ph = g_new(struct own_number, 1);
ph->speed = -1;
ph->service = -1;
ph->itc = -1;
ph->npi = (ton_npi >> 0) & 15;
ph->phone_number.type = (ton_npi >> 4) & 7;
ph->phone_number.type = bit_field(ton_npi, 4, 3);
ph->npi = bit_field(ton_npi, 0, 4);
if (number_len > 10)
number_len = 10;
number_len *= 2;
if (number_len > OFONO_MAX_PHONE_NUMBER_LENGTH)
number_len = OFONO_MAX_PHONE_NUMBER_LENGTH;
/* BCD coded, however the TON/NPI is given by the first byte */
number_len = (number_len - 1) * 2;
for (i = 0; i < number_len; i ++) {
digit = *sdata;
/* BCD coded */
if (i & 1) {
sdata ++;
digit >>= 4;
}
digit &= 0xf;
if (digit > 9)
break;
ph->phone_number.number[i] = '0' + digit;
}
memset(&ph->phone_number.number[i], 0,
OFONO_MAX_PHONE_NUMBER_LENGTH - i);
extract_bcd_number(sdata, number_len, ph->phone_number.number);
sim->own_numbers = g_slist_prepend(sim->own_numbers, ph);
@ -352,25 +344,25 @@ skip:
sim->own_numbers_current ++;
if (sim->own_numbers_current < sim->own_numbers_num)
sim->ops->read_file_linear(modem, SIM_EFMSISDN_FILEID,
sim->own_numbers_current,
sim->own_numbers_size,
sim_msisdn_read_cb, modem);
sim->own_numbers_current,
sim->own_numbers_size,
sim_msisdn_read_cb, modem);
else
/* All records retrieved */
if (sim->own_numbers)
sim->own_numbers = g_slist_reverse(sim->own_numbers);
}
static void sim_msisdn_info_cb(const struct ofono_error *error,
int length, enum ofono_simfile_struct structure,
int record_length, void *data)
static void sim_msisdn_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;
if (error->type != OFONO_ERROR_TYPE_NO_ERROR || length < 14 ||
record_length < 14 ||
structure != OFONO_SIM_FILE_FIXED)
structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
return;
sim->own_numbers_current = 0;