~ubuntu-branches/ubuntu/wily/ofono/wily-proposed

« back to all changes in this revision

Viewing changes to drivers/rilmodem/sim.c

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Alfonso Sanchez-Beato
  • Date: 2014-10-10 08:53:32 UTC
  • mfrom: (1.3.27)
  • Revision ID: package-import@ubuntu.com-20141010085332-upn6sggriej0rknk
Tags: 1.12.bzr6880+14.10.20141010-0ubuntu1
[ Alfonso Sanchez-Beato ]
* drivers/rilmodem/sim.c: enter PIN before unlocking (LP: #1375945)
  Some modems require the PIN to be unlocked with a separate
  command before the PIN lock can be disabled.

* src/sim.c: fix sim atom teardown crash (LP: #1374418)

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
 *
73
73
 * The same applies to the app_type.
74
74
 */
 
75
 
 
76
static void ril_pin_change_state(struct ofono_sim *sim,
 
77
                                enum ofono_sim_password_type passwd_type,
 
78
                                int enable, const char *passwd,
 
79
                                ofono_sim_lock_unlock_cb_t cb, void *data);
 
80
 
75
81
struct sim_data {
76
82
        GRil *ril;
77
83
        enum ofono_ril_vendor vendor;
85
91
        enum ofono_sim_password_type passwd_state;
86
92
        struct ofono_modem *modem;
87
93
        ofono_sim_state_event_cb_t ril_state_watch;
 
94
        ofono_bool_t unlock_pending;
 
95
};
 
96
 
 
97
struct change_state_cbd {
 
98
        struct ofono_sim *sim;
 
99
        enum ofono_sim_password_type passwd_type;
 
100
        int enable;
 
101
        const char *passwd;
 
102
        ofono_sim_lock_unlock_cb_t cb;
 
103
        void *data;
88
104
};
89
105
 
90
106
static void ril_file_info_cb(struct ril_msg *message, gpointer user_data)
789
805
{
790
806
        struct cb_data *cbd = user_data;
791
807
        ofono_sim_lock_unlock_cb_t cb = cbd->cb;
792
 
        struct ofono_sim *sim = cbd->data;
793
 
        struct sim_data *sd = cbd->user;
 
808
        struct ofono_sim *sim = cbd->user;
 
809
        struct sim_data *sd = ofono_sim_get_data(sim);
794
810
        int *retries;
795
811
        /*
796
812
         * There is no reason to ask SIM status until
824
840
static void ril_pin_send(struct ofono_sim *sim, const char *passwd,
825
841
                                ofono_sim_lock_unlock_cb_t cb, void *data)
826
842
{
 
843
        /*
 
844
         * TODO: This function is supposed to enter the pending password, which
 
845
         * might be also PIN2. So we must check the pending PIN in the future.
 
846
         */
 
847
 
827
848
        struct sim_data *sd = ofono_sim_get_data(sim);
828
 
        struct cb_data *cbd = cb_data_new(cb, data, sd);
 
849
        struct cb_data *cbd = cb_data_new(cb, data, sim);
829
850
        struct parcel rilp;
830
851
 
831
852
        sd->passwd_type = OFONO_SIM_PASSWORD_SIM_PIN;
842
863
        }
843
864
}
844
865
 
 
866
static void enter_pin_done(const struct ofono_error *error, void *data)
 
867
{
 
868
        struct change_state_cbd *csd = data;
 
869
        struct sim_data *sd = ofono_sim_get_data(csd->sim);
 
870
 
 
871
        if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
 
872
                ofono_error("%s: wrong password", __func__);
 
873
                sd->unlock_pending = FALSE;
 
874
                CALLBACK_WITH_FAILURE(csd->cb, csd->data);
 
875
        } else {
 
876
                ril_pin_change_state(csd->sim, csd->passwd_type, csd->enable,
 
877
                                        csd->passwd, csd->cb, csd->data);
 
878
        }
 
879
 
 
880
        g_free(csd);
 
881
}
 
882
 
845
883
static void ril_pin_change_state(struct ofono_sim *sim,
846
 
                                        enum ofono_sim_password_type passwd_type,
847
 
                                        int enable, const char *passwd,
848
 
                                        ofono_sim_lock_unlock_cb_t cb, void *data)
 
884
                                enum ofono_sim_password_type passwd_type,
 
885
                                int enable, const char *passwd,
 
886
                                ofono_sim_lock_unlock_cb_t cb, void *data)
849
887
{
850
888
        struct sim_data *sd = ofono_sim_get_data(sim);
851
 
        struct cb_data *cbd = cb_data_new(cb, data, sd);
 
889
        struct cb_data *cbd;
852
890
        struct parcel rilp;
853
891
        struct req_pin_change_state req;
854
892
        int ret = 0;
855
893
 
 
894
        /*
 
895
         * If we want to unlock a password that has not been entered yet,
 
896
         * we enter it before trying to unlock. We need sd->unlock_pending as
 
897
         * the password still has not yet been refreshed when this function is
 
898
         * called from enter_pin_done().
 
899
         */
 
900
        if (ofono_sim_get_password_type(sim) == passwd_type
 
901
                        && enable == FALSE && sd->unlock_pending == FALSE) {
 
902
                struct change_state_cbd *csd = g_malloc0(sizeof(*csd));
 
903
                csd->sim = sim;
 
904
                csd->passwd_type = passwd_type;
 
905
                csd->enable = enable;
 
906
                csd->passwd = passwd;
 
907
                csd->cb = cb;
 
908
                csd->data = data;
 
909
                sd->unlock_pending = TRUE;
 
910
 
 
911
                ril_pin_send(sim, passwd, enter_pin_done, csd);
 
912
 
 
913
                return;
 
914
        }
 
915
 
 
916
        sd->unlock_pending = FALSE;
 
917
 
 
918
        cbd = cb_data_new(cb, data, sim);
 
919
 
856
920
        sd->passwd_type = passwd_type;
857
921
 
858
922
        req.aid_str = sd->aid_str;
882
946
                                ofono_sim_lock_unlock_cb_t cb, void *data)
883
947
{
884
948
        struct sim_data *sd = ofono_sim_get_data(sim);
885
 
        struct cb_data *cbd = cb_data_new(cb, data, sd);
 
949
        struct cb_data *cbd = cb_data_new(cb, data, sim);
886
950
        struct parcel rilp;
887
951
 
888
952
        sd->passwd_type = OFONO_SIM_PASSWORD_SIM_PUK;
906
970
                                ofono_sim_lock_unlock_cb_t cb, void *data)
907
971
{
908
972
        struct sim_data *sd = ofono_sim_get_data(sim);
909
 
        struct cb_data *cbd = cb_data_new(cb, data, sd);
 
973
        struct cb_data *cbd = cb_data_new(cb, data, sim);
910
974
        struct parcel rilp;
911
975
        int request = RIL_REQUEST_CHANGE_SIM_PIN;
912
976