Merge lp:~phablet-team/phablet-extras/ofono-sim-pin-support into lp:phablet-extras/ofono

Proposed by Tony Espy
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 53
Merged at revision: 46
Proposed branch: lp:~phablet-team/phablet-extras/ofono-sim-pin-support
Merge into: lp:phablet-extras/ofono
Diff against target: 860 lines (+511/-107)
5 files modified
debian/changelog (+8/-0)
drivers/rilmodem/rilutil.c (+81/-61)
drivers/rilmodem/rilutil.h (+42/-11)
drivers/rilmodem/sim.c (+368/-30)
plugins/ril.c (+12/-5)
To merge this branch: bzr merge lp:~phablet-team/phablet-extras/ofono-sim-pin-support
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+172204@code.launchpad.net

Commit message

[rilmodem] Add SIM PIN/PUK support.

Description of the change

This merge adds SIM PIN/PUK support. It's based on code from Jolla that's been re-factored due to the fact that they're working on a older version of our code, and to remove some of the changes they made which were questionable.

https://github.com/nemomobile-packages/ofono/tree/master/ofono

Testing was performed on an un-flipped maguro, using the 20130629 build.

I tested an unlocked SIM, and only verified that I was able to make voice calls.

I tested a locked SIM. I manually started ofono. Before unlocked, the ofono DBus interfaces are restricted to VoiceCallManager and SimManager. I manually entered a pin via dbus-send:

I resorted to dbus-send, as I couldn't get the python enter-pin test script to run, but this was because it took me awhile to figure out that the 'pin_type' argument was the same as reported by the property ( eg. "pin" ). Here's the command I used:

# dbus-send --print-reply --system --dest=org.ofono /ril_0 org.ofono.SimManager.EnterPin string:"pin" string:"2112"

After entering the PIN, I verified that the rest of the modem initialization occurs, and I was able to make a phone call.

NOTE -- I did some minor cleanup of the branch before submitting, so this code definitely needs to be fully re-tested on maguro. It also needs to be tested on mako.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

435 + if (ril_util_parse_sim_status(sd->ril, message, &status, apps)) {
436 +
437 + if (status.num_apps) {

As you only cares about status.num_apps, you could check both at the same line (with &&), and that will save you one indentation level.

review: Needs Fixing
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

521 +static void ril_query_passwd_state(struct ofono_sim *sim,
522 + ofono_sim_passwd_cb_t cb, void *data)
523 +{
524 + struct sim_data *sd = ofono_sim_get_data(sim);
525 +
526 + DBG("passwd_state %u", sd->passwd_state);
527 + CALLBACK_WITH_SUCCESS(cb, sd->passwd_state, data);
528 +}

You also might want to handle the case which the passwd_state is invalid, check how this is done with isi and qmimodem.

review: Needs Fixing
48. By Tony Espy

[rilmodem] Minor re-factoring of PIN code.

49. By Tony Espy

Releasing 1.12phablet8

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
50. By Tony Espy

[rilmodem] Fix compile error.

Revision history for this message
Tony Espy (awe) wrote :

I re-factored sim_status_cb() and fixed the line length problem which still existed even after combining the "if" statements per the initial review comment.

I also fixed ril_query_passwd_state() to use CALLBACK_WITH_FAILURE if the passwd_state is invalid.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
51. By Tony Espy

[ril] Fix compile error.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

750 + g_ril_append_print_buf(sd->ril, "(puk=%s,pin=%s,aid=%s)",
751 + old, new,
752 + sd->aid_str);

The debug is wrong here, it should be old=%s,new=%d instead.

Also, there's a memory corruption when copying the aid_str string to sd, as you basically just assign the pointer (line 435), instead of copying the value (the corruption happens once ril_util_free_sim_apps is called). Same happens with app_str.

With such fix in place I'm able to lock/unlock my sim card.

review: Needs Fixing
52. By Tony Espy

[rildmodem] Fix SIM logic to make copies of aid/app strings.

Revision history for this message
Tony Espy (awe) wrote :

Both issues fixed, and pushed... Thanks!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
53. By Tony Espy

[rilmodem] Re-factor SIM aid/app string code to use g_strdup().

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Good, tested with mako and working as expected. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2013-06-26 17:24:24 +0000
+++ debian/changelog 2013-07-09 19:18:24 +0000
@@ -1,3 +1,11 @@
1ofono (1.12phablet8) saucy; urgency=low
2
3 * [rilmodem] Added SIM PIN/PUK support. This is
4 based on code from Jolla:
5 https://github.com/nemomobile-packages/ofono
6
7 -- Tony Espy <espy@canonical.com> Mon, 08 Jul 2013 13:08:32 -0400
8
1ofono (1.12phablet7) saucy; urgency=low9ofono (1.12phablet7) saucy; urgency=low
210
3 [ Tony Espy ]11 [ Tony Espy ]
412
=== modified file 'drivers/rilmodem/rilutil.c'
--- drivers/rilmodem/rilutil.c 2013-06-14 16:11:01 +0000
+++ drivers/rilmodem/rilutil.c 2013-07-09 19:18:24 +0000
@@ -394,24 +394,17 @@
394394
395gboolean ril_util_parse_sim_status(GRil *gril,395gboolean ril_util_parse_sim_status(GRil *gril,
396 struct ril_msg *message,396 struct ril_msg *message,
397 struct sim_app *app)397 struct sim_status *status,
398 struct sim_app **apps)
398{399{
399 struct parcel rilp;400 struct parcel rilp;
400 gboolean result = FALSE;401 gboolean result = FALSE;
401 char *aid_str = NULL;402 int i;
402 char *app_str = NULL;
403 int i, card_state, num_apps, pin_state, gsm_umts_index, ims_index;
404 int app_state, app_type, pin_replaced, pin1_state, pin2_state, perso_substate;
405403
406 g_ril_append_print_buf(gril, "[%04d]< %s",404 g_ril_append_print_buf(gril, "[%04d]< %s",
407 message->serial_no,405 message->serial_no,
408 ril_request_id_to_string(message->req));406 ril_request_id_to_string(message->req));
409407
410 if (app) {
411 app->app_type = RIL_APPTYPE_UNKNOWN;
412 app->app_id = NULL;
413 }
414
415 ril_util_init_parcel(message, &rilp);408 ril_util_init_parcel(message, &rilp);
416409
417 /*410 /*
@@ -420,24 +413,33 @@
420 * This could be a runtime assertion, disconnect, drop/ignore413 * This could be a runtime assertion, disconnect, drop/ignore
421 * the message, ...414 * the message, ...
422 *415 *
423 * Currently if the message is smaller than expected, our parcel
424 * code happily walks off the end of the buffer and segfaults.
425 *
426 * 20 is the min length of RIL_CardStatus_v6 as the AppState416 * 20 is the min length of RIL_CardStatus_v6 as the AppState
427 * array can be 0-length.417 * array can be 0-length.
428 */418 */
429 if (message->buf_len < 20) {419 if (message->buf_len < 20) {
430 ofono_error("Size of SIM_STATUS reply too small: %d bytes",420 ofono_error("Size of SIM_STATUS reply too small: %d bytes",
431 message->buf_len);421 message->buf_len);
432 goto done;422 return FALSE;
433 }423 }
434424
435 card_state = parcel_r_int32(&rilp);425 status->card_state = parcel_r_int32(&rilp);
436 pin_state = parcel_r_int32(&rilp);426
437 gsm_umts_index = parcel_r_int32(&rilp);427 /*
438 parcel_r_int32(&rilp); /* ignore: cdma_subscription_app_index */428 * NOTE:
439 ims_index = parcel_r_int32(&rilp);429 *
440 num_apps = parcel_r_int32(&rilp);430 * The global pin_status is used for multi-application
431 * UICC cards. For example, there are SIM cards that
432 * can be used in both GSM and CDMA phones. Instead
433 * of managed PINs for both applications, a global PIN
434 * is set instead. It's not clear at this point if
435 * such SIM cards are supported by ofono or RILD.
436 */
437
438 status->pin_state = parcel_r_int32(&rilp);
439 status->gsm_umts_index = parcel_r_int32(&rilp);
440 status->cdma_index = parcel_r_int32(&rilp);
441 status->ims_index = parcel_r_int32(&rilp);
442 status->num_apps = parcel_r_int32(&rilp);
441443
442 /* TODO:444 /* TODO:
443 * How do we handle long (>80 chars) ril_append_print_buf strings?445 * How do we handle long (>80 chars) ril_append_print_buf strings?
@@ -446,60 +448,68 @@
446 */448 */
447 g_ril_append_print_buf(gril,449 g_ril_append_print_buf(gril,
448 "(card_state=%d,universal_pin_state=%d,gsm_umts_index=%d,cdma_index=%d,ims_index=%d, ",450 "(card_state=%d,universal_pin_state=%d,gsm_umts_index=%d,cdma_index=%d,ims_index=%d, ",
449 card_state,451 status->card_state,
450 pin_state,452 status->pin_state,
451 gsm_umts_index,453 status->gsm_umts_index,
452 -1,454 status->cdma_index,
453 ims_index);455 status->ims_index);
454456
455 for (i = 0; i < num_apps; i++) {457 if (status->card_state == RIL_CARDSTATE_PRESENT)
456 app_type = parcel_r_int32(&rilp);458 result = TRUE;
457 app_state = parcel_r_int32(&rilp);459 else
458 perso_substate = parcel_r_int32(&rilp);460 goto done;
461
462 if (status->num_apps > MAX_UICC_APPS) {
463 ofono_error("SIM error; too many apps: %d", status->num_apps);
464 status->num_apps = MAX_UICC_APPS;
465 }
466
467 for (i = 0; i < status->num_apps; i++) {
468 DBG("processing app[%d]", i);
469 apps[i] = g_try_new0(struct sim_app, 1);
470 if (apps[i] == NULL) {
471 ofono_error("Can't allocate app_data");
472 goto error;
473 }
474
475 apps[i]->app_type = parcel_r_int32(&rilp);
476 apps[i]->app_state = parcel_r_int32(&rilp);
477 apps[i]->perso_substate = parcel_r_int32(&rilp);
459478
460 /* TODO: we need a way to instruct parcel to skip479 /* TODO: we need a way to instruct parcel to skip
461 * a string, without allocating memory...480 * a string, without allocating memory...
462 */481 */
463 aid_str = parcel_r_string(&rilp); /* application ID (AID) */482 apps[i]->aid_str = parcel_r_string(&rilp); /* application ID (AID) */
464 app_str = parcel_r_string(&rilp); /* application label */483 apps[i]->app_str = parcel_r_string(&rilp); /* application label */
465484
466 pin_replaced = parcel_r_int32(&rilp);485 apps[i]->pin_replaced = parcel_r_int32(&rilp);
467 pin1_state = parcel_r_int32(&rilp);486 apps[i]->pin1_state = parcel_r_int32(&rilp);
468 pin2_state = parcel_r_int32(&rilp);487 apps[i]->pin2_state = parcel_r_int32(&rilp);
469488
470 g_ril_append_print_buf(gril,489 g_ril_append_print_buf(gril,
471 "%s[app_type=%d,app_state=%d,perso_substate=%d,aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",490 "%s[app_type=%d,app_state=%d,perso_substate=%d,aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
472 print_buf,491 print_buf,
473 app_type,492 apps[i]->app_type,
474 app_state,493 apps[i]->app_state,
475 perso_substate,494 apps[i]->perso_substate,
476 aid_str,495 apps[i]->aid_str,
477 app_str,496 apps[i]->app_str,
478 pin_replaced,497 apps[i]->pin_replaced,
479 pin1_state,498 apps[i]->pin1_state,
480 pin2_state);499 apps[i]->pin2_state);
481
482 /* FIXME: CDMA/IMS -- see comment @ top-of-source. */
483 if (i == gsm_umts_index && app) {
484 if (aid_str) {
485 app->app_id = aid_str;
486 DBG("setting app_id (AID) to: %s", aid_str);
487 }
488
489 app->app_type = app_type;
490 } else
491 g_free(aid_str);
492
493 g_free(app_str);
494 }500 }
495501
496 g_ril_append_print_buf(gril, "%s}", print_buf);
497 g_ril_print_response(gril, message);
498
499 if (card_state == RIL_CARDSTATE_PRESENT)
500 result = TRUE;
501done:502done:
503 g_ril_append_print_buf(gril, "%s}", print_buf);
504 g_ril_print_response(gril, message);
505
502 return result;506 return result;
507
508error:
509 if (apps)
510 ril_util_free_sim_apps(apps, status->num_apps);
511
512 return FALSE;
503}513}
504514
505gboolean ril_util_parse_reg(GRil *gril,515gboolean ril_util_parse_reg(GRil *gril,
@@ -714,3 +724,13 @@
714724
715 return -1;725 return -1;
716}726}
727
728void ril_util_free_sim_apps(struct sim_app **apps, guint num_apps) {
729 guint i;
730
731 for (i = 0; i < num_apps; i++) {
732 g_free(apps[i]->aid_str);
733 g_free(apps[i]->app_str);
734 g_free(apps[i]);
735 }
736}
717737
=== modified file 'drivers/rilmodem/rilutil.h'
--- drivers/rilmodem/rilutil.h 2013-06-13 13:31:46 +0000
+++ drivers/rilmodem/rilutil.h 2013-07-09 19:18:24 +0000
@@ -62,21 +62,48 @@
62 RIL_UTIL_CHARSET_8859_H = 0x10000,62 RIL_UTIL_CHARSET_8859_H = 0x10000,
63};63};
6464
65/* TODO: consider moving these to ril_constants.h */
66enum app_state {
67 APPSTATE_UNKNOWN,
68 APPSTATE_DETECTED,
69 APPSTATE_PIN,
70 APPSTATE_PUK,
71 APPSTATE_SUBSCRIPTION_PERSO,
72 APPSTATE_READY,
73};
74
65struct data_call {75struct data_call {
66 int status;76 int status;
67 int retry;77 int retry;
68 int cid;78 int cid;
69 int active;79 int active;
70 char * type;80 char *type;
71 char * ifname;81 char *ifname;
72 char * addresses;82 char *addresses;
73 char * dnses;83 char *dnses;
74 char * gateways;84 char *gateways;
85};
86
87#define MAX_UICC_APPS 16
88
89struct sim_status {
90 guint card_state;
91 guint pin_state;
92 guint gsm_umts_index;
93 guint cdma_index;
94 guint ims_index;
95 guint num_apps;
75};96};
7697
77struct sim_app {98struct sim_app {
78 char *app_id;
79 guint app_type;99 guint app_type;
100 guint app_state;
101 guint perso_substate;
102 char *aid_str;
103 char *app_str;
104 guint pin_replaced;
105 guint pin1_state;
106 guint pin2_state;
80};107};
81108
82typedef void (*ril_util_sim_inserted_cb_t)(gboolean present, void *userdata);109typedef void (*ril_util_sim_inserted_cb_t)(gboolean present, void *userdata);
@@ -101,7 +128,9 @@
101char *ril_util_parse_sim_io_rsp(GRil *gril, struct ril_msg *message,128char *ril_util_parse_sim_io_rsp(GRil *gril, struct ril_msg *message,
102 int *sw1, int *sw2,129 int *sw1, int *sw2,
103 int *hex_len);130 int *hex_len);
104gboolean ril_util_parse_sim_status(GRil *gril, struct ril_msg *message, struct sim_app *app);131gboolean ril_util_parse_sim_status(GRil *gril, struct ril_msg *message,
132 struct sim_status *status,
133 struct sim_app **apps);
105gboolean ril_util_parse_reg(GRil *gril, struct ril_msg *message, int *status,134gboolean ril_util_parse_reg(GRil *gril, struct ril_msg *message, int *status,
106 int *lac, int *ci, int *tech, int *max_calls);135 int *lac, int *ci, int *tech, int *max_calls);
107136
@@ -109,6 +138,8 @@
109138
110gint ril_util_get_signal(GRil *gril, struct ril_msg *message);139gint ril_util_get_signal(GRil *gril, struct ril_msg *message);
111140
141void ril_util_free_sim_apps(struct sim_app **apps, guint num_apps);
142
112struct cb_data {143struct cb_data {
113 void *cb;144 void *cb;
114 void *data;145 void *data;
115146
=== modified file 'drivers/rilmodem/sim.c'
--- drivers/rilmodem/sim.c 2013-06-14 16:11:01 +0000
+++ drivers/rilmodem/sim.c 2013-07-09 19:18:24 +0000
@@ -35,6 +35,9 @@
35#include <ofono/log.h>35#include <ofono/log.h>
36#include <ofono/modem.h>36#include <ofono/modem.h>
37#include <ofono/sim.h>37#include <ofono/sim.h>
38
39#include "ofono.h"
40
38#include "simutil.h"41#include "simutil.h"
39#include "util.h"42#include "util.h"
4043
@@ -64,6 +67,17 @@
64/* FID/path of SIM/USIM root directory */67/* FID/path of SIM/USIM root directory */
65#define ROOTMF "3F00"68#define ROOTMF "3F00"
6669
70/* RIL_Request* parameter counts */
71#define GET_IMSI_NUM_PARAMS 1
72#define ENTER_SIM_PIN_PARAMS 2
73#define SET_FACILITY_LOCK_PARAMS 5
74#define ENTER_SIM_PUK_PARAMS 3
75#define CHANGE_SIM_PIN_PARAMS 3
76
77/* RIL_FACILITY_LOCK parameters */
78#define RIL_FACILITY_UNLOCK "0"
79#define RIL_FACILITY_LOCK "1"
80
67/*81/*
68 * TODO: CDMA/IMS82 * TODO: CDMA/IMS
69 *83 *
@@ -77,8 +91,12 @@
77 */91 */
78struct sim_data {92struct sim_data {
79 GRil *ril;93 GRil *ril;
80 char *app_id;94 gchar *aid_str;
81 guint app_type;95 guint app_type;
96 gchar *app_str;
97 guint app_index;
98 gboolean sim_registered;
99 enum ofono_sim_password_type passwd_state;
82};100};
83101
84static void set_path(struct sim_data *sd, struct parcel *rilp,102static void set_path(struct sim_data *sd, struct parcel *rilp,
@@ -245,7 +263,7 @@
245 parcel_w_int32(&rilp, 15); /* P3 - max length */263 parcel_w_int32(&rilp, 15); /* P3 - max length */
246 parcel_w_string(&rilp, NULL); /* data; only req'd for writes */264 parcel_w_string(&rilp, NULL); /* data; only req'd for writes */
247 parcel_w_string(&rilp, NULL); /* pin2; only req'd for writes */265 parcel_w_string(&rilp, NULL); /* pin2; only req'd for writes */
248 parcel_w_string(&rilp, sd->app_id); /* AID (Application ID) */266 parcel_w_string(&rilp, sd->aid_str); /* AID (Application ID) */
249267
250 ret = g_ril_send(sd->ril,268 ret = g_ril_send(sd->ril,
251 request,269 request,
@@ -256,7 +274,7 @@
256 g_ril_append_print_buf(sd->ril,274 g_ril_append_print_buf(sd->ril,
257 "%s0,0,15,(null),pin2=(null),aid=%s)",275 "%s0,0,15,(null),pin2=(null),aid=%s)",
258 print_buf,276 print_buf,
259 sd->app_id);277 sd->aid_str);
260 g_ril_print_request(sd->ril, ret, RIL_REQUEST_SIM_IO);278 g_ril_print_request(sd->ril, ret, RIL_REQUEST_SIM_IO);
261279
262 parcel_free(&rilp);280 parcel_free(&rilp);
@@ -330,7 +348,7 @@
330 parcel_w_int32(&rilp, length); /* P3 */348 parcel_w_int32(&rilp, length); /* P3 */
331 parcel_w_string(&rilp, NULL); /* data; only req'd for writes */349 parcel_w_string(&rilp, NULL); /* data; only req'd for writes */
332 parcel_w_string(&rilp, NULL); /* pin2; only req'd for writes */350 parcel_w_string(&rilp, NULL); /* pin2; only req'd for writes */
333 parcel_w_string(&rilp, sd->app_id); /* AID (Application ID) */351 parcel_w_string(&rilp, sd->aid_str);
334352
335 ret = g_ril_send(sd->ril,353 ret = g_ril_send(sd->ril,
336 request,354 request,
@@ -344,7 +362,7 @@
344 (start >> 8),362 (start >> 8),
345 (start & 0xff),363 (start & 0xff),
346 length,364 length,
347 sd->app_id);365 sd->aid_str);
348 g_ril_print_request(sd->ril, ret, request);366 g_ril_print_request(sd->ril, ret, request);
349367
350 parcel_free(&rilp);368 parcel_free(&rilp);
@@ -383,7 +401,7 @@
383 parcel_w_int32(&rilp, length); /* P3 */401 parcel_w_int32(&rilp, length); /* P3 */
384 parcel_w_string(&rilp, NULL); /* data; only req'd for writes */402 parcel_w_string(&rilp, NULL); /* data; only req'd for writes */
385 parcel_w_string(&rilp, NULL); /* pin2; only req'd for writes */403 parcel_w_string(&rilp, NULL); /* pin2; only req'd for writes */
386 parcel_w_string(&rilp, sd->app_id); /* AID (Application ID) */404 parcel_w_string(&rilp, sd->aid_str); /* AID (Application ID) */
387405
388 ret = g_ril_send(sd->ril,406 ret = g_ril_send(sd->ril,
389 request,407 request,
@@ -397,7 +415,7 @@
397 record,415 record,
398 4,416 4,
399 length,417 length,
400 sd->app_id);418 sd->aid_str);
401 g_ril_print_request(sd->ril, ret, request);419 g_ril_print_request(sd->ril, ret, request);
402420
403 parcel_free(&rilp);421 parcel_free(&rilp);
@@ -451,13 +469,13 @@
451 cbd->user = sd;469 cbd->user = sd;
452470
453 parcel_init(&rilp);471 parcel_init(&rilp);
454 parcel_w_int32(&rilp, 1); /* Number of params */472 parcel_w_int32(&rilp, GET_IMSI_NUM_PARAMS);
455 parcel_w_string(&rilp, sd->app_id); /* AID (Application ID) */473 parcel_w_string(&rilp, sd->aid_str);
456474
457 ret = g_ril_send(sd->ril, request,475 ret = g_ril_send(sd->ril, request,
458 rilp.data, rilp.size, ril_imsi_cb, cbd, g_free);476 rilp.data, rilp.size, ril_imsi_cb, cbd, g_free);
459477
460 g_ril_append_print_buf(sd->ril, "(%s)", sd->app_id);478 g_ril_append_print_buf(sd->ril, "(%s)", sd->aid_str);
461 g_ril_print_request(sd->ril, ret, request);479 g_ril_print_request(sd->ril, ret, request);
462480
463 parcel_free(&rilp);481 parcel_free(&rilp);
@@ -468,25 +486,90 @@
468 }486 }
469}487}
470488
489static void configure_active_app(struct sim_data *sd,
490 struct sim_app *app,
491 guint index)
492{
493 size_t aid_size = 0, app_size = 0;
494
495 sd->app_type = app->app_type;
496 sd->aid_str = g_strdup(app->aid_str);
497 sd->app_str = g_strdup(app->app_str);
498 sd->app_index = index;
499
500 DBG("setting aid_str (AID) to: %s", sd->aid_str);
501 switch (app->app_state) {
502 case APPSTATE_PIN:
503 sd->passwd_state = OFONO_SIM_PASSWORD_SIM_PIN;
504 break;
505 case APPSTATE_PUK:
506 sd->passwd_state = OFONO_SIM_PASSWORD_SIM_PUK;
507 break;
508 case APPSTATE_SUBSCRIPTION_PERSO:
509 /* TODO: Check out how to dig out exact
510 * SIM lock.
511 */
512 sd->passwd_state = OFONO_SIM_PASSWORD_PHSIM_PIN;
513 break;
514 case APPSTATE_READY:
515 sd->passwd_state = OFONO_SIM_PASSWORD_NONE;
516 break;
517 case APPSTATE_UNKNOWN:
518 case APPSTATE_DETECTED:
519 default:
520 sd->passwd_state = OFONO_SIM_PASSWORD_INVALID;
521 break;
522 }
523}
524
471static void sim_status_cb(struct ril_msg *message, gpointer user_data)525static void sim_status_cb(struct ril_msg *message, gpointer user_data)
472{526{
473 struct ofono_sim *sim = user_data;527 struct ofono_sim *sim = user_data;
474 struct sim_data *sd = ofono_sim_get_data(sim);528 struct sim_data *sd = ofono_sim_get_data(sim);
475 struct sim_app app;529 struct sim_app *apps[MAX_UICC_APPS];
476530 struct sim_status status;
477 if (ril_util_parse_sim_status(sd->ril, message, &app)) {531 guint i = 0;
478 if (app.app_id)532 guint search_index = -1;
479 sd->app_id = app.app_id;533
480534 if (ril_util_parse_sim_status(sd->ril, message, &status, apps) &&
481 if (app.app_type != RIL_APPTYPE_UNKNOWN)535 status.num_apps) {
482 sd->app_type = app.app_type;536
483537 DBG("num_apps: %d gsm_umts_index: %d", status.num_apps,
484 ofono_sim_register(sim);538 status.gsm_umts_index);
539
540 /* TODO(CDMA): need some kind of logic to
541 * set the correct app_index,
542 */
543 search_index = status.gsm_umts_index;
544
545 for (i = 0; i < status.num_apps; i++) {
546 if (i == search_index &&
547 apps[i]->app_type != RIL_APPTYPE_UNKNOWN) {
548 configure_active_app(sd, apps[i], i);
549 break;
550 }
551 }
552
553 if (sd->sim_registered == FALSE) {
554 ofono_sim_register(sim);
555 sd->sim_registered = TRUE;
556 } else
557 /* TODO: There doesn't seem to be any other
558 * way to force the core SIM code to
559 * recheck the PIN.
560 * Wouldn't __ofono_sim_refresh be
561 * more appropriate call here??
562 * __ofono_sim_refresh(sim, NULL, TRUE, TRUE);
563 */
564 __ofono_sim_recheck_pin(sim);
565
566 ril_util_free_sim_apps(apps, status.num_apps);
485 }567 }
486568
487 /* TODO: if no SIM present, handle emergency calling. */569 /* TODO: if no SIM present, handle emergency calling. */
488}570}
489571
572
490static int send_get_sim_status(struct ofono_sim *sim)573static int send_get_sim_status(struct ofono_sim *sim)
491{574{
492 struct sim_data *sd = ofono_sim_get_data(sim);575 struct sim_data *sd = ofono_sim_get_data(sim);
@@ -501,13 +584,265 @@
501 return ret;584 return ret;
502}585}
503586
587static void ril_sim_status_changed(struct ril_msg *message, gpointer user_data)
588{
589 struct ofono_sim *sim = (struct ofono_sim *) user_data;
590 struct sim_data *sd = ofono_sim_get_data(sim);
591
592 DBG("");
593
594 g_ril_print_unsol_no_args(sd->ril, message);
595
596 send_get_sim_status(sim);
597}
598
599static void ril_query_passwd_state(struct ofono_sim *sim,
600 ofono_sim_passwd_cb_t cb, void *data)
601{
602 struct sim_data *sd = ofono_sim_get_data(sim);
603 DBG("passwd_state %u", sd->passwd_state);
604
605 if (sd->passwd_state == OFONO_SIM_PASSWORD_INVALID)
606 CALLBACK_WITH_FAILURE(cb, -1, data);
607
608 CALLBACK_WITH_SUCCESS(cb, sd->passwd_state, data);
609}
610
611static void ril_pin_change_state_cb(struct ril_msg *message, gpointer user_data)
612{
613 struct cb_data *cbd = user_data;
614 ofono_sim_lock_unlock_cb_t cb = cbd->cb;
615 struct sim_data *sd = cbd->user;
616
617 /* There is no reason to ask SIM status until
618 * unsolicited sim status change indication
619 * Looks like state does not change before that.
620 */
621
622 /* TODO: re-bfactor to not use macro for FAILURE; doesn't return error! */
623 if (message->error == RIL_E_SUCCESS) {
624 CALLBACK_WITH_SUCCESS(cb, cbd->data);
625 g_ril_print_response_no_args(sd->ril, message);
626
627 } else
628 CALLBACK_WITH_FAILURE(cb, cbd->data);
629
630}
631
632static void ril_pin_send(struct ofono_sim *sim, const char *passwd,
633 ofono_sim_lock_unlock_cb_t cb, void *data)
634{
635 struct sim_data *sd = ofono_sim_get_data(sim);
636 struct cb_data *cbd = cb_data_new(cb, data);
637 struct parcel rilp;
638 int request = RIL_REQUEST_ENTER_SIM_PIN;
639 int ret;
640
641 cbd->user = sd;
642
643 parcel_init(&rilp);
644
645 parcel_w_int32(&rilp, ENTER_SIM_PIN_PARAMS);
646 parcel_w_string(&rilp, (char *) passwd);
647 parcel_w_string(&rilp, sd->aid_str);
648
649 ret = g_ril_send(sd->ril, request,
650 rilp.data, rilp.size, ril_pin_change_state_cb,
651 cbd, g_free);
652
653 g_ril_append_print_buf(sd->ril, "(%s,aid=%s)", passwd, sd->aid_str);
654 g_ril_print_request(sd->ril, ret, request);
655
656 parcel_free(&rilp);
657
658 if (ret <= 0) {
659 g_free(cbd);
660 CALLBACK_WITH_FAILURE(cb, data);
661 }
662}
663
664static void ril_pin_change_state(struct ofono_sim *sim,
665 enum ofono_sim_password_type passwd_type,
666 int enable, const char *passwd,
667 ofono_sim_lock_unlock_cb_t cb, void *data)
668{
669 struct sim_data *sd = ofono_sim_get_data(sim);
670 struct cb_data *cbd = cb_data_new(cb, data);
671 struct parcel rilp;
672 int request = RIL_REQUEST_SET_FACILITY_LOCK;
673 int ret = 0;
674
675 cbd->user = sd;
676
677 parcel_init(&rilp);
678 parcel_w_int32(&rilp, SET_FACILITY_LOCK_PARAMS);
679
680 /*
681 * TODO: clean up the use of string literals &
682 * the multiple g_ril_append_print_buf() calls
683 * by using a table lookup as does the core sim code
684 */
685 switch (passwd_type) {
686 case OFONO_SIM_PASSWORD_SIM_PIN:
687 g_ril_append_print_buf(sd->ril, "(SC,");
688 parcel_w_string(&rilp, "SC");
689 break;
690 case OFONO_SIM_PASSWORD_PHSIM_PIN:
691 g_ril_append_print_buf(sd->ril, "(PS,");
692 parcel_w_string(&rilp, "PS");
693 break;
694 case OFONO_SIM_PASSWORD_PHFSIM_PIN:
695 g_ril_append_print_buf(sd->ril, "(PF,");
696 parcel_w_string(&rilp, "PF");
697 break;
698 case OFONO_SIM_PASSWORD_SIM_PIN2:
699 g_ril_append_print_buf(sd->ril, "(P2,");
700 parcel_w_string(&rilp, "P2");
701 break;
702 case OFONO_SIM_PASSWORD_PHNET_PIN:
703 g_ril_append_print_buf(sd->ril, "(PN,");
704 parcel_w_string(&rilp, "PN");
705 break;
706 case OFONO_SIM_PASSWORD_PHNETSUB_PIN:
707 g_ril_append_print_buf(sd->ril, "(PU,");
708 parcel_w_string(&rilp, "PU");
709 break;
710 case OFONO_SIM_PASSWORD_PHSP_PIN:
711 g_ril_append_print_buf(sd->ril, "(PP,");
712 parcel_w_string(&rilp, "PP");
713 break;
714 case OFONO_SIM_PASSWORD_PHCORP_PIN:
715 g_ril_append_print_buf(sd->ril, "(PC,");
716 parcel_w_string(&rilp, "PC");
717 break;
718 default:
719 CALLBACK_WITH_FAILURE(cb, data);
720 return;
721 }
722
723 if (enable)
724 parcel_w_string(&rilp, RIL_FACILITY_LOCK);
725 else
726 parcel_w_string(&rilp, RIL_FACILITY_UNLOCK);
727
728 parcel_w_string(&rilp, (char *) passwd);
729
730 /* TODO: make this a constant... */
731 parcel_w_string(&rilp, "0"); /* class */
732
733 parcel_w_string(&rilp, sd->aid_str);
734
735 ret = g_ril_send(sd->ril, request,
736 rilp.data, rilp.size, ril_pin_change_state_cb,
737 cbd, g_free);
738
739 g_ril_append_print_buf(sd->ril, "%s,%d,%s,0,aid=%s)",
740 print_buf,
741 enable,
742 passwd,
743 sd->aid_str);
744
745 g_ril_print_request(sd->ril, ret, request);
746
747 parcel_free(&rilp);
748
749 if (ret <= 0) {
750 g_free(cbd);
751 CALLBACK_WITH_FAILURE(cb, data);
752 }
753}
754
755static void ril_pin_send_puk(struct ofono_sim *sim,
756 const char *puk, const char *passwd,
757 ofono_sim_lock_unlock_cb_t cb, void *data)
758{
759 struct sim_data *sd = ofono_sim_get_data(sim);
760 struct cb_data *cbd = cb_data_new(cb, data);
761 struct parcel rilp;
762 int request = RIL_REQUEST_ENTER_SIM_PUK;
763 int ret = 0;
764
765 cbd->user = sd;
766
767 parcel_init(&rilp);
768
769 parcel_w_int32(&rilp, ENTER_SIM_PUK_PARAMS);
770 parcel_w_string(&rilp, (char *) puk);
771 parcel_w_string(&rilp, (char *) passwd);
772 parcel_w_string(&rilp, sd->aid_str);
773
774 ret = g_ril_send(sd->ril, request,
775 rilp.data, rilp.size, ril_pin_change_state_cb,
776 cbd, g_free);
777
778 g_ril_append_print_buf(sd->ril, "(puk=%s,pin=%s,aid=%s)",
779 puk, passwd,
780 sd->aid_str);
781
782 g_ril_print_request(sd->ril, ret, request);
783
784 parcel_free(&rilp);
785
786 if (ret <= 0) {
787 g_free(cbd);
788 CALLBACK_WITH_FAILURE(cb, data);
789 }
790}
791
792static void ril_change_passwd(struct ofono_sim *sim,
793 enum ofono_sim_password_type passwd_type,
794 const char *old, const char *new,
795 ofono_sim_lock_unlock_cb_t cb, void *data)
796{
797 struct sim_data *sd = ofono_sim_get_data(sim);
798 struct cb_data *cbd = cb_data_new(cb, data);
799 struct parcel rilp;
800 int request = RIL_REQUEST_CHANGE_SIM_PIN;
801 int ret = 0;
802
803 cbd->user = sd;
804
805 parcel_init(&rilp);
806
807 parcel_w_int32(&rilp, CHANGE_SIM_PIN_PARAMS);
808 parcel_w_string(&rilp, (char *) old); /* PUK */
809 parcel_w_string(&rilp, (char *) new); /* PIN */
810 parcel_w_string(&rilp, sd->aid_str);
811
812 if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN2)
813 request = RIL_REQUEST_CHANGE_SIM_PIN2;
814
815 ret = g_ril_send(sd->ril, request, rilp.data, rilp.size,
816 ril_pin_change_state_cb, cbd, g_free);
817
818 g_ril_append_print_buf(sd->ril, "(old=%s,new=%s,aid=%s)",
819 old, new,
820 sd->aid_str);
821
822 g_ril_print_request(sd->ril, ret, request);
823
824 parcel_free(&rilp);
825
826 if (ret <= 0) {
827 g_free(cbd);
828 CALLBACK_WITH_FAILURE(cb, data);
829 }
830}
831
504static gboolean ril_sim_register(gpointer user)832static gboolean ril_sim_register(gpointer user)
505{833{
506 struct ofono_sim *sim = user;834 struct ofono_sim *sim = user;
507835 struct sim_data *sd = ofono_sim_get_data(sim);
508 DBG("");836
509837 DBG("");
510 send_get_sim_status(sim);838
839 send_get_sim_status(sim);
840
841 g_ril_register(sd->ril, RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED,
842 (GRilNotifyFunc) ril_sim_status_changed, sim);
843
844 /* TODO: should we also register for RIL_UNSOL_SIM_REFRESH? */
845
511 return FALSE;846 return FALSE;
512}847}
513848
@@ -519,8 +854,11 @@
519854
520 sd = g_new0(struct sim_data, 1);855 sd = g_new0(struct sim_data, 1);
521 sd->ril = g_ril_clone(ril);856 sd->ril = g_ril_clone(ril);
522 sd->app_id = NULL;857 sd->aid_str = NULL;
858 sd->app_str = NULL;
523 sd->app_type = RIL_APPTYPE_UNKNOWN;859 sd->app_type = RIL_APPTYPE_UNKNOWN;
860 sd->passwd_state = OFONO_SIM_PASSWORD_NONE;
861 sd->sim_registered = FALSE;
524862
525 ofono_sim_set_data(sim, sd);863 ofono_sim_set_data(sim, sd);
526864
@@ -559,6 +897,11 @@
559 .read_file_linear = ril_sim_read_record,897 .read_file_linear = ril_sim_read_record,
560 .read_file_cyclic = ril_sim_read_record,898 .read_file_cyclic = ril_sim_read_record,
561 .read_imsi = ril_read_imsi,899 .read_imsi = ril_read_imsi,
900 .query_passwd_state = ril_query_passwd_state,
901 .send_passwd = ril_pin_send,
902 .lock = ril_pin_change_state,
903 .reset_passwd = ril_pin_send_puk,
904 .change_passwd = ril_change_passwd,
562/*905/*
563 * TODO: Implmenting PIN/PUK support requires defining906 * TODO: Implmenting PIN/PUK support requires defining
564 * the following driver methods.907 * the following driver methods.
@@ -568,12 +911,7 @@
568 * presence of query_passwd_state, and if null, then the911 * presence of query_passwd_state, and if null, then the
569 * function sim_initialize_after_pin() is called.912 * function sim_initialize_after_pin() is called.
570 *913 *
571 * .query_passwd_state = ril_pin_query,
572 * .query_pin_retries = ril_pin_retries_query,914 * .query_pin_retries = ril_pin_retries_query,
573 * .send_passwd = ril_pin_send,
574 * .reset_passwd = ril_pin_send_puk,
575 * .lock = ril_pin_enable,
576 * .change_passwd = ril_change_passwd,
577 * .query_locked = ril_pin_query_enabled,915 * .query_locked = ril_pin_query_enabled,
578 *916 *
579 * TODO: Implementing SIM write file IO support requires917 * TODO: Implementing SIM write file IO support requires
580918
=== modified file 'plugins/ril.c'
--- plugins/ril.c 2013-06-17 17:17:45 +0000
+++ plugins/ril.c 2013-07-09 19:18:24 +0000
@@ -131,6 +131,9 @@
131{131{
132 struct ofono_modem *modem = user_data;132 struct ofono_modem *modem = user_data;
133 struct ril_data *ril = ofono_modem_get_data(modem);133 struct ril_data *ril = ofono_modem_get_data(modem);
134 struct sim_status status;
135 struct sim_app *apps[MAX_UICC_APPS];
136 guint i = 0;
134137
135 DBG("");138 DBG("");
136139
@@ -153,12 +156,16 @@
153 else156 else
154 ofono_error("Max retries for GET_SIM_STATUS exceeded!");157 ofono_error("Max retries for GET_SIM_STATUS exceeded!");
155 } else {158 } else {
159
156 /* Returns TRUE if cardstate == PRESENT */160 /* Returns TRUE if cardstate == PRESENT */
157 if (ril_util_parse_sim_status(ril->modem, message, NULL)) {161 if (ril_util_parse_sim_status(ril->modem, message,
158 DBG("have_sim = TRUE; powering on modem.");162 &status, apps)) {
159163 DBG("have_sim = TRUE; powering on modem; num_apps: %d",
160 /* TODO: check PinState=DISABLED, for now just164 status.num_apps);
161 * set state to valid... */165
166 if (status.num_apps)
167 ril_util_free_sim_apps(apps, status.num_apps);
168
162 ril->have_sim = TRUE;169 ril->have_sim = TRUE;
163 power_on(modem);170 power_on(modem);
164 } else171 } else

Subscribers

People subscribed via source and target branches