~indicator-network-developers/ofono/trunk.packaging

« back to all changes in this revision

Viewing changes to drivers/atmodem/sim.c

  • Committer: Kalle Valo
  • Date: 2011-02-21 07:46:07 UTC
  • mfrom: (2738.1.2125)
  • Revision ID: kalle.valo@canonical.com-20110221074607-u4rocuj2p75kpht9
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
static const char *clck_prefix[] = { "+CLCK:", NULL };
58
58
static const char *huawei_cpin_prefix[] = { "^CPIN:", NULL };
59
59
static const char *xpincnt_prefix[] = { "+XPINCNT:", NULL };
 
60
static const char *cpinr_prefixes[] = { "+CPINR:", "+CPINRE:", NULL };
 
61
static const char *epin_prefix[] = { "*EPIN:", NULL };
60
62
static const char *none_prefix[] = { NULL };
61
63
 
62
64
static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
142
144
        }
143
145
 
144
146
        cbd = cb_data_new(cb, data);
145
 
        if (cbd == NULL)
146
 
                goto error;
147
147
 
148
148
        snprintf(buf, sizeof(buf), "AT+CRSM=192,%i", fileid);
149
149
 
150
150
        switch (sd->vendor) {
151
151
        case OFONO_VENDOR_HUAWEI:
 
152
        case OFONO_VENDOR_SIERRA:
152
153
        case OFONO_VENDOR_QUALCOMM_MSM:
153
154
                strcat(buf, ",0,0,255"); /* Maximum possible length */
154
155
                break;
158
159
                                at_crsm_info_cb, cbd, g_free) > 0)
159
160
                return;
160
161
 
161
 
error:
 
162
        g_free(cbd);
 
163
 
162
164
        CALLBACK_WITH_FAILURE(cb, -1, -1, -1, NULL,
163
165
                                EF_STATUS_INVALIDATED, data);
164
166
}
219
221
        struct cb_data *cbd = cb_data_new(cb, data);
220
222
        char buf[64];
221
223
 
222
 
        if (cbd == NULL)
223
 
                goto error;
224
 
 
225
224
        snprintf(buf, sizeof(buf), "AT+CRSM=176,%i,%i,%i,%i", fileid,
226
225
                        start >> 8, start & 0xff, length);
227
226
 
229
228
                                at_crsm_read_cb, cbd, g_free) > 0)
230
229
                return;
231
230
 
232
 
error:
233
231
        g_free(cbd);
234
232
 
235
233
        CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
243
241
        struct cb_data *cbd = cb_data_new(cb, data);
244
242
        char buf[64];
245
243
 
246
 
        if (cbd == NULL)
247
 
                goto error;
248
 
 
249
244
        snprintf(buf, sizeof(buf), "AT+CRSM=178,%i,%i,4,%i", fileid,
250
245
                        record, length);
251
246
 
253
248
                                at_crsm_read_cb, cbd, g_free) > 0)
254
249
                return;
255
250
 
256
 
error:
257
251
        g_free(cbd);
258
252
 
259
253
        CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
308
302
        char *buf = g_try_new(char, 36 + length * 2);
309
303
        int len, ret;
310
304
 
311
 
        if (cbd == NULL || buf == NULL)
 
305
        if (buf == NULL)
312
306
                goto error;
313
307
 
314
308
        len = sprintf(buf, "AT+CRSM=214,%i,%i,%i,%i,", fileid,
341
335
        char *buf = g_try_new(char, 36 + length * 2);
342
336
        int len, ret;
343
337
 
344
 
        if (cbd == NULL || buf == NULL)
 
338
        if (buf == NULL)
345
339
                goto error;
346
340
 
347
341
        len = sprintf(buf, "AT+CRSM=220,%i,%i,4,%i,", fileid,
373
367
        char *buf = g_try_new(char, 36 + length * 2);
374
368
        int len, ret;
375
369
 
376
 
        if (cbd == NULL || buf == NULL)
 
370
        if (buf == NULL)
377
371
                goto error;
378
372
 
379
373
        len = sprintf(buf, "AT+CRSM=220,%i,0,3,%i,", fileid, length);
429
423
        struct sim_data *sd = ofono_sim_get_data(sim);
430
424
        struct cb_data *cbd = cb_data_new(cb, data);
431
425
 
432
 
        if (cbd == NULL)
433
 
                goto error;
434
 
 
435
426
        if (g_at_chat_send(sd->chat, "AT+CIMI", NULL,
436
427
                                at_cimi_cb, cbd, g_free) > 0)
437
428
                return;
438
429
 
439
 
error:
440
430
        g_free(cbd);
441
431
 
442
432
        CALLBACK_WITH_FAILURE(cb, NULL, data);
566
556
        CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
567
557
}
568
558
 
 
559
static void at_epin_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
560
{
 
561
        struct cb_data *cbd = user_data;
 
562
        ofono_sim_pin_retries_cb_t cb = cbd->cb;
 
563
        const char *final = g_at_result_final_response(result);
 
564
        GAtResultIter iter;
 
565
        struct ofono_error error;
 
566
        int retries[OFONO_SIM_PASSWORD_INVALID];
 
567
        size_t i;
 
568
        static enum ofono_sim_password_type password_types[] = {
 
569
                OFONO_SIM_PASSWORD_SIM_PIN,
 
570
                OFONO_SIM_PASSWORD_SIM_PUK,
 
571
                OFONO_SIM_PASSWORD_SIM_PIN2,
 
572
                OFONO_SIM_PASSWORD_SIM_PUK2,
 
573
        };
 
574
 
 
575
        decode_at_error(&error, final);
 
576
 
 
577
        if (!ok) {
 
578
                cb(&error, NULL, cbd->data);
 
579
                return;
 
580
        }
 
581
 
 
582
        g_at_result_iter_init(&iter, result);
 
583
 
 
584
        if (!g_at_result_iter_next(&iter, "*EPIN:"))
 
585
                goto error;
 
586
 
 
587
        BUILD_PIN_RETRIES_ARRAY(password_types, ARRAY_SIZE(password_types),
 
588
                                retries);
 
589
 
 
590
        cb(&error, retries, cbd->data);
 
591
 
 
592
        return;
 
593
 
 
594
error:
 
595
        CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
 
596
}
 
597
 
 
598
static void at_cpinr_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
599
{
 
600
        struct cb_data *cbd = user_data;
 
601
        ofono_sim_pin_retries_cb_t cb = cbd->cb;
 
602
        GAtResultIter iter;
 
603
        struct ofono_error error;
 
604
        int retries[OFONO_SIM_PASSWORD_INVALID];
 
605
        size_t len = sizeof(at_sim_name) / sizeof(*at_sim_name);
 
606
        size_t i;
 
607
 
 
608
        decode_at_error(&error, g_at_result_final_response(result));
 
609
 
 
610
        if (!ok) {
 
611
                cb(&error, NULL, cbd->data);
 
612
                return;
 
613
        }
 
614
 
 
615
        for (i = 0; i < OFONO_SIM_PASSWORD_INVALID; i++)
 
616
                retries[i] = -1;
 
617
 
 
618
        g_at_result_iter_init(&iter, result);
 
619
 
 
620
        /* Ignore +CPINRE results... */
 
621
        while (g_at_result_iter_next(&iter, "+CPINR:")) {
 
622
                const char *name;
 
623
                int val;
 
624
 
 
625
                if (!g_at_result_iter_next_unquoted_string(&iter, &name))
 
626
                        continue;
 
627
 
 
628
                if (!g_at_result_iter_next_number(&iter, &val))
 
629
                        continue;
 
630
 
 
631
                for (i = 1; i < len; i++) {
 
632
                        if (!strcmp(name, at_sim_name[i].name)) {
 
633
                                retries[i] = val;
 
634
                                break;
 
635
                        }
 
636
                }
 
637
        }
 
638
 
 
639
        cb(&error, retries, cbd->data);
 
640
}
 
641
 
569
642
static void at_pin_retries_query(struct ofono_sim *sim,
570
643
                                        ofono_sim_pin_retries_cb_t cb,
571
644
                                        void *data)
575
648
 
576
649
        DBG("");
577
650
 
578
 
        if (cbd == NULL)
579
 
                goto error;
580
 
 
581
651
        switch (sd->vendor) {
582
652
        case OFONO_VENDOR_IFX:
583
653
                if (g_at_chat_send(sd->chat, "AT+XPINCNT", xpincnt_prefix,
591
661
                        return;
592
662
 
593
663
                break;
 
664
        case OFONO_VENDOR_MBM:
 
665
                if (g_at_chat_send(sd->chat, "AT*EPIN?", epin_prefix,
 
666
                                        at_epin_cb, cbd, g_free) > 0)
 
667
                        return;
 
668
 
 
669
                break;
594
670
        default:
 
671
                if (g_at_chat_send(sd->chat, "AT+CPINR", cpinr_prefixes,
 
672
                                        at_cpinr_cb, cbd, g_free) > 0)
 
673
                        return;
595
674
                break;
596
675
        }
597
676
 
598
 
error:
599
677
        g_free(cbd);
600
678
 
601
679
        CALLBACK_WITH_FAILURE(cb, NULL, data);
662
740
        struct sim_data *sd = ofono_sim_get_data(sim);
663
741
        struct cb_data *cbd = cb_data_new(cb, data);
664
742
 
665
 
        if (cbd == NULL)
666
 
                goto error;
667
 
 
668
743
        cbd->user = sim;
669
744
 
670
745
        if (g_at_chat_send(sd->chat, "AT+CPIN?", cpin_prefix,
671
746
                                at_cpin_cb, cbd, g_free) > 0)
672
747
                return;
673
748
 
674
 
error:
675
749
        g_free(cbd);
676
750
 
677
751
        CALLBACK_WITH_FAILURE(cb, -1, data);
771
845
        char buf[64];
772
846
        int ret;
773
847
 
774
 
        if (cbd == NULL)
775
 
                goto error;
776
 
 
777
848
        cbd->user = sd;
778
849
 
779
850
        snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\"", passwd);
786
857
        if (ret > 0)
787
858
                return;
788
859
 
789
 
error:
790
860
        g_free(cbd);
791
861
 
792
862
        CALLBACK_WITH_FAILURE(cb, data);
801
871
        char buf[64];
802
872
        int ret;
803
873
 
804
 
        if (cbd == NULL)
805
 
                goto error;
806
 
 
807
874
        cbd->user = sd;
808
875
 
809
876
        snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\",\"%s\"", puk, passwd);
816
883
        if (ret > 0)
817
884
                return;
818
885
 
819
 
error:
820
886
        g_free(cbd);
821
887
 
822
888
        CALLBACK_WITH_FAILURE(cb, data);
856
922
        int ret;
857
923
        unsigned int len = sizeof(at_clck_cpwd_fac) / sizeof(*at_clck_cpwd_fac);
858
924
 
859
 
        if (cbd == NULL)
860
 
                goto error;
861
 
 
862
925
        if (passwd_type >= len || at_clck_cpwd_fac[passwd_type] == NULL)
863
926
                goto error;
864
927
 
881
944
 
882
945
static void at_change_passwd(struct ofono_sim *sim,
883
946
                        enum ofono_sim_password_type passwd_type,
884
 
                        const char *old, const char *new,
 
947
                        const char *old_passwd, const char *new_passwd,
885
948
                        ofono_sim_lock_unlock_cb_t cb, void *data)
886
949
{
887
950
        struct sim_data *sd = ofono_sim_get_data(sim);
890
953
        int ret;
891
954
        unsigned int len = sizeof(at_clck_cpwd_fac) / sizeof(*at_clck_cpwd_fac);
892
955
 
893
 
        if (cbd == NULL)
894
 
                goto error;
895
 
 
896
956
        if (passwd_type >= len ||
897
957
                        at_clck_cpwd_fac[passwd_type] == NULL)
898
958
                goto error;
899
959
 
900
960
        snprintf(buf, sizeof(buf), "AT+CPWD=\"%s\",\"%s\",\"%s\"",
901
 
                        at_clck_cpwd_fac[passwd_type], old, new);
 
961
                        at_clck_cpwd_fac[passwd_type], old_passwd, new_passwd);
902
962
 
903
963
        ret = g_at_chat_send(sd->chat, buf, none_prefix,
904
964
                                at_lock_unlock_cb, cbd, g_free);
953
1013
        char buf[64];
954
1014
        unsigned int len = sizeof(at_clck_cpwd_fac) / sizeof(*at_clck_cpwd_fac);
955
1015
 
956
 
        if (cbd == NULL)
957
 
                goto error;
958
 
 
959
1016
        if (passwd_type >= len || at_clck_cpwd_fac[passwd_type] == NULL)
960
1017
                goto error;
961
1018