Lines Matching refs:scard
252 static int _scard_select_file(struct scard_data *scard, unsigned short file_id,
256 static int scard_select_file(struct scard_data *scard, unsigned short file_id,
258 static int scard_verify_pin(struct scard_data *scard, const char *pin);
259 static int scard_get_record_len(struct scard_data *scard,
261 static int scard_read_record(struct scard_data *scard,
376 static int scard_pin_needed(struct scard_data *scard, in scard_pin_needed() argument
379 if (scard->sim_type == SCARD_GSM_SIM) { in scard_pin_needed()
386 if (scard->sim_type == SCARD_USIM) { in scard_pin_needed()
401 static int scard_get_aid(struct scard_data *scard, unsigned char *aid, in scard_get_aid() argument
420 if (scard_select_file(scard, SCARD_FILE_EF_DIR, buf, &blen)) { in scard_get_aid()
427 rlen = scard_get_record_len(scard, rec, in scard_get_aid()
439 if (scard_read_record(scard, buf, rlen, rec, in scard_get_aid()
521 struct scard_data *scard; in scard_init() local
535 scard = os_zalloc(sizeof(*scard)); in scard_init()
536 if (scard == NULL) in scard_init()
540 &scard->ctx); in scard_init()
547 ret = SCardListReaders(scard->ctx, NULL, NULL, &len); in scard_init()
563 ret = SCardListReaders(scard->ctx, NULL, readers, &len); in scard_init()
606 ret = SCardConnect(scard->ctx, &readers[pos], SCARD_SHARE_SHARED, in scard_init()
608 &scard->card, &scard->protocol); in scard_init()
621 (unsigned int) scard->card, (unsigned long) scard->protocol, in scard_init()
622 scard->protocol == SCARD_PROTOCOL_T0 ? "T0" : "T1"); in scard_init()
624 ret = SCardBeginTransaction(scard->card); in scard_init()
635 if (_scard_select_file(scard, SCARD_FILE_MF, buf, &blen, in scard_init()
638 scard->sim_type = SCARD_GSM_SIM; in scard_init()
641 scard->sim_type = SCARD_USIM; in scard_init()
644 if (scard->sim_type == SCARD_GSM_SIM) { in scard_init()
646 if (scard_select_file(scard, SCARD_FILE_MF, buf, &blen)) { in scard_init()
652 if (scard_select_file(scard, SCARD_FILE_GSM_DF, buf, &blen)) { in scard_init()
660 aid_len = scard_get_aid(scard, aid, sizeof(aid)); in scard_init()
672 if (_scard_select_file(scard, 0, buf, &blen, scard->sim_type, in scard_init()
683 pin_needed = scard_pin_needed(scard, buf, blen); in scard_init()
690 scard->pin1_required = 1; in scard_init()
692 "counter=%d)", scard_get_pin_retry_counter(scard)); in scard_init()
695 ret = SCardEndTransaction(scard->card, SCARD_LEAVE_CARD); in scard_init()
701 return scard; in scard_init()
705 SCardEndTransaction(scard->card, SCARD_LEAVE_CARD); in scard_init()
707 scard_deinit(scard); in scard_init()
718 int scard_set_pin(struct scard_data *scard, const char *pin) in scard_set_pin() argument
720 if (scard == NULL) in scard_set_pin()
724 if (scard->pin1_required) { in scard_set_pin()
730 if (scard_verify_pin(scard, pin)) { in scard_set_pin()
747 void scard_deinit(struct scard_data *scard) in scard_deinit() argument
751 if (scard == NULL) in scard_deinit()
755 if (scard->card) { in scard_deinit()
756 ret = SCardDisconnect(scard->card, SCARD_UNPOWER_CARD); in scard_deinit()
763 if (scard->ctx) { in scard_deinit()
764 ret = SCardReleaseContext(scard->ctx); in scard_deinit()
770 os_free(scard); in scard_deinit()
775 static long scard_transmit(struct scard_data *scard, in scard_transmit() argument
789 ret = SCardTransmit(scard->card, in scard_transmit()
790 scard->protocol == SCARD_PROTOCOL_T1 ? in scard_transmit()
806 static int _scard_select_file(struct scard_data *scard, unsigned short file_id, in _scard_select_file() argument
840 ret = scard_transmit(scard, cmd, cmdlen, resp, &len); in _scard_select_file()
876 ret = scard_transmit(scard, get_resp, sizeof(get_resp), buf, &rlen); in _scard_select_file()
887 static int scard_select_file(struct scard_data *scard, unsigned short file_id, in scard_select_file() argument
890 return _scard_select_file(scard, file_id, buf, buf_len, in scard_select_file()
891 scard->sim_type, NULL, 0); in scard_select_file()
895 static int scard_get_record_len(struct scard_data *scard, unsigned char recnum, in scard_get_record_len() argument
903 if (scard->sim_type == SCARD_USIM) in scard_get_record_len()
910 ret = scard_transmit(scard, cmd, sizeof(cmd), buf, &blen); in scard_get_record_len()
930 static int scard_read_record(struct scard_data *scard, in scard_read_record() argument
939 if (scard->sim_type == SCARD_USIM) in scard_read_record()
949 ret = scard_transmit(scard, cmd, sizeof(cmd), buf, &blen); in scard_read_record()
977 static int scard_read_file(struct scard_data *scard, in scard_read_file() argument
991 if (scard->sim_type == SCARD_USIM) in scard_read_file()
993 ret = scard_transmit(scard, cmd, sizeof(cmd), buf, &blen); in scard_read_file()
1021 static int scard_verify_pin(struct scard_data *scard, const char *pin) in scard_verify_pin() argument
1033 if (scard->sim_type == SCARD_USIM) in scard_verify_pin()
1039 ret = scard_transmit(scard, cmd, sizeof(cmd), resp, &len); in scard_verify_pin()
1053 int scard_get_pin_retry_counter(struct scard_data *scard) in scard_get_pin_retry_counter() argument
1063 if (scard->sim_type == SCARD_USIM) in scard_get_pin_retry_counter()
1068 ret = scard_transmit(scard, cmd, sizeof(cmd), resp, &len); in scard_get_pin_retry_counter()
1107 int scard_get_imsi(struct scard_data *scard, char *imsi, size_t *len) in scard_get_imsi() argument
1115 if (scard_select_file(scard, SCARD_FILE_GSM_EF_IMSI, buf, &blen)) in scard_get_imsi()
1123 if (scard->sim_type == SCARD_GSM_SIM) { in scard_get_imsi()
1145 if (scard_read_file(scard, buf, blen)) in scard_get_imsi()
1181 int scard_get_mnc_len(struct scard_data *scard) in scard_get_mnc_len() argument
1189 if (scard_select_file(scard, SCARD_FILE_GSM_EF_AD, buf, &blen)) in scard_get_mnc_len()
1197 if (scard->sim_type == SCARD_GSM_SIM) { in scard_get_mnc_len()
1213 if (scard_read_file(scard, buf, file_size)) in scard_get_mnc_len()
1241 int scard_gsm_auth(struct scard_data *scard, const unsigned char *_rand, in scard_gsm_auth() argument
1251 if (scard == NULL) in scard_gsm_auth()
1255 if (scard->sim_type == SCARD_GSM_SIM) { in scard_gsm_auth()
1268 ret = scard_transmit(scard, cmd, cmdlen, resp, &len); in scard_gsm_auth()
1272 if ((scard->sim_type == SCARD_GSM_SIM && in scard_gsm_auth()
1274 (scard->sim_type == SCARD_USIM && in scard_gsm_auth()
1284 ret = scard_transmit(scard, get_resp, sizeof(get_resp), buf, &len); in scard_gsm_auth()
1288 if (scard->sim_type == SCARD_GSM_SIM) { in scard_gsm_auth()
1340 int scard_umts_auth(struct scard_data *scard, const unsigned char *_rand, in scard_umts_auth() argument
1352 if (scard == NULL) in scard_umts_auth()
1355 if (scard->sim_type == SCARD_GSM_SIM) { in scard_umts_auth()
1369 ret = scard_transmit(scard, cmd, sizeof(cmd), resp, &len); in scard_umts_auth()
1389 ret = scard_transmit(scard, get_resp, sizeof(get_resp), buf, &len); in scard_umts_auth()
1448 int scard_supports_umts(struct scard_data *scard) in scard_supports_umts() argument
1450 return scard->sim_type == SCARD_USIM; in scard_supports_umts()