typedef void (*ofono_sim_ready_notify_cb_t)(void *data);
-typedef void (*ofono_sim_file_read_cb_t)(int ok,
- enum ofono_sim_file_structure structure,
- int total_length, int record,
+typedef void (*ofono_sim_file_read_cb_t)(int ok, int total_length, int record,
const unsigned char *data,
int record_length, void *userdata);
* Returns 0 if the request could be queued, -1 otherwise.
*/
int ofono_sim_read(struct ofono_sim *sim, int id,
+ enum ofono_sim_file_structure expected,
ofono_sim_file_read_cb_t cb, void *data);
int ofono_sim_write(struct ofono_sim *sim, int id,
return cbs;
}
-static void sim_cbmi_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_cbmi_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
return;
- if (structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
- return;
-
if ((length % 2) == 1 || length < 2)
return;
cbs->efcbmi_contents = NULL;
}
-static void sim_cbmir_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_cbmir_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
return;
- if (structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
- return;
-
if ((length % 4) != 0)
return;
cbs->efcbmir_contents = NULL;
}
-static void sim_cbmid_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_cbmid_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
return;
- if (structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
- return;
-
if ((length % 2) == 1 || length < 2)
return;
ofono_debug("Got IMSI: %s", imsi);
ofono_sim_read(cbs->sim, SIM_EFCBMI_FILEID,
- sim_cbmi_read_cb, cbs);
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_cbmi_read_cb, cbs);
ofono_sim_read(cbs->sim, SIM_EFCBMIR_FILEID,
- sim_cbmir_read_cb, cbs);
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_cbmir_read_cb, cbs);
ofono_sim_read(cbs->sim, SIM_EFCBMID_FILEID,
- sim_cbmid_read_cb, cbs);
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_cbmid_read_cb, cbs);
}
static gboolean reset_base_station_name(gpointer user)
{ }
};
-static void mw_mwis_read_cb(int ok,
- enum ofono_sim_file_structure structure, int total_length,
- int record, const unsigned char *data, int record_length,
- void *userdata)
+static void mw_mwis_read_cb(int ok, int total_length, int record,
+ const unsigned char *data,
+ int record_length, void *userdata)
{
struct ofono_message_waiting *mw = userdata;
int i, status;
DBusConnection *conn = ofono_dbus_get_connection();
const char *path = __ofono_atom_get_path(mw->atom);
- if (!ok ||
- structure != OFONO_SIM_FILE_STRUCTURE_FIXED ||
- record_length < 5) {
+ if (!ok || record_length < 5) {
ofono_error("Unable to read waiting messages numbers "
"from SIM");
mw->efmwis_length = record_length;
}
-static void mw_mbdn_read_cb(int ok,
- enum ofono_sim_file_structure structure, int total_length,
- int record, const unsigned char *data, int record_length,
- void *userdata)
+static void mw_mbdn_read_cb(int ok, int total_length, int record,
+ const unsigned char *data,
+ int record_length, void *userdata)
{
struct ofono_message_waiting *mw = userdata;
int i;
DBusConnection *conn = ofono_dbus_get_connection();
const char *value;
- if (!ok ||
- structure != OFONO_SIM_FILE_STRUCTURE_FIXED ||
- record_length < 14 || total_length < record_length) {
+ if (!ok || record_length < 14 || total_length < record_length) {
ofono_error("Unable to read mailbox dialling numbers "
"from SIM");
mw->efmbdn_length = record_length;
}
-static void mw_mbi_read_cb(int ok,
- enum ofono_sim_file_structure structure, int total_length,
- int record, const unsigned char *data, int record_length,
- void *userdata)
+static void mw_mbi_read_cb(int ok, int total_length, int record,
+ const unsigned char *data,
+ int record_length, void *userdata)
{
struct ofono_message_waiting *mw = userdata;
int i, err;
- if (!ok ||
- structure != OFONO_SIM_FILE_STRUCTURE_FIXED ||
- record_length < 4) {
+ if (!ok || record_length < 4) {
ofono_error("Unable to read mailbox identifies "
"from SIM");
for (i = 0; i < 5 && i < record_length; i++)
mw->efmbdn_record_id[i] = data[i];
- err = ofono_sim_read(mw->sim, SIM_EFMBDN_FILEID, mw_mbdn_read_cb, mw);
+ err = ofono_sim_read(mw->sim, SIM_EFMBDN_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_FIXED,
+ mw_mbdn_read_cb, mw);
if (err != 0)
ofono_error("Unable to read EF-MBDN from SIM");
mw->sim = __ofono_atom_get_data(sim_atom);
/* Loads MWI states and MBDN from SIM */
- ofono_sim_read(mw->sim, SIM_EFMWIS_FILEID, mw_mwis_read_cb, mw);
- ofono_sim_read(mw->sim, SIM_EFMBI_FILEID, mw_mbi_read_cb, mw);
+ ofono_sim_read(mw->sim, SIM_EFMWIS_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_FIXED,
+ mw_mwis_read_cb, mw);
+ ofono_sim_read(mw->sim, SIM_EFMBI_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_FIXED,
+ mw_mbi_read_cb, mw);
}
__ofono_atom_register(mw->atom, message_waiting_unregister);
ofono_netreg_strength_notify(netreg, strength);
}
-static void sim_opl_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_opl_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
return;
}
- if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
- return;
-
if (record_length < 8 || length < record_length)
return;
}
}
-static void sim_pnn_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_pnn_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
goto check;
- if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
- return;
-
if (length < 3 || record_length < 3 || length < record_length)
return;
* is present. */
if (netreg->eons && !sim_eons_pnn_is_empty(netreg->eons))
ofono_sim_read(netreg->sim, SIM_EFOPL_FILEID,
- sim_opl_read_cb, netreg);
+ OFONO_SIM_FILE_STRUCTURE_FIXED,
+ sim_opl_read_cb, netreg);
}
-static void sim_spdi_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_spdi_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
return;
- if (structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
- return;
-
netreg->spdi = sim_spdi_new(data, length);
if (!current)
}
}
-static void sim_spn_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_spn_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
return;
- if (structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
- return;
-
dcbyte = data[0];
/* TS 31.102 says:
}
netreg->spname = spn;
- ofono_sim_read(netreg->sim, SIM_EFSPDI_FILEID, sim_spdi_read_cb, netreg);
+ ofono_sim_read(netreg->sim, SIM_EFSPDI_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_spdi_read_cb, netreg);
if (dcbyte & SIM_EFSPN_DC_HOME_PLMN_BIT)
netreg->flags |= NETWORK_REGISTRATION_FLAG_HOME_SHOW_PLMN;
netreg->sim = __ofono_atom_get_data(sim_atom);
ofono_sim_read(netreg->sim, SIM_EFPNN_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_FIXED,
sim_pnn_read_cb, netreg);
ofono_sim_read(netreg->sim, SIM_EFSPN_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
sim_spn_read_cb, netreg);
}
return TRUE;
}
-static void sim_msisdn_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_msisdn_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
goto check;
- if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
- return;
-
if (record_length < 14 || length < record_length)
return;
sim->new_numbers = NULL;
}
-static void sim_ad_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_ad_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
return;
- if (structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
- return;
-
if (length < 4)
return;
return strcmp(sdn->id, id);
}
-static void sim_sdn_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_sdn_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
if (!ok)
goto check;
- if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
- return;
-
if (record_length < 14 || length < record_length)
return;
static void sim_own_numbers_update(struct ofono_sim *sim)
{
- ofono_sim_read(sim, SIM_EFMSISDN_FILEID,
+ ofono_sim_read(sim, SIM_EFMSISDN_FILEID, OFONO_SIM_FILE_STRUCTURE_FIXED,
sim_msisdn_read_cb, sim);
}
sim_own_numbers_update(sim);
- ofono_sim_read(sim, SIM_EFAD_FILEID, sim_ad_read_cb, sim);
- ofono_sim_read(sim, SIM_EFSDN_FILEID, sim_sdn_read_cb, sim);
+ ofono_sim_read(sim, SIM_EFAD_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_ad_read_cb, sim);
+ ofono_sim_read(sim, SIM_EFSDN_FILEID, OFONO_SIM_FILE_STRUCTURE_FIXED,
+ sim_sdn_read_cb, sim);
}
static void sim_imsi_cb(const struct ofono_error *error, const char *imsi,
sim->driver->query_passwd_state(sim, sim_pin_query_cb, sim);
}
-static void sim_efli_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_efli_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
struct ofono_sim *sim = userdata;
- if (!ok || structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
+ if (!ok)
return;
sim->efli = g_memdup(data, length);
return ret;
}
-static void sim_efpl_read_cb(int ok,
- enum ofono_sim_file_structure structure,
- int length, int record,
+static void sim_efpl_read_cb(int ok, int length, int record,
const unsigned char *data,
int record_length, void *userdata)
{
GSList *efli = NULL;
GSList *efpl = NULL;
- if (!ok || structure != OFONO_SIM_FILE_STRUCTURE_TRANSPARENT ||
- length < 2)
+ if (!ok || length < 2)
goto skip_efpl;
efpl = parse_language_list(data, length);
* However we don't depend on the user interface and so
* need to read both files now.
*/
- ofono_sim_read(sim, SIM_EFLI_FILEID, sim_efli_read_cb, sim);
- ofono_sim_read(sim, SIM_EFPL_FILEID, sim_efpl_read_cb, sim);
+ ofono_sim_read(sim, SIM_EFLI_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_efli_read_cb, sim);
+ ofono_sim_read(sim, SIM_EFPL_FILEID,
+ OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+ sim_efpl_read_cb, sim);
}
static void sim_op_error(struct ofono_sim *sim)
if (op->is_read == TRUE)
((ofono_sim_file_read_cb_t) op->cb)
- (0, 0, 0, 0, 0, 0, op->userdata);
+ (0, 0, 0, 0, 0, op->userdata);
else
((ofono_sim_file_write_cb_t) op->cb)
(0, op->userdata);
return;
}
- cb(1, op->structure, op->length, op->current,
- data, op->record_length, op->userdata);
+ cb(1, op->length, op->current, data, op->record_length, op->userdata);
if (op->cache && imsi) {
char *path = g_strdup_printf(SIM_CACHE_PATH, imsi, op->id);
return;
}
+ if (structure != op->structure) {
+ ofono_error("Requested file structure differs from SIM: %x",
+ op->id);
+ sim_op_error(sim);
+ return;
+ }
+
/* TS 11.11, Section 9.3 */
update = file_access_condition_decode(access[0] & 0xf);
rehabilitate = file_access_condition_decode((access[2] >> 4) & 0xf);
if (record_length == 0 || file_length < record_length)
goto cleanup;
- if (error_type != OFONO_ERROR_TYPE_NO_ERROR) {
+ if (error_type != OFONO_ERROR_TYPE_NO_ERROR ||
+ structure != op->structure) {
ret = TRUE;
- cb(0, 0, 0, 0, 0, 0, 0);
+ cb(0, 0, 0, 0, 0, 0);
goto cleanup;
}
goto cleanup;
for (record = 0; record < file_length / record_length; record++) {
- cb(1, structure, file_length, record + 1,
- &buffer[record * record_length], record_length,
- op->userdata);
+ cb(1, file_length, record + 1, &buffer[record * record_length],
+ record_length, op->userdata);
}
ret = TRUE;
}
int ofono_sim_read(struct ofono_sim *sim, int id,
+ enum ofono_sim_file_structure expected_type,
ofono_sim_file_read_cb_t cb, void *data)
{
struct sim_file_op *op;
op = g_new0(struct sim_file_op, 1);
op->id = id;
+ op->structure = expected_type;
op->cb = cb;
op->userdata = data;
op->is_read = TRUE;
emit_en_list_changed(vc);
}
-static void ecc_read_cb(int ok, enum ofono_sim_file_structure structure,
- int total_length, int record, const unsigned char *data,
+static void ecc_read_cb(int ok, int total_length, int record, const unsigned char *data,
int record_length, void *userdata)
{
struct ofono_voicecall *vc = userdata;
if (!ok)
goto check;
- if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED ||
- record_length < 4 || total_length < record_length) {
+ if (record_length < 4 || total_length < record_length) {
ofono_error("Unable to read emergency numbers from SIM");
return;
}
return;
}
- ofono_sim_read(sim, SIM_EFECC_FILEID, ecc_read_cb, vc);
+ ofono_sim_read(sim, SIM_EFECC_FILEID, OFONO_SIM_FILE_STRUCTURE_FIXED,
+ ecc_read_cb, vc);
}
void ofono_voicecall_register(struct ofono_voicecall *vc)