From: Jukka Saunamaki <[email protected]>
Using ofono_sim_ready_notify()
---
drivers/isimodem/debug.c | 32 +++
drivers/isimodem/debug.h | 3 +
drivers/isimodem/sim.c | 537 +++++++++++++++++++++++++++++++++++++++++++---
drivers/isimodem/sim.h | 50 +++++-
4 files changed, 588 insertions(+), 34 deletions(-)
diff --git a/drivers/isimodem/debug.c b/drivers/isimodem/debug.c
index c724b41..b77a64e 100644
--- a/drivers/isimodem/debug.c
+++ b/drivers/isimodem/debug.c
@@ -48,6 +48,7 @@ const char *pn_resource_name(int value)
_(PN_CALL);
_(PN_SMS);
_(PN_SIM);
+ _(PN_SECURITY);
_(PN_MTC);
_(PN_GSS);
_(PN_GPDS);
@@ -377,18 +378,43 @@ const char *sim_message_id_name(enum sim_message_id value)
_(SIM_IMSI_RESP_READ_IMSI);
_(SIM_SERV_PROV_NAME_REQ);
_(SIM_SERV_PROV_NAME_RESP);
+ _(SIM_DYNAMIC_FLAGS_REQ);
+ _(SIM_DYNAMIC_FLAGS_RESP);
_(SIM_READ_FIELD_REQ);
_(SIM_READ_FIELD_RESP);
_(SIM_SMS_REQ);
_(SIM_SMS_RESP);
+ _(SIM_STATUS_REQ);
+ _(SIM_STATUS_RESP);
_(SIM_PB_REQ_SIM_PB_READ);
_(SIM_PB_RESP_SIM_PB_READ);
+ _(SIM_SERVER_READY_IND);
_(SIM_IND);
_(SIM_COMMON_MESSAGE);
}
+
return "SIM_<UNKNOWN>";
}
+const char *sec_message_id_name(enum sec_message_id value)
+{
+ switch (value) {
+ _(SEC_CODE_STATE_REQ);
+ _(SEC_CODE_STATE_OK_RESP);
+ _(SEC_CODE_STATE_FAIL_RESP);
+ _(SEC_CODE_CHANGE_REQ);
+ _(SEC_CODE_CHANGE_OK_RESP);
+ _(SEC_CODE_CHANGE_FAIL_RESP);
+ _(SEC_CODE_VERIFY_REQ);
+ _(SEC_CODE_VERIFY_OK_RESP);
+ _(SEC_CODE_VERIFY_FAIL_RESP);
+ _(SEC_STATE_REQ);
+ _(SEC_STATE_RESP);
+ }
+
+ return "SEC_<UNKNOWN>";
+}
+
const char *sim_subblock_name(enum sim_subblock value)
{
switch (value) {
@@ -1069,6 +1095,12 @@ void sim_debug(const void *restrict buf, size_t len,
void *data)
hex_dump(sim_message_id_name(m[0]), m, len);
}
+void sec_debug(const void *restrict buf, size_t len, void *data)
+{
+ const uint8_t *m = buf;
+ hex_dump(sec_message_id_name(m[0]), m, len);
+}
+
void info_debug(const void *restrict buf, size_t len, void *data)
{
const uint8_t *m = buf;
diff --git a/drivers/isimodem/debug.h b/drivers/isimodem/debug.h
index dbdc4de..0127010 100644
--- a/drivers/isimodem/debug.h
+++ b/drivers/isimodem/debug.h
@@ -49,6 +49,8 @@ const char *sim_isi_cause_name(enum sim_isi_cause value);
const char *sim_message_id_name(enum sim_message_id value);
const char *sim_subblock_name(enum sim_subblock value);
+const char *sec_message_id_name(enum sec_message_id value);
+
const char *info_isi_cause_name(enum info_isi_cause value);
const char *info_message_id_name(enum info_message_id value);
const char *info_subblock_name(enum info_subblock value);
@@ -78,6 +80,7 @@ void ss_debug(const void *restrict buf, size_t len, void
*data);
void mtc_debug(const void *restrict buf, size_t len, void *data);
void sms_debug(const void *restrict buf, size_t len, void *data);
void sim_debug(const void *restrict buf, size_t len, void *data);
+void sec_debug(const void *restrict buf, size_t len, void *data);
void info_debug(const void *restrict buf, size_t len, void *data);
void call_debug(const void *restrict buf, size_t len, void *data);
void net_debug(const void *restrict buf, size_t len, void *data);
diff --git a/drivers/isimodem/sim.c b/drivers/isimodem/sim.c
index b79c52a..f16cb75 100644
--- a/drivers/isimodem/sim.c
+++ b/drivers/isimodem/sim.c
@@ -45,7 +45,10 @@
struct sim_data {
GIsiClient *client;
- gboolean registered;
+ GIsiClient *sec_client;
+ enum ofono_sim_password_type passwd_state;
+ ofono_bool_t ready;
+ ofono_bool_t notify_ready;
};
struct file_info {
@@ -355,50 +358,325 @@ error:
g_free(cbd);
}
-static void isi_sim_register(struct ofono_sim *sim)
+static void isi_query_passwd_state(struct ofono_sim *sim,
+ ofono_sim_passwd_cb_t cb, void *data)
{
struct sim_data *sd = ofono_sim_get_data(sim);
+ enum ofono_sim_password_type passwd_state = sd->passwd_state;
- if (!sd->registered) {
- sd->registered = TRUE;
- ofono_sim_register(sim);
- ofono_sim_inserted_notify(sim, TRUE);
+ DBG("passwd_state %u", passwd_state);
+
+ sd->notify_ready = TRUE;
+
+ if (passwd_state == OFONO_SIM_PASSWORD_INVALID) {
+ CALLBACK_WITH_FAILURE(cb, -1, data);
+ return;
}
+
+ CALLBACK_WITH_SUCCESS(cb, passwd_state, data);
+
+ if (sd->ready)
+ ofono_sim_ready_notify(sim);
}
-static gboolean read_hplmn_resp_cb(GIsiClient *client,
+static gboolean sec_code_verify_resp(GIsiClient *client,
const void *restrict data, size_t len,
uint16_t object, void *opaque)
{
const unsigned char *msg = data;
- struct ofono_sim *sim = opaque;
+ struct isi_cb_data *cbd = opaque;
+ ofono_sim_lock_unlock_cb_t cb = cbd->cb;
+ struct ofono_sim *sim = cbd->user;
+ struct sim_data *sd = ofono_sim_get_data(sim);
- if (!msg) {
- DBG("ISI client error: %d", g_isi_client_error(client));
+ DBG("");
+
+ if (len >= 1 && msg[0] == SEC_CODE_VERIFY_OK_RESP) {
+ sd->passwd_state = OFONO_SIM_PASSWORD_NONE;
+ CALLBACK_WITH_SUCCESS(cb, cbd->data);
return TRUE;
}
- if (len < 3 || msg[0] != SIM_NETWORK_INFO_RESP || msg[1] != READ_HPLMN)
- return FALSE;
+ if (len >= 2 && msg[0] == SEC_CODE_VERIFY_FAIL_RESP &&
+ msg[1] == SEC_CAUSE_CODE_BLOCKED)
+ sd->passwd_state = OFONO_SIM_PASSWORD_SIM_PUK;
+
+ DBG("verify failure %s", !msg ? "(timeout)" : "");
+ CALLBACK_WITH_FAILURE(cb, cbd->data);
+ return TRUE;
+}
+
+static void isi_send_passwd(struct ofono_sim *sim, const char *passwd,
+ ofono_sim_lock_unlock_cb_t cb, void *data)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+ struct isi_cb_data *cbd = isi_cb_data_new(sim, cb, data);
+ unsigned char msg[2 + SEC_CODE_MAX_LENGTH + 1] = {
+ SEC_CODE_VERIFY_REQ,
+ SEC_CODE_PIN,
+ };
+ int len = 2 + strlen(passwd) + 1;
+
+ DBG("");
+
+ if (!cbd)
+ goto error;
+
+ strcpy((char *) msg + 2, passwd);
+
+ if (g_isi_send(sd->sec_client, msg, len, SIM_TIMEOUT,
+ sec_code_verify_resp, cbd, g_free))
+ return;
+
+error:
+ g_free(cbd);
+ CALLBACK_WITH_FAILURE(cb, data);
+}
+
+static void isi_reset_passwd(struct ofono_sim *sim,
+ const char *puk, const char *passwd,
+ ofono_sim_lock_unlock_cb_t cb, void *data)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+ struct isi_cb_data *cbd = isi_cb_data_new(sim, cb, data);
+ enum ofono_sim_password_type passwd_type = OFONO_SIM_PASSWORD_SIM_PIN;
+ unsigned char msg[2 + 2 * (SEC_CODE_MAX_LENGTH + 1)] = {
+ SEC_CODE_VERIFY_REQ,
+ };
+
+ DBG("");
+
+ if (!cbd)
+ goto error;
+
+ if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN)
+ msg[1] = SEC_CODE_PIN;
+ else if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN2)
+ msg[1] = SEC_CODE_PIN2;
+ else
+ goto error;
+
+ strcpy((char *) &msg[2], puk);
+ strcpy((char *) &msg[2 + SEC_CODE_MAX_LENGTH + 1], passwd);
+
+ if (g_isi_send(sd->sec_client, msg, sizeof(msg), SIM_TIMEOUT,
+ sec_code_verify_resp, cbd, g_free))
+ return;
+
+error:
+ g_free(cbd);
+ CALLBACK_WITH_FAILURE(cb, data);
+}
- if (msg[2] != SIM_SERV_NOTREADY)
- isi_sim_register(sim);
+
+/* ISI callback: Enable/disable PIN */
+static gboolean pin_enable_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;
+ ofono_sim_lock_unlock_cb_t cb = cbd->cb;
+
+ DBG("");
+
+ if (len < 1 || msg[0] != SEC_CODE_STATE_OK_RESP)
+ CALLBACK_WITH_FAILURE(cb, cbd->data);
+ else
+ CALLBACK_WITH_SUCCESS(cb, cbd->data);
return TRUE;
}
+static void isi_lock(struct ofono_sim *sim,
+ enum ofono_sim_password_type passwd_type,
+ int enable, const char *passwd,
+ ofono_sim_lock_unlock_cb_t cb, void *data)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+ struct isi_cb_data *cbd = isi_cb_data_new(sim, cb, data);
+ unsigned char msg[3 + SEC_CODE_MAX_LENGTH + 1] = {
+ SEC_CODE_STATE_REQ,
+ };
+
+ if (!cbd)
+ goto error;
+
+ DBG("enable %d pintype %d pass %s", enable, passwd_type, passwd);
-static void isi_read_hplmn(struct ofono_sim *sim)
+ if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN)
+ msg[1] = SEC_CODE_PIN;
+ else if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN2)
+ msg[1] = SEC_CODE_PIN2;
+ else
+ goto error;
+
+ if (enable)
+ msg[2] = SEC_CODE_ENABLE;
+ else
+ msg[2] = SEC_CODE_DISABLE;
+
+ strcpy((char *) &msg[3], passwd);
+
+ if (g_isi_send(sd->sec_client, msg, sizeof(msg), SIM_TIMEOUT,
+ pin_enable_resp_cb, cbd, g_free))
+ return;
+
+error:
+ g_free(cbd);
+ CALLBACK_WITH_FAILURE(cb, data);
+}
+
+
+
+/* ISI callback: PIN state (enabled/disabled) query */
+static gboolean sec_code_change_resp(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;
+ ofono_sim_lock_unlock_cb_t cb = cbd->cb;
+
+ if (len < 1)
+ goto failure;
+
+ if (msg[0] != SEC_CODE_CHANGE_OK_RESP) {
+ if (msg[0] == SEC_CODE_CHANGE_FAIL_RESP && len >= 2)
+ DBG("SEC_CODE_CHANGE_FAIL_RESP(cause=%02x)", msg[1]);
+
+ goto failure;
+ }
+
+ CALLBACK_WITH_SUCCESS(cb, cbd->data);
+ return TRUE;
+
+failure:
+ CALLBACK_WITH_FAILURE(cb, cbd->data);
+ return TRUE;
+}
+
+
+static void isi_change_passwd(struct ofono_sim *sim,
+ enum ofono_sim_password_type passwd_type,
+ const char *old, const char *new,
+ ofono_sim_lock_unlock_cb_t cb, void *data)
{
struct sim_data *sd = ofono_sim_get_data(sim);
+ struct isi_cb_data *cbd = isi_cb_data_new(sim, cb, data);
+ unsigned char msg[2 + 2 * (SEC_CODE_MAX_LENGTH + 1)] = {
+ SEC_CODE_CHANGE_REQ,
+ };
- const unsigned char req[] = {
- SIM_NETWORK_INFO_REQ,
- READ_HPLMN, 0
+ DBG("passwd_type %d", passwd_type);
+
+ if (!cbd)
+ goto error;
+
+ if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN)
+ msg[1] = SEC_CODE_PIN;
+ else if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN2)
+ msg[1] = SEC_CODE_PIN2;
+ else
+ goto error;
+
+ strcpy((char *) &msg[2], old);
+ strcpy((char *) &msg[2 + SEC_CODE_MAX_LENGTH + 1], new);
+
+ if (g_isi_send(sd->sec_client, msg, sizeof(msg), SIM_TIMEOUT,
+ sec_code_change_resp, cbd, g_free))
+ return;
+
+error:
+ g_free(cbd);
+ CALLBACK_WITH_FAILURE(cb, data);
+}
+
+
+/* ISI callback: PIN state (enabled/disabled) query */
+static gboolean sec_code_state_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;
+ ofono_sim_locked_cb_t cb = cbd->cb;
+ int locked;
+
+ if (msg == NULL || len < 4)
+ goto failure;
+
+ if (msg[0] != SEC_CODE_STATE_OK_RESP)
+ goto failure;
+
+ DBG("sec state: %02x", msg[1]);
+
+ switch (msg[1]) {
+ case SEC_CODE_ENABLE:
+ locked = 1;
+ break;
+ case SEC_CODE_DISABLE:
+ locked = 0;
+ break;
+ default:
+ goto failure;
+ }
+
+ CALLBACK_WITH_SUCCESS(cb, locked, cbd->data);
+ return TRUE;
+
+failure:
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ return TRUE;
+}
+
+static void isi_query_locked(struct ofono_sim *sim,
+ enum ofono_sim_password_type passwd_type,
+ ofono_sim_locked_cb_t cb, void *data)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+ struct isi_cb_data *cbd = isi_cb_data_new(sim, cb, data);
+
+ unsigned char msg[] = {
+ SEC_CODE_STATE_REQ,
+ 0,
+ SEC_CODE_STATE_QUERY
};
- g_isi_request_make(sd->client, req, sizeof(req), SIM_TIMEOUT,
- read_hplmn_resp_cb, sim);
+ DBG("");
+
+ if (!cbd)
+ goto error;
+
+ if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN)
+ msg[1] = SEC_CODE_PIN;
+ else if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN2)
+ msg[1] = SEC_CODE_PIN2;
+ else
+ goto error;
+
+ if (g_isi_send(sd->sec_client, msg, sizeof(msg),
+ SIM_TIMEOUT, sec_code_state_resp_cb, cbd, g_free))
+ return;
+
+error:
+ g_free(cbd);
+ CALLBACK_WITH_FAILURE(cb, -1, data);
+}
+
+static void sim_set_passwd_state(struct ofono_sim *sim,
+ enum ofono_sim_password_type pin_type)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+
+ sd->passwd_state = pin_type;
+
+ if (pin_type != OFONO_SIM_PASSWORD_NONE) {
+ sd->ready = FALSE;
+ sd->notify_ready = FALSE;
+ }
+
+ ofono_sim_inserted_notify(sim, pin_type != OFONO_SIM_PASSWORD_INVALID);
}
static void sim_ind_cb(GIsiClient *client,
@@ -406,22 +684,185 @@ static void sim_ind_cb(GIsiClient *client,
uint16_t object, void *opaque)
{
struct ofono_sim *sim = opaque;
+ const unsigned char *msg = data;
+ uint8_t service;
+ uint8_t status;
+
+ DBG("");
+ if (!msg || len < 5 ||
+ (msg[0] != SIM_IND && msg[0] != SIM_SERVER_READY_IND))
+ return;
+
+ service = msg[1];
+ status = msg[2];
+
+ if (status == SIM_SERV_PIN_VERIFY_REQUIRED && service == SIM_ST_PIN)
+ sim_set_passwd_state(sim, OFONO_SIM_PASSWORD_SIM_PIN);
+ else if (status == SIM_SERV_SIM_BLOCKED)
+ sim_set_passwd_state(sim, OFONO_SIM_PASSWORD_SIM_PUK);
+ else if (status == SIM_SERV_INIT_OK && service == SIM_ST_INFO)
+ sim_set_passwd_state(sim, OFONO_SIM_PASSWORD_NONE);
+ else if (status == SIM_SERV_SIM_DISCONNECTED)
+ sim_set_passwd_state(sim, OFONO_SIM_PASSWORD_INVALID);
+}
+
+static void sim_server_ready_ind_cb(GIsiClient *client,
+ const void *restrict data, size_t len,
+ uint16_t object, void *opaque)
+{
+ struct ofono_sim *sim = opaque;
struct sim_data *sd = ofono_sim_get_data(sim);
const unsigned char *msg = data;
- if (sd->registered)
+ DBG("");
+
+ if (!msg || len < 5 || msg[0] != SIM_SERVER_READY_IND)
return;
+ sd->ready = TRUE;
+
+ if (sd->notify_ready)
+ ofono_sim_ready_notify(sim);
+}
+
+static gboolean isi_sim_read_dyn_flags_resp(GIsiClient *client,
+ const void *restrict data, size_t len,
+ uint16_t object, void *opaque)
+{
+ const unsigned char *msg = data;
+ struct ofono_sim *sim = opaque;
+ struct sim_data *sd = ofono_sim_get_data(sim);
+
+ if (!msg)
+ return TRUE;
+
+ if (len < 2 || msg[0] != SIM_DYNAMIC_FLAGS_RESP)
+ return FALSE;
+
+ if (msg[1] != READ_DYN_FLAGS || msg[2] == SIM_SERV_NOTREADY)
+ return TRUE;
+
+ sd->ready = TRUE;
+
+ if (sd->notify_ready)
+ ofono_sim_ready_notify(sim);
+
+ return TRUE;
+}
+
+static void isi_sim_read_dyn_flags_req(struct ofono_sim *sim)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+
+ unsigned char req[] = {
+ SIM_DYNAMIC_FLAGS_REQ,
+ READ_DYN_FLAGS,
+ 0
+ };
+
+ g_isi_send(sd->client, req, sizeof(req), SIM_TIMEOUT,
+ isi_sim_read_dyn_flags_resp, sim, NULL);
+}
+
+static gboolean sec_state_resp_cb(GIsiClient *client,
+ const void *restrict data, size_t len,
+ uint16_t object, void *opaque)
+{
+ const unsigned char *msg = data;
+ struct ofono_sim *sim = opaque;
+
+ DBG("");
+
+ if (!msg) {
+ DBG("ISI client error: %d", g_isi_client_error(client));
+ return TRUE;
+ }
+
+ if (len < 2 || msg[0] != SEC_STATE_RESP)
+ return FALSE;
+
switch (msg[1]) {
- case SIM_ST_PIN:
- isi_sim_register(sim);
+ case SEC_STARTUP_OK:
+ DBG("SEC_STARTUP_OK");
+ sim_set_passwd_state(sim, OFONO_SIM_PASSWORD_NONE);
+ /* Check if SIM server is already ready */
+ isi_sim_read_dyn_flags_req(sim);
break;
- case SIM_ST_INFO:
- isi_read_hplmn(sim);
+
+ case SEC_CAUSE_PIN_REQUIRED:
+ DBG("SEC_CAUSE_PIN_REQUIRED");
+ sim_set_passwd_state(sim, OFONO_SIM_PASSWORD_SIM_PIN);
+ break;
+
+ case SEC_CAUSE_PUK_REQUIRED:
+ DBG("SEC_CAUSE_PUK_REQUIRED");
+ sim_set_passwd_state(sim, OFONO_SIM_PASSWORD_SIM_PIN);
+ break;
+
+ case SEC_CAUSE_NO_SIM:
+ DBG("SEC_CAUSE_NO_SIM");
+ break;
+
+ case SEC_CAUSE_INVALID_SIM:
+ DBG("SEC_CAUSE_INVALID_SIM");
+ break;
+
+ case SEC_CAUSE_SIM_REJECTED:
+ DBG("SEC_CAUSE_SIM_REJECTED");
+ break;
+
+ default:
break;
}
+
+ return TRUE;
}
+static void isi_sec_state_req(struct ofono_sim *sim)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+
+ unsigned char req[] = {
+ SEC_STATE_REQ,
+ 0,
+ 0
+ };
+
+ g_isi_send(sd->sec_client, req, sizeof(req), SIM_TIMEOUT,
+ sec_state_resp_cb, sim, NULL);
+}
+
+static gboolean sim_status_resp_cb(GIsiClient *client,
+ const void *restrict data, size_t len,
+ uint16_t object, void *opaque)
+{
+ const unsigned char *msg = data;
+ struct ofono_sim *sim = opaque;
+
+ if (!msg || len < 3)
+ return TRUE;
+
+ if (msg[0] == SIM_STATUS_RESP && msg[1] == SIM_ST_CARD_STATUS &&
+ msg[2] != SIM_SERV_SIM_DISCONNECTED)
+ /* We probably have a SIM. Now get PIN/PUK status */
+ isi_sec_state_req(sim);
+
+ return TRUE;
+}
+
+static void isi_sim_status_req(struct ofono_sim *sim)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+ const unsigned char req[] = {
+ SIM_STATUS_REQ,
+ SIM_ST_CARD_STATUS
+ };
+
+ g_isi_send(sd->client, req, sizeof(req), SIM_TIMEOUT,
+ sim_status_resp_cb, sim, NULL);
+}
+
+
static void sim_reachable_cb(GIsiClient *client, gboolean alive,
uint16_t object, void *opaque)
{
@@ -439,33 +880,56 @@ static void sim_reachable_cb(GIsiClient *client, gboolean
alive,
g_isi_version_minor(client));
g_isi_subscribe(client, SIM_IND, sim_ind_cb, opaque);
+ g_isi_subscribe(client, SIM_SERVER_READY_IND,
+ sim_server_ready_ind_cb, opaque);
- /* Check if SIM is ready. */
- isi_read_hplmn(sim);
+ ofono_sim_register(sim);
+
+ /* Check if we have a SIM */
+ isi_sim_status_req(sim);
}
static int isi_sim_probe(struct ofono_sim *sim, unsigned int vendor,
void *user)
{
GIsiModem *idx = user;
- struct sim_data *sd = g_try_new0(struct sim_data, 1);
+ struct sim_data *sd;
+ GIsiClient *client = NULL;
+ GIsiClient *sec_client = NULL;
const char *debug = getenv("OFONO_ISI_DEBUG");
+ sd = g_try_new0(struct sim_data, 1);
if (sd == NULL)
- return -ENOMEM;
+ goto error;
- sd->client = g_isi_client_create(idx, PN_SIM);
- if (sd->client == NULL)
- return -ENOMEM;
+ client = g_isi_client_create(idx, PN_SIM);
+ if (client == NULL)
+ goto error;
+
+ sec_client = g_isi_client_create(idx, PN_SECURITY);
+ if (sec_client == NULL)
+ goto error;
+
+ sd->client = client;
+ sd->sec_client = sec_client;
+ sd->passwd_state = OFONO_SIM_PASSWORD_INVALID;
ofono_sim_set_data(sim, sd);
- if (debug && (strcmp(debug, "all") == 0 || strcmp(debug, "sim") == 0))
+ if (debug != NULL && (!strcmp(debug, "all") || !strcmp(debug, "sim"))) {
g_isi_client_set_debug(sd->client, sim_debug, NULL);
+ g_isi_client_set_debug(sd->sec_client, sec_debug, NULL);
+ }
g_isi_verify(sd->client, sim_reachable_cb, sim);
return 0;
+
+error:
+ g_isi_client_destroy(client);
+ g_isi_client_destroy(sec_client);
+
+ return -ENOMEM;
}
static void isi_sim_remove(struct ofono_sim *sim)
@@ -477,6 +941,7 @@ static void isi_sim_remove(struct ofono_sim *sim)
ofono_sim_set_data(sim, NULL);
g_isi_client_destroy(data->client);
+ g_isi_client_destroy(data->sec_client);
g_free(data);
}
@@ -492,6 +957,12 @@ static struct ofono_sim_driver driver = {
.write_file_linear = isi_write_file_linear,
.write_file_cyclic = isi_write_file_cyclic,
.read_imsi = isi_read_imsi,
+ .query_passwd_state = isi_query_passwd_state,
+ .send_passwd = isi_send_passwd,
+ .reset_passwd = isi_reset_passwd,
+ .lock = isi_lock,
+ .change_passwd = isi_change_passwd,
+ .query_locked = isi_query_locked,
};
void isi_sim_init()
diff --git a/drivers/isimodem/sim.h b/drivers/isimodem/sim.h
index f1d9f47..f416666 100644
--- a/drivers/isimodem/sim.h
+++ b/drivers/isimodem/sim.h
@@ -27,9 +27,12 @@ extern "C" {
#endif
#define PN_SIM 0x09
+#define PN_SECURITY 0x08
#define SIM_TIMEOUT 5
#define SIM_MAX_IMSI_LENGTH 15
+#define SEC_CODE_MAX_LENGTH 0x0A
+
enum sim_isi_cause {
SIM_SERV_NOT_AVAIL = 0x00,
SIM_SERV_OK = 0x01,
@@ -131,29 +134,74 @@ enum sim_message_id {
SIM_IMSI_RESP_READ_IMSI = 0x1E,
SIM_SERV_PROV_NAME_REQ = 0x21,
SIM_SERV_PROV_NAME_RESP = 0x22,
+ SIM_DYNAMIC_FLAGS_REQ = 0x29,
+ SIM_DYNAMIC_FLAGS_RESP = 0x2A,
SIM_READ_FIELD_REQ = 0xBA,
SIM_READ_FIELD_RESP = 0xBB,
SIM_SMS_REQ = 0xBC,
SIM_SMS_RESP = 0xBD,
+ SIM_STATUS_REQ = 0xC0,
+ SIM_STATUS_RESP = 0xC1,
SIM_PB_REQ_SIM_PB_READ = 0xDC,
SIM_PB_RESP_SIM_PB_READ = 0xDD,
+ SIM_SERVER_READY_IND = 0xED,
SIM_IND = 0xEF,
SIM_COMMON_MESSAGE = 0xF0
};
enum sim_service_type {
+ SIM_ST_CARD_STATUS = 0x00,
SIM_ST_PIN = 0x01,
SIM_ST_ALL_SERVICES = 0x05,
SIM_ST_INFO = 0x0D,
- SIM_ST_READ_SERV_PROV_NAME = 0x2C,
SIM_PB_READ = 0x0F,
+ SIM_ST_READ_SERV_PROV_NAME = 0x2C,
READ_IMSI = 0x2D,
READ_HPLMN = 0x2F,
+ READ_DYN_FLAGS = 0x35,
READ_PARAMETER = 0x52,
UPDATE_PARAMETER = 0x53,
ICC = 0x66,
};
+enum sec_message_id {
+ SEC_CODE_STATE_REQ = 0x01,
+ SEC_CODE_STATE_OK_RESP = 0x02,
+ SEC_CODE_STATE_FAIL_RESP = 0x03,
+ SEC_CODE_CHANGE_REQ = 0x04,
+ SEC_CODE_CHANGE_OK_RESP = 0x05,
+ SEC_CODE_CHANGE_FAIL_RESP = 0x06,
+ SEC_CODE_VERIFY_REQ = 0x07,
+ SEC_CODE_VERIFY_OK_RESP = 0x08,
+ SEC_CODE_VERIFY_FAIL_RESP = 0x09,
+ SEC_STATE_REQ = 0x11,
+ SEC_STATE_RESP = 0x12,
+};
+
+enum sec_code_id_info {
+ SEC_CODE_PIN = 0x02,
+ SEC_CODE_PUK = 0x03,
+ SEC_CODE_PIN2 = 0x04,
+ SEC_CODE_PUK2 = 0x05,
+};
+
+enum sec_code_state_info {
+ SEC_CODE_DISABLE = 0x00,
+ SEC_CODE_ENABLE = 0x01,
+ SEC_CODE_STATE_QUERY = 0x04,
+};
+
+enum sec_state_cause_info {
+ SEC_CAUSE_PIN_REQUIRED = 0x02,
+ SEC_CAUSE_PUK_REQUIRED = 0x03,
+ SEC_STARTUP_OK = 0x05,
+ SEC_STARTUP_ONGOING = 0x07,
+ SEC_CAUSE_CODE_BLOCKED = 0x08,
+ SEC_CAUSE_NO_SIM = 0x16,
+ SEC_CAUSE_SIM_REJECTED = 0x1A,
+ SEC_CAUSE_INVALID_SIM = 0x1E,
+};
+
#ifdef __cplusplus
};
#endif
--
1.7.1
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono