489
static void configure_active_app(struct sim_data *sd,
493
size_t aid_size = 0, app_size = 0;
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;
500
DBG("setting aid_str (AID) to: %s", sd->aid_str);
501
switch (app->app_state) {
503
sd->passwd_state = OFONO_SIM_PASSWORD_SIM_PIN;
506
sd->passwd_state = OFONO_SIM_PASSWORD_SIM_PUK;
508
case APPSTATE_SUBSCRIPTION_PERSO:
509
/* TODO: Check out how to dig out exact
512
sd->passwd_state = OFONO_SIM_PASSWORD_PHSIM_PIN;
515
sd->passwd_state = OFONO_SIM_PASSWORD_NONE;
517
case APPSTATE_UNKNOWN:
518
case APPSTATE_DETECTED:
520
sd->passwd_state = OFONO_SIM_PASSWORD_INVALID;
471
525
static void sim_status_cb(struct ril_msg *message, gpointer user_data)
473
527
struct ofono_sim *sim = user_data;
474
528
struct sim_data *sd = ofono_sim_get_data(sim);
477
if (ril_util_parse_sim_status(sd->ril, message, &app)) {
479
sd->app_id = app.app_id;
481
if (app.app_type != RIL_APPTYPE_UNKNOWN)
482
sd->app_type = app.app_type;
484
ofono_sim_register(sim);
529
struct sim_app *apps[MAX_UICC_APPS];
530
struct sim_status status;
532
guint search_index = -1;
534
if (ril_util_parse_sim_status(sd->ril, message, &status, apps) &&
537
DBG("num_apps: %d gsm_umts_index: %d", status.num_apps,
538
status.gsm_umts_index);
540
/* TODO(CDMA): need some kind of logic to
541
* set the correct app_index,
543
search_index = status.gsm_umts_index;
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);
553
if (sd->sim_registered == FALSE) {
554
ofono_sim_register(sim);
555
sd->sim_registered = TRUE;
557
/* TODO: There doesn't seem to be any other
558
* way to force the core SIM code to
560
* Wouldn't __ofono_sim_refresh be
561
* more appropriate call here??
562
* __ofono_sim_refresh(sim, NULL, TRUE, TRUE);
564
__ofono_sim_recheck_pin(sim);
566
ril_util_free_sim_apps(apps, status.num_apps);
487
569
/* TODO: if no SIM present, handle emergency calling. */
490
573
static int send_get_sim_status(struct ofono_sim *sim)
492
575
struct sim_data *sd = ofono_sim_get_data(sim);
587
static void ril_sim_status_changed(struct ril_msg *message, gpointer user_data)
589
struct ofono_sim *sim = (struct ofono_sim *) user_data;
590
struct sim_data *sd = ofono_sim_get_data(sim);
594
g_ril_print_unsol_no_args(sd->ril, message);
596
send_get_sim_status(sim);
599
static void ril_query_passwd_state(struct ofono_sim *sim,
600
ofono_sim_passwd_cb_t cb, void *data)
602
struct sim_data *sd = ofono_sim_get_data(sim);
603
DBG("passwd_state %u", sd->passwd_state);
605
if (sd->passwd_state == OFONO_SIM_PASSWORD_INVALID)
606
CALLBACK_WITH_FAILURE(cb, -1, data);
608
CALLBACK_WITH_SUCCESS(cb, sd->passwd_state, data);
611
static void ril_pin_change_state_cb(struct ril_msg *message, gpointer user_data)
613
struct cb_data *cbd = user_data;
614
ofono_sim_lock_unlock_cb_t cb = cbd->cb;
615
struct sim_data *sd = cbd->user;
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.
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);
628
CALLBACK_WITH_FAILURE(cb, cbd->data);
632
static void ril_pin_send(struct ofono_sim *sim, const char *passwd,
633
ofono_sim_lock_unlock_cb_t cb, void *data)
635
struct sim_data *sd = ofono_sim_get_data(sim);
636
struct cb_data *cbd = cb_data_new(cb, data);
638
int request = RIL_REQUEST_ENTER_SIM_PIN;
645
parcel_w_int32(&rilp, ENTER_SIM_PIN_PARAMS);
646
parcel_w_string(&rilp, (char *) passwd);
647
parcel_w_string(&rilp, sd->aid_str);
649
ret = g_ril_send(sd->ril, request,
650
rilp.data, rilp.size, ril_pin_change_state_cb,
653
g_ril_append_print_buf(sd->ril, "(%s,aid=%s)", passwd, sd->aid_str);
654
g_ril_print_request(sd->ril, ret, request);
660
CALLBACK_WITH_FAILURE(cb, data);
664
static 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)
669
struct sim_data *sd = ofono_sim_get_data(sim);
670
struct cb_data *cbd = cb_data_new(cb, data);
672
int request = RIL_REQUEST_SET_FACILITY_LOCK;
678
parcel_w_int32(&rilp, SET_FACILITY_LOCK_PARAMS);
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
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");
690
case OFONO_SIM_PASSWORD_PHSIM_PIN:
691
g_ril_append_print_buf(sd->ril, "(PS,");
692
parcel_w_string(&rilp, "PS");
694
case OFONO_SIM_PASSWORD_PHFSIM_PIN:
695
g_ril_append_print_buf(sd->ril, "(PF,");
696
parcel_w_string(&rilp, "PF");
698
case OFONO_SIM_PASSWORD_SIM_PIN2:
699
g_ril_append_print_buf(sd->ril, "(P2,");
700
parcel_w_string(&rilp, "P2");
702
case OFONO_SIM_PASSWORD_PHNET_PIN:
703
g_ril_append_print_buf(sd->ril, "(PN,");
704
parcel_w_string(&rilp, "PN");
706
case OFONO_SIM_PASSWORD_PHNETSUB_PIN:
707
g_ril_append_print_buf(sd->ril, "(PU,");
708
parcel_w_string(&rilp, "PU");
710
case OFONO_SIM_PASSWORD_PHSP_PIN:
711
g_ril_append_print_buf(sd->ril, "(PP,");
712
parcel_w_string(&rilp, "PP");
714
case OFONO_SIM_PASSWORD_PHCORP_PIN:
715
g_ril_append_print_buf(sd->ril, "(PC,");
716
parcel_w_string(&rilp, "PC");
719
CALLBACK_WITH_FAILURE(cb, data);
724
parcel_w_string(&rilp, RIL_FACILITY_LOCK);
726
parcel_w_string(&rilp, RIL_FACILITY_UNLOCK);
728
parcel_w_string(&rilp, (char *) passwd);
730
/* TODO: make this a constant... */
731
parcel_w_string(&rilp, "0"); /* class */
733
parcel_w_string(&rilp, sd->aid_str);
735
ret = g_ril_send(sd->ril, request,
736
rilp.data, rilp.size, ril_pin_change_state_cb,
739
g_ril_append_print_buf(sd->ril, "%s,%d,%s,0,aid=%s)",
745
g_ril_print_request(sd->ril, ret, request);
751
CALLBACK_WITH_FAILURE(cb, data);
755
static 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)
759
struct sim_data *sd = ofono_sim_get_data(sim);
760
struct cb_data *cbd = cb_data_new(cb, data);
762
int request = RIL_REQUEST_ENTER_SIM_PUK;
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);
774
ret = g_ril_send(sd->ril, request,
775
rilp.data, rilp.size, ril_pin_change_state_cb,
778
g_ril_append_print_buf(sd->ril, "(puk=%s,pin=%s,aid=%s)",
782
g_ril_print_request(sd->ril, ret, request);
788
CALLBACK_WITH_FAILURE(cb, data);
792
static 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)
797
struct sim_data *sd = ofono_sim_get_data(sim);
798
struct cb_data *cbd = cb_data_new(cb, data);
800
int request = RIL_REQUEST_CHANGE_SIM_PIN;
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);
812
if (passwd_type == OFONO_SIM_PASSWORD_SIM_PIN2)
813
request = RIL_REQUEST_CHANGE_SIM_PIN2;
815
ret = g_ril_send(sd->ril, request, rilp.data, rilp.size,
816
ril_pin_change_state_cb, cbd, g_free);
818
g_ril_append_print_buf(sd->ril, "(old=%s,new=%s,aid=%s)",
822
g_ril_print_request(sd->ril, ret, request);
828
CALLBACK_WITH_FAILURE(cb, data);
504
832
static gboolean ril_sim_register(gpointer user)
506
834
struct ofono_sim *sim = user;
510
send_get_sim_status(sim);
835
struct sim_data *sd = ofono_sim_get_data(sim);
839
send_get_sim_status(sim);
841
g_ril_register(sd->ril, RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED,
842
(GRilNotifyFunc) ril_sim_status_changed, sim);
844
/* TODO: should we also register for RIL_UNSOL_SIM_REFRESH? */