* [sim-reset-pin PATCH 0/4] sim: better PIN reset
@ 2010-08-26 12:49 Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver Pekka.Pessi
0 siblings, 1 reply; 8+ messages in thread
From: Pekka.Pessi @ 2010-08-26 12:49 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 613 bytes --]
Hello all,
As I've said, I've toyed with PINs and PUKs.
The first two patches deal with resetting the PIN code with PUK. In order
to reset the password, the modem must request for the PIN in first
place. Normally that is easy, driver gets +CPIN: SIM PUK response. However,
some (buggy?) SIM cards allow registering to network if the PIN was unlocked
before it got PUKed (and respond with +CPIN: READY).
Therefore, the pin reset now tries to trigger the appropriate +CPIN: SIM
PUK* state. Triggering is always needed for PIN2.
The two later patches add shell utilities for testing.
--Pekka
^ permalink raw reply [flat|nested] 8+ messages in thread
* [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver
2010-08-26 12:49 [sim-reset-pin PATCH 0/4] sim: better PIN reset Pekka.Pessi
@ 2010-08-26 12:49 ` Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Pekka.Pessi
2010-08-26 15:10 ` [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver Denis Kenzior
0 siblings, 2 replies; 8+ messages in thread
From: Pekka.Pessi @ 2010-08-26 12:49 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1775 bytes --]
From: Pekka Pessi <Pekka.Pessi@nokia.com>
---
include/sim.h | 5 +++--
src/sim.c | 9 +++++++--
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/sim.h b/include/sim.h
index 36a99b9..d3e564c 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -143,8 +143,9 @@ struct ofono_sim_driver {
ofono_sim_passwd_cb_t cb, void *data);
void (*send_passwd)(struct ofono_sim *sim, const char *passwd,
ofono_sim_lock_unlock_cb_t cb, void *data);
- void (*reset_passwd)(struct ofono_sim *sim, const char *puk,
- const char *passwd,
+ void (*reset_passwd)(struct ofono_sim *sim,
+ enum ofono_sim_password_type type,
+ const char *puk, const char *passwd,
ofono_sim_lock_unlock_cb_t cb, void *data);
void (*change_passwd)(struct ofono_sim *sim,
enum ofono_sim_password_type type,
diff --git a/src/sim.c b/src/sim.c
index 04a708b..bac77e0 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -753,8 +753,13 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, DBusMessage *msg,
type = sim_string_to_passwd(typestr);
- if (type == OFONO_SIM_PASSWORD_NONE || type != sim->pin_type)
+ switch (type) {
+ case OFONO_SIM_PASSWORD_SIM_PIN:
+ case OFONO_SIM_PASSWORD_SIM_PIN2:
+ break;
+ default:
return __ofono_error_invalid_format(msg);
+ }
if (!is_valid_pin(puk, PIN_TYPE_PUK))
return __ofono_error_invalid_format(msg);
@@ -763,7 +768,7 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, DBusMessage *msg,
return __ofono_error_invalid_format(msg);
sim->pending = dbus_message_ref(msg);
- sim->driver->reset_passwd(sim, puk, pin, sim_enter_pin_cb, sim);
+ sim->driver->reset_passwd(sim, type, puk, pin, sim_enter_pin_cb, sim);
return NULL;
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2
2010-08-26 12:49 ` [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver Pekka.Pessi
@ 2010-08-26 12:49 ` Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 3/4] Added test/change-pin Pekka.Pessi
2010-08-26 15:13 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Denis Kenzior
2010-08-26 15:10 ` [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver Denis Kenzior
1 sibling, 2 replies; 8+ messages in thread
From: Pekka.Pessi @ 2010-08-26 12:49 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 4867 bytes --]
From: Pekka Pessi <Pekka.Pessi@nokia.com>
The PIN or PIN2 reset requires that modem waits for corresponding PUK code.
If PIN is unlocked, modem does not wait for PUK code. Modem does not wait
for PUK2 by default. The modem is triggered into a state waiting for PUK
codes with AT+CPWD command.
Password reset may fail if some other command is executed between AT+CPWD,
AT+CPIN? and AT+CPIN.
---
drivers/atmodem/sim.c | 130 ++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 102 insertions(+), 28 deletions(-)
diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index 21bc933..2f68b5f 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -44,6 +44,7 @@
struct sim_data {
GAtChat *chat;
unsigned int vendor;
+ enum ofono_sim_password_type cpin_type;
guint epev_id;
guint epev_source;
};
@@ -459,6 +460,8 @@ static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
int len = sizeof(at_sim_name) / sizeof(*at_sim_name);
const char *final = g_at_result_final_response(result);
+ sd->cpin_type = OFONO_SIM_PASSWORD_NONE;
+
if (sd->vendor == OFONO_VENDOR_WAVECOM && ok && strlen(final) > 7)
decode_at_error(&error, "OK");
else
@@ -498,6 +501,8 @@ static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
DBG("crsm_pin_cb: %s", pin_required);
+ sd->cpin_type = pin_type;
+
cb(&error, pin_type, cbd->data);
}
@@ -616,34 +621,6 @@ error:
CALLBACK_WITH_FAILURE(cb, data);
}
-static void at_pin_send_puk(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 cb_data *cbd = cb_data_new(cb, data);
- char buf[64];
- int ret;
-
- if (!cbd)
- goto error;
-
- snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\",\"%s\"", puk, passwd);
-
- ret = g_at_chat_send(sd->chat, buf, none_prefix,
- at_lock_unlock_cb, cbd, g_free);
-
- memset(buf, 0, sizeof(buf));
-
- if (ret > 0)
- return;
-
-error:
- g_free(cbd);
-
- CALLBACK_WITH_FAILURE(cb, data);
-}
-
static const char *const at_clck_cpwd_fac[] = {
[OFONO_SIM_PASSWORD_SIM_PIN] = "SC",
[OFONO_SIM_PASSWORD_SIM_PIN2] = "P2",
@@ -724,6 +701,103 @@ error:
CALLBACK_WITH_FAILURE(cb, data);
}
+struct at_pin_reset_data {
+ struct cb_data base;
+ enum ofono_sim_password_type type;
+ char puk[9];
+ char pin[9];
+};
+
+static void at_pin_query_result(const struct ofono_error *error,
+ enum ofono_sim_password_type pin_type,
+ void *data)
+{
+ struct at_pin_reset_data *cbd = data;
+ struct sim_data *sd = ofono_sim_get_data(cbd->base.user);
+ ofono_sim_lock_unlock_cb_t cb = cbd->base.cb;
+ void *user_data = cbd->base.data;
+ char buf[64];
+ int ret;
+
+ if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
+ goto failed;
+
+ switch (pin_type) {
+ case OFONO_SIM_PASSWORD_SIM_PUK:
+ if (cbd->type != OFONO_SIM_PASSWORD_SIM_PIN)
+ goto failed;
+ break;
+ case OFONO_SIM_PASSWORD_SIM_PUK2:
+ if (cbd->type != OFONO_SIM_PASSWORD_SIM_PIN2)
+ goto failed;
+ break;
+ default:
+ goto failed;
+ }
+
+ snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\",\"%s\"", cbd->puk, cbd->pin);
+
+ memset(cbd->pin, 0, sizeof(cbd->pin));
+ memset(cbd->puk, 0, sizeof(cbd->puk));
+
+ ret = g_at_chat_send(sd->chat, buf, none_prefix,
+ at_lock_unlock_cb, cbd, g_free);
+
+ memset(buf, 0, sizeof(buf));
+
+ if (ret > 0)
+ return;
+
+failed:
+ g_free(cbd);
+ CALLBACK_WITH_FAILURE(cb, user_data);
+}
+
+static void at_pin_send_puk(struct ofono_sim *sim,
+ enum ofono_sim_password_type type,
+ const char *puk, const char *pin,
+ ofono_sim_lock_unlock_cb_t cb, void *data)
+{
+ struct sim_data *sd = ofono_sim_get_data(sim);
+ struct at_pin_reset_data *cbd = g_new0(struct at_pin_reset_data, 1);
+ char buf[64];
+
+ if (!cbd)
+ goto error;
+
+ cbd->base.cb = cb;
+ cbd->base.data = data;
+ cbd->base.user = sim;
+ cbd->type = type;
+ strcpy(cbd->puk, puk);
+ strcpy(cbd->pin, pin);
+
+ if (type == OFONO_SIM_PASSWORD_SIM_PIN && sd->cpin_type == type) {
+ /* +CPIN: SIM PUK is not transient, we can take shortcut */
+ struct ofono_error error = { OFONO_ERROR_TYPE_NO_ERROR };
+
+ at_pin_query_result(&error, type, cbd);
+
+ return;
+ }
+
+ /* We need to trigger AT+CPIN? to return SIM PUK or SIM PUK2 */
+
+ snprintf(buf, sizeof(buf), "AT+CPWD=\"%s\",\"%s\",\"%s\"",
+ at_clck_cpwd_fac[type], pin, pin);
+
+ g_at_chat_send(sd->chat, buf, none_prefix, NULL, NULL, NULL);
+
+ memset(buf, 0, sizeof(buf));
+
+ at_pin_query(sim, at_pin_query_result, cbd);
+
+ return;
+
+error:
+ CALLBACK_WITH_FAILURE(cb, data);
+}
+
static void at_lock_status_cb(gboolean ok, GAtResult *result,
gpointer user_data)
{
--
1.7.0.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [sim-reset-pin PATCH 3/4] Added test/change-pin
2010-08-26 12:49 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Pekka.Pessi
@ 2010-08-26 12:49 ` Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 4/4] Added test/reset-pin Pekka.Pessi
2010-08-26 15:13 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Denis Kenzior
1 sibling, 1 reply; 8+ messages in thread
From: Pekka.Pessi @ 2010-08-26 12:49 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1193 bytes --]
From: Pekka Pessi <Pekka.Pessi@nokia.com>
---
test/change-pin | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
create mode 100755 test/change-pin
diff --git a/test/change-pin b/test/change-pin
new file mode 100755
index 0000000..19e9302
--- /dev/null
+++ b/test/change-pin
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+def default_modem():
+ manager = bus.get_object('org.ofono', '/')
+ properties = manager.GetProperties(dbus_interface = 'org.ofono.Manager')
+ modems = properties["Modems"]
+ if not modems:
+ sys.stderr.write("No modems available\n")
+ sys.exit(1)
+ return modems[0]
+
+if len(sys.argv) == 5:
+ path, pin_type, old_pin, new_pin = sys.argv[1:]
+elif len(sys.argv) == 4:
+ path = default_modem()
+ pin_type, old_pin, new_pin = sys.argv[1:]
+else:
+ print "%s [PATH] pin_type old_pin new_pin" % (sys.argv[0])
+
+print "Change %s for modem %s..." % (pin_type, path)
+
+modem = bus.get_object('org.ofono', path)
+
+simmanager = dbus.Interface(modem, 'org.ofono.SimManager')
+
+simmanager.ChangePin(pin_type, old_pin, new_pin)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [sim-reset-pin PATCH 4/4] Added test/reset-pin
2010-08-26 12:49 ` [sim-reset-pin PATCH 3/4] Added test/change-pin Pekka.Pessi
@ 2010-08-26 12:49 ` Pekka.Pessi
0 siblings, 0 replies; 8+ messages in thread
From: Pekka.Pessi @ 2010-08-26 12:49 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1170 bytes --]
From: Pekka Pessi <Pekka.Pessi@nokia.com>
---
test/reset-pin | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
create mode 100755 test/reset-pin
diff --git a/test/reset-pin b/test/reset-pin
new file mode 100755
index 0000000..f7b5449
--- /dev/null
+++ b/test/reset-pin
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+def default_modem():
+ manager = bus.get_object('org.ofono', '/')
+ properties = manager.GetProperties(dbus_interface = 'org.ofono.Manager')
+ modems = properties["Modems"]
+ if not modems:
+ sys.stderr.write("No modems available\n")
+ sys.exit(1)
+ return modems[0]
+
+if len(sys.argv) == 5:
+ path, pin_type, puk, pin = sys.argv[1:]
+elif len(sys.argv) == 4:
+ path = default_modem()
+ pin_type, puk, pin = sys.argv[1:]
+else:
+ print "%s [PATH] pin_type puk pin" % (sys.argv[0])
+ sys.exit(0)
+
+print "Reset %s for modem %s..." % (pin_type, path)
+
+modem = bus.get_object('org.ofono', path)
+
+simmanager = dbus.Interface(modem, 'org.ofono.SimManager')
+
+simmanager.ResetPin(pin_type, puk, pin)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver
2010-08-26 12:49 ` [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Pekka.Pessi
@ 2010-08-26 15:10 ` Denis Kenzior
1 sibling, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2010-08-26 15:10 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2094 bytes --]
Hi Pekka,
On 08/26/2010 07:49 AM, Pekka.Pessi(a)nokia.com wrote:
> From: Pekka Pessi <Pekka.Pessi@nokia.com>
>
> ---
> include/sim.h | 5 +++--
> src/sim.c | 9 +++++++--
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/include/sim.h b/include/sim.h
> index 36a99b9..d3e564c 100644
> --- a/include/sim.h
> +++ b/include/sim.h
> @@ -143,8 +143,9 @@ struct ofono_sim_driver {
> ofono_sim_passwd_cb_t cb, void *data);
> void (*send_passwd)(struct ofono_sim *sim, const char *passwd,
> ofono_sim_lock_unlock_cb_t cb, void *data);
> - void (*reset_passwd)(struct ofono_sim *sim, const char *puk,
> - const char *passwd,
> + void (*reset_passwd)(struct ofono_sim *sim,
> + enum ofono_sim_password_type type,
> + const char *puk, const char *passwd,
> ofono_sim_lock_unlock_cb_t cb, void *data);
I don't get it, reset_passwd maps to +CPIN which does not take a type
parameter...
> void (*change_passwd)(struct ofono_sim *sim,
> enum ofono_sim_password_type type,
> diff --git a/src/sim.c b/src/sim.c
> index 04a708b..bac77e0 100644
> --- a/src/sim.c
> +++ b/src/sim.c
> @@ -753,8 +753,13 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, DBusMessage *msg,
>
> type = sim_string_to_passwd(typestr);
>
> - if (type == OFONO_SIM_PASSWORD_NONE || type != sim->pin_type)
> + switch (type) {
> + case OFONO_SIM_PASSWORD_SIM_PIN:
> + case OFONO_SIM_PASSWORD_SIM_PIN2:
> + break;
sim->pin_type is PUK or PUK2 here, not PIN/PIN2.
> + default:
> return __ofono_error_invalid_format(msg);
> + }
>
> if (!is_valid_pin(puk, PIN_TYPE_PUK))
> return __ofono_error_invalid_format(msg);
> @@ -763,7 +768,7 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, DBusMessage *msg,
> return __ofono_error_invalid_format(msg);
>
> sim->pending = dbus_message_ref(msg);
> - sim->driver->reset_passwd(sim, puk, pin, sim_enter_pin_cb, sim);
> + sim->driver->reset_passwd(sim, type, puk, pin, sim_enter_pin_cb, sim);
>
> return NULL;
> }
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2
2010-08-26 12:49 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 3/4] Added test/change-pin Pekka.Pessi
@ 2010-08-26 15:13 ` Denis Kenzior
2010-08-26 16:03 ` Pekka Pessi
1 sibling, 1 reply; 8+ messages in thread
From: Denis Kenzior @ 2010-08-26 15:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 561 bytes --]
Hi Pekka,
On 08/26/2010 07:49 AM, Pekka.Pessi(a)nokia.com wrote:
> From: Pekka Pessi <Pekka.Pessi@nokia.com>
>
> The PIN or PIN2 reset requires that modem waits for corresponding PUK code.
> If PIN is unlocked, modem does not wait for PUK code. Modem does not wait
> for PUK2 by default. The modem is triggered into a state waiting for PUK
> codes with AT+CPWD command.
>
> Password reset may fail if some other command is executed between AT+CPWD,
> AT+CPIN? and AT+CPIN.
Was this patch tested with modems other than mbm?
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2
2010-08-26 15:13 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Denis Kenzior
@ 2010-08-26 16:03 ` Pekka Pessi
0 siblings, 0 replies; 8+ messages in thread
From: Pekka Pessi @ 2010-08-26 16:03 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 585 bytes --]
Hi Denis,
2010/8/26 Denis Kenzior <denkenz@gmail.com>:
>> The PIN or PIN2 reset requires that modem waits for corresponding PUK code.
>> If PIN is unlocked, modem does not wait for PUK code. Modem does not wait
>> for PUK2 by default. The modem is triggered into a state waiting for PUK
>> codes with AT+CPWD command.
>>
>> Password reset may fail if some other command is executed between AT+CPWD,
>> AT+CPIN? and AT+CPIN.
>
> Was this patch tested with modems other than mbm?
I'm testing on on the best. None other support PIN2.
--
Pekka.Pessi mail at nokia.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-08-26 16:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-26 12:49 [sim-reset-pin PATCH 0/4] sim: better PIN reset Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 3/4] Added test/change-pin Pekka.Pessi
2010-08-26 12:49 ` [sim-reset-pin PATCH 4/4] Added test/reset-pin Pekka.Pessi
2010-08-26 15:13 ` [sim-reset-pin PATCH 2/4] atmodem/sim: reset PIN or PIN2 Denis Kenzior
2010-08-26 16:03 ` Pekka Pessi
2010-08-26 15:10 ` [sim-reset-pin PATCH 1/4] sim: pass reset password type to driver Denis Kenzior
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.