summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-07-27 16:53:03 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-07-27 17:09:56 -0500
commit555e2e689d3d9b32f5c7946dc37d28bad12ba1c3 (patch)
tree56a28abc6c334593d9e0adcc0ce9a94bc1095e6e /src
parent5fcbc68f3e54a00580747d33851134cdebd03b69 (diff)
downloadofono-555e2e689d3d9b32f5c7946dc37d28bad12ba1c3.tar.bz2
Refactor SIM file access code
SIM File Access conditions would be reported similarly between various stacks, so it seems like the core logic of figuring out the access conditions belongs up in the daemon. This also fixes various problems, including: - access conditions read from bytes 10-12, instead of 9-11. - read/update, invalidate/rehabilitate and increase conditions read from the wrong bits (0-3 instead of 4-7 and vice versa)
Diffstat (limited to 'src')
-rw-r--r--src/driver.h21
-rw-r--r--src/sim.c22
-rw-r--r--src/simutil.h17
3 files changed, 33 insertions, 27 deletions
diff --git a/src/driver.h b/src/driver.h
index dfd28a0f..928c20a2 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -101,25 +101,6 @@ enum ofono_sim_file_structure {
OFONO_SIM_FILE_STRUCTURE_CYCLIC = 3
};
-/* 51.011 Section 9.3 */
-enum ofono_sim_file_access {
- OFONO_SIM_FILE_ACCESS_ALWAYS = 0,
- OFONO_SIM_FILE_ACCESS_CHV1 = 1,
- OFONO_SIM_FILE_ACCESS_CHV2 = 2,
- OFONO_SIM_FILE_ACCESS_RESERVED = 3,
- OFONO_SIM_FILE_ACCESS_ADM = 4,
- OFONO_SIM_FILE_ACCESS_NEVER = 15,
-};
-
-enum ofono_sim_file_condition {
- OFONO_SIM_FILE_CONDITION_READ = 0,
- OFONO_SIM_FILE_CONDITION_UPDATE,
- OFONO_SIM_FILE_CONDITION_INCREASE,
- OFONO_SIM_FILE_CONDITION_INVALIDATE,
- OFONO_SIM_FILE_CONDITION_REHABILITATE,
- __OFONO_SIM_FILE_CONDITION_NUM,
-};
-
/* Notification functions, the integer values here should map to
* values obtained from the modem. The enumerations are the same
* as the values for the fields found in 3GPP TS 27.007
@@ -182,7 +163,7 @@ typedef void (*ofono_sim_file_info_cb_t)(const struct ofono_error *error,
int filelength,
enum ofono_sim_file_structure structure,
int recordlength,
- enum ofono_sim_file_access *access,
+ const unsigned char access[3],
void *data);
typedef void (*ofono_sim_read_cb_t)(const struct ofono_error *error,
diff --git a/src/sim.c b/src/sim.c
index 8119b5c3..ff4e63dc 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -417,30 +417,38 @@ static gboolean sim_op_retrieve_next(gpointer user)
static void sim_op_info_cb(const struct ofono_error *error, int length,
enum ofono_sim_file_structure structure,
int record_length,
- enum ofono_sim_file_access *access, void *data)
+ const unsigned char access[3], void *data)
{
struct ofono_modem *modem = data;
struct sim_manager_data *sim = modem->sim_manager;
struct sim_file_op *op = g_queue_peek_head(sim->simop_q);
-
char *imsi = sim->imsi;
char *path;
unsigned char fileinfo[6];
int fd = -1;
+ enum sim_file_access update;
+ enum sim_file_access invalidate;
+ enum sim_file_access rehabilitate;
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
sim_op_error(modem);
return;
}
+ /* TS 11.11, Section 9.3 */
+ update = file_access_condition_decode(access[0] & 0xf);
+ rehabilitate = file_access_condition_decode((access[2] >> 4) & 0xf);
+ invalidate = file_access_condition_decode(access[2] & 0xf);
+
op->structure = structure;
op->length = length;
/* Never cache card holder writable files */
- op->cache = (
- access[OFONO_SIM_FILE_CONDITION_UPDATE] ==
- OFONO_SIM_FILE_ACCESS_ADM ||
- access[OFONO_SIM_FILE_CONDITION_UPDATE] ==
- OFONO_SIM_FILE_ACCESS_NEVER);
+ op->cache = (update == SIM_FILE_ACCESS_ADM ||
+ update == SIM_FILE_ACCESS_NEVER) &&
+ (invalidate == SIM_FILE_ACCESS_ADM ||
+ invalidate == SIM_FILE_ACCESS_NEVER) &&
+ (rehabilitate == SIM_FILE_ACCESS_ADM ||
+ rehabilitate == SIM_FILE_ACCESS_NEVER);
if (structure == OFONO_SIM_FILE_STRUCTURE_TRANSPARENT)
op->record_length = length;
diff --git a/src/simutil.h b/src/simutil.h
index d74706a2..d6526fca 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -27,6 +27,16 @@ enum sim_fileid {
SIM_EFSPDI_FILEID = 0x6fcd,
};
+/* 51.011 Section 9.3 */
+enum sim_file_access {
+ SIM_FILE_ACCESS_ALWAYS = 0,
+ SIM_FILE_ACCESS_CHV1 = 1,
+ SIM_FILE_ACCESS_CHV2 = 2,
+ SIM_FILE_ACCESS_RESERVED = 3,
+ SIM_FILE_ACCESS_ADM = 4,
+ SIM_FILE_ACCESS_NEVER = 15,
+};
+
#define SIM_EFSPN_DC_HOME_PLMN_BIT 0x1
#define SIM_EFSPN_DC_ROAMING_SPN_BIT 0x2
@@ -59,3 +69,10 @@ struct sim_spdi *sim_spdi_new(const guint8 *tlv, int length);
gboolean sim_spdi_lookup(struct sim_spdi *spdi,
const char *mcc, const char *mnc);
void sim_spdi_free(struct sim_spdi *spdi);
+
+static inline enum sim_file_access file_access_condition_decode(int bcd)
+{
+ if (bcd >= 4 && bcd <= 14)
+ return SIM_FILE_ACCESS_ADM;
+ return bcd;
+}