[PATCH] sim: enable usage of SIM pass codes longer than 8 digits
--- Hi, On Tue, 2011-02-08 at 06:17 +0200, Denis Kenzior wrote: Why don't we keep things simple. Modify is_valid_pin to take a pin and a min and max number of digits. gboolean is_valid_pin_with_limits(const char *pin, int min, int max) (feel free to pick some better name) Then just add two functions: __ofono_valid_net_pin(const char *pin) __ofono_valid_sim_pin(const char *pin, enum ofono_sim_password_type type) Stick both in ofono.h / sim.c somewhere Right. Here it is. Br, Jussi src/call-barring.c | 12 src/call-meter.c |4 +- src/common.c | 37 - src/common.h |9 -- src/ofono.h|5 +++ src/sim.c | 76 +++ 6 files changed, 83 insertions(+), 60 deletions(-) diff --git a/src/call-barring.c b/src/call-barring.c index 649826e..384eb43 100644 --- a/src/call-barring.c +++ b/src/call-barring.c @@ -402,7 +402,7 @@ static gboolean cb_ss_control(int type, const char *sc, if (strlen(dn) 0) goto bad_format; - if (type != SS_CONTROL_TYPE_QUERY !is_valid_pin(sia, PIN_TYPE_NET)) + if (type != SS_CONTROL_TYPE_QUERY !__ofono_is_valid_net_pin(sia)) goto bad_format; switch (type) { @@ -524,7 +524,7 @@ static gboolean cb_ss_passwd(const char *sc, if (fac == NULL) return FALSE; - if (!is_valid_pin(old, PIN_TYPE_NET) || !is_valid_pin(new, PIN_TYPE_NET)) + if (!__ofono_is_valid_net_pin(old) || !__ofono_is_valid_net_pin(new)) goto bad_format; cb-pending = dbus_message_ref(msg); @@ -862,7 +862,7 @@ static DBusMessage *cb_set_property(DBusConnection *conn, DBusMessage *msg, return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(iter, passwd); - if (!is_valid_pin(passwd, PIN_TYPE_NET)) + if (!__ofono_is_valid_net_pin(passwd)) return __ofono_error_invalid_format(msg); } @@ -909,7 +909,7 @@ static DBusMessage *cb_disable_all(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); - if (!is_valid_pin(passwd, PIN_TYPE_NET)) + if (!__ofono_is_valid_net_pin(passwd)) return __ofono_error_invalid_format(msg); cb_set_query_bounds(cb, fac, FALSE); @@ -957,10 +957,10 @@ static DBusMessage *cb_set_passwd(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); - if (!is_valid_pin(old_passwd, PIN_TYPE_NET)) + if (!__ofono_is_valid_net_pin(old_passwd)) return __ofono_error_invalid_format(msg); - if (!is_valid_pin(new_passwd, PIN_TYPE_NET)) + if (!__ofono_is_valid_net_pin(new_passwd)) return __ofono_error_invalid_format(msg); cb-pending = dbus_message_ref(msg); diff --git a/src/call-meter.c b/src/call-meter.c index d483e2e..0789935 100644 --- a/src/call-meter.c +++ b/src/call-meter.c @@ -549,7 +549,7 @@ static DBusMessage *cm_set_property(DBusConnection *conn, DBusMessage *msg, dbus_message_iter_get_basic(iter, passwd); - if (!is_valid_pin(passwd, PIN_TYPE_PIN)) + if (!__ofono_is_valid_sim_pin(passwd, OFONO_SIM_PASSWORD_SIM_PIN2)) return __ofono_error_invalid_format(msg); for (property = cm_properties; property-name; property++) { @@ -621,7 +621,7 @@ static DBusMessage *cm_acm_reset(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); - if (!is_valid_pin(pin2, PIN_TYPE_PIN)) + if (!__ofono_is_valid_sim_pin(pin2, OFONO_SIM_PASSWORD_SIM_PIN2)) return __ofono_error_invalid_format(msg); cm-pending = dbus_message_ref(msg); diff --git a/src/common.c b/src/common.c index f25f105..247fff0 100644 --- a/src/common.c +++ b/src/common.c @@ -649,43 +649,6 @@ const char *bearer_class_to_string(enum bearer_class cls) return NULL; } -gboolean is_valid_pin(const char *pin, enum pin_type type) -{ - unsigned int i; - - /* Pin must not be empty */ - if (pin == NULL || pin[0] == '\0') - return FALSE; - - i = strlen(pin); - if (i != strspn(pin, 0123456789)) - return FALSE; - - switch (type) { - case PIN_TYPE_PIN: - /* 11.11 Section 9.3 (CHV): 4..8 IA-5 digits */ - if (4 = i i = 8) - return TRUE; - break; - case PIN_TYPE_PUK: - /* 11.11 Section 9.3 (UNBLOCK CHV), 8 IA-5 digits */ - if (i == 8) - return TRUE; - break; - case
Re: [PATCH] sim: enable usage of SIM pass codes longer than 8 digits
Hi Jussi, On 02/08/2011 06:48 AM, Jussi Kangas wrote: --- Hi, On Tue, 2011-02-08 at 06:17 +0200, Denis Kenzior wrote: Why don't we keep things simple. Modify is_valid_pin to take a pin and a min and max number of digits. gboolean is_valid_pin_with_limits(const char *pin, int min, int max) (feel free to pick some better name) Then just add two functions: __ofono_valid_net_pin(const char *pin) __ofono_valid_sim_pin(const char *pin, enum ofono_sim_password_type type) Stick both in ofono.h / sim.c somewhere Right. Here it is. I applied your patch, but it did have multiple problems, namely blank line at EOF in sim.c, mixing tab/space for indentation and a compilation warning. I was nice enough and fixed all these for you, but please pay attention to this the next time. Regards, -Denis ___ ofono mailing list ofono@ofono.org http://lists.ofono.org/listinfo/ofono
Re: [PATCH] sim: enable usage of SIM pass codes longer than 8 digits
Hi Jussi, On 02/07/2011 08:49 AM, Jussi Kangas wrote: --- Hi, Here is my second proposal for how to enable usage of SIM lock codes longer than eight digits. I removed the namespace problem and fixed a problem with puk reset. Br, Jussi include/sim.h |1 + src/call-barring.c | 14 -- src/call-meter.c |4 ++-- src/common.c | 29 - src/common.h | 11 +++ src/ofono.h|3 +++ src/sim.c | 15 +-- 7 files changed, 50 insertions(+), 27 deletions(-) diff --git a/include/sim.h b/include/sim.h index 5e3ba5b..7f0313e 100644 --- a/include/sim.h +++ b/include/sim.h @@ -54,6 +54,7 @@ enum ofono_sim_password_type { OFONO_SIM_PASSWORD_PHNETSUB_PUK, OFONO_SIM_PASSWORD_PHSP_PUK, OFONO_SIM_PASSWORD_PHCORP_PUK, + OFONO_SIM_PASSWORD_PIN_TYPE_NET, So just adding an enum here is a little dangerous since we use the array size for things like look up tables and iterators inside src/sim.c OFONO_SIM_PASSWORD_INVALID, }; diff --git a/src/call-barring.c b/src/call-barring.c index 649826e..fdcecbf 100644 --- a/src/call-barring.c +++ b/src/call-barring.c @@ -402,7 +402,8 @@ static gboolean cb_ss_control(int type, const char *sc, if (strlen(dn) 0) goto bad_format; - if (type != SS_CONTROL_TYPE_QUERY !is_valid_pin(sia, PIN_TYPE_NET)) + if (type != SS_CONTROL_TYPE_QUERY + !is_valid_pin(sia, OFONO_SIM_PASSWORD_PIN_TYPE_NET)) Watch out for coding style, see item M4. goto bad_format; switch (type) { @@ -524,7 +525,8 @@ static gboolean cb_ss_passwd(const char *sc, if (fac == NULL) return FALSE; - if (!is_valid_pin(old, PIN_TYPE_NET) || !is_valid_pin(new, PIN_TYPE_NET)) + if (!is_valid_pin(old, OFONO_SIM_PASSWORD_PIN_TYPE_NET) || + !is_valid_pin(new, OFONO_SIM_PASSWORD_PIN_TYPE_NET)) As above goto bad_format; cb-pending = dbus_message_ref(msg); @@ -862,7 +864,7 @@ static DBusMessage *cb_set_property(DBusConnection *conn, DBusMessage *msg, return __ofono_error_invalid_args(msg); dbus_message_iter_get_basic(iter, passwd); - if (!is_valid_pin(passwd, PIN_TYPE_NET)) + if (!is_valid_pin(passwd, OFONO_SIM_PASSWORD_PIN_TYPE_NET)) return __ofono_error_invalid_format(msg); } @@ -909,7 +911,7 @@ static DBusMessage *cb_disable_all(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); - if (!is_valid_pin(passwd, PIN_TYPE_NET)) + if (!is_valid_pin(passwd, OFONO_SIM_PASSWORD_PIN_TYPE_NET)) return __ofono_error_invalid_format(msg); cb_set_query_bounds(cb, fac, FALSE); @@ -957,10 +959,10 @@ static DBusMessage *cb_set_passwd(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); - if (!is_valid_pin(old_passwd, PIN_TYPE_NET)) + if (!is_valid_pin(old_passwd, OFONO_SIM_PASSWORD_PIN_TYPE_NET)) return __ofono_error_invalid_format(msg); - if (!is_valid_pin(new_passwd, PIN_TYPE_NET)) + if (!is_valid_pin(new_passwd, OFONO_SIM_PASSWORD_PIN_TYPE_NET)) return __ofono_error_invalid_format(msg); cb-pending = dbus_message_ref(msg); diff --git a/src/call-meter.c b/src/call-meter.c index d483e2e..a7f8ebb 100644 --- a/src/call-meter.c +++ b/src/call-meter.c @@ -549,7 +549,7 @@ static DBusMessage *cm_set_property(DBusConnection *conn, DBusMessage *msg, dbus_message_iter_get_basic(iter, passwd); - if (!is_valid_pin(passwd, PIN_TYPE_PIN)) + if (!is_valid_pin(passwd, OFONO_SIM_PASSWORD_SIM_PIN2)) return __ofono_error_invalid_format(msg); for (property = cm_properties; property-name; property++) { @@ -621,7 +621,7 @@ static DBusMessage *cm_acm_reset(DBusConnection *conn, DBusMessage *msg, DBUS_TYPE_INVALID) == FALSE) return __ofono_error_invalid_args(msg); - if (!is_valid_pin(pin2, PIN_TYPE_PIN)) + if (!is_valid_pin(pin2, OFONO_SIM_PASSWORD_SIM_PIN2)) return __ofono_error_invalid_format(msg); cm-pending = dbus_message_ref(msg); diff --git a/src/common.c b/src/common.c index f25f105..60bf20c 100644 --- a/src/common.c +++ b/src/common.c @@ -649,7 +649,7 @@ const char *bearer_class_to_string(enum bearer_class cls) return NULL; } -gboolean is_valid_pin(const char *pin, enum pin_type type) +gboolean is_valid_pin(const char *pin, enum ofono_sim_password_type type) Why don't we keep things simple. Modify is_valid_pin to take a pin and a min and max number