Move PNN reading to network.c

This commit is contained in:
Denis Kenzior 2009-07-13 12:57:08 -05:00
parent 9a565d88b1
commit 82ede4d647
2 changed files with 42 additions and 64 deletions

View File

@ -37,6 +37,7 @@
#include "driver.h"
#include "common.h"
#include "sim.h"
#include "simutil.h"
#define NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration"
#define NETWORK_OPERATOR_INTERFACE "org.ofono.NetworkOperator"
@ -64,6 +65,7 @@ struct network_registration_data {
int signal_strength;
char display_name[OFONO_MAX_OPERATOR_NAME_LENGTH];
char *spname;
GSList *pnn_list;
};
static void operator_list_callback(const struct ofono_error *error, int total,
@ -565,6 +567,9 @@ static void network_registration_destroy(gpointer userdata)
g_slist_free(data->operator_list);
g_slist_foreach(data->pnn_list, (GFunc)sim_pnn_operator_free, NULL);
g_slist_free(data->pnn_list);
if (data->spname)
g_free(data->spname);
@ -1131,6 +1136,43 @@ static void ofono_update_spn(struct ofono_modem *modem, const char *spn,
&operator);
}
static void sim_pnn_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)
{
struct network_registration_data *netreg = modem->network_registration;
struct sim_pnn_operator *oper;
int total = length / record_length;
if (!ok)
return;
if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
return;
if (length < 3 || record_length < 3 || length < record_length)
return;
oper = sim_pnn_operator_parse(data, record_length);
if (oper)
netreg->pnn_list = g_slist_prepend(netreg->pnn_list, oper);
/* If PNN is not present then OPL is not useful, don't
* retrieve it. If OPL is not there then PNN[1] will
* still be used for the HPLMN and/or EHPLMN, if PNN
* is present. */
if (record == total && g_slist_length(netreg->pnn_list) > 0)
ofono_sim_read(modem, SIM_EFOPL_FILEID, sim_opl_read_cb, NULL);
}
static void sim_ready(struct ofono_modem *modem)
{
ofono_sim_read(modem, SIM_EFPNN_FILEID, sim_pnn_read_cb, NULL);
}
int ofono_network_registration_register(struct ofono_modem *modem,
struct ofono_network_registration_ops *ops)
{

View File

@ -589,70 +589,6 @@ const char *ofono_operator_name_sim_override(struct ofono_modem *modem,
return sim->pnn[opl_op->id - 1].longname;
}
static void sim_pnn_read_cb(const struct ofono_error *error,
const unsigned char *pnndata, int length, void *data)
{
struct ofono_modem *modem = data;
struct sim_manager_data *sim = modem->sim_manager;
struct opl_operator *oper;
if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
goto skip;
if (length < sim->pnn_size)
goto skip;
pnn_operator_parse(&sim->pnn[sim->pnn_current], pnndata, length);
skip:
sim->pnn_current ++;
if (sim->pnn_current < sim->pnn_num)
sim->ops->read_file_linear(modem, SIM_EFPNN_FILEID,
sim->pnn_current,
sim->pnn_size,
sim_pnn_read_cb, modem);
else
/* All records retrieved */
/* We now need EF-OPL if it's there for PNN to be
* useful. */
sim_retrieve_opl(modem);
}
static void sim_pnn_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 < 3 ||
record_length < 3 ||
structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
/* If PNN is not present then OPL is not useful, don't
* retrieve it. If OPL is not there then PNN[1] will
* still be used for the HPLMN and/or EHPLMN, if PNN
* is present. */
return;
sim->pnn_current = 0;
sim->pnn_size = record_length;
sim->pnn_num = length / record_length;
sim->pnn = g_new0(struct pnn_operator, sim->pnn_num);
sim->ops->read_file_linear(modem, SIM_EFPNN_FILEID, 0,
record_length, sim_pnn_read_cb, modem);
}
static gboolean sim_retrieve_pnn(void *user_data)
{
struct ofono_modem *modem = user_data;
struct sim_manager_data *sim = modem->sim_manager;
sim->ops->read_file_info(modem, SIM_EFPNN_FILEID,
sim_pnn_info_cb, modem);
return FALSE;
}
static void sim_ready(struct ofono_modem *modem)
{
ofono_sim_read(modem, SIM_EFMSISDN_FILEID, sim_msisdn_read_cb, NULL);