atmodem: implement standard PIN retries

This commit is contained in:
Rémi Denis-Courmont 2011-01-31 14:48:20 +02:00 committed by Marcel Holtmann
parent 1f0318d244
commit 56dfe5066b
1 changed files with 48 additions and 0 deletions

View File

@ -57,6 +57,7 @@ static const char *cpin_prefix[] = { "+CPIN:", NULL };
static const char *clck_prefix[] = { "+CLCK:", NULL };
static const char *huawei_cpin_prefix[] = { "^CPIN:", NULL };
static const char *xpincnt_prefix[] = { "+XPINCNT:", NULL };
static const char *cpinr_prefixes[] = { "+CPINR:", "+CPINRE:", NULL };
static const char *none_prefix[] = { NULL };
static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
@ -554,6 +555,50 @@ error:
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
}
static void at_cpinr_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
ofono_sim_pin_retries_cb_t cb = cbd->cb;
GAtResultIter iter;
struct ofono_error error;
int retries[OFONO_SIM_PASSWORD_INVALID];
size_t len = sizeof(at_sim_name) / sizeof(*at_sim_name);
size_t i;
decode_at_error(&error, g_at_result_final_response(result));
if (!ok) {
cb(&error, NULL, cbd->data);
return;
}
for (i = 0; i < OFONO_SIM_PASSWORD_INVALID; i++)
retries[i] = -1;
g_at_result_iter_init(&iter, result);
/* Ignore +CPINRE results... */
while (g_at_result_iter_next(&iter, "+CPINR:")) {
const char *name;
int val;
if (!g_at_result_iter_next_unquoted_string(&iter, &name))
continue;
if (!g_at_result_iter_next_number(&iter, &val))
continue;
for (i = 1; i < len; i++) {
if (!strcmp(name, at_sim_name[i].name)) {
retries[i] = val;
break;
}
}
}
cb(&error, retries, cbd->data);
}
static void at_pin_retries_query(struct ofono_sim *sim,
ofono_sim_pin_retries_cb_t cb,
void *data)
@ -577,6 +622,9 @@ static void at_pin_retries_query(struct ofono_sim *sim,
break;
default:
if (g_at_chat_send(sd->chat, "AT+CPINR", cpinr_prefixes,
at_cpinr_cb, cbd, g_free) > 0)
return;
break;
}